Changed: #1275 Create an OpenGL ES driver

This commit is contained in:
kervala 2011-05-01 19:11:10 +02:00
parent 37adf50601
commit 7368462f20
4 changed files with 116 additions and 17 deletions

View file

@ -2508,8 +2508,13 @@ void CDriverGL::checkTextureOn() const
GLboolean flagCM; GLboolean flagCM;
GLboolean flagTR; GLboolean flagTR;
glGetBooleanv(GL_TEXTURE_2D, &flag2D); glGetBooleanv(GL_TEXTURE_2D, &flag2D);
#ifdef USE_OPENGLES
glGetBooleanv(GL_TEXTURE_CUBE_MAP_OES, &flagCM);
flagTR = true; // always true in OpenGL ES
#else
glGetBooleanv(GL_TEXTURE_CUBE_MAP_ARB, &flagCM); glGetBooleanv(GL_TEXTURE_CUBE_MAP_ARB, &flagCM);
glGetBooleanv(GL_TEXTURE_RECTANGLE_NV, &flagTR); glGetBooleanv(GL_TEXTURE_RECTANGLE_NV, &flagTR);
#endif
switch(dgs.getTextureMode()) switch(dgs.getTextureMode())
{ {
case CDriverGLStates::TextureDisabled: case CDriverGLStates::TextureDisabled:
@ -2545,7 +2550,8 @@ bool CDriverGL::supportOcclusionQuery() const
// *************************************************************************** // ***************************************************************************
bool CDriverGL::supportTextureRectangle() const bool CDriverGL::supportTextureRectangle() const
{ {
H_AUTO_OGL(CDriverGL_supportTextureRectangle) H_AUTO_OGL(CDriverGL_supportTextureRectangle);
return (_Extensions.NVTextureRectangle || _Extensions.EXTTextureRectangle || _Extensions.ARBTextureRectangle); return (_Extensions.NVTextureRectangle || _Extensions.EXTTextureRectangle || _Extensions.ARBTextureRectangle);
} }

View file

@ -137,7 +137,9 @@ void CDriverGL::setTextureEnvFunction(uint stage, CMaterial& mat)
_DriverGLStates.setTexGenMode (stage, GL_OBJECT_LINEAR); _DriverGLStates.setTexGenMode (stage, GL_OBJECT_LINEAR);
} }
else if(mode==CMaterial::TexCoordGenEyeSpace) else if(mode==CMaterial::TexCoordGenEyeSpace)
{
_DriverGLStates.setTexGenMode (stage, GL_EYE_LINEAR); _DriverGLStates.setTexGenMode (stage, GL_EYE_LINEAR);
}
} }
else else
{ {
@ -918,7 +920,11 @@ void CDriverGL::setupLightMapPass(uint pass)
if (mat._LightMapsMulx2) if (mat._LightMapsMulx2)
{ {
// Multiply x 2 // Multiply x 2
#ifdef USE_OPENGLES
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, 2);
#else
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2); glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2);
#endif
} }
} }
} }
@ -1027,7 +1033,11 @@ void CDriverGL::endLightMapMultiPass()
for (uint32 i = 0; i < (_NLightMapPerPass+1); ++i) for (uint32 i = 0; i < (_NLightMapPerPass+1); ++i)
{ {
_DriverGLStates.activeTextureARB(i); _DriverGLStates.activeTextureARB(i);
#ifdef USE_OPENGLES
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, 1);
#else
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1); glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1);
#endif
} }
} }
} }
@ -1102,13 +1112,16 @@ void CDriverGL::setupSpecularBegin()
// todo hulud remove // todo hulud remove
// _DriverGLStates.setTextureMode(CDriverGLStates::TextureCubeMap); // _DriverGLStates.setTextureMode(CDriverGLStates::TextureCubeMap);
#ifdef USE_OPENGLES
_DriverGLStates.setTexGenMode (1, GL_REFLECTION_MAP_OES);
#else
_DriverGLStates.setTexGenMode (1, GL_REFLECTION_MAP_ARB); _DriverGLStates.setTexGenMode (1, GL_REFLECTION_MAP_ARB);
#endif
// setup the good matrix for stage 1. // setup the good matrix for stage 1.
glMatrixMode(GL_TEXTURE); glMatrixMode(GL_TEXTURE);
glLoadMatrixf( _SpecularTexMtx.get() ); glLoadMatrixf( _SpecularTexMtx.get() );
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
} }
// *************************************************************************** // ***************************************************************************
@ -1292,7 +1305,8 @@ void CDriverGL::setupSpecularPass(uint pass)
_DriverGLStates.setTextureMode(CDriverGLStates::TextureDisabled); _DriverGLStates.setTextureMode(CDriverGLStates::TextureDisabled);
} }
else else
{ // Multiply texture1 by alpha_texture0 and display with add {
// Multiply texture1 by alpha_texture0 and display with add
_DriverGLStates.enableBlend(true); _DriverGLStates.enableBlend(true);
_DriverGLStates.blendFunc(GL_ONE, GL_ONE); _DriverGLStates.blendFunc(GL_ONE, GL_ONE);

View file

@ -77,7 +77,8 @@ void CDriverGLStates::init(bool supportTextureCubeMap, bool supportTextureRect
// *************************************************************************** // ***************************************************************************
void CDriverGLStates::forceDefaults(uint nbStages) void CDriverGLStates::forceDefaults(uint nbStages)
{ {
H_AUTO_OGL(CDriverGLStates_forceDefaults) H_AUTO_OGL(CDriverGLStates_forceDefaults);
// Enable / disable. // Enable / disable.
_CurFog= false; _CurFog= false;
_CurBlend= false; _CurBlend= false;
@ -86,6 +87,7 @@ void CDriverGLStates::forceDefaults(uint nbStages)
_CurLighting= false; _CurLighting= false;
_CurZWrite= true; _CurZWrite= true;
_CurStencilTest=false; _CurStencilTest=false;
// setup GLStates. // setup GLStates.
glDisable(GL_FOG); glDisable(GL_FOG);
glDisable(GL_BLEND); glDisable(GL_BLEND);
@ -642,10 +644,14 @@ void CDriverGLStates::setTexGenMode (uint stage, GLint mode)
if(mode==0) if(mode==0)
{ {
#ifdef USE_OPENGLES
glDisable(GL_TEXTURE_GEN_STR_OES);
#else
glDisable( GL_TEXTURE_GEN_S ); glDisable( GL_TEXTURE_GEN_S );
glDisable( GL_TEXTURE_GEN_T ); glDisable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R ); glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q ); glDisable( GL_TEXTURE_GEN_Q );
#endif
} }
else else
{ {
@ -667,6 +673,7 @@ void CDriverGLStates::setTexGenMode (uint stage, GLint mode)
{ {
glDisable( GL_TEXTURE_GEN_Q ); glDisable( GL_TEXTURE_GEN_Q );
} }
// Enable All. // Enable All.
#ifdef USE_OPENGLES #ifdef USE_OPENGLES
glEnable(GL_TEXTURE_GEN_STR_OES); glEnable(GL_TEXTURE_GEN_STR_OES);
@ -853,22 +860,25 @@ void CDriverGLStates::enableNormalArray(bool enable)
// *************************************************************************** // ***************************************************************************
void CDriverGLStates::enableWeightArray(bool enable) void CDriverGLStates::enableWeightArray(bool enable)
{ {
H_AUTO_OGL(CDriverGLStates_enableWeightArray) H_AUTO_OGL(CDriverGLStates_enableWeightArray);
if(_WeightArrayEnabled != enable) if(_WeightArrayEnabled != enable)
{ {
#ifndef USE_OPENGLES
if(enable) if(enable)
glEnableClientState(GL_VERTEX_WEIGHTING_EXT); glEnableClientState(GL_VERTEX_WEIGHTING_EXT);
else else
glDisableClientState(GL_VERTEX_WEIGHTING_EXT); glDisableClientState(GL_VERTEX_WEIGHTING_EXT);
#endif
_WeightArrayEnabled= enable; _WeightArrayEnabled= enable;
} }
} }
// *************************************************************************** // ***************************************************************************
void CDriverGLStates::enableColorArray(bool enable) void CDriverGLStates::enableColorArray(bool enable)
{ {
H_AUTO_OGL(CDriverGLStates_enableColorArray) H_AUTO_OGL(CDriverGLStates_enableColorArray);
if(_ColorArrayEnabled != enable) if(_ColorArrayEnabled != enable)
{ {
if(enable) if(enable)
@ -885,14 +895,16 @@ void CDriverGLStates::enableColorArray(bool enable)
// *************************************************************************** // ***************************************************************************
void CDriverGLStates::enableSecondaryColorArray(bool enable) void CDriverGLStates::enableSecondaryColorArray(bool enable)
{ {
H_AUTO_OGL(CDriverGLStates_enableSecondaryColorArray) H_AUTO_OGL(CDriverGLStates_enableSecondaryColorArray);
if(_SecondaryColorArrayEnabled != enable) if(_SecondaryColorArrayEnabled != enable)
{ {
#ifndef USE_OPENGLES
if(enable) if(enable)
glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT); glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
else else
glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT); glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
#endif
_SecondaryColorArrayEnabled= enable; _SecondaryColorArrayEnabled= enable;
@ -910,10 +922,15 @@ void CDriverGLStates::enableSecondaryColorArray(bool enable)
// *************************************************************************** // ***************************************************************************
void CDriverGLStates::clientActiveTextureARB(uint stage) void CDriverGLStates::clientActiveTextureARB(uint stage)
{ {
H_AUTO_OGL(CDriverGLStates_clientActiveTextureARB) H_AUTO_OGL(CDriverGLStates_clientActiveTextureARB);
if( _CurrentClientActiveTextureARB != stage ) if( _CurrentClientActiveTextureARB != stage )
{ {
#ifdef USE_OPENGLES
glClientActiveTexture(GL_TEXTURE0+stage);
#else
nglClientActiveTextureARB(GL_TEXTURE0_ARB+stage); nglClientActiveTextureARB(GL_TEXTURE0_ARB+stage);
#endif
_CurrentClientActiveTextureARB= stage; _CurrentClientActiveTextureARB= stage;
} }
} }
@ -921,7 +938,8 @@ void CDriverGLStates::clientActiveTextureARB(uint stage)
// *************************************************************************** // ***************************************************************************
void CDriverGLStates::enableTexCoordArray(bool enable) void CDriverGLStates::enableTexCoordArray(bool enable)
{ {
H_AUTO_OGL(CDriverGLStates_enableTexCoordArray) H_AUTO_OGL(CDriverGLStates_enableTexCoordArray);
if(_TexCoordArrayEnabled[_CurrentClientActiveTextureARB] != enable) if(_TexCoordArrayEnabled[_CurrentClientActiveTextureARB] != enable)
{ {
if(enable) if(enable)
@ -937,14 +955,16 @@ void CDriverGLStates::enableTexCoordArray(bool enable)
// *************************************************************************** // ***************************************************************************
void CDriverGLStates::enableVertexAttribArray(uint glIndex, bool enable) void CDriverGLStates::enableVertexAttribArray(uint glIndex, bool enable)
{ {
H_AUTO_OGL(CDriverGLStates_enableVertexAttribArray) H_AUTO_OGL(CDriverGLStates_enableVertexAttribArray);
if(_VertexAttribArrayEnabled[glIndex] != enable) if(_VertexAttribArrayEnabled[glIndex] != enable)
{ {
#ifndef USE_OPENGLES
if(enable) if(enable)
glEnableClientState(glIndex+GL_VERTEX_ATTRIB_ARRAY0_NV); glEnableClientState(glIndex+GL_VERTEX_ATTRIB_ARRAY0_NV);
else else
glDisableClientState(glIndex+GL_VERTEX_ATTRIB_ARRAY0_NV); glDisableClientState(glIndex+GL_VERTEX_ATTRIB_ARRAY0_NV);
#endif
_VertexAttribArrayEnabled[glIndex]= enable; _VertexAttribArrayEnabled[glIndex]= enable;
} }
@ -953,15 +973,18 @@ void CDriverGLStates::enableVertexAttribArray(uint glIndex, bool enable)
// *************************************************************************** // ***************************************************************************
void CDriverGLStates::enableVertexAttribArrayARB(uint glIndex,bool enable) void CDriverGLStates::enableVertexAttribArrayARB(uint glIndex,bool enable)
{ {
H_AUTO_OGL(CDriverGLStates_enableVertexAttribArrayARB) H_AUTO_OGL(CDriverGLStates_enableVertexAttribArrayARB);
#ifndef NL3D_GLSTATE_DISABLE_CACHE #ifndef NL3D_GLSTATE_DISABLE_CACHE
if(_VertexAttribArrayEnabled[glIndex] != enable) if(_VertexAttribArrayEnabled[glIndex] != enable)
#endif #endif
{ {
#ifndef USE_OPENGLES
if(enable) if(enable)
nglEnableVertexAttribArrayARB(glIndex); nglEnableVertexAttribArrayARB(glIndex);
else else
nglDisableVertexAttribArrayARB(glIndex); nglDisableVertexAttribArrayARB(glIndex);
#endif
_VertexAttribArrayEnabled[glIndex]= enable; _VertexAttribArrayEnabled[glIndex]= enable;
} }

View file

@ -1210,19 +1210,37 @@ IVertexBufferHardGL *CVertexArrayRangeARB::createVBHardGL(uint size, CVertexBuff
// create a ARB VBHard // create a ARB VBHard
GLuint vertexBufferID; GLuint vertexBufferID;
glGetError(); glGetError();
#ifdef USE_OPENGLES
glGenBuffers(1, &vertexBufferID);
#else
nglGenBuffersARB(1, &vertexBufferID); nglGenBuffersARB(1, &vertexBufferID);
#endif
if (glGetError() != GL_NO_ERROR) return false; if (glGetError() != GL_NO_ERROR) return false;
_Driver->_DriverGLStates.forceBindARBVertexBuffer(vertexBufferID); _Driver->_DriverGLStates.forceBindARBVertexBuffer(vertexBufferID);
switch(_VBType) switch(_VBType)
{ {
case CVertexBuffer::AGPPreferred: case CVertexBuffer::AGPPreferred:
#ifdef USE_OPENGLES
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW);
#else
nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB); nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB);
#endif
break; break;
case CVertexBuffer::StaticPreferred: case CVertexBuffer::StaticPreferred:
if (_Driver->getStaticMemoryToVRAM()) if (_Driver->getStaticMemoryToVRAM())
#ifdef USE_OPENGLES
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW);
#else
nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_STATIC_DRAW_ARB); nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_STATIC_DRAW_ARB);
#endif
else else
#ifdef USE_OPENGLES
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW);
#else
nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB); nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB);
#endif
break; break;
default: default:
nlassert(0); nlassert(0);
@ -1230,7 +1248,12 @@ IVertexBufferHardGL *CVertexArrayRangeARB::createVBHardGL(uint size, CVertexBuff
} }
if (glGetError() != GL_NO_ERROR) if (glGetError() != GL_NO_ERROR)
{ {
#ifdef USE_OPENGLES
glDeleteBuffers(1, &vertexBufferID);
#else
nglDeleteBuffersARB(1, &vertexBufferID); nglDeleteBuffersARB(1, &vertexBufferID);
#endif
return false; return false;
} }
CVertexBufferHardARB *newVbHard= new CVertexBufferHardARB(_Driver, vb); CVertexBufferHardARB *newVbHard= new CVertexBufferHardARB(_Driver, vb);
@ -1272,8 +1295,13 @@ void CVertexArrayRangeARB::updateLostBuffers()
{ {
nlassert((*it)->_VertexObjectId); nlassert((*it)->_VertexObjectId);
GLuint id = (GLuint) (*it)->_VertexObjectId; GLuint id = (GLuint) (*it)->_VertexObjectId;
#ifdef USE_OPENGLES
nlassert(glIsBuffer(id));
glDeleteBuffers(1, &id);
#else
nlassert(nglIsBufferARB(id)); nlassert(nglIsBufferARB(id));
nglDeleteBuffersARB(1, &id); nglDeleteBuffersARB(1, &id);
#endif
(*it)->_VertexObjectId = 0; (*it)->_VertexObjectId = 0;
(*it)->VB->setLocation(CVertexBuffer::NotResident); (*it)->VB->setLocation(CVertexBuffer::NotResident);
} }
@ -1316,8 +1344,13 @@ CVertexBufferHardARB::~CVertexBufferHardARB()
if (_VertexObjectId) if (_VertexObjectId)
{ {
GLuint id = (GLuint) _VertexObjectId; GLuint id = (GLuint) _VertexObjectId;
#ifdef USE_OPENGLES
nlassert(glIsBuffer(id));
glDeleteBuffers(1, &id);
#else
nlassert(nglIsBufferARB(id)); nlassert(nglIsBufferARB(id));
nglDeleteBuffersARB(1, &id); nglDeleteBuffersARB(1, &id);
#endif
} }
if (_VertexArrayRange) if (_VertexArrayRange)
{ {
@ -1341,7 +1374,8 @@ CVertexBufferHardARB::~CVertexBufferHardARB()
// *************************************************************************** // ***************************************************************************
void *CVertexBufferHardARB::lock() void *CVertexBufferHardARB::lock()
{ {
H_AUTO_OGL(CVertexBufferHardARB_lock) H_AUTO_OGL(CVertexBufferHardARB_lock);
if (_VertexPtr) return _VertexPtr; // already locked if (_VertexPtr) return _VertexPtr; // already locked
if (_Invalid) if (_Invalid)
{ {
@ -1352,7 +1386,13 @@ void *CVertexBufferHardARB::lock()
} }
// recreate a vb // recreate a vb
GLuint vertexBufferID; GLuint vertexBufferID;
#ifdef USE_OPENGLES
glGenBuffers(1, &vertexBufferID);
#else
nglGenBuffersARB(1, &vertexBufferID); nglGenBuffersARB(1, &vertexBufferID);
#endif
if (glGetError() != GL_NO_ERROR) if (glGetError() != GL_NO_ERROR)
{ {
_Driver->incrementResetCounter(); _Driver->incrementResetCounter();
@ -1363,13 +1403,25 @@ void *CVertexBufferHardARB::lock()
switch(_MemType) switch(_MemType)
{ {
case CVertexBuffer::AGPPreferred: case CVertexBuffer::AGPPreferred:
#ifdef USE_OPENGLES
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW);
#else
nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB); nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB);
#endif
break; break;
case CVertexBuffer::StaticPreferred: case CVertexBuffer::StaticPreferred:
if (_Driver->getStaticMemoryToVRAM()) if (_Driver->getStaticMemoryToVRAM())
#ifdef USE_OPENGLES
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW);
#else
nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_STATIC_DRAW_ARB); nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_STATIC_DRAW_ARB);
#endif
else else
#ifdef USE_OPENGLES
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW);
#else
nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB); nglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB);
#endif
break; break;
default: default:
nlassert(0); nlassert(0);
@ -1378,7 +1430,11 @@ void *CVertexBufferHardARB::lock()
if (glGetError() != GL_NO_ERROR) if (glGetError() != GL_NO_ERROR)
{ {
_Driver->incrementResetCounter(); _Driver->incrementResetCounter();
#ifdef USE_OPENGLES
glDeleteBuffers(1, &vertexBufferID);
#else
nglDeleteBuffersARB(1, &vertexBufferID); nglDeleteBuffersARB(1, &vertexBufferID);
#endif
return &_DummyVB[0];; return &_DummyVB[0];;
} }
_VertexObjectId = vertexBufferID; _VertexObjectId = vertexBufferID;