Removed dependency on GL_ARB_shading_language_420pack

This commit is contained in:
parax0 2015-07-29 20:25:27 -04:00
parent ae0b6f97df
commit dafa05d5d2
2 changed files with 65 additions and 58 deletions

View File

@ -306,8 +306,6 @@ bool CShaderGenerator::CreatePixelShader(const CMaterial& Mat)
{ {
std::stringstream ShaderCode; std::stringstream ShaderCode;
ShaderCode << "#version 330 core\n" ShaderCode << "#version 330 core\n"
<< "\n"
<< "#extension GL_ARB_shading_language_420pack : enable\n" // Needed to set texture binding layouts
<< "\n"; << "\n";
EVertexDescription VtxDesc = Mat.VtxDesc(); EVertexDescription VtxDesc = Mat.VtxDesc();
@ -335,7 +333,7 @@ bool CShaderGenerator::CreatePixelShader(const CMaterial& Mat)
for (u32 iPass = 0; iPass < PassCount; iPass++) for (u32 iPass = 0; iPass < PassCount; iPass++)
if (Mat.Pass(iPass)->Texture() != nullptr) if (Mat.Pass(iPass)->Texture() != nullptr)
ShaderCode << "layout(binding = " << iPass << ") uniform sampler2D Texture" << iPass << ";\n"; ShaderCode << "uniform sampler2D Texture" << iPass << ";\n";
ShaderCode <<"\n"; ShaderCode <<"\n";

View File

@ -49,17 +49,14 @@ void CMaterial::GenerateShader()
bool CMaterial::SetCurrent(ERenderOptions Options) bool CMaterial::SetCurrent(ERenderOptions Options)
{ {
// Bind textures // Bind textures
for (u32 iPass = 0; iPass < mPasses.size(); iPass++) const char *skpSamplers[8] = {
mPasses[iPass]->LoadTexture(iPass); "Texture0", "Texture1", "Texture2", "Texture3",
"Texture4", "Texture5", "Texture6", "Texture7"
};
// Skip material setup if the currently bound material is identical // Skip material setup if the currently bound material is identical
if (sCurrentMaterial == HashParameters()) if (sCurrentMaterial != HashParameters())
{ {
GLuint NumLightsLoc = CShader::CurrentShader()->GetUniformLocation("NumLights");
glUniform1i(NumLightsLoc, CGraphics::sNumLights);
return true;
}
// Shader setup // Shader setup
if (mShaderStatus == eNoShader) GenerateShader(); if (mShaderStatus == eNoShader) GenerateShader();
mpShader->SetCurrent(); mpShader->SetCurrent();
@ -107,12 +104,24 @@ bool CMaterial::SetCurrent(ERenderOptions Options)
for (u32 iPass = 0; iPass < mPasses.size(); iPass++) for (u32 iPass = 0; iPass < mPasses.size(); iPass++)
mPasses[iPass]->SetAnimCurrent(Options, iPass); mPasses[iPass]->SetAnimCurrent(Options, iPass);
GLuint NumLightsLoc = mpShader->GetUniformLocation("NumLights");
glUniform1i(NumLightsLoc, CGraphics::sNumLights);
CGraphics::UpdateVertexBlock(); CGraphics::UpdateVertexBlock();
CGraphics::UpdatePixelBlock(); CGraphics::UpdatePixelBlock();
sCurrentMaterial = HashParameters(); sCurrentMaterial = HashParameters();
}
// Bind textures
CShader *pShader = CShader::CurrentShader();
for (u32 iPass = 0; iPass < mPasses.size(); iPass++)
{
mPasses[iPass]->LoadTexture(iPass);
GLint sampler = pShader->GetUniformLocation(skpSamplers[iPass]);
glUniform1i(sampler, iPass);
}
// Bind num lights
GLuint NumLightsLoc = pShader->GetUniformLocation("NumLights");
glUniform1i(NumLightsLoc, CGraphics::sNumLights);
return true; return true;
} }