Skip to content

Commit

Permalink
GLES1: glClientActiveTexture
Browse files Browse the repository at this point in the history
+ adds query for GL_MAX_TEXTURE_UNITS

BUG=angleproject:2306

Change-Id: Ie89fa6a067551170856bf0f7e6d7b4452b3da132
Reviewed-on: https://chromium-review.googlesource.com/984894
Commit-Queue: Lingfeng Yang <lfy@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
  • Loading branch information
741g authored and Commit Bot committed Mar 29, 2018
1 parent a3b220f commit 96310cd
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/libANGLE/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,10 @@ void Context::getIntegervImpl(GLenum pname, GLint *params)
case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
*params = mCaps.maxGeometryShaderStorageBlocks;
break;
// GLES1 emulation: Caps queries
case GL_MAX_TEXTURE_UNITS:
*params = mCaps.maxMultitextureUnits;
break;
default:
handleError(mGLState.getIntegerv(this, pname, params));
break;
Expand Down Expand Up @@ -6385,6 +6389,14 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
*type = GL_FLOAT;
*numParams = 1;
return true;
case GL_MAX_TEXTURE_UNITS:
*type = GL_INT;
*numParams = 1;
return true;
case GL_CLIENT_ACTIVE_TEXTURE:
*type = GL_INT;
*numParams = 1;
return true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/Context_gles_1_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void Context::clearDepthx(GLfixed depth)

void Context::clientActiveTexture(GLenum texture)
{
UNIMPLEMENTED();
mGLState.gles1().setClientTextureUnit(texture - GL_TEXTURE0);
}

void Context::clipPlanef(GLenum p, const GLfloat *eqn)
Expand Down
4 changes: 4 additions & 0 deletions src/libANGLE/ErrorStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ ERRMSG(InvalidBorder, "Border must be 0.");
ERRMSG(InvalidBufferTypes, "Invalid buffer target enum.");
ERRMSG(InvalidBufferUsage, "Invalid buffer usage enum.");
ERRMSG(InvalidClearMask, "Invalid mask bits.");
ERRMSG(InvalidCombinedImageUnit,
"Specified unit must be in [GL_TEXTURE0, GL_TEXTURE0 + GL_MAX_COMBINED_IMAGE_UNITS)");
ERRMSG(InvalidConstantColor,
"CONSTANT_COLOR (or ONE_MINUS_CONSTANT_COLOR) and CONSTANT_ALPHA (or "
"ONE_MINUS_CONSTANT_ALPHA) cannot be used together as source and destination factors in the "
Expand Down Expand Up @@ -91,6 +93,8 @@ ERRMSG(InvalidInternalFormat, "Invalid internal format.");
ERRMSG(InvalidMatrixMode, "Invalid matrix mode.");
ERRMSG(InvalidMemoryBarrierBit, "Invalid memory barrier bit.");
ERRMSG(InvalidMipLevel, "Level of detail outside of range.");
ERRMSG(InvalidMultitextureUnit,
"Specified unit must be in [GL_TEXTURE0, GL_TEXTURE0 + GL_MAX_TEXTURE_UNITS)");
ERRMSG(InvalidName, "Invalid name.");
ERRMSG(InvalidNameCharacters, "Name contains invalid characters.");
ERRMSG(InvalidPname, "Invalid pname.");
Expand Down
13 changes: 12 additions & 1 deletion src/libANGLE/GLES1State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ GLES1State::GLES1State()
mReflectionMapEnabled(false),
mCurrentColor({0.0f, 0.0f, 0.0f, 0.0f}),
mCurrentNormal({0.0f, 0.0f, 0.0f}),
mClientActiveTexture(0),
mCurrMatrixMode(MatrixType::Modelview),
mShadeModel(ShadingModel::Smooth),
mAlphaTestFunc(AlphaTestFunc::AlwaysPass),
Expand Down Expand Up @@ -80,8 +81,8 @@ void GLES1State::initialize(const Context *context)

mCurrentColor = {1.0f, 1.0f, 1.0f, 1.0f};
mCurrentNormal = {0.0f, 0.0f, 1.0f};

mCurrentTextureCoords.resize(caps.maxMultitextureUnits);
mClientActiveTexture = 0;

mTextureEnvironments.resize(caps.maxMultitextureUnits);

Expand Down Expand Up @@ -148,4 +149,14 @@ void GLES1State::setAlphaFunc(AlphaTestFunc func, GLfloat ref)
mAlphaTestRef = ref;
}

void GLES1State::setClientTextureUnit(unsigned int unit)
{
mClientActiveTexture = unit;
}

unsigned int GLES1State::getClientTextureUnit() const
{
return mClientActiveTexture;
}

} // namespace gl
6 changes: 6 additions & 0 deletions src/libANGLE/GLES1State.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class GLES1State final : angle::NonCopyable
void initialize(const Context *context);

void setAlphaFunc(AlphaTestFunc func, GLfloat ref);
void setClientTextureUnit(unsigned int unit);
unsigned int getClientTextureUnit() const;

private:
friend class State;
Expand Down Expand Up @@ -156,8 +158,12 @@ class GLES1State final : angle::NonCopyable
// Table 6.3
ColorF mCurrentColor;
angle::Vector3 mCurrentNormal;
// Invariant: mCurrentTextureCoords size is == GL_MAX_TEXTURE_UNITS.
std::vector<TextureCoordF> mCurrentTextureCoords;

// Table 6.4
unsigned int mClientActiveTexture;

// Table 6.7
using MatrixStack = std::vector<angle::Mat4>;
MatrixType mCurrMatrixMode;
Expand Down
3 changes: 3 additions & 0 deletions src/libANGLE/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,9 @@ Error State::getIntegerv(const Context *context, GLenum pname, GLint *params)
case GL_ALPHA_TEST_FUNC:
*params = ToGLenum(mGLES1State.mAlphaTestFunc);
break;
case GL_CLIENT_ACTIVE_TEXTURE:
*params = mGLES1State.mClientActiveTexture + GL_TEXTURE0;
break;
default:
UNREACHABLE();
break;
Expand Down
9 changes: 8 additions & 1 deletion src/libANGLE/validationES1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ bool ValidateClearDepthx(Context *context, GLfixed depth)

bool ValidateClientActiveTexture(Context *context, GLenum texture)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
if (texture < GL_TEXTURE0 ||
texture > GL_TEXTURE0 + context->getCaps().maxMultitextureUnits - 1)
{
ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMultitextureUnit);
return false;
}

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/validationES2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4340,7 +4340,7 @@ bool ValidateActiveTexture(Context *context, GLenum texture)
if (texture < GL_TEXTURE0 ||
texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
{
context->handleError(InvalidEnum());
ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCombinedImageUnit);
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/tests/angle_end2end_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'<(angle_path)/src/tests/gl_tests/FramebufferTest.cpp',
'<(angle_path)/src/tests/gl_tests/GeometryShaderTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/AlphaFuncTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/ClientActiveTextureTest.cpp',
'<(angle_path)/src/tests/gl_tests/GLSLTest.cpp',
'<(angle_path)/src/tests/gl_tests/ImageTest.cpp',
'<(angle_path)/src/tests/gl_tests/IncompleteTextureTest.cpp',
Expand Down
80 changes: 80 additions & 0 deletions src/tests/gl_tests/gles1/ClientActiveTextureTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

// ClientActiveTextureTest.cpp: Tests basic usage of glClientActiveTexture.

#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"

#include "random_utils.h"

#include <stdint.h>

using namespace angle;

class ClientActiveTextureTest : public ANGLETest
{
protected:
ClientActiveTextureTest()
{
setWindowWidth(32);
setWindowHeight(32);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
};

// State query: Checks the initial state is correct.
TEST_P(ClientActiveTextureTest, InitialState)
{
GLint clientActiveTexture = 0;
glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &clientActiveTexture);
EXPECT_GL_NO_ERROR();
EXPECT_GLENUM_EQ(GL_TEXTURE0, clientActiveTexture);
}

// Negative test: Checks against invalid use of glClientActiveTexture.
TEST_P(ClientActiveTextureTest, Negative)
{
glClientActiveTexture(0);
EXPECT_GL_ERROR(GL_INVALID_ENUM);

GLint maxTextureUnits = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextureUnits);

glClientActiveTexture(GL_TEXTURE0 + maxTextureUnits);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
}

// Checks that the number of multitexturing units is above spec minimum.
TEST_P(ClientActiveTextureTest, Limits)
{
GLint maxTextureUnits = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextureUnits);
EXPECT_GE(maxTextureUnits, 2);
}

// Set test: Checks that GL_TEXTURE0..GL_TEXTURE[GL_MAX_TEXTURE_UNITS-1] can be set.
TEST_P(ClientActiveTextureTest, Set)
{
GLint maxTextureUnits = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextureUnits);

for (GLint i = 0; i < maxTextureUnits; i++)
{
glClientActiveTexture(GL_TEXTURE0 + i);
EXPECT_GL_NO_ERROR();
GLint clientActiveTexture = 0;
glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, (GLint *)&clientActiveTexture);
EXPECT_GL_NO_ERROR();
EXPECT_GLENUM_EQ(GL_TEXTURE0 + i, clientActiveTexture);
}
}

ANGLE_INSTANTIATE_TEST(ClientActiveTextureTest, ES1_D3D11(), ES1_OPENGL(), ES1_OPENGLES());

0 comments on commit 96310cd

Please sign in to comment.