From: <jo...@us...> - 2003-09-02 11:59:12
|
Update of /cvsroot/crystal/CS/plugins/video/render3d/opengl In directory sc8-pr-cvs1:/tmp/cvs-serv7033/plugins/video/render3d/opengl Modified Files: gl_render3d.cpp gl_render3d.h Log Message: - Jorrit changed the new renderer iGraphics3D API as follows: Removed ActivateBuffer, DeactivateBuffer, ActivateTexture, and DeactivateTexture. Instead there is now SetBufferState() and SetTextureState(). This has two advantages: - Avoid the overhead of many virtual function calls when external modules (shader manager) have to activate and deactivate buffers and textures. - Make it possible to do further optimizations in those routines to avoid the work of deactivating if not needed. - Jorrit implemented the new API in the new renderer software and OpenGL renderers. - Jorrit fixed a bug in the new renderer in relation to the activation of vertex buffer. There was only one table used to indicate if a vertex table was active or not but two tables are needed to distinguish between conventional and extra buffers (range 0 to 15 and 100+0 to 100+15). - Jorrit optimized the OpenGL version of SetBufferState() and SetTextureState() by avoiding the deactivation of the buffers if this is not needed. Index: gl_render3d.cpp =================================================================== RCS file: /cvsroot/crystal/CS/plugins/video/render3d/opengl/gl_render3d.cpp,v retrieving revision 1.94 retrieving revision 1.95 diff -u -d -r1.94 -r1.95 --- gl_render3d.cpp 29 Aug 2003 00:08:05 -0000 1.94 +++ gl_render3d.cpp 2 Sep 2003 11:59:08 -0000 1.95 @@ -135,6 +135,7 @@ { vertattrib[i] = 0; vertattribenabled[i] = false; + vertattribenabled100[i] = false; texunit[i] = 0; texunitenabled[i] = false; } @@ -1073,19 +1074,33 @@ bool csGLGraphics3D::ActivateBuffer (csVertexAttrib attrib, iRenderBuffer* buffer) { bool bind = true; - int att = attrib<100?attrib:attrib-100; - if (vertattrib[att] == buffer) + int att; + if (attrib < 100) { - if (vertattribenabled[att]) - return true; - //bind = false; //@@@[res]: causes graphical errors in some cases + if (vertattrib[attrib] == buffer) + { + if (vertattribenabled[attrib]) + return true; + //bind = false; //@@@[res]: causes graphical errors in some cases + } + att = attrib; + } + else + { + att = attrib-100; + if (vertattrib[att] == buffer) + { + if (vertattribenabled100[att]) + return true; + //bind = false; //@@@[res]: causes graphical errors in some cases + } } if (bind && vertattrib[att]) { vertattrib[att]->Release (); vertattrib[att] = 0; } - + void* data = ((csGLRenderBuffer*)buffer)->RenderLock (CS_GLBUF_RENDERLOCK_ARRAY); //buffer->Lock (CS_BUF_LOCK_RENDER); if (data != (void*)-1) { @@ -1132,14 +1147,27 @@ } } vertattrib[att] = buffer; - vertattribenabled[att] = true; + if (attrib < 100) + vertattribenabled[att] = true; + else + vertattribenabled100[att] = true; } return true; } void csGLGraphics3D::DeactivateBuffer (csVertexAttrib attrib) { - int att = attrib<100?attrib:attrib-100; + int att; + if (attrib < 100) + { + if (vertattribenabled[attrib] == false) return; + att = attrib; + } + else + { + att = attrib-100; + if (vertattribenabled100[att] == false) return; + } if (ext->glDisableVertexAttribArrayARB && attrib<100) { ext->glDisableVertexAttribArrayARB (attrib); @@ -1147,7 +1175,8 @@ ext->glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0); ext->glVertexAttribPointerARB(attrib, 1, GL_FLOAT, true, 0, 0);*/ - } else + } + else { switch (attrib) { @@ -1171,7 +1200,24 @@ { vertattrib[att]->Release (); vertattrib[att] = 0; - vertattribenabled[att] = false; + if (attrib < 100) + vertattribenabled[att] = false; + else + vertattribenabled100[att] = false; + } +} + +void csGLGraphics3D::SetBufferState (csVertexAttrib* attribs, iRenderBuffer** buffers, int count) +{ + int i; + for (i = 0 ; i < count ; i++) + { + csVertexAttrib attrib = attribs[i]; + iRenderBuffer* buf = buffers[i]; + if (buf) + ActivateBuffer (attrib, buf); + else + DeactivateBuffer (attrib); } } @@ -1355,6 +1401,20 @@ break; } texunitenabled[unit] = false; +} + +void csGLGraphics3D::SetTextureState (int* units, iTextureHandle** textures, int count) +{ + int i; + for (i = 0 ; i < count ; i++) + { + int unit = units[i]; + iTextureHandle* txt = textures[i]; + if (txt) + ActivateTexture (txt, unit); + else + DeactivateTexture (unit); + } } void csGLGraphics3D::DrawMesh(csRenderMesh* mymesh) Index: gl_render3d.h =================================================================== RCS file: /cvsroot/crystal/CS/plugins/video/render3d/opengl/gl_render3d.h,v retrieving revision 1.57 retrieving revision 1.58 diff -u -d -r1.57 -r1.58 --- gl_render3d.h 28 Aug 2003 20:22:36 -0000 1.57 +++ gl_render3d.h 2 Sep 2003 11:59:08 -0000 1.58 @@ -201,6 +201,7 @@ iRenderBuffer* vertattrib[16]; // @@@ Hardcoded max number of attributes bool vertattribenabled[16]; // @@@ Hardcoded max number of attributes + bool vertattribenabled100[16]; // @@@ Hardcoded max number of attributes (for conventional) iTextureHandle* texunit[16]; // @@@ Hardcoded max number of units bool texunitenabled[16]; // @@@ Hardcoded max number of units @@ -238,19 +239,16 @@ int componentCount, bool index); /// Activate a vertex buffer - virtual bool ActivateBuffer (csVertexAttrib attrib, iRenderBuffer* buffer); - - /// Deactivate a vertex buffer - virtual void DeactivateBuffer (csVertexAttrib attrib); + bool ActivateBuffer (csVertexAttrib attrib, iRenderBuffer* buffer); + void DeactivateBuffer (csVertexAttrib attrib); + virtual void SetBufferState (csVertexAttrib* attribs, iRenderBuffer** buffers, int count); /// Activate a texture - virtual bool ActivateTexture (iTextureHandle *txthandle, int unit = 0); - + bool ActivateTexture (iTextureHandle *txthandle, int unit = 0); /// Activate a texture (Should probably handled some better way) - virtual bool ActivateTexture (iMaterialHandle *mathandle, int layer, int unit = 0); - - /// Deactivate a texture - virtual void DeactivateTexture (int unit = 0); + bool ActivateTexture (iMaterialHandle *mathandle, int layer, int unit = 0); + void DeactivateTexture (int unit = 0); + virtual void SetTextureState (int* units, iTextureHandle** textures, int count); /// Set dimensions of window void SetDimensions (int width, int height) |