* clean up CLightEnv a bit

* add CLightEnv::m_TerrainShadowTransparency
* shadows will let a fraction of diffuse light through
* added JS LightEnv objects, so the lighting environment can be changed
  from the console
* new element TerrainShadowTransparency supported in the scenario .xml
format,
  changed cantabrian_generated with an example

This was SVN commit r3513.
This commit is contained in:
prefect
2006-02-15 00:45:16 +00:00
parent 1560a17dfb
commit 36fa5ec2bf
18 changed files with 649 additions and 191 deletions
+29 -29
View File
@@ -36,13 +36,13 @@ struct FFModelDef : public CModelDefRPrivate
{
/// Indices are the same for all models, so share them
u16* m_Indices;
/// Static per-CModelDef vertex array
VertexArray m_Array;
/// UV coordinates are stored in the static array
VertexArray::Attribute m_UV;
FFModelDef(CModelDefPtr mdef);
~FFModelDef() { delete[] m_Indices; }
};
@@ -52,21 +52,21 @@ FFModelDef::FFModelDef(CModelDefPtr mdef)
: m_Array(false)
{
size_t numVertices = mdef->GetNumVertices();
m_UV.type = GL_FLOAT;
m_UV.elems = 2;
m_Array.AddAttribute(&m_UV);
m_Array.SetNumVertices(numVertices);
m_Array.Layout();
VertexArrayIterator<float[2]> UVit = m_UV.GetIterator<float[2]>();
ModelRenderer::BuildUV(mdef, UVit);
m_Array.Upload();
m_Array.FreeBackingStore();
m_Indices = new u16[mdef->GetNumFaces()*3];
ModelRenderer::BuildIndices(mdef, m_Indices);
}
@@ -76,11 +76,11 @@ struct FFModel
{
/// Dynamic per-CModel vertex array
VertexArray m_Array;
/// Position and lighting are recalculated on CPU every frame
VertexArray::Attribute m_Position;
VertexArray::Attribute m_Color;
FFModel() : m_Array(true) { }
};
@@ -89,7 +89,7 @@ struct FixedFunctionModelRendererInternals
{
/// Transformed vertex normals - required for recalculating lighting on skinned models
std::vector<CVector3D> normals;
/// Previously prepared modeldef
FFModelDef* ffmodeldef;
};
@@ -130,7 +130,7 @@ void* FixedFunctionModelRenderer::CreateModelData(CModel* model)
ffmodel->m_Color.type = GL_UNSIGNED_BYTE;
ffmodel->m_Color.elems = 4;
ffmodel->m_Array.AddAttribute(&ffmodel->m_Color);
ffmodel->m_Array.SetNumVertices(mdef->GetNumVertices());
ffmodel->m_Array.Layout();
@@ -142,25 +142,25 @@ void* FixedFunctionModelRenderer::CreateModelData(CModel* model)
void FixedFunctionModelRenderer::UpdateModelData(CModel* model, void* data, u32 updateflags)
{
FFModel* ffmodel = (FFModel*)data;
if (updateflags & RENDERDATA_UPDATE_VERTICES)
if (updateflags & (RENDERDATA_UPDATE_VERTICES|RENDERDATA_UPDATE_COLOR))
{
CModelDefPtr mdef = model->GetModelDef();
size_t numVertices = mdef->GetNumVertices();
// build vertices
if (m->normals.size() < numVertices)
m->normals.resize(numVertices);
VertexArrayIterator<CVector3D> Position = ffmodel->m_Position.GetIterator<CVector3D>();
VertexArrayIterator<CVector3D> Normal = VertexArrayIterator<CVector3D>((char*)&m->normals[0], sizeof(CVector3D));
ModelRenderer::BuildPositionAndNormals(model, Position, Normal);
VertexArrayIterator<SColor4ub> Color = ffmodel->m_Color.GetIterator<SColor4ub>();
ModelRenderer::BuildColor4ub(model, Normal, Color);
// upload everything to vertex buffer
ffmodel->m_Array.Upload();
}
@@ -172,7 +172,7 @@ void FixedFunctionModelRenderer::UpdateModelData(CModel* model, void* data, u32
void FixedFunctionModelRenderer::DestroyModelData(CModel* UNUSED(model), void* data)
{
FFModel* ffmodel = (FFModel*)data;
delete ffmodel;
}
@@ -181,7 +181,7 @@ void FixedFunctionModelRenderer::DestroyModelData(CModel* UNUSED(model), void* d
void FixedFunctionModelRenderer::BeginPass(uint streamflags)
{
glEnableClientState(GL_VERTEX_ARRAY);
if (streamflags & STREAM_UV0) glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (streamflags & STREAM_COLOR) glEnableClientState(GL_COLOR_ARRAY);
}
@@ -192,7 +192,7 @@ void FixedFunctionModelRenderer::EndPass(uint streamflags)
{
if (streamflags & STREAM_UV0) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (streamflags & STREAM_COLOR) glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
@@ -201,14 +201,14 @@ void FixedFunctionModelRenderer::EndPass(uint streamflags)
void FixedFunctionModelRenderer::PrepareModelDef(uint streamflags, CModelDefPtr def)
{
m->ffmodeldef = (FFModelDef*)def->GetRenderData(m);
debug_assert(m->ffmodeldef);
if (streamflags & STREAM_UV0)
{
u8* base = m->ffmodeldef->m_Array.Bind();
GLsizei stride = (GLsizei)m->ffmodeldef->m_Array.GetStride();
glTexCoordPointer(2, GL_FLOAT, stride, base + m->ffmodeldef->m_UV.offset);
}
}
@@ -219,13 +219,13 @@ void FixedFunctionModelRenderer::RenderModel(uint streamflags, CModel* model, vo
{
CModelDefPtr mdldef = model->GetModelDef();
FFModel* ffmodel = (FFModel*)data;
u8* base = ffmodel->m_Array.Bind();
GLsizei stride = (GLsizei)ffmodel->m_Array.GetStride();
glVertexPointer(3, GL_FLOAT, stride, base + ffmodel->m_Position.offset);
if (streamflags & STREAM_COLOR)
glColorPointer(3, ffmodel->m_Color.type, stride, base + ffmodel->m_Color.offset);
glColorPointer(3, ffmodel->m_Color.type, stride, base + ffmodel->m_Color.offset);
// render the lot
size_t numFaces = mdldef->GetNumFaces();