GL3: Cleanup samplers

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 7691e22a28
commit f62228592e

@ -81,8 +81,8 @@ namespace NL3D
} }
ss << std::endl; ss << std::endl;
#if 0 // LIGHTING DEBUG #if 1 // LIGHTING DEBUG
if (desc->lightingEnabled()) if (desc->lightingEnabled() || material->getShader() != CMaterial::Normal)
{ {
generateInvalidPS(); generateInvalidPS();
} }
@ -523,7 +523,7 @@ namespace NL3D
if (desc->lightingEnabled()) if (desc->lightingEnabled())
addLightsFS(); addLightsFS();
//ss << "fragColor = fragColor + vec4(0.0, 0.25, 0.0, 0.0);" << std::endl; ss << "fragColor = fragColor + vec4(0.25, 0.0, 0.0, 0.0);" << std::endl;
/*if (desc->fogEnabled()) /*if (desc->fogEnabled())
addFog(); addFog();
@ -619,6 +619,8 @@ namespace NL3D
addAlphaTest(); addAlphaTest();
ss << "fragColor = fragColor + vec4(0.0, 0.25, 0.0, 0.0);" << std::endl;
ss << "}" << std::endl; ss << "}" << std::endl;
} }
@ -1109,11 +1111,11 @@ namespace NL3D
ss << "smooth in vec3 cubeTexCoords2;" << std::endl; ss << "smooth in vec3 cubeTexCoords2;" << std::endl;
ss << std::endl; ss << std::endl;
ss << "uniform samplerCube cubeSampler0;" << std::endl; ss << "uniform samplerCube sampler0;" << std::endl;
ss << "uniform sampler2D sampler1;" << std::endl; ss << "uniform sampler2D sampler1;" << std::endl;
if (material->getShader() == CMaterial::PerPixelLighting) if (material->getShader() == CMaterial::PerPixelLighting)
ss << "uniform samplerCube cubeSampler2;" << std::endl; ss << "uniform samplerCube sampler2;" << std::endl;
addDiffuse(); addDiffuse();
@ -1126,11 +1128,11 @@ namespace NL3D
ss << "void main(void)" << std::endl; ss << "void main(void)" << std::endl;
ss << "{" << std::endl; ss << "{" << std::endl;
ss << "vec4 texel0 = texture(cubeSampler0, cubeTexCoords0);" << std::endl; ss << "vec4 texel0 = texture(sampler0, cubeTexCoords0);" << std::endl;
ss << "vec4 texel1 = texture(sampler1, texCoord1.st);" << std::endl; ss << "vec4 texel1 = texture(sampler1, texCoord1.st);" << std::endl;
if (material->getShader() == CMaterial::PerPixelLighting) if (material->getShader() == CMaterial::PerPixelLighting)
ss << "vec4 texel2 = texture(cubeSampler2, cubeTexCoords2);" << std::endl; ss << "vec4 texel2 = texture(sampler2, cubeTexCoords2);" << std::endl;
ss << "vec4 texel;" << std::endl; ss << "vec4 texel;" << std::endl;

@ -1884,38 +1884,18 @@ void CDriverGL3::reloadUserShaders()
loader.loadShaders("./shaders"); loader.loadShaders("./shaders");
} }
CVertexProgramDrvInfosGL3::CVertexProgramDrvInfosGL3(CDriverGL3 *drv, ItGPUPrgDrvInfoPtrList it) : CProgramDrvInfosGL3::CProgramDrvInfosGL3(CDriverGL3 *drv, ItGPUPrgDrvInfoPtrList it) :
IProgramDrvInfos(drv, it) IProgramDrvInfos(drv, it)
{ {
programId = 0; programId = 0;
} }
CVertexProgramDrvInfosGL3::~CVertexProgramDrvInfosGL3() CProgramDrvInfosGL3::~CProgramDrvInfosGL3()
{ {
programId = 0; programId = 0;
} }
uint CVertexProgramDrvInfosGL3::getUniformIndex(const char *name) const uint CProgramDrvInfosGL3::getUniformIndex(const char *name) const
{
int idx = nglGetUniformLocation(programId, name);
if (idx == -1)
return ~0;
else
return idx;
}
CPixelProgramDrvInfosGL3::CPixelProgramDrvInfosGL3(CDriverGL3 *drv, ItGPUPrgDrvInfoPtrList it) :
IProgramDrvInfos(drv, it)
{
programId = 0;
}
CPixelProgramDrvInfosGL3::~CPixelProgramDrvInfosGL3()
{
programId = 0;
}
uint CPixelProgramDrvInfosGL3::getUniformIndex(const char *name) const
{ {
int idx = nglGetUniformLocation(programId, name); int idx = nglGetUniformLocation(programId, name);
if (idx == -1) if (idx == -1)
@ -1924,7 +1904,6 @@ uint CPixelProgramDrvInfosGL3::getUniformIndex(const char *name) const
return idx; return idx;
} }
// *************************************************************************** // ***************************************************************************
void displayGLError(GLenum error) void displayGLError(GLenum error)
{ {

@ -384,6 +384,7 @@ public:
bool setupDynMatProgram(CMaterial& mat, uint pass); bool setupDynMatProgram(CMaterial& mat, uint pass);
bool setupUniforms(); bool setupUniforms();
void setupUniforms(TProgram program); void setupUniforms(TProgram program);
void setupInitialUniforms(IProgram *program);
void generateBuiltinVertexProgram(); void generateBuiltinVertexProgram();
void enableFogVP(bool enable); void enableFogVP(bool enable);
@ -1414,11 +1415,25 @@ public:
}; };
class CVertexProgramDrvInfosGL3 : public IProgramDrvInfos class CProgramDrvInfosGL3 : public IProgramDrvInfos
{ {
public: public:
CVertexProgramDrvInfosGL3(CDriverGL3 *drv, ItGPUPrgDrvInfoPtrList it); CProgramDrvInfosGL3(CDriverGL3 *drv, ItGPUPrgDrvInfoPtrList it);
~CVertexProgramDrvInfosGL3(); ~CProgramDrvInfosGL3();
uint getUniformIndex(const char *name) const;
GLuint getProgramId() const{ return programId; }
void setProgramId(GLuint id) { programId = id; }
private:
GLuint programId;
};
/*
class CProgramDrvInfosGL3 : public IProgramDrvInfos
{
public:
CProgramDrvInfosGL3(CDriverGL3 *drv, ItGPUPrgDrvInfoPtrList it);
~CProgramDrvInfosGL3();
uint getUniformIndex(const char *name) const; uint getUniformIndex(const char *name) const;
uint getProgramId() const{ return programId; } uint getProgramId() const{ return programId; }
void setProgramId(uint id) { programId = id; } void setProgramId(uint id) { programId = id; }
@ -1427,11 +1442,11 @@ private:
uint programId; uint programId;
}; };
class CPixelProgramDrvInfosGL3 : public IProgramDrvInfos class CProgramDrvInfosGL3 : public IProgramDrvInfos
{ {
public: public:
CPixelProgramDrvInfosGL3(CDriverGL3 *drv, ItGPUPrgDrvInfoPtrList it); CProgramDrvInfosGL3(CDriverGL3 *drv, ItGPUPrgDrvInfoPtrList it);
~CPixelProgramDrvInfosGL3(); ~CProgramDrvInfosGL3();
uint getUniformIndex(const char *name) const; uint getUniformIndex(const char *name) const;
uint getProgramId() const{ return programId; } uint getProgramId() const{ return programId; }
void setProgramId(uint id) { programId = id; } void setProgramId(uint id) { programId = id; }
@ -1440,6 +1455,7 @@ private:
uint programId; uint programId;
}; };
*/
#ifdef NL_STATIC #ifdef NL_STATIC
} // NLDRIVERGL3 } // NLDRIVERGL3

@ -165,6 +165,7 @@ void CDriverGL3::setLightMapDynamicLight (bool enable, const CLight& light)
void CDriverGL3::setupLightMapDynamicLighting(bool enable) void CDriverGL3::setupLightMapDynamicLighting(bool enable)
{ {
H_AUTO_OGL(CDriverGL3_setupLightMapDynamicLighting) H_AUTO_OGL(CDriverGL3_setupLightMapDynamicLighting)
// start lightmap dynamic lighting // start lightmap dynamic lighting
if (enable) if (enable)
{ {

@ -738,17 +738,6 @@ void CDriverGL3::setupNormalPass()
setUniform4f(IDriver::PixelProgram, cl, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]); setUniform4f(IDriver::PixelProgram, cl, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]);
} }
} }
// Set texture
ITexture *t = mat.getTexture(i);
if (t == NULL)
continue;
int index = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Sampler0 + i));
if (index == -1)
continue;
setUniform1i(IDriver::PixelProgram, index, i);
} }
} }
@ -936,12 +925,6 @@ void CDriverGL3::setupLightMapPass(uint pass)
setUniform4f(IDriver::PixelProgram, cl, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]); setUniform4f(IDriver::PixelProgram, cl, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]);
} }
int tl = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Sampler0 + stage));
if (tl != -1)
{
setUniform1i(IDriver::PixelProgram, tl, stage);
}
activateTexEnvColor(stage, stdEnv); activateTexEnvColor(stage, stdEnv);
// Setup env for texture stage. // Setup env for texture stage.
@ -976,13 +959,6 @@ void CDriverGL3::setupLightMapPass(uint pass)
// Setup gen tex off // Setup gen tex off
_DriverGLStates.activeTexture(stage); _DriverGLStates.activeTexture(stage);
_DriverGLStates.setTexGenMode(stage, 0); _DriverGLStates.setTexGenMode(stage, 0);
int tl = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Sampler0 + stage));
if (tl != -1)
{
setUniform1i(IDriver::PixelProgram, tl, stage);
}
} }
} }
else else
@ -1174,22 +1150,22 @@ void CDriverGL3::setupSpecularPass(uint pass)
return; return;
} }
int sl0 = m_DriverPixelProgram->getUniformIndex(CProgramIndex::Sampler0); int tm0 = m_DriverVertexProgram->getUniformIndex(CProgramIndex::TexMatrix0); // FIXME GL3 VERTEX PROGRAM
if (sl0 != -1) if (tm0 != -1)
{ {
setUniform1i(IDriver::PixelProgram, sl0, 0); setUniform4x4f(IDriver::VertexProgram, tm0, _UserTexMat[ 0 ]); // OR is it just 1 (and not 0 2 3)?
} }
int sl1 = m_DriverPixelProgram->getUniformIndex(CProgramIndex::Sampler1); int tm2 = m_DriverVertexProgram->getUniformIndex(CProgramIndex::TexMatrix2); // FIXME GL3 VERTEX PROGRAM
if (sl1 != -1) if (tm2 != -1)
{ {
setUniform1i(IDriver::PixelProgram, sl1, 1); setUniform4x4f(IDriver::VertexProgram, tm2, _UserTexMat[ 2 ]);
} }
int tml = m_DriverVertexProgram->getUniformIndex(CProgramIndex::TexMatrix0); // FIXME GL3 VERTEX PROGRAM int tm3 = m_DriverVertexProgram->getUniformIndex(CProgramIndex::TexMatrix3); // FIXME GL3 VERTEX PROGRAM
if (tml != -1) if (tm3 != -1)
{ {
setUniform4x4f(IDriver::VertexProgram, tml, _UserTexMat[ 1 ]); setUniform4x4f(IDriver::VertexProgram, tm3, _UserTexMat[ 3 ]);
} }
{ {

@ -87,10 +87,7 @@ const char *g_ConstantNames[4] =
bool CDriverGL3::supportVertexProgram(CVertexProgram::TProfile profile) const bool CDriverGL3::supportVertexProgram(CVertexProgram::TProfile profile) const
{ {
if (profile == IProgram::glsl330v) return (profile == IProgram::glsl330v);
return true;
else
return false;
} }
bool CDriverGL3::compileVertexProgram(CVertexProgram *program) bool CDriverGL3::compileVertexProgram(CVertexProgram *program)
@ -142,21 +139,20 @@ bool CDriverGL3::compileVertexProgram(CVertexProgram *program)
} }
} }
GLenum error = glGetError(); GLenum error = glGetError();
if (error != GL_NO_ERROR) if (error != GL_NO_ERROR)
return false; return false;
ItGPUPrgDrvInfoPtrList it = _GPUPrgDrvInfos.insert(_GPUPrgDrvInfos.end(),(NL3D::IProgramDrvInfos*)NULL); ItGPUPrgDrvInfoPtrList it = _GPUPrgDrvInfos.insert(_GPUPrgDrvInfos.end(),(NL3D::IProgramDrvInfos*)NULL);
CVertexProgramDrvInfosGL3 *drvInfo = new CVertexProgramDrvInfosGL3(this, it); CProgramDrvInfosGL3 *drvInfo = new CProgramDrvInfosGL3(this, it);
*it = drvInfo; *it = drvInfo;
program->m_DrvInfo = drvInfo; program->m_DrvInfo = drvInfo;
drvInfo->setProgramId(id); drvInfo->setProgramId(id);
program->buildInfo(src); program->buildInfo(src);
setupInitialUniforms(program);
return true; return true;
} }
@ -181,7 +177,7 @@ bool CDriverGL3::activeVertexProgram(CVertexProgram *program, bool driver)
} }
IProgramDrvInfos *di = program->m_DrvInfo; IProgramDrvInfos *di = program->m_DrvInfo;
CVertexProgramDrvInfosGL3 *drvInfo = dynamic_cast< CVertexProgramDrvInfosGL3* >(di); CProgramDrvInfosGL3 *drvInfo = dynamic_cast< CProgramDrvInfosGL3* >(di);
if (drvInfo == NULL) if (drvInfo == NULL)
{ {
m_UserVertexProgram = NULL; m_UserVertexProgram = NULL;
@ -258,13 +254,15 @@ bool CDriverGL3::compilePixelProgram(CPixelProgram *program)
return false; return false;
ItGPUPrgDrvInfoPtrList it = _GPUPrgDrvInfos.insert(_GPUPrgDrvInfos.end(), (NL3D::IProgramDrvInfos*)NULL); ItGPUPrgDrvInfoPtrList it = _GPUPrgDrvInfos.insert(_GPUPrgDrvInfos.end(), (NL3D::IProgramDrvInfos*)NULL);
CPixelProgramDrvInfosGL3 *drvInfo = new CPixelProgramDrvInfosGL3(this, it); CProgramDrvInfosGL3 *drvInfo = new CProgramDrvInfosGL3(this, it);
*it = drvInfo; *it = drvInfo;
drvInfo->setProgramId(id); drvInfo->setProgramId(id);
program->m_DrvInfo = drvInfo; program->m_DrvInfo = drvInfo;
program->buildInfo(src); program->buildInfo(src);
setupInitialUniforms(program);
return true; return true;
} }
@ -296,7 +294,7 @@ bool CDriverGL3::activePixelProgram(CPixelProgram *program, bool driver)
} }
IProgramDrvInfos *di = program->m_DrvInfo; IProgramDrvInfos *di = program->m_DrvInfo;
CPixelProgramDrvInfosGL3 *drvInfo = dynamic_cast< CPixelProgramDrvInfosGL3* >(di); CProgramDrvInfosGL3 *drvInfo = dynamic_cast< CProgramDrvInfosGL3* >(di);
if (drvInfo == NULL) if (drvInfo == NULL)
{ {
m_UserPixelProgram = NULL; m_UserPixelProgram = NULL;
@ -330,7 +328,7 @@ uint32 CDriverGL3::getProgramId(TProgram program) const
if (m_DriverVertexProgram) if (m_DriverVertexProgram)
{ {
IProgramDrvInfos *di = m_DriverVertexProgram->m_DrvInfo; IProgramDrvInfos *di = m_DriverVertexProgram->m_DrvInfo;
CVertexProgramDrvInfosGL3 *drvInfo = dynamic_cast< CVertexProgramDrvInfosGL3* >(di); CProgramDrvInfosGL3 *drvInfo = dynamic_cast< CProgramDrvInfosGL3* >(di);
if (drvInfo != NULL) if (drvInfo != NULL)
id = drvInfo->getProgramId(); id = drvInfo->getProgramId();
} }
@ -340,7 +338,7 @@ uint32 CDriverGL3::getProgramId(TProgram program) const
if (m_DriverPixelProgram) if (m_DriverPixelProgram)
{ {
IProgramDrvInfos *di = m_DriverPixelProgram->m_DrvInfo; IProgramDrvInfos *di = m_DriverPixelProgram->m_DrvInfo;
CPixelProgramDrvInfosGL3 *drvInfo = dynamic_cast< CPixelProgramDrvInfosGL3* >(di); CProgramDrvInfosGL3 *drvInfo = dynamic_cast< CProgramDrvInfosGL3* >(di);
if (drvInfo != NULL) if (drvInfo != NULL)
id = drvInfo->getProgramId(); id = drvInfo->getProgramId();
} }
@ -1106,6 +1104,23 @@ void CDriverGL3::setupUniforms(TProgram program)
} }
} }
void CDriverGL3::setupInitialUniforms(IProgram *program)
{
IProgramDrvInfos *di = program->m_DrvInfo;
CProgramDrvInfosGL3 *drvInfo = dynamic_cast<CProgramDrvInfosGL3 *>(di);
if (drvInfo != NULL)
{
GLuint id = drvInfo->getProgramId();
for (uint i = 0; i < IDRV_MAT_MAXTEXTURES; ++i)
{
uint samplerIdx = program->getUniformIndex((CProgramIndex::TName)(CProgramIndex::Sampler0 + i));
if (samplerIdx >= 0)
nglProgramUniform1i(id, samplerIdx, i);
}
}
}
bool CDriverGL3::initProgramPipeline() bool CDriverGL3::initProgramPipeline()
{ {
ppoId = 0; ppoId = 0;

@ -205,8 +205,6 @@ namespace
// Ambient color of all lights is precalculated and added with self illumination, and multiplied with the material ambient. // Ambient color of all lights is precalculated and added with self illumination, and multiplied with the material ambient.
if (desc.Lighting) if (desc.Lighting)
ss << "uniform vec4 selfIllumination;" << std::endl; ss << "uniform vec4 selfIllumination;" << std::endl;
// ss << "uniform vec4 diffuseColor;" << std::endl;
// ss << "uniform vec4 specularColor;" << std::endl; // }
if (desc.Fog || desc.Lighting) if (desc.Fog || desc.Lighting)
ss << "uniform mat4 modelView;" << std::endl; ss << "uniform mat4 modelView;" << std::endl;

Loading…
Cancel
Save