GL3: Cleanup and fix lighting state bug in pp

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent d5d82ce900
commit 75e650432f

@ -14,101 +14,17 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "sstream"
#include "stdopengl.h"
#include "driver_glsl_shader_generator.h"
#include "nel/3d/vertex_buffer.h"
#include "driver_opengl_shader_desc.h"
namespace
{
inline bool hasFlag(uint32 data, uint32 flag)
{
if ((data & flag) != 0)
return true;
else
return false;
}
#include <sstream>
enum AttribOffset
{
Position,
Weight,
Normal,
PrimaryColor,
SecondaryColor,
Fog,
PaletteSkin,
Empty,
TexCoord0,
TexCoord1,
TexCoord2,
TexCoord3,
TexCoord4,
TexCoord5,
TexCoord6,
TexCoord7,
NumOffsets
};
}
#include "nel/3d/vertex_buffer.h"
#include "driver_opengl_program.h"
#include "driver_opengl_shader_desc.h"
namespace NL3D
{
uint16 vertexFlags[ CVertexBuffer::NumValue ] =
{
CVertexBuffer::PositionFlag,
CVertexBuffer::WeightFlag,
CVertexBuffer::NormalFlag,
CVertexBuffer::PrimaryColorFlag,
CVertexBuffer::SecondaryColorFlag,
CVertexBuffer::FogFlag,
CVertexBuffer::PaletteSkinFlag,
0,
CVertexBuffer::TexCoord0Flag,
CVertexBuffer::TexCoord1Flag,
CVertexBuffer::TexCoord2Flag,
CVertexBuffer::TexCoord3Flag,
CVertexBuffer::TexCoord4Flag,
CVertexBuffer::TexCoord5Flag,
CVertexBuffer::TexCoord6Flag,
CVertexBuffer::TexCoord7Flag
};
const char *attribNames[ CVertexBuffer::NumValue ] =
{
"position",
"weight",
"normal",
"color",
"color2",
"fog",
"paletteSkin",
"none",
"texCoord0",
"texCoord1",
"texCoord2",
"texCoord3",
"texCoord4",
"texCoord5",
"texCoord6",
"texCoord7"
};
const char *texelNames[ SHADER_MAX_TEXTURES ] =
{
"texel0",
"texel1",
"texel2",
"texel3"
};
const char *constantNames[ 4 ] =
{
"constant0",
"constant1",
"constant2",
"constant3"
};
const char *shaderNames[] =
{
"Normal",
@ -130,6 +46,7 @@ namespace NL3D
CGLSLShaderGenerator::~CGLSLShaderGenerator()
{
}
void CGLSLShaderGenerator::reset()
@ -156,14 +73,23 @@ namespace NL3D
for (int i = Weight; i < NumOffsets; i++)
{
if (hasFlag(vbFormat, vertexFlags[ i ]))
if (hasFlag(vbFormat, g_VertexFlags[i]))
{
ss << "smooth in vec4 ";
ss << attribNames[ i ] << ";" << std::endl;
ss << g_AttribNames[i] << ";" << std::endl;
}
}
ss << std::endl;
/*if (desc->lightingEnabled()) // LIGHTING DEBUG
{
generateInvalidPS();
}
else
{
generateNormalPS();
}*/
switch(material->getShader())
{
case CMaterial::Normal:
@ -292,7 +218,7 @@ namespace NL3D
void CGLSLShaderGenerator::addLightUniformsFS()
{
for (int i = 0; i < SHADER_MAX_LIGHTS; i++)
for (int i = 0; i < NL_OPENGL3_MAX_LIGHT; i++)
{
switch(desc->getLight(i))
{
@ -364,7 +290,7 @@ namespace NL3D
ss << "void main(void)" << std::endl;
ss << "{" << std::endl;
ss << "vec4 eyePosition = modelView * v" << attribNames[ 0 ] << ";" << std::endl;
ss << "vec4 eyePosition = modelView * v" << g_AttribNames[ 0 ] << ";" << std::endl;
if (desc->hasPointLight())
ss << "ecPos4 = eyePosition;" << std::endl;
@ -378,18 +304,18 @@ namespace NL3D
ss << "vec4 t = vec4(cubeTexCoords, 1.0);" << std::endl;
ss << "t = t * texMatrix0;" << std::endl;
ss << "cubeTexCoords = t.xyz;" << std::endl;
ss << "gl_Position = modelViewProjection * v" << attribNames[ 0 ] << ";" << std::endl;
ss << "gl_Position = modelViewProjection * v" << g_AttribNames[ 0 ] << ";" << std::endl;
if (desc->lightingEnabled())
addLightsVS();
for (int i = Weight; i < NumOffsets; i++)
{
if (hasFlag(vbFormat, vertexFlags[ i ]))
if (hasFlag(vbFormat, g_VertexFlags[i]))
{
ss << attribNames[ i ];
ss << g_AttribNames[i];
ss << " = ";
ss << "v" << attribNames[ i ] << ";" << std::endl;
ss << "v" << g_AttribNames[i] << ";" << std::endl;
}
}
@ -415,15 +341,15 @@ namespace NL3D
ss << "void main(void)" << std::endl;
ss << "{" << std::endl;
ss << "gl_Position = modelViewProjection * v" << attribNames[ 0 ] << ";" << std::endl;
ss << "gl_Position = modelViewProjection * v" << g_AttribNames[ 0 ] << ";" << std::endl;
for (int i = Weight; i < NumOffsets; i++)
{
if (hasFlag(vbFormat, vertexFlags[ i ]))
if (hasFlag(vbFormat, g_VertexFlags[i]))
{
ss << attribNames[ i ];
ss << g_AttribNames[i];
ss << " = ";
ss << "v" << attribNames[ i ] << ";" << std::endl;
ss << "v" << g_AttribNames[i] << ";" << std::endl;
}
}
@ -514,10 +440,101 @@ namespace NL3D
ss << "}" << std::endl;
}*/
void CGLSLShaderGenerator::generateInvalidPS()
{
/*uint sampler = 0;
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
{
if (desc->getUseTexStage(i))
ss << "uniform sampler2D sampler" << sampler << ";" << std::endl;
sampler++;
}
addColor();
addConstants();
addAlphaTreshold();
addFogUniform();*/
if (desc->fogEnabled())
ss << "smooth in vec4 ecPos;" << std::endl;
ss << std::endl;
if (desc->lightingEnabled())
{
addLightUniformsFS();
addLightInsFS();
ss << std::endl;
addLightsFunctionFS();
ss << std::endl;
}
/*if (desc->fogEnabled())
addFogFunction();*/
ss << "void main(void)" << std::endl;
ss << "{" << std::endl;
/*bool textures = false;
sampler = 0;
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
{
if (desc->getUseTexStage(i))
{
ss << "vec4 texel" << sampler << " = texture(sampler" << sampler << ",";
if (!desc->getUseFirstTexCoords())
ss << g_AttribNames[ TexCoord0 + i ] << ".st);";
else
ss << g_AttribNames[ TexCoord0 ] << ".st);";
ss << std::endl;
textures = true;
}
sampler++;
}
bool vertexColor = false;
if (hasFlag(vbFormat, g_VertexFlags[ PrimaryColor ]))
vertexColor = true;
if (textures && !vertexColor)
ss << "vec4 texel = vec4(1.0, 1.0, 1.0, 1.0);" << std::endl;
else
if (vertexColor)
ss << "vec4 texel = color;" << std::endl;
else
ss << "vec4 texel = vec4(0.5, 0.5, 0.5, 1.0);" << std::endl;
generateTexEnv();
// This is just an idea I had, but it seems to be working.
// Unfortunately it's not documented anywhere I looked in the GL spec, but if I don't have this modulation here,
// the Ryzom UI looks horrific.
if (vertexColor)
ss << "texel = color * texel;" << std::endl;*/
ss << "fragColor = vec4(1.0, 1.0, 1.0, 1.0);" << std::endl;
if (desc->lightingEnabled())
addLightsFS();
ss << "fragColor = fragColor + vec4(0.0, 0.25, 0.0, 0.0);" << std::endl;
/*if (desc->fogEnabled())
addFog();
addAlphaTest();*/
ss << "}" << std::endl;
}
void CGLSLShaderGenerator::generateNormalPS()
{
uint sampler = 0;
for (int i = 0; i < SHADER_MAX_TEXTURES; i++)
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
{
if (desc->getUseTexStage(i))
ss << "uniform sampler2D sampler" << sampler << ";" << std::endl;
@ -552,16 +569,16 @@ namespace NL3D
bool textures = false;
sampler = 0;
for (int i = 0; i < SHADER_MAX_TEXTURES; i++)
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
{
if (desc->getUseTexStage(i))
{
ss << "vec4 texel" << sampler << " = texture(sampler" << sampler << ",";
if (!desc->getUseFirstTexCoords())
ss << attribNames[ TexCoord0 + i ] << ".st);";
ss << g_AttribNames[ TexCoord0 + i ] << ".st);";
else
ss << attribNames[ TexCoord0 ] << ".st);";
ss << g_AttribNames[ TexCoord0 ] << ".st);";
ss << std::endl;
@ -571,7 +588,7 @@ namespace NL3D
}
bool vertexColor = false;
if (hasFlag(vbFormat, vertexFlags[ PrimaryColor ]))
if (hasFlag(vbFormat, g_VertexFlags[ PrimaryColor ]))
vertexColor = true;
if (textures && !vertexColor)
@ -606,7 +623,7 @@ namespace NL3D
void CGLSLShaderGenerator::generateTexEnv()
{
uint32 stage = 0;
for (int i = 0; i < SHADER_MAX_TEXTURES; i++)
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
{
if (desc->getUseTexStage(i))
{
@ -623,7 +640,7 @@ namespace NL3D
std::string arg1;
std::string arg2;
switch(material->_TexEnvs[ stage ].Env.OpRGB)
switch(material->_TexEnvs[stage].Env.OpRGB)
{
case CMaterial::Replace:
{
@ -674,7 +691,7 @@ namespace NL3D
buildArg(stage, 0, false, arg0);
buildArg(stage, 1, false, arg1);
std::string As = texelNames[ stage ];
std::string As = g_TexelNames[stage];
As.append(".a");
ss << "texel.rgb = " << arg0 << " * " << As << ";" << std::endl;
@ -711,7 +728,7 @@ namespace NL3D
buildArg(stage, 0, false, arg0);
buildArg(stage, 1, false, arg1);
std::string As = constantNames[ stage ];
std::string As = g_ConstantNames[stage];
As.append(".a");
ss << "texel.rgb = " << arg0 << " * " << As << ";" << std::endl;
@ -727,7 +744,7 @@ namespace NL3D
std::string arg1;
std::string arg2;
switch(material->_TexEnvs[ stage ].Env.OpRGB)
switch(material->_TexEnvs[stage].Env.OpRGB)
{
case CMaterial::Replace:
{
@ -777,7 +794,7 @@ namespace NL3D
buildArg(stage, 0, true, arg0);
buildArg(stage, 1, true, arg1);
std::string As = texelNames[ stage ];
std::string As = g_TexelNames[stage];
As.append(".a");
ss << "texel.a = " << arg0 << " * " << As << ";" << std::endl;
@ -814,7 +831,7 @@ namespace NL3D
buildArg(stage, 0, true, arg0);
buildArg(stage, 1, true, arg1);
std::string As = constantNames[ stage ];
std::string As = g_ConstantNames[stage];
As.append(".a");
ss << "texel.a = " << arg0 << " * " << As << ";" << std::endl;
@ -851,21 +868,21 @@ namespace NL3D
switch(op)
{
case CMaterial::SrcColor:
ds << texelNames[ stage ] << ".rgb";
ds << g_TexelNames[stage] << ".rgb";
break;
case CMaterial::InvSrcColor:
ds << "(vec3(1.0, 1.0, 1.0) - ";
ds << texelNames[ stage ] << ".rgb)";
ds << g_TexelNames[stage] << ".rgb)";
break;
case CMaterial::SrcAlpha:
ds << texelNames[ stage ] << ".a";
ds << g_TexelNames[stage] << ".a";
break;
case CMaterial::InvSrcAlpha:
ds << "(1.0 - ";
ds << texelNames[ stage ] << ".a)";
ds << g_TexelNames[stage] << ".a)";
break;
}
}
@ -920,19 +937,19 @@ namespace NL3D
switch(op)
{
case CMaterial::SrcColor:
ds << constantNames[ stage ] << ".rgb";
ds << g_ConstantNames[stage] << ".rgb";
break;
case CMaterial::InvSrcColor:
ds << "(vec3(1.0, 1.0, 1.0) - " << constantNames[ stage ] << ".rgb)";
ds << "(vec3(1.0, 1.0, 1.0) - " << g_ConstantNames[stage] << ".rgb)";
break;
case CMaterial::SrcAlpha:
ds << constantNames[ stage ] << ".a";
ds << g_ConstantNames[stage] << ".a";
break;
case CMaterial::InvSrcAlpha:
ds << "(1.0 - " << constantNames[ stage ] << ".a)";
ds << "(1.0 - " << g_ConstantNames[stage] << ".a)";
break;
}
break;
@ -950,7 +967,7 @@ namespace NL3D
int ntextures = 0;
for (int i = TexCoord0; i < TexCoord4; i++)
{
if (hasFlag(vbFormat, vertexFlags[ i ]))
if (hasFlag(vbFormat, g_VertexFlags[i]))
ntextures++;
}
@ -993,11 +1010,11 @@ namespace NL3D
{
ss << "vec4 texel" << i;
ss << " = texture(sampler" << i;
ss << ", " << attribNames[ TexCoord1 ] << ".st);" << std::endl;
ss << ", " << g_AttribNames[ TexCoord1 ] << ".st);" << std::endl;
}
// Color map UV coords are at position 0
ss << "vec4 texel" << ntextures - 1 << " = texture(sampler" << ntextures - 1 << ", " << attribNames[ TexCoord0 ] << ".st);" << std::endl;
ss << "vec4 texel" << ntextures - 1 << " = texture(sampler" << ntextures - 1 << ", " << g_AttribNames[ TexCoord0 ] << ".st);" << std::endl;
//ss << "vec4 texel = diffuseColor;" << std::endl;
//ss << "vec4 texel = vec4(1.0, 1.0, 1.0, 1.0);" << std::endl;
@ -1006,13 +1023,13 @@ namespace NL3D
// Lightmaps
for (int i = 0; i < ntextures - 1; i++)
{
ss << "texel.rgb = " << texelNames[ i ] << ".rgb * " << constantNames[ i ] << ".rgb + texel.rgb;" << std::endl;
ss << "texel.a = " << texelNames[ i ] << ".a * texel.a + texel.a;" << std::endl;
ss << "texel.rgb = " << g_TexelNames[i] << ".rgb * " << g_ConstantNames[i] << ".rgb + texel.rgb;" << std::endl;
ss << "texel.a = " << g_TexelNames[i] << ".a * texel.a + texel.a;" << std::endl;
}
// Texture
ss << "texel.rgb = " << texelNames[ ntextures - 1 ] << ".rgb * texel.rgb;" << std::endl;
ss << "texel.a = " << texelNames[ ntextures - 1] << ".a;" << std::endl;
ss << "texel.rgb = " << g_TexelNames[ ntextures - 1 ] << ".rgb * texel.rgb;" << std::endl;
ss << "texel.a = " << g_TexelNames[ ntextures - 1] << ".a;" << std::endl;
if (material->_LightMapsMulx2)
{

@ -124,6 +124,7 @@ namespace NL3D
/////////////////////////////////////// Pixel Shader generation ///////////////////////////////////////
void generateInvalidPS();
void generateNormalPS();

@ -487,7 +487,7 @@ bool CDriverGL3::stretchRect(ITexture * /* srcText */, NLMISC::CRect &/* srcRect
// ***************************************************************************
bool CDriverGL3::supportBloomEffect() const
{
return false; // FIXME GL3
return false; // FIXME GL3 // _Extensions.GLCore;
}
// ***************************************************************************
@ -1156,7 +1156,7 @@ bool CDriverGL3::supportPerPixelLighting(bool specular) const
{
H_AUTO_OGL(CDriverGL3_supportPerPixelLighting)
return _Extensions.GLCore;
return false; // FIXME GL3 // _Extensions.GLCore;
}
// ***************************************************************************

@ -1311,9 +1311,6 @@ private:
private:
// The last vertex program that was setupped
NLMISC::CRefPtr<CVertexProgram> _LastSetuppedVP;
bool _ForceDXTCCompression;
/// Divisor for textureResize (power).
uint _ForceTextureResizePower;
@ -1351,13 +1348,13 @@ private:
uint32 ppoId;
CVertexProgram *m_UserVertexProgram;
CGeometryProgram *m_UserGeometryProgram;
CPixelProgram *m_UserPixelProgram;
NLMISC::CRefPtr<CVertexProgram> m_UserVertexProgram;
NLMISC::CRefPtr<CGeometryProgram> m_UserGeometryProgram;
NLMISC::CRefPtr<CPixelProgram> m_UserPixelProgram;
CVertexProgram *m_DriverVertexProgram;
CGeometryProgram *m_DriverGeometryProgram;
CPixelProgram *m_DriverPixelProgram;
NLMISC::CRefPtr<CVertexProgram> m_DriverVertexProgram;
NLMISC::CRefPtr<CGeometryProgram> m_DriverGeometryProgram;
NLMISC::CRefPtr<CPixelProgram> m_DriverPixelProgram;
std::set<CVPBuiltin> m_VPBuiltinCache;
CVPBuiltin m_VPBuiltinCurrent;

@ -200,15 +200,6 @@ void CDriverGL3::setupLightMapDynamicLighting(bool enable)
}
}
void CDriverGL3::disableAllLights()
{
for (int i = 0; i < MaxLight; ++i)
{
_UserLightEnable[i] = false;
touchLightVP(i);
}
}
#ifdef NL_STATIC
} // NLDRIVERGL3
#endif

@ -244,6 +244,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
}
CShaderGL3* pShader;
CMaterial::TShader matShader;
GLenum glenum = GL_ZERO;
uint32 touched = mat.getTouched();
uint stage;
@ -319,14 +320,25 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
mat.clearTouched(0xFFFFFFFF);
}
// Now we can get the supported shader from the cache.
CMaterial::TShader matShader = pShader->SupportedShader;
// 2b. User supplied pixel shader overrides material
//==================================
if (m_UserPixelProgram)
{
matShader = CMaterial::Program;
}
else
{
// Now we can get the supported shader from the cache.
matShader = pShader->SupportedShader;
}
// 2b. Update more shader state
//==================================
// if the shader has changed since last time
if (matShader != _CurrentMaterialSupportedShader)
{
// if old was lightmap, restore standard lighting
if (_CurrentMaterialSupportedShader==CMaterial::LightMap)
if (_CurrentMaterialSupportedShader == CMaterial::LightMap)
setupLightMapDynamicLighting(false);
// if new is lightmap, setup dynamic lighting
@ -335,14 +347,14 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
}
// setup the global
_CurrentMaterialSupportedShader= matShader;
_CurrentMaterialSupportedShader = matShader;
// 2. Setup / Bind Textures.
//==========================
// Must setup textures each frame. (need to test if touched).
// Must separate texture setup and texture activation in 2 "for"...
// because setupTexture() may disable all stage.
if (matShader != CMaterial::Water)
if (matShader != CMaterial::Water && matShader != CMaterial::Program)
{
for (stage=0 ; stage<inlGetNumTextStages() ; stage++)
{
@ -378,6 +390,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
&& matShader != CMaterial::Cloud
&& matShader != CMaterial::Water
&& matShader != CMaterial::Specular
&& matShader != CMaterial::Program
)
{
for (stage=0 ; stage<inlGetNumTextStages() ; stage++)
@ -404,13 +417,13 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// Double Sided Part.
//===================
// NB: inverse state: DoubleSided <=> !CullFace.
uint32 twoSided= mat.getFlags()&IDRV_MAT_DOUBLE_SIDED;
_DriverGLStates.enableCullFace(twoSided==0);
uint32 twoSided = mat.getFlags() & IDRV_MAT_DOUBLE_SIDED;
_DriverGLStates.enableCullFace(twoSided == 0);
// Alpha Test Part.
//=================
uint32 alphaTest= mat.getFlags()&IDRV_MAT_ALPHA_TEST;
uint32 alphaTest = mat.getFlags() & IDRV_MAT_ALPHA_TEST;
_DriverGLStates.enableAlphaTest(alphaTest);
if (alphaTest)
{
@ -420,9 +433,9 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// Bind ZBuffer Part.
//===================
_DriverGLStates.enableZWrite(mat.getFlags()&IDRV_MAT_ZWRITE);
_DriverGLStates.enableZWrite(mat.getFlags() & IDRV_MAT_ZWRITE);
_DriverGLStates.depthFunc(pShader->ZComp);
_DriverGLStates.setZBias (mat.getZBias () * _OODeltaZ);
_DriverGLStates.setZBias(mat.getZBias() * _OODeltaZ);
// Bind Stencil Buffer Part.
//===================
@ -436,12 +449,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
//=====================
// Light Part.
enableLightingVP(mat.getFlags() & IDRV_MAT_LIGHTING);
if ((mat.getFlags() & IDRV_MAT_LIGHTING) == 0)
disableAllLights();
if (mat.getFlags()&IDRV_MAT_LIGHTING)
{
_DriverGLStates.setEmissive(pShader->PackedEmissive, pShader->Emissive);
@ -454,6 +462,10 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
}
else
{
// Color unlit
// CRGBA col= mat.getColor();
// glColor4ub(col.R, col.G, col.B, col.A);
_DriverGLStates.setVertexColorLighted(false);
}
@ -479,7 +491,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
//=====================================
// Textures user matrix
if (matShader == CMaterial::Normal)
if (matShader == CMaterial::Normal || matShader == CMaterial::Program)
{
setupUserTextureMatrix(inlGetNumTextStages(), mat);
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,74 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2014 by authors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NL_DRIVER_OPENGL_PROGRAM_H
#define NL_DRIVER_OPENGL_PROGRAM_H
#include "nel/misc/types_nl.h"
namespace NL3D {
#ifdef NL_STATIC
namespace NLDRIVERGL3 {
#endif
enum TAttribOffset
{
Position,
Weight,
Normal,
PrimaryColor,
SecondaryColor,
Fog,
PaletteSkin,
Empty,
TexCoord0,
TexCoord1,
TexCoord2,
TexCoord3,
TexCoord4,
TexCoord5,
TexCoord6,
TexCoord7,
NumOffsets
};
extern const uint16 g_VertexFlags[CVertexBuffer::NumValue];
extern const char *g_AttribNames[CVertexBuffer::NumValue];
extern const char *g_TexelNames[IDRV_MAT_MAXTEXTURES];
extern const char *g_ConstantNames[4];
namespace /* anonymous */ {
inline bool hasFlag(uint32 data, uint32 flag)
{
if ((data & flag) != 0)
return true;
else
return false;
}
} /* anonymous namespace */
#ifdef NL_STATIC
} // NLDRIVERGL3
#endif
} // NL3D
#endif // NL_DRIVER_OPENGL_PROGRAM_H
/* end of file */

@ -19,9 +19,6 @@
#include "nel/misc/types_nl.h"
#define SHADER_MAX_TEXTURES 4
#define SHADER_MAX_LIGHTS 8
namespace NL3D
{
class CVertexProgram;
@ -86,13 +83,13 @@ namespace NL3D
};
CShaderDesc() {
for (int i = 0; i < SHADER_MAX_TEXTURES; i++)
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
texEnvMode[ i ] = 0;
for (int i = 0; i < SHADER_MAX_LIGHTS; i++)
for (int i = 0; i < NL_OPENGL3_MAX_LIGHT; i++)
lightMode[ i ] = Nolight;
for (int i = 0; i < SHADER_MAX_TEXTURES; i++)
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
useTextureStage[ i ] = false;
useFirstTextureCoordSet = false;
noTextures = true;
@ -146,18 +143,18 @@ namespace NL3D
if (useFirstTextureCoordSet != o.useFirstTextureCoordSet)
return false;
for (int i = 0; i < SHADER_MAX_TEXTURES; i++)
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
if (texEnvMode[ i ] != o.texEnvMode[ i ])
return false;
for (int i = 0; i < SHADER_MAX_TEXTURES; i++)
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
if (useTextureStage[ i ] != o.useTextureStage[ i ])
return false;
}
if (lightingEnabled())
{
for (int i = 0; i < SHADER_MAX_LIGHTS; i++)
for (int i = 0; i < NL_OPENGL3_MAX_LIGHT; i++)
if (lightMode[ i ] != o.lightMode[ i ])
return false;
}
@ -258,8 +255,8 @@ namespace NL3D
};
uint32 features;
uint32 texEnvMode[ SHADER_MAX_TEXTURES ];
bool useTextureStage[ SHADER_MAX_TEXTURES ];
uint32 texEnvMode[ IDRV_MAT_MAXTEXTURES ];
bool useTextureStage[ IDRV_MAT_MAXTEXTURES ];
bool useFirstTextureCoordSet;
bool noTextures;
uint32 vbFlags;
@ -267,7 +264,7 @@ namespace NL3D
uint32 nlightmaps;
float alphaTestTreshold;
uint32 fogMode;
TLightMode lightMode[ SHADER_MAX_LIGHTS ];
TLightMode lightMode[ NL_OPENGL3_MAX_LIGHT ];
bool pointLight;
SShaderPair shaderPair;

@ -26,8 +26,6 @@ namespace NL3D {
namespace NLDRIVERGL3 {
#endif
#define NL_OPENGL3_MAX_LIGHT 8
// ***************************************************************************
/**
* Class for optimizing calls to openGL states, by caching old ones.

@ -23,6 +23,7 @@
#include "nel/3d/light.h"
#include "driver_opengl.h"
#include "driver_opengl_program.h"
#include "driver_opengl_vertex_buffer_hard.h"
namespace NL3D {
@ -51,91 +52,6 @@ bool operator<(const CVPBuiltin &left, const CVPBuiltin &right)
namespace
{
inline bool hasFlag(uint32 data, uint32 flag)
{
if ((data & flag) != 0)
return true;
else
return false;
}
enum TAttribOffset
{
Position,
Weight,
Normal,
PrimaryColor,
SecondaryColor,
Fog,
PaletteSkin,
Empty,
TexCoord0,
TexCoord1,
TexCoord2,
TexCoord3,
TexCoord4,
TexCoord5,
TexCoord6,
TexCoord7,
NumOffsets
};
const uint16 s_VertexFlags[CVertexBuffer::NumValue] =
{
CVertexBuffer::PositionFlag,
CVertexBuffer::WeightFlag,
CVertexBuffer::NormalFlag,
CVertexBuffer::PrimaryColorFlag,
CVertexBuffer::SecondaryColorFlag,
CVertexBuffer::FogFlag,
CVertexBuffer::PaletteSkinFlag,
0,
CVertexBuffer::TexCoord0Flag,
CVertexBuffer::TexCoord1Flag,
CVertexBuffer::TexCoord2Flag,
CVertexBuffer::TexCoord3Flag,
CVertexBuffer::TexCoord4Flag,
CVertexBuffer::TexCoord5Flag,
CVertexBuffer::TexCoord6Flag,
CVertexBuffer::TexCoord7Flag
};
const char *s_AttribNames[ CVertexBuffer::NumValue ] =
{
"position",
"weight",
"normal",
"color",
"color2",
"fog",
"paletteSkin",
"none",
"texCoord0",
"texCoord1",
"texCoord2",
"texCoord3",
"texCoord4",
"texCoord5",
"texCoord6",
"texCoord7"
};
const char *s_TexelNames[ SHADER_MAX_TEXTURES ] =
{
"texel0",
"texel1",
"texel2",
"texel3"
};
const char *s_ConstantNames[ 4 ] =
{
"constant0",
"constant1",
"constant2",
"constant3"
};
void vpLightUniforms(std::stringstream &ss, const CVPBuiltin &desc, int i)
{
switch (desc.LightMode[i])
@ -288,13 +204,13 @@ namespace
ss << std::endl;
for (int i = Position; i < NumOffsets; ++i)
if (hasFlag(desc.VertexFormat, s_VertexFlags[i]))
ss << "layout (location = " << i << ") " << "in vec4 " << "v" << s_AttribNames[i] << ";" << std::endl;
if (hasFlag(desc.VertexFormat, g_VertexFlags[i]))
ss << "layout (location = " << i << ") " << "in vec4 " << "v" << g_AttribNames[i] << ";" << std::endl;
ss << std::endl;
for (int i = Weight; i < NumOffsets; ++i)
if (hasFlag(desc.VertexFormat, s_VertexFlags[i]))
ss << "smooth out vec4 " << s_AttribNames[i] << ";" << std::endl;
if (hasFlag(desc.VertexFormat, g_VertexFlags[i]))
ss << "smooth out vec4 " << g_AttribNames[i] << ";" << std::endl;
ss << std::endl;
// if (!useTextures) {
@ -327,10 +243,10 @@ namespace
ss << "void main(void)" << std::endl;
ss << "{" << std::endl;
ss << "gl_Position = modelViewProjection * " << "v" << s_AttribNames[0] << ";" << std::endl;
ss << "gl_Position = modelViewProjection * " << "v" << g_AttribNames[0] << ";" << std::endl;
if (desc.Fog || desc.Lighting)
ss << "ecPos4 = modelView * v" << s_AttribNames[0] << ";" << std::endl;
ss << "ecPos4 = modelView * v" << g_AttribNames[0] << ";" << std::endl;
if (desc.Fog)
ss << "ecPos = ecPos4;" << std::endl;
@ -344,9 +260,9 @@ namespace
for (int i = Weight; i < NumOffsets; i++)
{
if (hasFlag(desc.VertexFormat, s_VertexFlags[i]))
if (hasFlag(desc.VertexFormat, g_VertexFlags[i]))
{
ss << s_AttribNames[i] << " = " << "v" << s_AttribNames[i] << ";" << std::endl;
ss << g_AttribNames[i] << " = " << "v" << g_AttribNames[i] << ";" << std::endl;
}
}

@ -62,3 +62,5 @@
#include "nel/misc/command.h"
#include "nel/3d/driver.h"
#define NL_OPENGL3_MAX_LIGHT 8

Loading…
Cancel
Save