Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW ==== Added the GLEW opengl extension library into extern/, always compiled into Blender now. This is much nicer than doing this kind of extension management manually, and will be used in the game engine, for GLSL, and other opengl extensions. * According to the GLEW website it works on Windows, Linux, Mac OS X, FreeBSD, Irix, and Solaris. There might still be platform specific issues due to this commit, so let me know and I'll look into it. * This means also that all extensions will now always be compiled in, regardless of the glext.h on the platform where compilation happens. Game Engine =========== Refactoring of the use of opengl extensions and other drawing code in the game engine, and cleaning up some hacks related to GLSL integration. These changes will be merged into trunk too after this. The game engine graphics demos & apricot level survived my tests, but this could use some good testing of course. For users: please test with the options "Generate Display Lists" and "Vertex Arrays" enabled, these should be the fastest and are supposed to be "unreliable", but if that's the case that's probably due to bugs that can be fixed. * The game engine now also uses GLEW for extensions, replacing the custom opengl extensions code that was there. Removes a lot of #ifdef's, but the runtime checks stay of course. * Removed the WITHOUT_GLEXT environment variable. This was added to work around a specific bug and only disabled multitexturing anyway. It might also have caused a slowdown since it was retrieving the environment variable for every vertex in immediate mode (bug #13680). * Refactored the code to allow drawing skinned meshes with vertex arrays too, removing some specific immediate mode drawing functions for this that only did extra normal calculation. Now it always splits vertices of flat faces instead. * Refactored normal recalculation with some minor optimizations, required for the above change. * Removed some outdated code behind the __NLA_OLDDEFORM #ifdef. * Fixed various bugs in setting of multitexture coordinates and vertex attributes for vertex arrays. These were not being enabled/disabled correct according to the opengl spec, leading to crashes. Also tangent attributes used an immediate mode call for vertex arrays, which can't work. * Fixed use of uninitialized variable in RAS_TexVert. * Exporting skinned meshes was doing O(n^2) lookups for vertices and deform weights, now uses same trick as regular meshes.
This commit is contained in:
@@ -32,34 +32,21 @@
|
||||
#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 "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()
|
||||
{
|
||||
}
|
||||
@@ -82,53 +69,36 @@ 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:
|
||||
{
|
||||
case KX_BOUNDINGBOX:
|
||||
case KX_WIREFRAME:
|
||||
glDisable (GL_CULL_FACE);
|
||||
break;
|
||||
}
|
||||
case KX_TEXTURED:
|
||||
{
|
||||
}
|
||||
case KX_SHADED:
|
||||
{
|
||||
case KX_TEXTURED:
|
||||
case KX_SHADED:
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
case KX_SOLID:
|
||||
{
|
||||
case KX_SOLID:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RAS_VAOpenGLRasterizer::Exit()
|
||||
{
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
EnableTextures(false);
|
||||
|
||||
RAS_OpenGLRasterizer::Exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays,
|
||||
const vecIndexArrays & indexarrays,
|
||||
int mode,
|
||||
@@ -142,24 +112,16 @@ void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays
|
||||
GLenum drawmode;
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
drawmode = GL_TRIANGLES;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
drawmode = GL_QUADS;
|
||||
break;
|
||||
}
|
||||
case 1: //lines
|
||||
{
|
||||
}
|
||||
default:
|
||||
{
|
||||
drawmode = GL_LINES;
|
||||
break;
|
||||
}
|
||||
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;
|
||||
@@ -208,7 +170,6 @@ void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexarrays,
|
||||
const vecIndexArrays & indexarrays,
|
||||
int mode,
|
||||
@@ -222,28 +183,19 @@ void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexa
|
||||
GLenum drawmode;
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
drawmode = GL_TRIANGLES;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
drawmode = GL_QUADS;
|
||||
break;
|
||||
}
|
||||
case 1: //lines
|
||||
{
|
||||
}
|
||||
default:
|
||||
{
|
||||
drawmode = GL_LINES;
|
||||
break;
|
||||
}
|
||||
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)
|
||||
{
|
||||
@@ -251,7 +203,8 @@ void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexa
|
||||
{
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
glColor4d(0,0,0,1.0);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
@@ -271,11 +224,10 @@ void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexa
|
||||
|
||||
if (!numindices)
|
||||
continue;
|
||||
|
||||
glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ());
|
||||
TexCoordPtr(vertexarray, enabled);
|
||||
|
||||
//glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1());
|
||||
glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ());
|
||||
TexCoordPtr(vertexarray);
|
||||
|
||||
glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA());
|
||||
glNormalPointer(GL_FLOAT,vtxstride,vertexarray->getNormal());
|
||||
|
||||
@@ -290,62 +242,146 @@ void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexa
|
||||
}
|
||||
}
|
||||
|
||||
void RAS_VAOpenGLRasterizer::TexCoordPtr(const RAS_TexVert *tv, int enabled)
|
||||
void RAS_VAOpenGLRasterizer::TexCoordPtr(const RAS_TexVert *tv)
|
||||
{
|
||||
#if defined(GL_ARB_multitexture) && defined(WITH_GLEXT)
|
||||
if (!getenv("WITHOUT_GLEXT")) {
|
||||
if(bgl::RAS_EXT_support._ARB_multitexture)
|
||||
{
|
||||
for(int unit=0; unit<enabled; unit++)
|
||||
{
|
||||
bgl::blClientActiveTextureARB(GL_TEXTURE0_ARB+unit);
|
||||
/* 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(unit=0; unit<m_texco_num; unit++)
|
||||
{
|
||||
glClientActiveTextureARB(GL_TEXTURE0_ARB+unit);
|
||||
if(tv->getFlag() & TV_2NDUV && (int)tv->getUnit() == unit) {
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
if( tv->getFlag() & TV_2NDUV && tv->getUnit() == unit ) {
|
||||
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());
|
||||
break;
|
||||
case RAS_TEXCO_UV1:
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert),tv->getUV1());
|
||||
break;
|
||||
case RAS_TEXCO_NORM:
|
||||
glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getNormal());
|
||||
break;
|
||||
case RAS_TEXTANGENT:
|
||||
glTexCoordPointer(4, GL_FLOAT, sizeof(RAS_TexVert),tv->getTangent());
|
||||
break;
|
||||
case RAS_TEXCO_UV2:
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert),tv->getUV2());
|
||||
break;
|
||||
}
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert), tv->getUV2());
|
||||
continue;
|
||||
}
|
||||
switch(m_texco[unit])
|
||||
{
|
||||
case RAS_TEXCO_ORCO:
|
||||
case RAS_TEXCO_GLOB:
|
||||
glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getLocalXYZ());
|
||||
break;
|
||||
case RAS_TEXCO_UV1:
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert),tv->getUV1());
|
||||
break;
|
||||
case RAS_TEXCO_NORM:
|
||||
glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getNormal());
|
||||
break;
|
||||
case RAS_TEXTANGENT:
|
||||
glTexCoordPointer(4, GL_FLOAT, sizeof(RAS_TexVert),tv->getTangent());
|
||||
break;
|
||||
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
|
||||
}
|
||||
#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:
|
||||
glVertexAttribPointer(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getLocalXYZ());
|
||||
break;
|
||||
case RAS_TEXCO_UV1:
|
||||
glVertexAttribPointer(unit, 2, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getUV1());
|
||||
break;
|
||||
case RAS_TEXCO_NORM:
|
||||
glVertexAttribPointer(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getNormal());
|
||||
break;
|
||||
case RAS_TEXTANGENT:
|
||||
glVertexAttribPointer(unit, 4, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getTangent());
|
||||
break;
|
||||
case RAS_TEXCO_UV2:
|
||||
glVertexAttribPointer(unit, 2, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getUV2());
|
||||
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;
|
||||
|
||||
/* disable previously enabled texture coordinates and attributes. ideally
|
||||
* this shouldn't be necessary .. */
|
||||
if(enable)
|
||||
EnableTextures(false);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
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:
|
||||
if(enable) glEnableVertexAttribArray(unit);
|
||||
else glDisableVertexAttribArray(unit);
|
||||
break;
|
||||
default:
|
||||
glDisableVertexAttribArray(unit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user