From 997a231bff84585733cea15210fb8ca30a7b0ab6 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 1 Sep 2013 11:01:40 +0200 Subject: [PATCH] Conditionally build some deprecated functions. Also little adjustment to the shader texenv generator. --HG-- branch : gsoc2013-dfighter --- .../OpenGL3/driver_glsl_shader_generator.cpp | 51 ++++++++++++------- .../src/3d/driver/OpenGL3/driver_opengl.cpp | 13 +++++ .../nel/src/3d/driver/OpenGL3/driver_opengl.h | 2 + .../driver/OpenGL3/driver_opengl_material.cpp | 42 ++++++++------- .../driver/OpenGL3/driver_opengl_program.cpp | 8 ++- .../driver/OpenGL3/driver_opengl_states.cpp | 4 ++ .../driver/OpenGL3/driver_opengl_vertex.cpp | 4 ++ .../OpenGL3/driver_opengl_vertex_program.cpp | 2 + 8 files changed, 88 insertions(+), 38 deletions(-) diff --git a/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp b/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp index 52b30cf7c..5b9fb26c7 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp @@ -458,6 +458,7 @@ namespace NL3D addDiffuse(); + bool textures = false; sampler = 0; for( int i = TexCoord0; i < NumOffsets; i++ ) { @@ -466,13 +467,20 @@ namespace NL3D ss << "vec4 texel" << sampler; ss << " = texture2D( sampler" << sampler << ","; ss << attribNames[ i ] << " );" << std::endl; + textures = true; } sampler++; } - ss << "vec4 texel = vec4( 0.0, 0.0, 0.0, 1.0 );" << std::endl; + if( textures ) + ss << "vec4 texel = vec4( 1.0, 1.0, 1.0, 1.0 );" << std::endl; + else + ss << "vec4 texel = vec4( 0.5, 0.5, 0.5, 1.0 );" << std::endl; generateTexEnv(); + + // Alpha test + //ss << "if( texel.a <= 0.5 ) discard;" << std::endl; ss << "fragColor = texel;" << std::endl; ss << "}" << std::endl; @@ -514,33 +522,37 @@ namespace NL3D { buildArg( stage, 0, false, arg0 ); buildArg( stage, 1, false, arg1 ); - ss << "texel.rgb = " << arg0 << ";" << std::endl; - ss << "texel.rgb = texel.rgb * " << arg1 << ";" << std::endl; + ss << "texel.rgb = " << arg0 << " * " << arg1 << ";" << std::endl; + //ss << "texel.rgb = " << arg0 << ";" << std::endl; + //ss << "texel.rgb = texel.rgb * " << arg1 << ";" << std::endl; } break; case CMaterial::Add: buildArg( stage, 0, false, arg0 ); buildArg( stage, 1, false, arg1 ); - ss << "texel.rgb = " << arg0 << ";" << std::endl; - ss << "texel.rgb = texel.rgb + " << arg1 << ";" << std::endl; + ss << "texel.rgb = " << arg0 << " + " << arg1 << ";" << std::endl; + //ss << "texel.rgb = " << arg0 << ";" << std::endl; + //ss << "texel.rgb = texel.rgb + " << arg1 << ";" << std::endl; break; case CMaterial::AddSigned: buildArg( stage, 0, false, arg0 ); buildArg( stage, 1, false, arg1 ); - ss << "texel.rgb = " << arg0 << ";" << std::endl; - ss << "texel.rgb = texel.rgb + " << arg1 << ";" << std::endl; - ss << "texel.rgb = texel.rgb - vec3( 0.5, 0.5, 0.5 );" << std::endl; + ss << "texel.rgb = " << arg0 << " + " << arg1 << " - vec3( 0.5, 0.5, 0.5 );" << std::endl; + //ss << "texel.rgb = " << arg0 << ";" << std::endl; + //ss << "texel.rgb = texel.rgb + " << arg1 << ";" << std::endl; + //ss << "texel.rgb = texel.rgb - vec3( 0.5, 0.5, 0.5 );" << std::endl; break; case CMaterial::Mad: buildArg( stage, 0, false, arg0 ); buildArg( stage, 1, false, arg1 ); buildArg( stage, 2, false, arg2 ); - ss << "texel.rgb = " << arg0 << ";" << std::endl; - ss << "texel.rgb = texel.rgb * " << arg1 << ";" << std::endl; - ss << "texel.rgb = texel.rgb + " << arg2 << ";" << std::endl; + ss << "texel.rgb = " << arg0 << " * " << arg1 << " + " << arg2 << ";" << std::endl; + //ss << "texel.rgb = " << arg0 << ";" << std::endl; + //ss << "texel.rgb = texel.rgb * " << arg1 << ";" << std::endl; + //ss << "texel.rgb = texel.rgb + " << arg2 << ";" << std::endl; break; case CMaterial::InterpolateTexture: @@ -614,24 +626,27 @@ namespace NL3D { buildArg( stage, 0, true, arg0 ); buildArg( stage, 1, true, arg1 ); - ss << "texel.a = " << arg0 << ";" << std::endl; - ss << "texel.a = texel.a * " << arg1 << ";" << std::endl; + ss << "texel.a = " << arg0 << " * " << arg1 << ";" << std::endl; + //ss << "texel.a = " << arg0 << ";" << std::endl; + //ss << "texel.a = texel.a * " << arg1 << ";" << std::endl; } break; case CMaterial::Add: buildArg( stage, 0, true, arg0 ); buildArg( stage, 1, true, arg1 ); - ss << "texel.a = " << arg0 << ";" << std::endl; - ss << "texel.a = texel.a + " << arg1 << ";" << std::endl; + ss << "texel.a = " << arg0 << " + " << arg1 << ";" << std::endl; + //ss << "texel.a = " << arg0 << ";" << std::endl; + //ss << "texel.a = texel.a + " << arg1 << ";" << std::endl; break; case CMaterial::AddSigned: buildArg( stage, 0, true, arg0 ); buildArg( stage, 1, true, arg1 ); - ss << "texel.rgb = " << arg0 << ";" << std::endl; - ss << "texel.rgb = texel.rgb + " << arg1 << ";" << std::endl; - ss << "texel.rgb = texel.rgb - vec3( 0.5, 0.5, 0.5 );" << std::endl; + ss << "texel.a = " << arg0 << " * " << arg1 << " - vec3( 0.5, 0.5, 0.5 );" << std::endl; + //ss << "texel.rgb = " << arg0 << ";" << std::endl; + //ss << "texel.rgb = texel.rgb + " << arg1 << ";" << std::endl; + //ss << "texel.rgb = texel.rgb - vec3( 0.5, 0.5, 0.5 );" << std::endl; break; case CMaterial::Mad: diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp index 8212e5f7f..73375b2e1 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp @@ -410,11 +410,13 @@ bool CDriverGL3::setupDisplay() // Init OpenGL/Driver defaults. //============================= glViewport(0,0,_CurrentMode.Width,_CurrentMode.Height); +#ifndef GLSL glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,_CurrentMode.Width,_CurrentMode.Height,0,-1.0f,1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); +#endif glDisable(GL_AUTO_NORMAL); glDisable(GL_COLOR_MATERIAL); glEnable(GL_DITHER); @@ -437,10 +439,17 @@ bool CDriverGL3::setupDisplay() // Be always in EXTSeparateSpecularColor. if(_Extensions.EXTSeparateSpecularColor) { +#ifndef GLSL glLightModeli((GLenum)GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT); +#endif } +#ifndef GLSL _VertexProgramEnabled= false; +#else + _VertexProgramEnabled = true; +#endif + _LastSetupGLArrayVertexProgram= false; // Init VertexArrayRange according to supported extenstion. @@ -477,8 +486,10 @@ bool CDriverGL3::setupDisplay() // init default env. CMaterial::CTexEnv env; // envmode init to default. env.ConstantColor.set(255,255,255,255); +#ifndef GLSL forceActivateTexEnvMode(stage, env); forceActivateTexEnvColor(stage, env); +#endif // Not special TexEnv. _CurrentTexEnvSpecial[stage]= TexEnvSpecialDisabled; @@ -486,6 +497,7 @@ bool CDriverGL3::setupDisplay() // set All TexGen by default to identity matrix (prefer use the textureMatrix scheme) _DriverGLStates.activeTextureARB(stage); +#ifndef GLSL GLfloat params[4]; params[0]=1; params[1]=0; params[2]=0; params[3]=0; glTexGenfv(GL_S, GL_OBJECT_PLANE, params); @@ -499,6 +511,7 @@ bool CDriverGL3::setupDisplay() params[0]=0; params[1]=0; params[2]=0; params[3]=1; glTexGenfv(GL_Q, GL_OBJECT_PLANE, params); glTexGenfv(GL_Q, GL_EYE_PLANE, params); +#endif } _PPLExponent = 1.f; diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h index ea420d546..d40713bba 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h @@ -19,6 +19,8 @@ #include "nel/misc/types_nl.h" +#define GLSL + //#define NL_PROFILE_DRIVER_OGL #ifdef NL_PROFILE_DRIVER_OGL # define H_AUTO_OGL(label) H_AUTO(label) diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp index 02a4ab511..005202053 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp @@ -377,9 +377,11 @@ bool CDriverGL3::setupMaterial(CMaterial& mat) // activate the texture, or disable texturing if NULL. activateTexture(stage,text); +#ifndef GLSL // If texture not NULL, Change texture env function. //================================================== setTextureEnvFunction(stage, mat); +#endif } } @@ -429,6 +431,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat) //===================== // Light Part. +#ifndef GLSL _DriverGLStates.enableLighting(mat.getFlags()&IDRV_MAT_LIGHTING); if(mat.getFlags()&IDRV_MAT_LIGHTING) { @@ -448,6 +451,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat) _DriverGLStates.setVertexColorLighted(false); } + // Fog Part. //================= @@ -462,6 +466,8 @@ bool CDriverGL3::setupMaterial(CMaterial& mat) _DriverGLStates.enableFog(_FogEnabled); } +#endif + _CurrentMaterial=&mat; } @@ -577,28 +583,28 @@ void CDriverGL3::endMultiPass() } } - const char *samplers[ 4 ] = - { - "sampler0", - "sampler1", - "sampler2", - "sampler3" + const char *samplers[ 4 ] = + { + "sampler0", + "sampler1", + "sampler2", + "sampler3" }; void CDriverGL3::setupNormalPass() { - const CMaterial &mat = *_CurrentMaterial; - - for( int i = 0; i < 4; i++ ) - { - ITexture *t = mat.getTexture( i ); - if( t == NULL ) - continue; - - int index = getUniformLocation( samplers[ i ] ); - if( index == -1 ) - continue; - + const CMaterial &mat = *_CurrentMaterial; + + for( int i = 0; i < 4; i++ ) + { + ITexture *t = mat.getTexture( i ); + if( t == NULL ) + continue; + + int index = getUniformLocation( samplers[ i ] ); + if( index == -1 ) + continue; + setUniform1i( index, i ); } } diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp index b3d00e646..64d0a546e 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp @@ -12,7 +12,9 @@ namespace NL3D { if( !program ) { +#ifndef GLSL _VertexProgramEnabled = false; +#endif currentProgram = NULL; return true; } @@ -124,8 +126,6 @@ namespace NL3D if( !setupProgram( mat ) ) return false; - //glDrawArrays( GL_TRIANGLES, startIndex * 3, numTris * 3 ); - if( numTris ) { if (_LastIB._Format == CIndexBuffer::Indices16) @@ -160,6 +160,7 @@ namespace NL3D shaderGenerator->generateVS( vs ); shaderGenerator->generatePS( ps ); +#ifdef GLSL vp = createVertexProgram(); std::string log; @@ -213,6 +214,7 @@ namespace NL3D setupNormalPass(); break; } +#endif return true; } @@ -224,7 +226,9 @@ namespace NL3D vp = NULL; pp = NULL; currentProgram = NULL; +#ifndef GLSL _VertexProgramEnabled = false; +#endif } } diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.cpp index 75a16ab18..3badba9f9 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.cpp @@ -120,7 +120,9 @@ void CDriverGLStates3::forceDefaults(uint nbStages) glStencilFunc(_CurStencilFunc, _CurStencilRef, _CurStencilMask); glStencilOp(_CurStencilOpFail, _CurStencilOpZFail, _CurStencilOpZPass); glStencilMask(_CurStencilWriteMask); +#ifndef GLSL glAlphaFunc(GL_GREATER, _CurAlphaTestThreshold); +#endif @@ -140,11 +142,13 @@ void CDriverGLStates3::forceDefaults(uint nbStages) // setup GLStates. static const GLfloat one[4]= {1,1,1,1}; static const GLfloat zero[4]= {0,0,0,1}; +#ifndef GLSL glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, zero); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, one); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, one); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, _CurShininess); +#endif // TexModes uint stage; diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp index 2da49cad0..1b31576cc 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp @@ -256,7 +256,9 @@ bool CDriverGL3::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines) bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris) { +#ifdef GLSL return renderTriangles2( mat, firstIndex, ntris ); +#endif H_AUTO_OGL(CDriverGL3_renderTriangles); @@ -1003,7 +1005,9 @@ void CDriverGL3::setupGlArrays(CVertexBufferInfo &vb) // Use a vertex program ? if (!isVertexProgramEnabled ()) { +#ifndef GLSL setupGlArraysStd(vb); +#endif } else { diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex_program.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex_program.cpp index cd7d225f4..5abafeadf 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex_program.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex_program.cpp @@ -401,7 +401,9 @@ bool CDriverGL3::activeARBVertexProgram (CVertexProgram *program) { glDisable( GL_VERTEX_PROGRAM_ARB ); glDisable( GL_COLOR_SUM_ARB ); +#ifndef GLSL _VertexProgramEnabled = false; +#endif } return true; }