Changed: #1275 Create an OpenGL ES driver

This commit is contained in:
kervala 2011-05-01 18:27:05 +02:00
parent ea39e6ac7a
commit ae9de611f6
5 changed files with 169 additions and 16 deletions

View file

@ -139,8 +139,13 @@ void CDriverGL::setLightInternal(uint8 num, const CLight& light)
else
{
// Deactivate spot properties
#ifdef USE_OPENGLES
glLightf (lightNum, GL_SPOT_CUTOFF, 180.f);
glLightf (lightNum, GL_SPOT_EXPONENT, 0.f);
#else
glLighti (lightNum, GL_SPOT_CUTOFF, 180);
glLighti (lightNum, GL_SPOT_EXPONENT, 0);
#endif
}
// Flag this light as dirt.

View file

@ -15,24 +15,35 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdopengl.h"
#include "driver_opengl.h"
namespace NL3D {
// ***************************************************************************
void CDriverGL::setFrustum(float left, float right, float bottom, float top, float znear, float zfar, bool perspective)
{
H_AUTO_OGL(CDriverGL_setFrustum)
H_AUTO_OGL(CDriverGL_setFrustum);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (perspective)
{
#ifdef USE_OPENGLES
glFrustumf(left,right,bottom,top,znear,zfar);
#else
glFrustum(left,right,bottom,top,znear,zfar);
#endif
}
else
{
#ifdef USE_OPENGLES
glOrthof(left,right,bottom,top,znear,zfar);
#else
glOrtho(left,right,bottom,top,znear,zfar);
#endif
}
_ProjMatDirty = true;
// Backup znear and zfar for zbias setup

View file

@ -144,33 +144,62 @@ void CDriverGLStates::forceDefaults(uint nbStages)
for(stage=0;stage<nbStages; stage++)
{
// disable texturing.
#ifdef USE_OPENGLES
glActiveTexture(GL_TEXTURE0+stage);
#else
nglActiveTextureARB(GL_TEXTURE0_ARB+stage);
#endif
glDisable(GL_TEXTURE_2D);
if(_TextureCubeMapSupported)
{
#ifdef USE_OPENGLES
glDisable(GL_TEXTURE_CUBE_MAP_OES);
glDisable(GL_TEXTURE_GEN_STR_OES);
#else
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
if(_TextureRectangleSupported)
glDisable(GL_TEXTURE_RECTANGLE_NV);
#endif
}
_TextureMode[stage]= TextureDisabled;
// Tex gen init
_TexGenMode[stage] = 0;
glDisable( GL_TEXTURE_GEN_S );
glDisable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
#ifndef USE_OPENGLES
if(_TextureRectangleSupported)
glDisable(GL_TEXTURE_RECTANGLE_NV);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_Q);
#endif
}
// ActiveTexture current texture to 0.
#ifdef USE_OPENGLES
glActiveTexture(GL_TEXTURE0);
glClientActiveTexture(GL_TEXTURE0);
#else
nglActiveTextureARB(GL_TEXTURE0_ARB);
_CurrentActiveTextureARB= 0;
nglClientActiveTextureARB(GL_TEXTURE0_ARB);
#endif
_CurrentActiveTextureARB= 0;
_CurrentClientActiveTextureARB= 0;
// Depth range
_DepthRangeNear = 0.f;
_DepthRangeFar = 1.f;
_ZBias = 0.f;
#ifdef USE_OPENGLES
glDepthRangef (0.f, 1.f);
#else
glDepthRange (0, 1);
#endif
// Cull order
_CullMode = CCW;
@ -536,7 +565,9 @@ void CDriverGLStates::setVertexColorLighted(bool enable)
if (_VertexColorLighted)
{
glEnable (GL_COLOR_MATERIAL);
#ifndef USE_OPENGLES
glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE);
#endif
}
else
{
@ -558,9 +589,15 @@ void CDriverGLStates::setVertexColorLighted(bool enable)
// ***************************************************************************
void CDriverGLStates::updateDepthRange()
{
H_AUTO_OGL(CDriverGLStates_updateDepthRange)
H_AUTO_OGL(CDriverGLStates_updateDepthRange);
float delta = _ZBias * (_DepthRangeFar - _DepthRangeNear);
#ifdef USE_OPENGLES
glDepthRangef(delta + _DepthRangeNear, delta + _DepthRangeFar);
#else
glDepthRange(delta + _DepthRangeNear, delta + _DepthRangeFar);
#endif
}
// ***************************************************************************
@ -631,9 +668,13 @@ void CDriverGLStates::setTexGenMode (uint stage, GLint mode)
glDisable( GL_TEXTURE_GEN_Q );
}
// Enable All.
#ifdef USE_OPENGLES
glEnable(GL_TEXTURE_GEN_STR_OES);
#else
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
#endif
}
}
}
@ -649,12 +690,19 @@ void CDriverGLStates::resetTextureMode()
if (_TextureCubeMapSupported)
{
#ifdef USE_OPENGLES
glDisable(GL_TEXTURE_CUBE_MAP_OES);
#else
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
#endif
}
#ifndef USE_OPENGLES
if (_TextureRectangleSupported)
{
glDisable(GL_TEXTURE_RECTANGLE_NV);
}
#endif
_TextureMode[_CurrentActiveTextureARB]= TextureDisabled;
}
@ -674,11 +722,13 @@ void CDriverGLStates::setTextureMode(TTextureMode texMode)
}
else if(oldTexMode == TextureRect)
{
#ifndef USE_OPENGLES
if(_TextureRectangleSupported)
{
glDisable(GL_TEXTURE_RECTANGLE_NV);
}
else
#endif
{
glDisable(GL_TEXTURE_2D);
}
@ -687,7 +737,11 @@ void CDriverGLStates::setTextureMode(TTextureMode texMode)
{
if(_TextureCubeMapSupported)
{
#ifdef USE_OPENGLES
glDisable(GL_TEXTURE_CUBE_MAP_OES);
#else
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
#endif
}
else
{
@ -702,24 +756,30 @@ void CDriverGLStates::setTextureMode(TTextureMode texMode)
}
else if(texMode == TextureRect)
{
#ifndef USE_OPENGLES
if(_TextureRectangleSupported)
{
glEnable(GL_TEXTURE_RECTANGLE_NV);
}
else
#endif
{
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
}
}
else if(texMode == TextureCubeMap)
{
if(_TextureCubeMapSupported)
{
#ifdef USE_OPENGLES
glEnable(GL_TEXTURE_CUBE_MAP_OES);
#else
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
#endif
}
else
{
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
}
}
@ -736,8 +796,11 @@ void CDriverGLStates::activeTextureARB(uint stage)
if( _CurrentActiveTextureARB != stage )
{
#ifdef USE_OPENGLES
glActiveTexture(GL_TEXTURE0+stage);
#else
nglActiveTextureARB(GL_TEXTURE0_ARB+stage);
#endif
_CurrentActiveTextureARB= stage;
}
@ -748,7 +811,11 @@ void CDriverGLStates::forceActiveTextureARB(uint stage)
{
H_AUTO_OGL(CDriverGLStates_forceActiveTextureARB);
#ifdef USE_OPENGLES
glActiveTexture(GL_TEXTURE0+stage);
#else
nglActiveTextureARB(GL_TEXTURE0_ARB+stage);
#endif
_CurrentActiveTextureARB= stage;
}
@ -828,12 +895,15 @@ void CDriverGLStates::enableSecondaryColorArray(bool enable)
_SecondaryColorArrayEnabled= enable;
#ifndef USE_OPENGLES
// If disable
if(!enable)
{
// GeForceFx Bug: Must reset Secondary color to 0 (if comes from a VP), else bugs
nglSecondaryColor3ubEXT(0,0,0);
}
#endif
}
}
@ -988,7 +1058,13 @@ void CDriverGLStates::enableFog(uint enable)
void CDriverGLStates::forceBindARBVertexBuffer(uint objectID)
{
H_AUTO_OGL(CDriverGLStates_forceBindARBVertexBuffer)
#ifdef USE_OPENGLES
glBindBuffer(GL_ARRAY_BUFFER, objectID);
#else
nglBindBufferARB(GL_ARRAY_BUFFER_ARB, objectID);
#endif
_CurrARBVertexBuffer = objectID;
}

View file

@ -280,8 +280,12 @@ bool CDriverGL::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines)
}
else
{
#ifdef USE_OPENGLES
nlerror("not available in OpenGL ES 1.0, only use 16 bits indices");
#else
nlassert(_LastIB._Format == CIndexBuffer::Indices32);
glDrawElements(GL_LINES,2*nlines,GL_UNSIGNED_INT,((uint32 *) _LastIB._Values)+firstIndex);
#endif
}
}
}
@ -336,8 +340,12 @@ bool CDriverGL::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris)
}
else
{
#ifdef USE_OPENGLES
nlerror("not available in OpenGL ES 1.0, only use 16 bits indices");
#else
nlassert(_LastIB._Format == CIndexBuffer::Indices32);
glDrawElements(GL_TRIANGLES,3*ntris,GL_UNSIGNED_INT, ((uint32 *) _LastIB._Values)+firstIndex);
#endif
}
}
}
@ -380,8 +388,12 @@ bool CDriverGL::renderSimpleTriangles(uint32 firstTri, uint32 ntris)
}
else
{
#ifdef USE_OPENGLES
nlerror("not available in OpenGL ES 1.0, only use 16 bits indices");
#else
nlassert(_LastIB._Format == CIndexBuffer::Indices32);
glDrawElements(GL_TRIANGLES,3*ntris,GL_UNSIGNED_INT, ((uint32 *) _LastIB._Values)+firstTri);
#endif
}
// Profiling.
@ -608,6 +620,9 @@ bool CDriverGL::renderRawQuads(CMaterial& mat, uint32 startIndex, uint32 numQuad
}
else
{
#ifdef USE_OPENGLES
nlerror("not available in OpenGL ES 1.0, only use 16 bits indices");
#else
// indices fits on 32 bits
GLint indices[QUAD_BATCH_SIZE];
GLint *curr = indices;
@ -625,6 +640,7 @@ bool CDriverGL::renderRawQuads(CMaterial& mat, uint32 startIndex, uint32 numQuad
}
while(curr != end);
glDrawElements(GL_TRIANGLES, 6 * numQuadsToDraw, GL_UNSIGNED_INT, indices);
#endif
}
numLeftQuads -= numQuadsToDraw;
currIndex += 4 * numQuadsToDraw;
@ -665,10 +681,12 @@ void CDriverGL::setupUVPtr(uint stage, CVertexBufferInfo &VB, uint uvId)
// Setup ATI VBHard or std ptr.
switch(VB.VBMode)
{
#ifndef USE_OPENGLES
case CVertexBufferInfo::HwATI:
nglArrayObjectATI(GL_TEXTURE_COORD_ARRAY, numTexCoord, GL_FLOAT, VB.VertexSize, VB.VertexObjectId,
(ptrdiff_t) VB.ValuePtr[CVertexBuffer::TexCoord0+uvId]);
break;
#endif
case CVertexBufferInfo::HwARB:
_DriverGLStates.bindARBVertexBuffer(VB.VertexObjectId);
// with arb buffers, position is relative to the start of the stream
@ -811,6 +829,21 @@ const uint CDriverGL::NumCoordinatesType[CVertexBuffer::NumType]=
// ***************************************************************************
const uint CDriverGL::GLType[CVertexBuffer::NumType]=
{
#ifdef USE_OPENGLES
GL_FLOAT, // Double1
GL_FLOAT, // Float1
GL_SHORT, // Short1
GL_FLOAT, // Double2
GL_FLOAT, // Float2
GL_SHORT, // Short2
GL_FLOAT, // Double3
GL_FLOAT, // Float3
GL_SHORT, // Short3
GL_FLOAT, // Double4
GL_FLOAT, // Float4
GL_SHORT, // Short4
GL_UNSIGNED_BYTE // UChar4
#else
GL_DOUBLE, // Double1
GL_FLOAT, // Float1
GL_SHORT, // Short1
@ -824,6 +857,7 @@ const uint CDriverGL::GLType[CVertexBuffer::NumType]=
GL_FLOAT, // Float4
GL_SHORT, // Short4
GL_UNSIGNED_BYTE // UChar4
#endif
};
// ***************************************************************************
@ -926,6 +960,7 @@ void CDriverGL::setupGlArraysStd(CVertexBufferInfo &vb)
}
}
break;
#ifndef USE_OPENGLES
case CVertexBufferInfo::HwATI:
{
// setup vertex ptr.
@ -963,9 +998,12 @@ void CDriverGL::setupGlArraysStd(CVertexBufferInfo &vb)
nglArrayObjectATI(GL_COLOR_ARRAY, 4, GL_UNSIGNED_BYTE, vb.VertexSize, vb.VertexObjectId, (ptrdiff_t) vb.ValuePtr[CVertexBuffer::PrimaryColor]);
}
else
{
_DriverGLStates.enableColorArray(false);
}
}
break;
#endif
default:
nlassert(0);
break;
@ -1035,7 +1073,9 @@ void CDriverGL::toggleGlArraysForARBVertexProgram()
// If last was a VertexProgram setup, and now it is a standard GL array setup.
if( _LastSetupGLArrayVertexProgram && !isVertexProgramEnabled () )
{
#ifndef USE_OPENGLES
if (_Extensions.ATITextureEnvCombine3)
#endif
{
// fix for ATI : when switching from Vertex Program to fixed Pipe, must clean texture, otherwise texture may be disabled in next render
// (seems to be a driver bug)
@ -1046,12 +1086,16 @@ void CDriverGL::toggleGlArraysForARBVertexProgram()
// activate the texture, or disable texturing if NULL.
activateTexture(stage, NULL);
}
#ifndef USE_OPENGLES
glBegin(GL_QUADS);
glVertex4f(0.f, 0.f, 0.f, 1.f);
glVertex4f(0.f, 0.f, 0.f, 1.f);
glVertex4f(0.f, 0.f, 0.f, 1.f);
glVertex4f(0.f, 0.f, 0.f, 1.f);
glEnd();
#endif
for(uint stage=0 ; stage<inlGetNumTextStages() ; stage++)
{
// activate the texture, or disable texturing if NULL.
@ -1185,7 +1229,9 @@ void CDriverGL::setupGlArraysForNVVertexProgram(CVertexBufferInfo &vb)
{
// Secondary color
_DriverGLStates.enableSecondaryColorArray(true);
nglSecondaryColorPointerEXT(4,GL_UNSIGNED_BYTE, vb.VertexSize, vb.ValuePtr[value]);
#ifndef USE_OPENGLES
nglSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, vb.VertexSize, vb.ValuePtr[value]);
#endif
}
}
else
@ -1199,7 +1245,9 @@ void CDriverGL::setupGlArraysForNVVertexProgram(CVertexBufferInfo &vb)
// Active this value
_DriverGLStates.enableVertexAttribArray(glIndex, true);
#ifndef USE_OPENGLES
nglVertexAttribPointerNV (glIndex, NumCoordinatesType[type], GLType[type], vb.VertexSize, vb.ValuePtr[value]);
#endif
}
}
// Else normal case, can't do anything for other values with UChar4....
@ -1207,7 +1255,9 @@ void CDriverGL::setupGlArraysForNVVertexProgram(CVertexBufferInfo &vb)
{
// Active this value
_DriverGLStates.enableVertexAttribArray(glIndex, true);
#ifndef USE_OPENGLES
nglVertexAttribPointerNV (glIndex, NumCoordinatesType[type], GLType[type], vb.VertexSize, vb.ValuePtr[value]);
#endif
}
}
else

View file

@ -1420,7 +1420,8 @@ void *CVertexBufferHardARB::lock()
// ***************************************************************************
void CVertexBufferHardARB::unlock()
{
H_AUTO_OGL(CVertexBufferHardARB_unlock)
H_AUTO_OGL(CVertexBufferHardARB_unlock);
_VertexPtr = NULL;
if (_Invalid) return;
if (!_VertexObjectId) return;
@ -1434,7 +1435,17 @@ void CVertexBufferHardARB::unlock()
#ifdef NL_DEBUG
_Unmapping = true;
#endif
GLboolean unmapOk = nglUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
GLboolean unmapOk = false;
#ifdef USE_OPENGLES
if (_Driver->_Extensions.OESMapBuffer)
{
unmapOk = nglUnmapBufferOES(GL_ARRAY_BUFFER);
}
#else
unmapOk = nglUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
#endif
#ifdef NL_DEBUG
_Unmapping = false;
#endif