Conditionally build some deprecated functions. Also little adjustment to the shader texenv generator.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent c74e279282
commit 997a231bff

@ -458,6 +458,7 @@ namespace NL3D
addDiffuse(); addDiffuse();
bool textures = false;
sampler = 0; sampler = 0;
for( int i = TexCoord0; i < NumOffsets; i++ ) for( int i = TexCoord0; i < NumOffsets; i++ )
{ {
@ -466,13 +467,20 @@ namespace NL3D
ss << "vec4 texel" << sampler; ss << "vec4 texel" << sampler;
ss << " = texture2D( sampler" << sampler << ","; ss << " = texture2D( sampler" << sampler << ",";
ss << attribNames[ i ] << " );" << std::endl; ss << attribNames[ i ] << " );" << std::endl;
textures = true;
} }
sampler++; 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(); generateTexEnv();
// Alpha test
//ss << "if( texel.a <= 0.5 ) discard;" << std::endl;
ss << "fragColor = texel;" << std::endl; ss << "fragColor = texel;" << std::endl;
ss << "}" << std::endl; ss << "}" << std::endl;
@ -514,33 +522,37 @@ namespace NL3D
{ {
buildArg( stage, 0, false, arg0 ); buildArg( stage, 0, false, arg0 );
buildArg( stage, 1, false, arg1 ); buildArg( stage, 1, false, arg1 );
ss << "texel.rgb = " << arg0 << ";" << std::endl; ss << "texel.rgb = " << arg0 << " * " << arg1 << ";" << std::endl;
ss << "texel.rgb = texel.rgb * " << arg1 << ";" << std::endl; //ss << "texel.rgb = " << arg0 << ";" << std::endl;
//ss << "texel.rgb = texel.rgb * " << arg1 << ";" << std::endl;
} }
break; break;
case CMaterial::Add: case CMaterial::Add:
buildArg( stage, 0, false, arg0 ); buildArg( stage, 0, false, arg0 );
buildArg( stage, 1, false, arg1 ); buildArg( stage, 1, false, arg1 );
ss << "texel.rgb = " << arg0 << ";" << std::endl; ss << "texel.rgb = " << arg0 << " + " << arg1 << ";" << std::endl;
ss << "texel.rgb = texel.rgb + " << arg1 << ";" << std::endl; //ss << "texel.rgb = " << arg0 << ";" << std::endl;
//ss << "texel.rgb = texel.rgb + " << arg1 << ";" << std::endl;
break; break;
case CMaterial::AddSigned: case CMaterial::AddSigned:
buildArg( stage, 0, false, arg0 ); buildArg( stage, 0, false, arg0 );
buildArg( stage, 1, false, arg1 ); buildArg( stage, 1, false, arg1 );
ss << "texel.rgb = " << arg0 << ";" << std::endl; ss << "texel.rgb = " << arg0 << " + " << arg1 << " - vec3( 0.5, 0.5, 0.5 );" << std::endl;
ss << "texel.rgb = texel.rgb + " << arg1 << ";" << std::endl; //ss << "texel.rgb = " << arg0 << ";" << std::endl;
ss << "texel.rgb = texel.rgb - vec3( 0.5, 0.5, 0.5 );" << 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; break;
case CMaterial::Mad: case CMaterial::Mad:
buildArg( stage, 0, false, arg0 ); buildArg( stage, 0, false, arg0 );
buildArg( stage, 1, false, arg1 ); buildArg( stage, 1, false, arg1 );
buildArg( stage, 2, false, arg2 ); buildArg( stage, 2, false, arg2 );
ss << "texel.rgb = " << arg0 << ";" << std::endl; ss << "texel.rgb = " << arg0 << " * " << arg1 << " + " << arg2 << ";" << std::endl;
ss << "texel.rgb = texel.rgb * " << arg1 << ";" << std::endl; //ss << "texel.rgb = " << arg0 << ";" << std::endl;
ss << "texel.rgb = texel.rgb + " << arg2 << ";" << std::endl; //ss << "texel.rgb = texel.rgb * " << arg1 << ";" << std::endl;
//ss << "texel.rgb = texel.rgb + " << arg2 << ";" << std::endl;
break; break;
case CMaterial::InterpolateTexture: case CMaterial::InterpolateTexture:
@ -614,24 +626,27 @@ namespace NL3D
{ {
buildArg( stage, 0, true, arg0 ); buildArg( stage, 0, true, arg0 );
buildArg( stage, 1, true, arg1 ); buildArg( stage, 1, true, arg1 );
ss << "texel.a = " << arg0 << ";" << std::endl; ss << "texel.a = " << arg0 << " * " << arg1 << ";" << std::endl;
ss << "texel.a = texel.a * " << arg1 << ";" << std::endl; //ss << "texel.a = " << arg0 << ";" << std::endl;
//ss << "texel.a = texel.a * " << arg1 << ";" << std::endl;
} }
break; break;
case CMaterial::Add: case CMaterial::Add:
buildArg( stage, 0, true, arg0 ); buildArg( stage, 0, true, arg0 );
buildArg( stage, 1, true, arg1 ); buildArg( stage, 1, true, arg1 );
ss << "texel.a = " << arg0 << ";" << std::endl; ss << "texel.a = " << arg0 << " + " << arg1 << ";" << std::endl;
ss << "texel.a = texel.a + " << arg1 << ";" << std::endl; //ss << "texel.a = " << arg0 << ";" << std::endl;
//ss << "texel.a = texel.a + " << arg1 << ";" << std::endl;
break; break;
case CMaterial::AddSigned: case CMaterial::AddSigned:
buildArg( stage, 0, true, arg0 ); buildArg( stage, 0, true, arg0 );
buildArg( stage, 1, true, arg1 ); buildArg( stage, 1, true, arg1 );
ss << "texel.rgb = " << arg0 << ";" << std::endl; ss << "texel.a = " << arg0 << " * " << arg1 << " - vec3( 0.5, 0.5, 0.5 );" << std::endl;
ss << "texel.rgb = texel.rgb + " << arg1 << ";" << std::endl; //ss << "texel.rgb = " << arg0 << ";" << std::endl;
ss << "texel.rgb = texel.rgb - vec3( 0.5, 0.5, 0.5 );" << 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; break;
case CMaterial::Mad: case CMaterial::Mad:

@ -410,11 +410,13 @@ bool CDriverGL3::setupDisplay()
// Init OpenGL/Driver defaults. // Init OpenGL/Driver defaults.
//============================= //=============================
glViewport(0,0,_CurrentMode.Width,_CurrentMode.Height); glViewport(0,0,_CurrentMode.Width,_CurrentMode.Height);
#ifndef GLSL
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glOrtho(0,_CurrentMode.Width,_CurrentMode.Height,0,-1.0f,1.0f); glOrtho(0,_CurrentMode.Width,_CurrentMode.Height,0,-1.0f,1.0f);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
#endif
glDisable(GL_AUTO_NORMAL); glDisable(GL_AUTO_NORMAL);
glDisable(GL_COLOR_MATERIAL); glDisable(GL_COLOR_MATERIAL);
glEnable(GL_DITHER); glEnable(GL_DITHER);
@ -437,10 +439,17 @@ bool CDriverGL3::setupDisplay()
// Be always in EXTSeparateSpecularColor. // Be always in EXTSeparateSpecularColor.
if(_Extensions.EXTSeparateSpecularColor) if(_Extensions.EXTSeparateSpecularColor)
{ {
#ifndef GLSL
glLightModeli((GLenum)GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT); glLightModeli((GLenum)GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT);
#endif
} }
#ifndef GLSL
_VertexProgramEnabled= false; _VertexProgramEnabled= false;
#else
_VertexProgramEnabled = true;
#endif
_LastSetupGLArrayVertexProgram= false; _LastSetupGLArrayVertexProgram= false;
// Init VertexArrayRange according to supported extenstion. // Init VertexArrayRange according to supported extenstion.
@ -477,8 +486,10 @@ bool CDriverGL3::setupDisplay()
// init default env. // init default env.
CMaterial::CTexEnv env; // envmode init to default. CMaterial::CTexEnv env; // envmode init to default.
env.ConstantColor.set(255,255,255,255); env.ConstantColor.set(255,255,255,255);
#ifndef GLSL
forceActivateTexEnvMode(stage, env); forceActivateTexEnvMode(stage, env);
forceActivateTexEnvColor(stage, env); forceActivateTexEnvColor(stage, env);
#endif
// Not special TexEnv. // Not special TexEnv.
_CurrentTexEnvSpecial[stage]= TexEnvSpecialDisabled; _CurrentTexEnvSpecial[stage]= TexEnvSpecialDisabled;
@ -486,6 +497,7 @@ bool CDriverGL3::setupDisplay()
// set All TexGen by default to identity matrix (prefer use the textureMatrix scheme) // set All TexGen by default to identity matrix (prefer use the textureMatrix scheme)
_DriverGLStates.activeTextureARB(stage); _DriverGLStates.activeTextureARB(stage);
#ifndef GLSL
GLfloat params[4]; GLfloat params[4];
params[0]=1; params[1]=0; params[2]=0; params[3]=0; params[0]=1; params[1]=0; params[2]=0; params[3]=0;
glTexGenfv(GL_S, GL_OBJECT_PLANE, params); 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; params[0]=0; params[1]=0; params[2]=0; params[3]=1;
glTexGenfv(GL_Q, GL_OBJECT_PLANE, params); glTexGenfv(GL_Q, GL_OBJECT_PLANE, params);
glTexGenfv(GL_Q, GL_EYE_PLANE, params); glTexGenfv(GL_Q, GL_EYE_PLANE, params);
#endif
} }
_PPLExponent = 1.f; _PPLExponent = 1.f;

@ -19,6 +19,8 @@
#include "nel/misc/types_nl.h" #include "nel/misc/types_nl.h"
#define GLSL
//#define NL_PROFILE_DRIVER_OGL //#define NL_PROFILE_DRIVER_OGL
#ifdef NL_PROFILE_DRIVER_OGL #ifdef NL_PROFILE_DRIVER_OGL
# define H_AUTO_OGL(label) H_AUTO(label) # define H_AUTO_OGL(label) H_AUTO(label)

@ -377,9 +377,11 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// activate the texture, or disable texturing if NULL. // activate the texture, or disable texturing if NULL.
activateTexture(stage,text); activateTexture(stage,text);
#ifndef GLSL
// If texture not NULL, Change texture env function. // If texture not NULL, Change texture env function.
//================================================== //==================================================
setTextureEnvFunction(stage, mat); setTextureEnvFunction(stage, mat);
#endif
} }
} }
@ -429,6 +431,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
//===================== //=====================
// Light Part. // Light Part.
#ifndef GLSL
_DriverGLStates.enableLighting(mat.getFlags()&IDRV_MAT_LIGHTING); _DriverGLStates.enableLighting(mat.getFlags()&IDRV_MAT_LIGHTING);
if(mat.getFlags()&IDRV_MAT_LIGHTING) if(mat.getFlags()&IDRV_MAT_LIGHTING)
{ {
@ -448,6 +451,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
_DriverGLStates.setVertexColorLighted(false); _DriverGLStates.setVertexColorLighted(false);
} }
// Fog Part. // Fog Part.
//================= //=================
@ -462,6 +466,8 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
_DriverGLStates.enableFog(_FogEnabled); _DriverGLStates.enableFog(_FogEnabled);
} }
#endif
_CurrentMaterial=&mat; _CurrentMaterial=&mat;
} }
@ -577,28 +583,28 @@ void CDriverGL3::endMultiPass()
} }
} }
const char *samplers[ 4 ] = const char *samplers[ 4 ] =
{ {
"sampler0", "sampler0",
"sampler1", "sampler1",
"sampler2", "sampler2",
"sampler3" "sampler3"
}; };
void CDriverGL3::setupNormalPass() void CDriverGL3::setupNormalPass()
{ {
const CMaterial &mat = *_CurrentMaterial; const CMaterial &mat = *_CurrentMaterial;
for( int i = 0; i < 4; i++ ) for( int i = 0; i < 4; i++ )
{ {
ITexture *t = mat.getTexture( i ); ITexture *t = mat.getTexture( i );
if( t == NULL ) if( t == NULL )
continue; continue;
int index = getUniformLocation( samplers[ i ] ); int index = getUniformLocation( samplers[ i ] );
if( index == -1 ) if( index == -1 )
continue; continue;
setUniform1i( index, i ); setUniform1i( index, i );
} }
} }

@ -12,7 +12,9 @@ namespace NL3D
{ {
if( !program ) if( !program )
{ {
#ifndef GLSL
_VertexProgramEnabled = false; _VertexProgramEnabled = false;
#endif
currentProgram = NULL; currentProgram = NULL;
return true; return true;
} }
@ -124,8 +126,6 @@ namespace NL3D
if( !setupProgram( mat ) ) if( !setupProgram( mat ) )
return false; return false;
//glDrawArrays( GL_TRIANGLES, startIndex * 3, numTris * 3 );
if( numTris ) if( numTris )
{ {
if (_LastIB._Format == CIndexBuffer::Indices16) if (_LastIB._Format == CIndexBuffer::Indices16)
@ -160,6 +160,7 @@ namespace NL3D
shaderGenerator->generateVS( vs ); shaderGenerator->generateVS( vs );
shaderGenerator->generatePS( ps ); shaderGenerator->generatePS( ps );
#ifdef GLSL
vp = createVertexProgram(); vp = createVertexProgram();
std::string log; std::string log;
@ -213,6 +214,7 @@ namespace NL3D
setupNormalPass(); setupNormalPass();
break; break;
} }
#endif
return true; return true;
} }
@ -224,7 +226,9 @@ namespace NL3D
vp = NULL; vp = NULL;
pp = NULL; pp = NULL;
currentProgram = NULL; currentProgram = NULL;
#ifndef GLSL
_VertexProgramEnabled = false; _VertexProgramEnabled = false;
#endif
} }
} }

@ -120,7 +120,9 @@ void CDriverGLStates3::forceDefaults(uint nbStages)
glStencilFunc(_CurStencilFunc, _CurStencilRef, _CurStencilMask); glStencilFunc(_CurStencilFunc, _CurStencilRef, _CurStencilMask);
glStencilOp(_CurStencilOpFail, _CurStencilOpZFail, _CurStencilOpZPass); glStencilOp(_CurStencilOpFail, _CurStencilOpZFail, _CurStencilOpZPass);
glStencilMask(_CurStencilWriteMask); glStencilMask(_CurStencilWriteMask);
#ifndef GLSL
glAlphaFunc(GL_GREATER, _CurAlphaTestThreshold); glAlphaFunc(GL_GREATER, _CurAlphaTestThreshold);
#endif
@ -140,11 +142,13 @@ void CDriverGLStates3::forceDefaults(uint nbStages)
// setup GLStates. // setup GLStates.
static const GLfloat one[4]= {1,1,1,1}; static const GLfloat one[4]= {1,1,1,1};
static const GLfloat zero[4]= {0,0,0,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_EMISSION, zero);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, one); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, one);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, one); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, one);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, _CurShininess); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, _CurShininess);
#endif
// TexModes // TexModes
uint stage; uint stage;

@ -256,7 +256,9 @@ bool CDriverGL3::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines)
bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris) bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris)
{ {
#ifdef GLSL
return renderTriangles2( mat, firstIndex, ntris ); return renderTriangles2( mat, firstIndex, ntris );
#endif
H_AUTO_OGL(CDriverGL3_renderTriangles); H_AUTO_OGL(CDriverGL3_renderTriangles);
@ -1003,7 +1005,9 @@ void CDriverGL3::setupGlArrays(CVertexBufferInfo &vb)
// Use a vertex program ? // Use a vertex program ?
if (!isVertexProgramEnabled ()) if (!isVertexProgramEnabled ())
{ {
#ifndef GLSL
setupGlArraysStd(vb); setupGlArraysStd(vb);
#endif
} }
else else
{ {

@ -401,7 +401,9 @@ bool CDriverGL3::activeARBVertexProgram (CVertexProgram *program)
{ {
glDisable( GL_VERTEX_PROGRAM_ARB ); glDisable( GL_VERTEX_PROGRAM_ARB );
glDisable( GL_COLOR_SUM_ARB ); glDisable( GL_COLOR_SUM_ARB );
#ifndef GLSL
_VertexProgramEnabled = false; _VertexProgramEnabled = false;
#endif
} }
return true; return true;
} }

Loading…
Cancel
Save