diff --git a/source/renderer/ModelRData.cpp b/source/renderer/ModelRData.cpp index a094316f25..f3193bfd0c 100755 --- a/source/renderer/ModelRData.cpp +++ b/source/renderer/ModelRData.cpp @@ -77,12 +77,12 @@ void CModelRData::BuildIndices() } } -inline int clamp(int x,int min,int max) -{ - if (xmax) return max; - else return x; -} + + + + + + static SColor4ub ConvertColor(const RGBColor& src) { @@ -297,14 +297,17 @@ void CModelRData::SubmitBatches() ///////////////////////////////////////////////////////////////////////////////////////////////////// // RenderModels: render all submitted models; assumes necessary client states already enabled, // and texture environment already setup as required -void CModelRData::RenderModels(u32 streamflags) +void CModelRData::RenderModels(u32 streamflags,u32 flags) { uint i; #if 1 // submit batches for each model to the vertex buffer for (i=0;iGetRenderData(); - modeldata->SubmitBatches(); + u32 mflags=m_Models[i]->GetFlags(); + if (!flags || (m_Models[i]->GetFlags()&flags)) { + CModelRData* modeldata=(CModelRData*) m_Models[i]->GetRenderData(); + modeldata->SubmitBatches(); + } } // step through all accumulated batches @@ -342,8 +345,10 @@ void CModelRData::RenderModels(u32 streamflags) g_VBMan.ClearBatchIndices(); #else for (i=0;iGetRenderData(); - modeldata->RenderStreams(streamflags); + if (!flags || (m_Models[i]->GetFlags()&flags)) { + CModelRData* modeldata=(CModelRData*) m_Models[i]->GetRenderData(); + modeldata->RenderStreams(streamflags); + } } #endif } diff --git a/source/renderer/ModelRData.h b/source/renderer/ModelRData.h index 0a01357a16..baa4ca1e21 100755 --- a/source/renderer/ModelRData.h +++ b/source/renderer/ModelRData.h @@ -33,7 +33,7 @@ public: static void ClearSubmissions() { m_Models.clear(); } // render all submitted models - static void RenderModels(u32 streamflags); + static void RenderModels(u32 streamflags,u32 flags=0); private: // build this renderdata object diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index f1065d6b90..e1a56860b0 100755 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -25,12 +25,12 @@ const int BlendOffsets[8][2] = { { 1, -1 } }; -inline int clamp(int x,int min,int max) -{ - if (xmax) return max; - else return x; -} + + + + + + static SColor4ub ConvertColor(const RGBColor& src) { @@ -259,34 +259,37 @@ void CPatchRData::BuildBlends() if (m_VBBlends) { // release existing vertex buffer chunk g_VBMan.Release(m_VBBlends); + m_VBBlends=0; } - m_VBBlends=g_VBMan.Allocate(sizeof(SBlendVertex),m_BlendVertices.size(),false); - m_VBBlends->m_Owner->UpdateChunkVertices(m_VBBlends,&m_BlendVertices[0]); - - // now build outgoing splats - m_BlendSplats.resize(splatTextures.size()); - int splatCount=0; - - assert(m_VBBlends->m_Index < 65536); - unsigned short base = (unsigned short)m_VBBlends->m_Index; - std::set::iterator iter=splatTextures.begin(); - for (;iter!=splatTextures.end();++iter) { - Handle tex=*iter; - - SSplat& splat=m_BlendSplats[splatCount]; - splat.m_IndexStart=(u32)m_BlendIndices.size(); - splat.m_Texture=tex; - - for (uint k=0;k<(uint)splats.size();k++) { - if (splats[k].m_Texture==tex) { - m_BlendIndices.push_back(splats[k].m_Indices[0]+base); - m_BlendIndices.push_back(splats[k].m_Indices[1]+base); - m_BlendIndices.push_back(splats[k].m_Indices[2]+base); - m_BlendIndices.push_back(splats[k].m_Indices[3]+base); - splat.m_IndexCount+=4; + if (m_BlendVertices.size()) { + m_VBBlends=g_VBMan.Allocate(sizeof(SBlendVertex),m_BlendVertices.size(),false); + m_VBBlends->m_Owner->UpdateChunkVertices(m_VBBlends,&m_BlendVertices[0]); + + // now build outgoing splats + m_BlendSplats.resize(splatTextures.size()); + int splatCount=0; + + assert(m_VBBlends->m_Index < 65536); + unsigned short base = (unsigned short)m_VBBlends->m_Index; + std::set::iterator iter=splatTextures.begin(); + for (;iter!=splatTextures.end();++iter) { + Handle tex=*iter; + + SSplat& splat=m_BlendSplats[splatCount]; + splat.m_IndexStart=(u32)m_BlendIndices.size(); + splat.m_Texture=tex; + + for (uint k=0;k<(uint)splats.size();k++) { + if (splats[k].m_Texture==tex) { + m_BlendIndices.push_back(splats[k].m_Indices[0]+base); + m_BlendIndices.push_back(splats[k].m_Indices[1]+base); + m_BlendIndices.push_back(splats[k].m_Indices[2]+base); + m_BlendIndices.push_back(splats[k].m_Indices[3]+base); + splat.m_IndexCount+=4; + } } + splatCount++; } - splatCount++; } } @@ -300,6 +303,7 @@ void CPatchRData::BuildIndices() // release existing indices and bins m_Indices.clear(); + m_ShadowMapIndices.clear(); m_Splats.clear(); // build grid of textures on this patch and boundaries of adjacent patches @@ -446,8 +450,11 @@ void CPatchRData::RenderStreams(u32 streamflags) // setup data pointers glVertexPointer(3,GL_FLOAT,sizeof(SBaseVertex),base+offsetof(SBaseVertex,m_Position)); - if (streamflags & STREAM_UV0) glTexCoordPointer(2,GL_FLOAT,sizeof(SBaseVertex),base+offsetof(SBaseVertex,m_UVs)); - else if (streamflags & STREAM_POSTOUV0) glTexCoordPointer(3,GL_FLOAT,sizeof(SBaseVertex),base+offsetof(SBaseVertex,m_Position)); + if (streamflags & STREAM_UV0) { + glTexCoordPointer(2,GL_FLOAT,sizeof(SBaseVertex),base+offsetof(SBaseVertex,m_UVs)); + } else if (streamflags & STREAM_POSTOUV0) { + glTexCoordPointer(3,GL_FLOAT,sizeof(SBaseVertex),base+offsetof(SBaseVertex,m_Position)); + } // render all base splats at once glDrawElements(GL_QUADS,(GLsizei)m_Indices.size(),GL_UNSIGNED_SHORT,&m_Indices[0]); @@ -489,26 +496,52 @@ void CPatchRData::RenderBlends() } } +void CPatchRData::RenderOutlines() +{ + for (uint i=0;iGetRenderData(); + patchdata->RenderOutline(); + } +} + +void CPatchRData::RenderStreamsAll(u32 streamflags) +{ + for (uint i=0;iGetRenderData(); + patchdata->RenderStreams(streamflags); + } +} + void CPatchRData::RenderOutline() { - // TODO, RC - fixme, only works for PATCH_SIZE = 16 - const u16 EdgeIndices[PATCH_SIZE*4] = { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 33, 50, 67, 84, 101, 118, 135, 152, 169, 186, 203, 220, 237, 254, 271, 288, - 287, 286, 285, 284, 283, 282, 281, 280, 279, 278, 277, 276, 275, 274, 273, 272, - 255, 238, 221, 204, 187, 170, 153, 136, 119, 102, 85, 68, 51, 34, 17, 0 - }; - + uint i; + uint vsize=PATCH_SIZE+1; u8* base=m_VBBase->m_Owner->Bind(); - // setup data pointers - glVertexPointer(3,GL_FLOAT,sizeof(SBaseVertex),base+offsetof(SBaseVertex,m_Position)); - // render outline as line loop - u32 numIndices=sizeof(EdgeIndices)/sizeof(u16); - glDrawElements(GL_LINE_LOOP,numIndices,GL_UNSIGNED_SHORT,EdgeIndices); - - g_Renderer.m_Stats.m_DrawCalls++; - g_Renderer.m_Stats.m_TerrainTris+=numIndices/2; + glBegin(GL_LINES); + for (i=0;iGetRenderData(); patchdata->RenderBlends(); } @@ -747,9 +781,6 @@ void CPatchRData::ApplyShadowMap(GLuint shadowmaphandle) { uint i; -// glEnable(GL_ALPHA_TEST); -// glAlphaFunc(GL_GREATER,0.0f); - g_Renderer.BindTexture(0,shadowmaphandle); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); @@ -810,8 +841,6 @@ void CPatchRData::ApplyShadowMap(GLuint shadowmaphandle) } #endif - glDisable(GL_ALPHA_TEST); - glDisable(GL_BLEND); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); diff --git a/source/renderer/PatchRData.h b/source/renderer/PatchRData.h index ec5d91466a..5dbeaa7a96 100755 --- a/source/renderer/PatchRData.h +++ b/source/renderer/PatchRData.h @@ -34,6 +34,10 @@ public: static void RenderBaseSplats(); // render the blend pass of all patches static void RenderBlendSplats(); + // render the outlines of all patches + static void RenderOutlines(); + // render given streams of all patches; don't fiddle with renderstate + static void RenderStreamsAll(u32 streamflags); // apply given shadow map to all terrain patches static void ApplyShadowMap(GLuint handle); diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index a7173ffa73..c407992971 100755 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -658,7 +658,7 @@ void CRenderer::RenderShadowMap() glDisable(GL_CULL_FACE); // render models - CModelRData::RenderModels(STREAM_POS); + CModelRData::RenderModels(STREAM_POS,MODELFLAG_CASTSHADOWS); // call on the transparency renderer to render all the transparent stuff g_TransparencyRenderer.RenderShadows(); @@ -739,8 +739,6 @@ void CRenderer::RenderPatches() MICROLOG(L"wireframe off"); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); } else if (m_TerrainRenderMode==EDGED_FACES) { -/* - // TODO, RC - fix this // edged faces: need to make a second pass over the data: // first switch on wireframe glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); @@ -756,26 +754,14 @@ void CRenderer::RenderPatches() // .. and some client states glEnableClientState(GL_VERTEX_ARRAY); - - uint i; - - // render each patch in wireframe - for (i=0;iGetRenderData(); - patchdata->RenderStreams(STREAM_POS); - } + CPatchRData::RenderStreamsAll(STREAM_POS); // set color for outline glColor3f(0,0,1); glLineWidth(4.0f); // render outline of each patch - for (i=0;iGetRenderData(); - patchdata->RenderOutline(); - } + CPatchRData::RenderOutlines(); // .. and switch off the client states glDisableClientState(GL_VERTEX_ARRAY); @@ -786,7 +772,6 @@ void CRenderer::RenderPatches() // restore fill mode, and we're done glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); -*/ } } @@ -881,8 +866,6 @@ struct SortModelsByTexture { // FlushFrame: force rendering of any batched objects void CRenderer::FlushFrame() { - // sort all the models by texture -// std::sort(m_Models.begin(),m_Models.end(),SortModelsByTexture()); if(!g_Game || !g_Game->IsGameStarted()) return; @@ -981,7 +964,7 @@ void CRenderer::Submit(CPatch* patch) void CRenderer::Submit(CModel* model) { - if (1 /*ThisModelCastsShadows*/) { + if (model->GetFlags() & MODELFLAG_CASTSHADOWS) { m_ShadowBound+=model->GetBounds(); } diff --git a/source/renderer/TransparencyRenderer.cpp b/source/renderer/TransparencyRenderer.cpp index 19329f2c2c..9e6ff70e7f 100755 --- a/source/renderer/TransparencyRenderer.cpp +++ b/source/renderer/TransparencyRenderer.cpp @@ -173,7 +173,7 @@ void CTransparencyRenderer::RenderShadows() glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); - RenderObjectsStreams(STREAM_POS|STREAM_UV0); + RenderObjectsStreams(STREAM_POS|STREAM_UV0,MODELFLAG_CASTSHADOWS); glDepthMask(1); glDisable(GL_BLEND); @@ -184,10 +184,12 @@ void CTransparencyRenderer::RenderShadows() /////////////////////////////////////////////////////////////////////////////////////////////// // RenderObjectsStreams: render given streams on all objects -void CTransparencyRenderer::RenderObjectsStreams(u32 streamflags) +void CTransparencyRenderer::RenderObjectsStreams(u32 streamflags,u32 mflags) { for (uint i=0;iGetRenderData(); - modeldata->RenderStreams(streamflags); + if (!mflags || (m_Objects[i].m_Model->GetFlags() & mflags)) { + CModelRData* modeldata=(CModelRData*) m_Objects[i].m_Model->GetRenderData(); + modeldata->RenderStreams(streamflags); + } } } diff --git a/source/renderer/TransparencyRenderer.h b/source/renderer/TransparencyRenderer.h index 3f6635c1c3..cb6991c142 100755 --- a/source/renderer/TransparencyRenderer.h +++ b/source/renderer/TransparencyRenderer.h @@ -37,7 +37,7 @@ public: private: // render given streams on all objects - void RenderObjectsStreams(u32 streamflags); + void RenderObjectsStreams(u32 streamflags,u32 mflags=0); // list of transparent objects to render std::vector m_Objects; };