GL3: Render up to 31 lightmaps at once!

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 5d542ed91e
commit 96d4a17340

@ -621,7 +621,7 @@ void CDriverGL3::computeLightMapInfos(const CMaterial &mat)
} }
// Compute how many pass, according to driver caps. // Compute how many pass, according to driver caps.
_NLightMapPerPass = IDRV_MAT_MAXTEXTURES - 1; _NLightMapPerPass = std::min(_Extensions.MaxFragmentTextureImageUnits, (GLint)IDRV_PROGRAM_MAXSAMPLERS) - 1;
// Number of pass. // Number of pass.
_NLightMapPass = (_NLightMaps + _NLightMapPerPass - 1) / (_NLightMapPerPass); _NLightMapPass = (_NLightMaps + _NLightMapPerPass - 1) / (_NLightMapPerPass);
@ -678,7 +678,7 @@ void CDriverGL3::setupLightMapPass(uint pass)
// No lightmap or all blacks??, just setup "black texture" for stage 0. // No lightmap or all blacks??, just setup "black texture" for stage 0.
if (_NLightMaps == 0) if (_NLightMaps == 0)
{ {
nldebug("No lightmaps"); // nldebug("No lightmaps");
ITexture *text = mat.getTexture(0); ITexture *text = mat.getTexture(0);
activateTexture(0, text); activateTexture(0, text);
@ -743,10 +743,10 @@ void CDriverGL3::setupLightMapPass(uint pass)
// Lightmap factors // Lightmap factors
NLMISC::CRGBAF selfIllumination(col); NLMISC::CRGBAF selfIllumination(col);
NLMISC::CRGBAF constant[IDRV_MAT_MAXTEXTURES]; NLMISC::CRGBAF constant[IDRV_PROGRAM_MAXSAMPLERS];
// setup all stages. // setup all stages.
for (uint stage = 0; stage < IDRV_MAT_MAXTEXTURES; ++stage) for (uint stage = 0; stage < std::min(_Extensions.MaxFragmentTextureImageUnits, (GLint)IDRV_PROGRAM_MAXSAMPLERS); ++stage)
{ {
// if must setup a lightmap stage // if must setup a lightmap stage
if (stage < nstages - 1) // last stage is user texture if (stage < nstages - 1) // last stage is user texture
@ -770,8 +770,11 @@ void CDriverGL3::setupLightMapPass(uint pass)
//================================================== //==================================================
if (text) if (text)
{ {
// Setup env for texture stage. if (stage < IDRV_MAT_MAXTEXTURES)
setTexGenModeVP(stage, TexGenDisabled); {
// Setup env for texture stage.
setTexGenModeVP(stage, TexGenDisabled);
}
// FIXME GL3: builtin TexEnv[stage] = TexEnvSpecialLightMap // FIXME GL3: builtin TexEnv[stage] = TexEnvSpecialLightMap
@ -818,8 +821,11 @@ void CDriverGL3::setupLightMapPass(uint pass)
// setup ModulateRGB/ReplaceAlpha env. (this may disable possible COMBINE4_NV setup). // setup ModulateRGB/ReplaceAlpha env. (this may disable possible COMBINE4_NV setup).
// activateTexEnvMode(stage, _LightMapLastStageEnv); // SHADER BUILTIN // activateTexEnvMode(stage, _LightMapLastStageEnv); // SHADER BUILTIN
// Setup gen tex off if (stage < IDRV_MAT_MAXTEXTURES)
setTexGenModeVP(stage, TexGenDisabled); {
// Setup gen tex off
setTexGenModeVP(stage, TexGenDisabled);
}
} }
} }
else else
@ -903,7 +909,7 @@ void CDriverGL3::setupLightMapPass(uint pass)
setupBuiltinPrograms(); setupBuiltinPrograms();
// Set constants // Set constants
for (uint stage = 0; stage < IDRV_MAT_MAXTEXTURES; ++stage) for (uint stage = 0; stage < std::min(_Extensions.MaxFragmentTextureImageUnits, (GLint)IDRV_PROGRAM_MAXSAMPLERS); ++stage)
{ {
uint constantIdx = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Constant0 + stage)); uint constantIdx = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Constant0 + stage));
if (constantIdx != ~0) if (constantIdx != ~0)

@ -354,10 +354,10 @@ void ppSpecular(std::stringstream &ss, const CPPBuiltin &desc)
} }
} }
void ppLightmap(std::stringstream &ss, const CPPBuiltin &desc) void ppLightmap(std::stringstream &ss, const CPPBuiltin &desc, CGlExtensions &glext)
{ {
uint nstages; uint nstages;
for (nstages = 0; nstages < IDRV_MAT_MAXTEXTURES; ++nstages) for (nstages = 0; nstages < std::min(glext.MaxFragmentTextureImageUnits, (GLint)IDRV_PROGRAM_MAXSAMPLERS); ++nstages)
if (!useTex(desc, nstages)) if (!useTex(desc, nstages))
break; break;
if (nstages == 0) if (nstages == 0)
@ -382,7 +382,7 @@ void ppLightmap(std::stringstream &ss, const CPPBuiltin &desc)
} }
} }
void ppGenerate(std::string &result, const CPPBuiltin &desc) void ppGenerate(std::string &result, const CPPBuiltin &desc, CGlExtensions &glext)
{ {
std::stringstream ss; std::stringstream ss;
ss << "// Builtin Pixel Shader: " << s_ShaderNames[desc.Shader] << std::endl; ss << "// Builtin Pixel Shader: " << s_ShaderNames[desc.Shader] << std::endl;
@ -405,7 +405,9 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
ss << std::endl; ss << std::endl;
uint maxTex = maxTextures(desc.Shader); uint maxTex = maxTextures(desc.Shader);
for (uint stage = 0; stage < maxTex; ++stage) uint maxSam = maxSamplers(desc.Shader, glext);
for (uint stage = 0; stage < maxSam; ++stage)
{ {
if (stage == 1 && desc.Shader == CMaterial::UserColor) if (stage == 1 && desc.Shader == CMaterial::UserColor)
{ {
@ -426,11 +428,21 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
ss << std::endl; ss << std::endl;
// TexEnv // TexEnv
ss << "uniform vec4 constant0;" << std::endl; // FIXME: we must optimize this by texenv!... switch (desc.Shader)
ss << "uniform vec4 constant1;" << std::endl; {
ss << "uniform vec4 constant2;" << std::endl; case CMaterial::Normal:
ss << "uniform vec4 constant3;" << std::endl; case CMaterial::UserColor:
ss << std::endl; case CMaterial::LightMap:
for (uint stage = 0; stage < maxSam; ++stage)
{
if (useTex(desc, stage))
{
ss << "uniform vec4 constant" << stage << ";" << std::endl;
ss << std::endl;
}
}
break;
}
// Alpha test // Alpha test
if (desc.Flags & IDRV_MAT_ALPHA_TEST) if (desc.Flags & IDRV_MAT_ALPHA_TEST)
@ -480,7 +492,7 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
// Vertex color (light or unlit diffuse, primary and secondary) // Vertex color (light or unlit diffuse, primary and secondary)
ss << "fragColor = vertexColor;" << std::endl; ss << "fragColor = vertexColor;" << std::endl;
for (uint stage = 0; stage < maxTex; ++stage) for (uint stage = 0; stage < maxSam; ++stage)
{ {
if (stage == 1 && desc.Shader == CMaterial::UserColor) if (stage == 1 && desc.Shader == CMaterial::UserColor)
{ {
@ -489,7 +501,7 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
else if (useTex(desc, stage)) else if (useTex(desc, stage))
{ {
ss << "vec4 texel" << stage << " = texture(sampler" << stage << ", "; ss << "vec4 texel" << stage << " = texture(sampler" << stage << ", ";
if (desc.Shader == CMaterial::LightMap && stage != (maxTex - 1) && useTex(desc, stage + 1) && hasFlag(desc.VertexFormat, g_VertexFlags[TexCoord1])) if (desc.Shader == CMaterial::LightMap && stage != (maxSam - 1) && useTex(desc, stage + 1) && hasFlag(desc.VertexFormat, g_VertexFlags[TexCoord1]))
{ {
ss << g_AttribNames[TexCoord1]; ss << g_AttribNames[TexCoord1];
} }
@ -497,7 +509,7 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
{ {
ss << g_AttribNames[TexCoord0]; ss << g_AttribNames[TexCoord0];
} }
else if (hasFlag(desc.VertexFormat, g_VertexFlags[TexCoord0 + stage])) else if (stage < maxTex && hasFlag(desc.VertexFormat, g_VertexFlags[TexCoord0 + stage]))
{ {
ss << g_AttribNames[TexCoord0 + stage]; ss << g_AttribNames[TexCoord0 + stage];
} }
@ -526,7 +538,7 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
ppSpecular(ss, desc); ppSpecular(ss, desc);
break; break;
case CMaterial::LightMap: case CMaterial::LightMap:
ppLightmap(ss, desc); ppLightmap(ss, desc, glext);
break; break;
default: default:
nlwarning("GL3: Try to generate unknown shader type (%s)", s_ShaderNames[desc.Shader]); nlwarning("GL3: Try to generate unknown shader type (%s)", s_ShaderNames[desc.Shader]);
@ -564,7 +576,7 @@ void CDriverGL3::generateBuiltinPixelProgram(CMaterial &mat)
} }
std::string result; std::string result;
ppGenerate(result, matDrv->PPBuiltin); ppGenerate(result, matDrv->PPBuiltin, _Extensions);
CPixelProgram *program = new CPixelProgram(); CPixelProgram *program = new CPixelProgram();
IProgram::CSource *src = new IProgram::CSource(); IProgram::CSource *src = new IProgram::CSource();

Loading…
Cancel
Save