GL3: Prepare TexGen implementation

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 8532f79833
commit 2aa36f413d

@ -52,7 +52,6 @@ namespace NL3D
void CGLSLShaderGenerator::reset()
{
material = NULL;
vbFormat = 0;
desc = NULL;
ss.str("");
ss.clear();
@ -73,7 +72,7 @@ namespace NL3D
for (int i = Weight; i < NumOffsets; i++)
{
if (hasFlag(vbFormat, g_VertexFlags[i]))
if (hasFlag(desc->vbFlags, g_VertexFlags[i]))
{
ss << "smooth in vec4 ";
ss << g_AttribNames[i] << ";" << std::endl;
@ -540,7 +539,11 @@ namespace NL3D
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
{
if (desc->getUseTexStage(i))
ss << "uniform sampler2D sampler" << sampler << ";" << std::endl;
{
ss << "uniform "
<< ((desc->textureSamplerMode[i] == SamplerCube) ? "samplerCube" : "sampler2D")
<< " sampler" << sampler << ";" << std::endl;
}
sampler++;
}
@ -577,7 +580,7 @@ namespace NL3D
ss << "diffuse = applyLights(diffuse);" << std::endl;
ss << "diffuse.a = 1.0;" << std::endl;
}
if (hasFlag(vbFormat, g_VertexFlags[PrimaryColor]))
if (hasFlag(desc->vbFlags, g_VertexFlags[PrimaryColor]))
ss << "diffuse = color * diffuse;" << std::endl; // TODO: If this is the correct location, we should premultiply light and color in VS.
bool textures = false;
@ -587,9 +590,10 @@ namespace NL3D
{
ss << "vec4 texel" << i << " = texture(sampler" << i << ", ";
if (desc->hasVBFlags(g_VertexFlags[TexCoord0 + i]))
ss << g_AttribNames[TexCoord0 + i] << ".st);";
ss << g_AttribNames[TexCoord0 + i];
else
ss << g_AttribNames[TexCoord0] << ".st);";
ss << g_AttribNames[TexCoord0];
ss << ((desc->textureSamplerMode[i] == SamplerCube) ? ".str);" : ".st);");
ss << std::endl;
textures = true;
}
@ -823,7 +827,7 @@ namespace NL3D
int ntextures = 0;
for (int i = TexCoord0; i < TexCoord4; i++)
{
if (hasFlag(vbFormat, g_VertexFlags[i]))
if (hasFlag(desc->vbFlags, g_VertexFlags[i]))
ntextures++;
}

@ -40,7 +40,6 @@ namespace NL3D
void generatePS(std::string &ps);
void setMaterial(CMaterial *mat) { material = mat; }
void setVBFormat(uint16 format) { vbFormat = format; }
void setShaderDesc(CShaderDesc *d) { desc = d; }
private:
@ -143,7 +142,6 @@ namespace NL3D
////////////////////////////////////////////////////////////////////////////////////////////////////////
std::stringstream ss;
uint16 vbFormat;
CMaterial const *material;
CShaderDesc const *desc;
};

@ -1091,9 +1091,12 @@ void CDriverGL3::setupSpecularBegin()
// For all cases, setup the TexCoord gen for stage1
_DriverGLStates.activeTexture(1);
// setup the good matrix for stage 1.
_UserTexMat[ 1 ] = _SpecularTexMtx;
// todo hulud remove - lol
// _DriverGLStates.setTextureMode(CDriverGLStates::TextureCubeMap);
setTexGenModeVP(1, TexGenReflectionMap);
// setup the good matrix for stage 1.
_UserTexMat[1] = _SpecularTexMtx;
}
// ***************************************************************************
@ -1103,8 +1106,8 @@ void CDriverGL3::setupSpecularEnd()
// Disable Texture coord generation.
setTexGenModeVP(1, TexGenDisabled);
// Happiness !!! we have already enabled the stage 1
_UserTexMat[ 1 ].identity();
// Happiness !!! we have already enabled the stage 1 - lolwhat
_UserTexMat[1].identity();
}
// ***************************************************************************

@ -556,8 +556,13 @@ void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat)
desc.setShaderType(mat.getShader());
uint16 vbFlags = _CurrentVertexBufferHard->VB->getVertexFormat();
for (sint i = 0; i < IDRV_MAT_MAXTEXTURES; ++i)
if (m_VPBuiltinCurrent.TexGenMode[0] >= 0)
vbFlags |= g_VertexFlags[TexCoord0 + i]; // texgen hack for keeping pp simpler
{
if (m_VPBuiltinCurrent.TexGenMode[i] >= 0)
{
//nldebug("texgen hack for keeping pp simpler, stage %i, tex %s valid", i, mat.getTexture(i) ? "IS" : "NOT");
vbFlags |= g_VertexFlags[TexCoord0 + i];
}
}
desc.setVBFlags(vbFlags);
if (mat.getShader() == CMaterial::LightMap)
@ -565,14 +570,20 @@ void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat)
//int i = 0;
if (mat.getShader() == CMaterial::Normal)
if (mat.getShader() == CMaterial::Normal
|| mat.getShader() == CMaterial::UserColor
|| mat.getShader() == CMaterial::Specular)
{
bool useTextures = false;
int maxTextures = std::min(int(IDRV_MAT_MAXTEXTURES), int(IDRV_MAT_MAXTEXTURES));
for (int i = 0; i < maxTextures; i++)
if (mat.getShader() == CMaterial::Normal)
{
desc.setTexEnvMode(i, mat.getTexEnvMode(i));
for (int i = 0; i < maxTextures; i++)
{
desc.setTexEnvMode(i, mat.getTexEnvMode(i));
} // todo specular env mode..
}
for (int i = 0; i < maxTextures; i++)
@ -582,8 +593,18 @@ void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat)
&& (desc.hasVBFlags(g_VertexFlags[TexCoord0]) || desc.hasVBFlags(g_VertexFlags[TexCoord0 + i]))
)
{
//nldebug("use stage %i", i);
desc.setUseTexStage(i, true);
useTextures = true;
desc.textureSamplerMode[i] = mat.getTexture(i)->isTextureCube() ? SamplerCube : Sampler2D; // Driver state
}
else
{
/*nldebug("stage fail %i, tex %s, tc0 %s, tci, %s", i, mat.getTexture(i) ? "VALID" : "NO",
desc.hasVBFlags(g_VertexFlags[TexCoord0]) ? "YES" : "NO",
desc.hasVBFlags(g_VertexFlags[TexCoord0 + i]) ? "YES" : "NO");*/
}
}
@ -599,7 +620,7 @@ void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat)
desc.setAlphaTestThreshold(mat.getAlphaTestThreshold());
}
if (m_VPBuiltinCurrent.Fog)
if (m_VPBuiltinCurrent.Fog) // Driver state
{
desc.setFog(true);
desc.setFogMode(CShaderDesc::Linear);
@ -711,7 +732,6 @@ bool CDriverGL3::setupBuiltinPixelProgram(CMaterial &mat)
shaderGenerator->reset();
shaderGenerator->setMaterial(&mat);
shaderGenerator->setVBFormat(_CurrentVertexBufferHard->VB->getVertexFormat());
shaderGenerator->setShaderDesc(&desc);
// If we don't already have a vertex program attached, we'll generate it now

@ -153,6 +153,10 @@ namespace NL3D
if (texEnvMode[ i ] != o.texEnvMode[ i ])
return false;
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
if (textureSamplerMode[ i ] != o.textureSamplerMode[ i ])
return false;
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
if (useTextureStage[ i ] != o.useTextureStage[ i ])
return false;
@ -250,7 +254,7 @@ namespace NL3D
void setShaders(SShaderPair sp) { shaderPair = sp; }
SShaderPair getShaders() const{ return shaderPair; }
private:
public:
enum TShaderFeatures
{

@ -356,8 +356,8 @@ void CDriverGL3::setTexGenModeVP(uint stage, sint mode)
H_AUTO_OGL(CDriverGL3_setTexGenModeVP)
if (m_VPBuiltinCurrent.TexGenMode[stage] != mode)
{
if (mode >= 0)
nlwarning("enable texgen %i, %i, not implemented", stage, mode);
//if (mode >= 0)
// nlwarning("enable texgen %i, %i, not implemented", stage, mode);
m_VPBuiltinCurrent.TexGenMode[stage] = mode;
m_VPBuiltinTouched = true;
}

Loading…
Cancel
Save