From 7c024fb47913252d2640c9f2ae83f1a9585b4a7d Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 27 Oct 2012 16:27:13 +0200 Subject: [PATCH] Changed: Simplify OpenGL ES driver by using some aliases --- .../src/3d/driver/opengl/driver_opengl.cpp | 7 +-- .../driver/opengl/driver_opengl_extension.cpp | 26 ++++------ .../opengl/driver_opengl_extension_def.h | 14 ++++++ .../driver/opengl/driver_opengl_material.cpp | 31 +++--------- .../3d/driver/opengl/driver_opengl_states.cpp | 31 ++++-------- .../driver/opengl/driver_opengl_texture.cpp | 50 ++----------------- 6 files changed, 46 insertions(+), 113 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index b4cff6121..e8cae3530 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1337,11 +1337,7 @@ void CDriverGL::copyFrameBufferToTexture(ITexture *tex, { if(_Extensions.ARBTextureCubeMap) { -#ifdef USE_OPENGLES - glBindTexture(GL_TEXTURE_CUBE_MAP_OES, gltext->ID); -#else glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, gltext->ID); -#endif glCopyTexSubImage2D(NLCubeFaceToGLCubeFace[cubeFace], level, offsetx, offsety, x, y, width, height); } } @@ -2626,11 +2622,10 @@ void CDriverGL::checkTextureOn() const GLboolean flagCM; GLboolean flagTR; glGetBooleanv(GL_TEXTURE_2D, &flag2D); + glGetBooleanv(GL_TEXTURE_CUBE_MAP_ARB, &flagCM); #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_RECTANGLE_NV, &flagTR); #endif switch(dgs.getTextureMode()) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp index 770e273dc..d38ff8f51 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp @@ -628,7 +628,7 @@ static bool setupARBTextureNonPowerOfTwo(const char *glext) { H_AUTO_OGL(setupARBTextureCompression); -#ifndef USE_OPENGL_ES +#ifndef USE_OPENGLES CHECK_EXT("GL_ARB_texture_non_power_of_two"); #endif @@ -805,20 +805,20 @@ static bool setupARBTextureCubeMap(const char *glext) #ifdef USE_OPENGLES CHECK_EXT("OES_texture_cube_map"); + + CHECK_ADDRESS(NEL_PFNGLTEXGENFOESPROC, glTexGenfOES); + CHECK_ADDRESS(NEL_PFNGLTEXGENFVOESPROC, glTexGenfvOES); + CHECK_ADDRESS(NEL_PFNGLTEXGENIOESPROC, glTexGeniOES); + CHECK_ADDRESS(NEL_PFNGLTEXGENIVOESPROC, glTexGenivOES); + CHECK_ADDRESS(NEL_PFNGLTEXGENXOESPROC, glTexGenxOES); + CHECK_ADDRESS(NEL_PFNGLTEXGENXVOESPROC, glTexGenxvOES); + CHECK_ADDRESS(NEL_PFNGLGETTEXGENFVOESPROC, glGetTexGenfvOES); + CHECK_ADDRESS(NEL_PFNGLGETTEXGENIVOESPROC, glGetTexGenivOES); + CHECK_ADDRESS(NEL_PFNGLGETTEXGENXVOESPROC, glGetTexGenxvOES); #else CHECK_EXT("GL_ARB_texture_cube_map"); #endif -// CHECK_ADDRESS(NEL_PFNGLTEXGENFOESPROC, glTexGenfOES); -// CHECK_ADDRESS(NEL_PFNGLTEXGENFVOESPROC, glTexGenfvOES); -// CHECK_ADDRESS(NEL_PFNGLTEXGENIOESPROC, glTexGeniOES); -// CHECK_ADDRESS(NEL_PFNGLTEXGENIVOESPROC, glTexGenivOES); -// CHECK_ADDRESS(NEL_PFNGLTEXGENXOESPROC, glTexGenxOES); -// CHECK_ADDRESS(NEL_PFNGLTEXGENXVOESPROC, glTexGenxvOES); -// CHECK_ADDRESS(NEL_PFNGLGETTEXGENFVOESPROC, glGetTexGenfvOES); -// CHECK_ADDRESS(NEL_PFNGLGETTEXGENIVOESPROC, glGetTexGenivOES); -// CHECK_ADDRESS(NEL_PFNGLGETTEXGENXVOESPROC, glGetTexGenxvOES); - return true; } @@ -1499,11 +1499,7 @@ void registerGlExtensions(CGlExtensions &ext) ext.ARBMultiTexture= setupARBMultiTexture(glext); if(ext.ARBMultiTexture) { -#ifdef USE_OPENGLES - glGetIntegerv(GL_MAX_TEXTURE_UNITS, &ntext); -#else glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &ntext); -#endif // We could have more than IDRV_MAT_MAXTEXTURES but the interface only // support IDRV_MAT_MAXTEXTURES texture stages so take min ext.NbTextureStages= (ntext<((GLint)IDRV_MAT_MAXTEXTURES)?ntext:IDRV_MAT_MAXTEXTURES); diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_extension_def.h b/code/nel/src/3d/driver/opengl/driver_opengl_extension_def.h index d8862ff14..a9df7c4bc 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_extension_def.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl_extension_def.h @@ -63,6 +63,20 @@ typedef void (APIENTRY * NEL_PFNGLGETTEXGENFVOESPROC) (GLenum coord, GLenum pnam typedef void (APIENTRY * NEL_PFNGLGETTEXGENIVOESPROC) (GLenum coord, GLenum pname, GLint *params); typedef void (APIENTRY * NEL_PFNGLGETTEXGENXVOESPROC) (GLenum coord, GLenum pname, GLfixed *params); +#define GL_MULTISAMPLE_ARB GL_MULTISAMPLE +#define GL_TEXTURE_CUBE_MAP_ARB GL_TEXTURE_CUBE_MAP_OES +#define GL_NONE 0 +#define GL_MAX_TEXTURE_UNITS_ARB GL_MAX_TEXTURE_UNITS +#define GL_REFLECTION_MAP_ARB GL_REFLECTION_MAP_OES +#define GL_RGB_SCALE_EXT GL_RGB_SCALE +#define GL_REFLECTION_MAP_ARB GL_REFLECTION_MAP_OES +#define GL_PREVIOUS_EXT GL_PREVIOUS +#define GL_PRIMARY_COLOR_EXT GL_PRIMARY_COLOR +#define GL_CONSTANT_EXT GL_CONSTANT +#define GL_ADD_SIGNED_EXT GL_ADD_SIGNED +#define GL_INTERPOLATE_EXT GL_INTERPOLATE +#define GL_BUMP_ENVMAP_ATI GL_INTERPOLATE + #else // *************************************************************************** diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_material.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_material.cpp index ff73eb480..6d9dbb247 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_material.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_material.cpp @@ -87,10 +87,9 @@ static inline void convTexAddr(ITexture *tex, CMaterial::TTexAddressingMode mode nlassert(mode < CMaterial::TexAddrCount); static const GLenum glTex2dAddrModesNV[] = { -#ifdef USE_OPENGLES - 0, GL_TEXTURE_2D -#else - GL_NONE, GL_TEXTURE_2D, GL_PASS_THROUGH_NV, GL_CULL_FRAGMENT_NV, + GL_NONE, GL_TEXTURE_2D, +#ifndef USE_OPENGLES + GL_PASS_THROUGH_NV, GL_CULL_FRAGMENT_NV, GL_OFFSET_TEXTURE_2D_NV, GL_OFFSET_TEXTURE_2D_SCALE_NV, GL_DEPENDENT_AR_TEXTURE_2D_NV, GL_DEPENDENT_GB_TEXTURE_2D_NV, GL_DOT_PRODUCT_NV, GL_DOT_PRODUCT_TEXTURE_2D_NV, GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV, @@ -101,10 +100,9 @@ static inline void convTexAddr(ITexture *tex, CMaterial::TTexAddressingMode mode static const GLenum glTexCubeAddrModesNV[] = { -#ifdef USE_OPENGLES - 0, GL_TEXTURE_CUBE_MAP_OES -#else - GL_NONE, GL_TEXTURE_CUBE_MAP_ARB, GL_PASS_THROUGH_NV, GL_CULL_FRAGMENT_NV, + GL_NONE, GL_TEXTURE_CUBE_MAP_ARB, +#ifndef USE_OPENGLES + GL_PASS_THROUGH_NV, GL_CULL_FRAGMENT_NV, GL_OFFSET_TEXTURE_2D_NV, GL_OFFSET_TEXTURE_2D_SCALE_NV, GL_DEPENDENT_AR_TEXTURE_2D_NV, GL_DEPENDENT_GB_TEXTURE_2D_NV, GL_DOT_PRODUCT_NV, GL_DOT_PRODUCT_TEXTURE_2D_NV, GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV, @@ -147,11 +145,7 @@ void CDriverGL::setTextureEnvFunction(uint stage, CMaterial& mat) { // Cubic or normal ? if (text->isTextureCube ()) -#ifdef USE_OPENGLES - _DriverGLStates.setTexGenMode (stage, GL_REFLECTION_MAP_OES); -#else _DriverGLStates.setTexGenMode (stage, GL_REFLECTION_MAP_ARB); -#endif else #ifdef USE_OPENGLES _DriverGLStates.setTexGenMode (stage, GL_TEXTURE_CUBE_MAP_OES); @@ -974,11 +968,7 @@ void CDriverGL::setupLightMapPass(uint pass) if (mat._LightMapsMulx2) { // Multiply x 2 -#ifdef USE_OPENGLES - glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, 2); -#else glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2); -#endif } } } @@ -1087,11 +1077,7 @@ void CDriverGL::endLightMapMultiPass() for (uint32 i = 0; i < (_NLightMapPerPass+1); ++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); -#endif } } } @@ -1165,12 +1151,7 @@ void CDriverGL::setupSpecularBegin() // todo hulud remove // _DriverGLStates.setTextureMode(CDriverGLStates::TextureCubeMap); - -#ifdef USE_OPENGLES - _DriverGLStates.setTexGenMode (1, GL_REFLECTION_MAP_OES); -#else _DriverGLStates.setTexGenMode (1, GL_REFLECTION_MAP_ARB); -#endif // setup the good matrix for stage 1. glMatrixMode(GL_TEXTURE); diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_states.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_states.cpp index 1d517d0fc..60a0609dc 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_states.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_states.cpp @@ -165,11 +165,9 @@ void CDriverGLStates::forceDefaults(uint nbStages) if(_TextureCubeMapSupported) { -#ifdef USE_OPENGLES - glDisable(GL_TEXTURE_CUBE_MAP_OES); - glDisable(GL_TEXTURE_GEN_STR_OES); -#else glDisable(GL_TEXTURE_CUBE_MAP_ARB); +#ifdef USE_OPENGLES + glDisable(GL_TEXTURE_GEN_STR_OES); #endif } @@ -393,6 +391,7 @@ void CDriverGLStates::enableMultisample(bool enable) { // new state. _CurMultisample= enable; + // Setup GLState. if(_CurMultisample) glEnable(GL_MULTISAMPLE_ARB); @@ -686,7 +685,7 @@ void CDriverGLStates::setTexGenMode (uint stage, GLint mode) else { #ifdef USE_OPENGLES -// nglTexGeniOES(GL_TEXTURE_GEN_STR_OES, GL_TEXTURE_GEN_MODE_OES, mode); + nglTexGeniOES(GL_TEXTURE_GEN_STR_OES, GL_TEXTURE_GEN_MODE_OES, mode); #else glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, mode); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, mode); @@ -702,8 +701,8 @@ void CDriverGLStates::setTexGenMode (uint stage, GLint mode) #ifdef USE_OPENGLES // if(mode==GL_OBJECT_LINEAR || mode==GL_EYE_LINEAR) // { - nglTexGeniOES(GL_TEXTURE_GEN_STR_OES, GL_TEXTURE_GEN_MODE_OES, mode); - glEnable(GL_TEXTURE_GEN_STR_OES); +// nglTexGeniOES(GL_TEXTURE_GEN_STR_OES, GL_TEXTURE_GEN_MODE_OES, mode); +// glEnable(GL_TEXTURE_GEN_STR_OES); // } // else // { @@ -742,11 +741,7 @@ 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 @@ -789,11 +784,7 @@ 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 { @@ -823,11 +814,7 @@ void CDriverGLStates::setTextureMode(TTextureMode texMode) { if(_TextureCubeMapSupported) { -#ifdef USE_OPENGLES - glEnable(GL_TEXTURE_CUBE_MAP_OES); -#else glEnable(GL_TEXTURE_CUBE_MAP_ARB); -#endif } else { @@ -872,11 +859,11 @@ void CDriverGLStates::forceActiveTextureARB(uint stage) _CurrentActiveTextureARB= stage; } - // *************************************************************************** void CDriverGLStates::enableVertexArray(bool enable) { - H_AUTO_OGL(CDriverGLStates_enableVertexArray) + H_AUTO_OGL(CDriverGLStates_enableVertexArray); + if(_VertexArrayEnabled != enable) { if(enable) @@ -1038,7 +1025,7 @@ void CDriverGLStates::enableVertexAttribArrayARB(uint glIndex,bool enable) // *************************************************************************** void CDriverGLStates::enableVertexAttribArrayForEXTVertexShader(uint glIndex, bool enable, uint *variants) { - H_AUTO_OGL(CDriverGLStates_enableVertexAttribArrayForEXTVertexShader) + H_AUTO_OGL(CDriverGLStates_enableVertexAttribArrayForEXTVertexShader); if(_VertexAttribArrayEnabled[glIndex] != enable) { diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp index f0aab8938..3e11f5651 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp @@ -781,11 +781,7 @@ void CDriverGL::bindTextureWithMode(ITexture &tex) { _DriverGLStates.setTextureMode(CDriverGLStates::TextureCubeMap); // Bind this texture -#ifdef USE_OPENGLES - glBindTexture(GL_TEXTURE_CUBE_MAP_OES, gltext->ID); -#else glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, gltext->ID); -#endif } } else @@ -820,19 +816,13 @@ void CDriverGL::setupTextureBasicParameters(ITexture &tex) { if (_Extensions.ARBTextureCubeMap) { -#ifdef USE_OPENGLES - glTexParameteri(GL_TEXTURE_CUBE_MAP_OES,GL_TEXTURE_WRAP_S, translateWrapToGl(ITexture::Clamp, _Extensions)); - glTexParameteri(GL_TEXTURE_CUBE_MAP_OES,GL_TEXTURE_WRAP_T, translateWrapToGl(ITexture::Clamp, _Extensions)); -// glTexParameteri(GL_TEXTURE_CUBE_MAP_OES,GL_TEXTURE_WRAP_R, translateWrapToGl(ITexture::Clamp, _Extensions)); - glTexParameteri(GL_TEXTURE_CUBE_MAP_OES,GL_TEXTURE_MAG_FILTER, translateMagFilterToGl(gltext)); - glTexParameteri(GL_TEXTURE_CUBE_MAP_OES,GL_TEXTURE_MIN_FILTER, translateMinFilterToGl(gltext)); -#else glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_WRAP_S, translateWrapToGl(ITexture::Clamp, _Extensions)); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_WRAP_T, translateWrapToGl(ITexture::Clamp, _Extensions)); +#ifndef USE_OPENGLES glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_WRAP_R, translateWrapToGl(ITexture::Clamp, _Extensions)); +#endif glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_MAG_FILTER, translateMagFilterToGl(gltext)); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_MIN_FILTER, translateMinFilterToGl(gltext)); -#endif } } else @@ -1516,31 +1506,19 @@ bool CDriverGL::activateTexture(uint stage, ITexture *tex) _CurrentTextureInfoGL[stage]= gltext; // setup this texture -#ifdef USE_OPENGLES - glBindTexture(GL_TEXTURE_CUBE_MAP_OES, gltext->ID); -#else glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, gltext->ID); -#endif // Change parameters of texture, if necessary. //============================================ if(gltext->MagFilter!= tex->getMagFilter()) { gltext->MagFilter= tex->getMagFilter(); -#ifdef USE_OPENGLES - glTexParameteri(GL_TEXTURE_CUBE_MAP_OES,GL_TEXTURE_MAG_FILTER, translateMagFilterToGl(gltext)); -#else glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_MAG_FILTER, translateMagFilterToGl(gltext)); -#endif } if(gltext->MinFilter!= tex->getMinFilter()) { gltext->MinFilter= tex->getMinFilter(); -#ifdef USE_OPENGLES - glTexParameteri(GL_TEXTURE_CUBE_MAP_OES,GL_TEXTURE_MIN_FILTER, translateMinFilterToGl(gltext)); -#else glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_MIN_FILTER, translateMinFilterToGl(gltext)); -#endif } } } @@ -1617,34 +1595,16 @@ bool CDriverGL::activateTexture(uint stage, ITexture *tex) // This maps the CMaterial::TTexOperator -static const GLenum OperatorLUT[9]= { GL_REPLACE, GL_MODULATE, GL_ADD, -#ifdef USE_OPENGLES - GL_ADD_SIGNED, GL_INTERPOLATE, GL_INTERPOLATE, GL_INTERPOLATE, GL_INTERPOLATE, GL_INTERPOLATE -#else - GL_ADD_SIGNED_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_BUMP_ENVMAP_ATI -#endif -}; +static const GLenum OperatorLUT[9]= { GL_REPLACE, GL_MODULATE, GL_ADD, GL_ADD_SIGNED_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_BUMP_ENVMAP_ATI }; // This maps the CMaterial::TTexSource -static const GLenum SourceLUT[4]= { GL_TEXTURE, -#ifdef USE_OPENGLES - GL_PREVIOUS, GL_PRIMARY_COLOR, GL_CONSTANT -#else - GL_PREVIOUS_EXT, GL_PRIMARY_COLOR_EXT, GL_CONSTANT_EXT -#endif -}; +static const GLenum SourceLUT[4]= { GL_TEXTURE, GL_PREVIOUS_EXT, GL_PRIMARY_COLOR_EXT, GL_CONSTANT_EXT }; // This maps the CMaterial::TTexOperand static const GLenum OperandLUT[4]= { GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }; // This maps the CMaterial::TTexOperator, used for openGL Arg2 setup. -static const GLenum InterpolateSrcLUT[8]= { GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, -#ifdef USE_OPENGLES - GL_PREVIOUS, GL_PRIMARY_COLOR, GL_CONSTANT -#else - GL_PREVIOUS_EXT, GL_PRIMARY_COLOR_EXT, GL_CONSTANT_EXT -#endif -}; +static const GLenum InterpolateSrcLUT[8]= { GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, GL_PREVIOUS_EXT, GL_PRIMARY_COLOR_EXT, GL_CONSTANT_EXT }; #ifndef USE_OPENGLES