diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
commit | bdfe7d89e2f1292644577972c716931b4ce3c6c3 (patch) | |
tree | d00eb50b749cb001e2b08272c91791e66740b05d /source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp | |
parent | 78a1c27c4a6abe0ed31ca93ad21910f3df04da56 (diff) | |
parent | 7e4db234cee71ead34ee81a12e27da4bd548eb4b (diff) |
Merge of trunk into blender 2.5:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r12987:17416
Issues:
* GHOST/X11 had conflicting changes. Some code was added in 2.5, which was
later added in trunk also, but reverted partially, specifically revision
16683. I have left out this reversion in the 2.5 branch since I think it is
needed there.
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16683
* Scons had various conflicting changes, I decided to go with trunk version
for everything except priorities and some library renaming.
* In creator.c, there were various fixes and fixes for fixes related to the -w
-W and -p options. In 2.5 -w and -W is not coded yet, and -p is done
differently. Since this is changed so much, and I don't think those fixes
would be needed in 2.5, I've left them out.
* Also in creator.c: there was code for a python bugfix where the screen was not
initialized when running with -P. The code that initializes the screen there
I had to disable, that can't work in 2.5 anymore but left it commented as a
reminder.
Further I had to disable some new function calls. using src/ and python/, as
was done already in this branch, disabled function calls:
* bpath.c: error reporting
* BME_conversions.c: editmesh conversion functions.
* SHD_dynamic: disabled almost completely, there is no python/.
* KX_PythonInit.cpp and Ketsji/ build files: Mathutils is not there, disabled.
* text.c: clipboard copy call.
* object.c: OB_SUPPORT_MATERIAL.
* DerivedMesh.c and subsurf_ccg, stipple_quarttone.
Still to be done:
* Go over files and functions that were moved to a different location but could
still use changes that were done in trunk.
Diffstat (limited to 'source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp')
-rw-r--r-- | source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp | 441 |
1 files changed, 232 insertions, 209 deletions
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp index 3e4eef5bd45..2cb3b52adfb 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp @@ -30,35 +30,24 @@ #endif #include "RAS_VAOpenGLRasterizer.h" +#include <stdlib.h> -#ifdef WIN32 -#include <windows.h> -#endif // WIN32 -#ifdef __APPLE__ -#define GL_GLEXT_LEGACY 1 -#include <OpenGL/gl.h> -#else -#include <GL/gl.h> -#endif +#include "GL/glew.h" +#include "GPU_extensions.h" #include "STR_String.h" #include "RAS_TexVert.h" #include "MT_CmMatrix4x4.h" #include "RAS_IRenderTools.h" // rendering text - -#include "RAS_GLExtensionManager.h" - -using namespace bgl; - RAS_VAOpenGLRasterizer::RAS_VAOpenGLRasterizer(RAS_ICanvas* canvas, bool lock) : RAS_OpenGLRasterizer(canvas), - m_Lock(lock && RAS_EXT_support._EXT_compiled_vertex_array) + m_Lock(lock && GLEW_EXT_compiled_vertex_array), + m_last_texco_num(0), + m_last_attrib_num(0) { } - - RAS_VAOpenGLRasterizer::~RAS_VAOpenGLRasterizer() { } @@ -71,9 +60,9 @@ bool RAS_VAOpenGLRasterizer::Init(void) if (result) { glEnableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -81,238 +70,175 @@ bool RAS_VAOpenGLRasterizer::Init(void) return result; } - - void RAS_VAOpenGLRasterizer::SetDrawingMode(int drawingmode) { m_drawingmode = drawingmode; - switch (m_drawingmode) + switch (m_drawingmode) { - case KX_BOUNDINGBOX: - { - } - case KX_WIREFRAME: - { - glDisable (GL_CULL_FACE); + case KX_BOUNDINGBOX: + case KX_WIREFRAME: + //glDisableClientState(GL_COLOR_ARRAY); + //glDisable(GL_CULL_FACE); break; - } - case KX_TEXTURED: - { - } - case KX_SHADED: - { - glEnableClientState(GL_COLOR_ARRAY); - } - case KX_SOLID: - { + case KX_SOLID: + //glDisableClientState(GL_COLOR_ARRAY); + break; + case KX_TEXTURED: + case KX_SHADED: + case KX_SHADOW: + //glEnableClientState(GL_COLOR_ARRAY); + default: break; - } - default: - { - } } } - - void RAS_VAOpenGLRasterizer::Exit() { - glDisableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); RAS_OpenGLRasterizer::Exit(); } - - -void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays, - const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, - bool useObjectColor, - const MT_Vector4& rgbacolor, - class KX_ListSlot** slot) +void RAS_VAOpenGLRasterizer::IndexPrimitives(RAS_MeshSlot& ms) { - static const GLsizei vtxstride = sizeof(RAS_TexVert); + static const GLsizei stride = sizeof(RAS_TexVert); + bool wireframe = m_drawingmode <= KX_WIREFRAME; + RAS_MeshSlot::iterator it; GLenum drawmode; - switch (mode) - { - case 0: - { - drawmode = GL_TRIANGLES; - break; - } - case 2: - { - drawmode = GL_QUADS; - break; - } - case 1: //lines - { - } - default: - { - drawmode = GL_LINES; - break; - } - } - const RAS_TexVert* vertexarray; - unsigned int numindices, vt; - if (drawmode != GL_LINES) - { - if (useObjectColor) - { - glDisableClientState(GL_COLOR_ARRAY); - glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]); - } else - { - glColor4d(0,0,0,1.0); - glEnableClientState(GL_COLOR_ARRAY); - } - } - else - { - glColor3d(0,0,0); - } - // use glDrawElements to draw each vertexarray - for (vt=0;vt<vertexarrays.size();vt++) - { - vertexarray = &((*vertexarrays[vt]) [0]); - const KX_IndexArray & indexarray = (*indexarrays[vt]); - numindices = indexarray.size(); + if(!wireframe) + glEnableClientState(GL_TEXTURE_COORD_ARRAY); - if (!numindices) + // use glDrawElements to draw each vertexarray + for(ms.begin(it); !ms.end(it); ms.next(it)) { + if(it.totindex == 0) continue; - - glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ()); - glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1()); - glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA()); - glNormalPointer(GL_FLOAT,vtxstride,vertexarray->getNormal()); - //if(m_Lock) - // local->Begin(vertexarrays[vt]->size()); + // drawing mode + if(it.array->m_type == RAS_DisplayArray::TRIANGLE) + drawmode = GL_TRIANGLES; + else if(it.array->m_type == RAS_DisplayArray::QUAD) + drawmode = GL_QUADS; + else + drawmode = GL_LINES; + + // colors + if (drawmode != GL_LINES && !wireframe) { + if (ms.m_bObjectColor) { + const MT_Vector4& rgba = ms.m_RGBAcolor; + + glDisableClientState(GL_COLOR_ARRAY); + glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]); + } + else { + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + glEnableClientState(GL_COLOR_ARRAY); + } + } + else + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + + glVertexPointer(3, GL_FLOAT, stride, it.vertex->getXYZ()); + glNormalPointer(GL_FLOAT, stride, it.vertex->getNormal()); + if(!wireframe) { + glTexCoordPointer(2, GL_FLOAT, stride, it.vertex->getUV1()); + if(glIsEnabled(GL_COLOR_ARRAY)) + glColorPointer(4, GL_UNSIGNED_BYTE, stride, it.vertex->getRGBA()); + } // here the actual drawing takes places - glDrawElements(drawmode,numindices,GL_UNSIGNED_SHORT,&(indexarray[0])); - - //if(m_Lock) - // local->End(); - + glDrawElements(drawmode, it.totindex, GL_UNSIGNED_SHORT, it.index); + } + if(!wireframe) { + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); } } - -void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexarrays, - const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, - bool useObjectColor, - const MT_Vector4& rgbacolor, - class KX_ListSlot** slot) +void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti(RAS_MeshSlot& ms) { - static const GLsizei vtxstride = sizeof(RAS_TexVert); + static const GLsizei stride = sizeof(RAS_TexVert); + bool wireframe = m_drawingmode <= KX_WIREFRAME; + RAS_MeshSlot::iterator it; GLenum drawmode; - switch (mode) - { - case 0: - { - drawmode = GL_TRIANGLES; - break; - } - case 2: - { - drawmode = GL_QUADS; - break; - } - case 1: //lines - { - } - default: - { - drawmode = GL_LINES; - break; - } - } - const RAS_TexVert* vertexarray; - unsigned int numindices, vt; - const unsigned int enabled = polymat->GetEnabled(); - if (drawmode != GL_LINES) - { - if (useObjectColor) - { - glDisableClientState(GL_COLOR_ARRAY); - glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]); - } else - { - glColor4d(0,0,0,1.0); - glEnableClientState(GL_COLOR_ARRAY); - } - } - else - { - glColor3d(0,0,0); - } + if(!wireframe) + EnableTextures(true); // use glDrawElements to draw each vertexarray - for (vt=0;vt<vertexarrays.size();vt++) - { - vertexarray = &((*vertexarrays[vt]) [0]); - const KX_IndexArray & indexarray = (*indexarrays[vt]); - numindices = indexarray.size(); - - if (!numindices) + for(ms.begin(it); !ms.end(it); ms.next(it)) { + if(it.totindex == 0) continue; - - glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ()); - TexCoordPtr(vertexarray, enabled); - //glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1()); - glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA()); - glNormalPointer(GL_FLOAT,vtxstride,vertexarray->getNormal()); - - //if(m_Lock) - // local->Begin(vertexarrays[vt]->size()); + // drawing mode + if(it.array->m_type == RAS_DisplayArray::TRIANGLE) + drawmode = GL_TRIANGLES; + else if(it.array->m_type == RAS_DisplayArray::QUAD) + drawmode = GL_QUADS; + else + drawmode = GL_LINES; + + // colors + if (drawmode != GL_LINES && !wireframe) { + if (ms.m_bObjectColor) { + const MT_Vector4& rgba = ms.m_RGBAcolor; + + glDisableClientState(GL_COLOR_ARRAY); + glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]); + } + else { + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + glEnableClientState(GL_COLOR_ARRAY); + } + } + else + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + + glVertexPointer(3, GL_FLOAT, stride, it.vertex->getXYZ()); + glNormalPointer(GL_FLOAT, stride, it.vertex->getNormal()); + if(!wireframe) { + TexCoordPtr(it.vertex); + if(glIsEnabled(GL_COLOR_ARRAY)) + glColorPointer(4, GL_UNSIGNED_BYTE, stride, it.vertex->getRGBA()); + } // here the actual drawing takes places - glDrawElements(drawmode,numindices,GL_UNSIGNED_SHORT,&(indexarray[0])); - - //if(m_Lock) - // local->End(); + glDrawElements(drawmode, it.totindex, GL_UNSIGNED_SHORT, it.index); + } + + if(!wireframe) { + glDisableClientState(GL_COLOR_ARRAY); + EnableTextures(false); } } -void RAS_VAOpenGLRasterizer::TexCoordPtr(const RAS_TexVert *tv, int enabled) +void RAS_VAOpenGLRasterizer::TexCoordPtr(const RAS_TexVert *tv) { -#ifdef GL_ARB_multitexture - if(bgl::RAS_EXT_support._ARB_multitexture) + /* note: this function must closely match EnableTextures to enable/disable + * the right arrays, otherwise coordinate and attribute pointers from other + * materials can still be used and cause crashes */ + int unit; + + if(GLEW_ARB_multitexture) { - for(int unit=0; unit<enabled; unit++) + for(unit=0; unit<m_texco_num; unit++) { - bgl::blClientActiveTextureARB(GL_TEXTURE0_ARB+unit); - - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - if( tv->getFlag() & TV_2NDUV && tv->getUnit() == unit ) { + glClientActiveTextureARB(GL_TEXTURE0_ARB+unit); + if(tv->getFlag() & RAS_TexVert::SECOND_UV && (int)tv->getUnit() == unit) { + glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert), tv->getUV2()); continue; } switch(m_texco[unit]) { - case RAS_TEXCO_DISABLE: - case RAS_TEXCO_OBJECT: - case RAS_TEXCO_GEN: - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - break; case RAS_TEXCO_ORCO: case RAS_TEXCO_GLOB: - glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getLocalXYZ()); + glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getXYZ()); break; case RAS_TEXCO_UV1: glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert),tv->getUV1()); @@ -326,24 +252,121 @@ void RAS_VAOpenGLRasterizer::TexCoordPtr(const RAS_TexVert *tv, int enabled) case RAS_TEXCO_UV2: glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert),tv->getUV2()); break; + default: + break; } } - } -#ifdef GL_ARB_vertex_program - if(m_useTang && bgl::RAS_EXT_support._ARB_vertex_program) - bgl::blVertexAttrib4fvARB(1/*tangent*/, tv->getTangent()); -#endif + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } -#endif + if(GLEW_ARB_vertex_program) { + for(unit=0; unit<m_attrib_num; unit++) { + switch(m_attrib[unit]) { + case RAS_TEXCO_ORCO: + case RAS_TEXCO_GLOB: + glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getXYZ()); + break; + case RAS_TEXCO_UV1: + glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getUV1()); + break; + case RAS_TEXCO_NORM: + glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getNormal()); + break; + case RAS_TEXTANGENT: + glVertexAttribPointerARB(unit, 4, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getTangent()); + break; + case RAS_TEXCO_UV2: + glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getUV2()); + break; + case RAS_TEXCO_VCOL: + glVertexAttribPointerARB(unit, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(RAS_TexVert), tv->getRGBA()); + break; + default: + break; + } + } + } } - void RAS_VAOpenGLRasterizer::EnableTextures(bool enable) { - if (enable) - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - else - glDisableClientState(GL_TEXTURE_COORD_ARRAY); + TexCoGen *texco, *attrib; + int unit, texco_num, attrib_num; + + /* we cache last texcoords and attribs to ensure we disable the ones that + * were actually last set */ + if(enable) { + texco = m_texco; + texco_num = m_texco_num; + attrib = m_attrib; + attrib_num = m_attrib_num; + + memcpy(m_last_texco, m_texco, sizeof(TexCoGen)*m_texco_num); + m_last_texco_num = m_texco_num; + memcpy(m_last_attrib, m_attrib, sizeof(TexCoGen)*m_attrib_num); + m_last_attrib_num = m_attrib_num; + } + else { + texco = m_last_texco; + texco_num = m_last_texco_num; + attrib = m_last_attrib; + attrib_num = m_last_attrib_num; + } + + if(GLEW_ARB_multitexture) { + for(unit=0; unit<texco_num; unit++) { + glClientActiveTextureARB(GL_TEXTURE0_ARB+unit); + + switch(texco[unit]) + { + case RAS_TEXCO_ORCO: + case RAS_TEXCO_GLOB: + case RAS_TEXCO_UV1: + case RAS_TEXCO_NORM: + case RAS_TEXTANGENT: + case RAS_TEXCO_UV2: + if(enable) glEnableClientState(GL_TEXTURE_COORD_ARRAY); + else glDisableClientState(GL_TEXTURE_COORD_ARRAY); + break; + default: + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + break; + } + } + + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + else { + if(texco_num) { + if(enable) glEnableClientState(GL_TEXTURE_COORD_ARRAY); + else glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + } + + if(GLEW_ARB_vertex_program) { + for(unit=0; unit<attrib_num; unit++) { + switch(attrib[unit]) { + case RAS_TEXCO_ORCO: + case RAS_TEXCO_GLOB: + case RAS_TEXCO_UV1: + case RAS_TEXCO_NORM: + case RAS_TEXTANGENT: + case RAS_TEXCO_UV2: + case RAS_TEXCO_VCOL: + if(enable) glEnableVertexAttribArrayARB(unit); + else glDisableVertexAttribArrayARB(unit); + break; + default: + glDisableVertexAttribArrayARB(unit); + break; + } + } + } + + if(!enable) { + m_last_texco_num = 0; + m_last_attrib_num = 0; + } } |