Validate the sampler uniform against the number of (combined) texture image units.

Issue=95 TRAC #16568 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@642 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 424bb49d
#define MAJOR_VERSION 0
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 641
#define BUILD_REVISION 642
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -2604,7 +2604,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
applyShaders();
applyTextures();
if (!getCurrentProgram()->validateSamplers())
if (!getCurrentProgram()->validateSamplers(false))
{
return error(GL_INVALID_OPERATION);
}
......@@ -2671,7 +2671,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *
applyShaders();
applyTextures();
if (!getCurrentProgram()->validateSamplers())
if (!getCurrentProgram()->validateSamplers(false))
{
return error(GL_INVALID_OPERATION);
}
......
......@@ -2844,9 +2844,8 @@ void Program::validate()
else
{
applyUniforms();
if (!validateSamplers())
if (!validateSamplers(true))
{
appendToInfoLog("Samplers of conflicting types refer to the same texture image unit.");
mValidated = false;
}
else
......@@ -2856,12 +2855,13 @@ void Program::validate()
}
}
bool Program::validateSamplers() const
bool Program::validateSamplers(bool logErrors)
{
// if any two active samplers in a program are of different types, but refer to the same
// texture image unit, and this is the current program, then ValidateProgram will fail, and
// DrawArrays and DrawElements will issue the INVALID_OPERATION error.
const int maxCombinedTextureImageUnits = getContext()->getMaximumCombinedTextureImageUnits();
TextureType textureUnitType[MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF];
for (unsigned int i = 0; i < MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF; ++i)
......@@ -2874,12 +2874,26 @@ bool Program::validateSamplers() const
if (mSamplersPS[i].active)
{
int unit = mSamplersPS[i].logicalTextureUnit;
ASSERT(unit >= 0 && unit < MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF);
if (unit < 0 || unit >= maxCombinedTextureImageUnits)
{
if (logErrors)
{
appendToInfoLog("Sampler uniform (%d) exceeds MAX_COMBINED_TEXTURE_IMAGE_UNITS (%d)", unit, maxCombinedTextureImageUnits);
}
return false;
}
if (textureUnitType[unit] != TEXTURE_UNKNOWN)
{
if (mSamplersPS[i].textureType != textureUnitType[unit])
{
if (logErrors)
{
appendToInfoLog("Samplers of conflicting types refer to the same texture image unit (%d).", unit);
}
return false;
}
}
......@@ -2895,12 +2909,26 @@ bool Program::validateSamplers() const
if (mSamplersVS[i].active)
{
int unit = mSamplersVS[i].logicalTextureUnit;
ASSERT(unit >= 0 && unit < MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF);
if (unit < 0 || unit >= maxCombinedTextureImageUnits)
{
if (logErrors)
{
appendToInfoLog("Sampler uniform (%d) exceeds MAX_COMBINED_TEXTURE_IMAGE_UNITS (%d)", unit, maxCombinedTextureImageUnits);
}
return false;
}
if (textureUnitType[unit] != TEXTURE_UNKNOWN)
{
if (mSamplersVS[i].textureType != textureUnitType[unit])
{
if (logErrors)
{
appendToInfoLog("Samplers of conflicting types refer to the same texture image unit (%d).", unit);
}
return false;
}
}
......
......@@ -122,7 +122,7 @@ class Program
bool isFlaggedForDeletion() const;
void validate();
bool validateSamplers() const;
bool validateSamplers(bool logErrors);
bool isValidated() const;
unsigned int getSerial() const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment