Skip to content

Commit e547aac

Browse files
741gCommit Bot
authored andcommitted
GLES1: gl(Push|Pop)Matrix
BUG=angleproject:2306 Change-Id: I96498aebbbc62ebd53e5320db17ef6a54d20d2dc Reviewed-on: https://chromium-review.googlesource.com/998308 Commit-Queue: Lingfeng Yang <[email protected]> Reviewed-by: Geoff Lang <[email protected]>
1 parent 8957e83 commit e547aac

File tree

10 files changed

+222
-33
lines changed

10 files changed

+222
-33
lines changed

src/libANGLE/Caps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ struct Caps
589589
GLuint maxMultitextureUnits;
590590
GLuint maxClipPlanes;
591591
GLuint maxLights;
592+
static constexpr int GlobalMatrixStackDepth = 16;
592593
GLuint maxModelviewMatrixStackDepth;
593594
GLuint maxProjectionMatrixStackDepth;
594595
GLuint maxTextureMatrixStackDepth;

src/libANGLE/Context.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,15 @@ void Context::getIntegervImpl(GLenum pname, GLint *params)
16471647
case GL_MAX_TEXTURE_UNITS:
16481648
*params = mCaps.maxMultitextureUnits;
16491649
break;
1650+
case GL_MAX_MODELVIEW_STACK_DEPTH:
1651+
*params = mCaps.maxModelviewMatrixStackDepth;
1652+
break;
1653+
case GL_MAX_PROJECTION_STACK_DEPTH:
1654+
*params = mCaps.maxProjectionMatrixStackDepth;
1655+
break;
1656+
case GL_MAX_TEXTURE_STACK_DEPTH:
1657+
*params = mCaps.maxTextureMatrixStackDepth;
1658+
break;
16501659
default:
16511660
handleError(mGLState.getIntegerv(this, pname, params));
16521661
break;
@@ -2860,9 +2869,9 @@ void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool rob
28602869
mCaps.maxMultitextureUnits = 4;
28612870
mCaps.maxClipPlanes = 6;
28622871
mCaps.maxLights = 8;
2863-
mCaps.maxModelviewMatrixStackDepth = 16;
2864-
mCaps.maxProjectionMatrixStackDepth = 16;
2865-
mCaps.maxTextureMatrixStackDepth = 16;
2872+
mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
2873+
mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
2874+
mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
28662875
}
28672876

28682877
mExtensions = mImplementation->getNativeExtensions();
@@ -6845,37 +6854,28 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
68456854
switch (pname)
68466855
{
68476856
case GL_ALPHA_TEST_FUNC:
6857+
case GL_CLIENT_ACTIVE_TEXTURE:
6858+
case GL_MATRIX_MODE:
6859+
case GL_MAX_TEXTURE_UNITS:
6860+
case GL_MAX_MODELVIEW_STACK_DEPTH:
6861+
case GL_MAX_PROJECTION_STACK_DEPTH:
6862+
case GL_MAX_TEXTURE_STACK_DEPTH:
68486863
*type = GL_INT;
68496864
*numParams = 1;
68506865
return true;
68516866
case GL_ALPHA_TEST_REF:
68526867
*type = GL_FLOAT;
68536868
*numParams = 1;
68546869
return true;
6855-
case GL_MAX_TEXTURE_UNITS:
6856-
*type = GL_INT;
6857-
*numParams = 1;
6858-
return true;
6859-
case GL_CLIENT_ACTIVE_TEXTURE:
6860-
*type = GL_INT;
6861-
*numParams = 1;
6862-
return true;
68636870
case GL_CURRENT_COLOR:
6871+
case GL_CURRENT_TEXTURE_COORDS:
68646872
*type = GL_FLOAT;
68656873
*numParams = 4;
68666874
return true;
68676875
case GL_CURRENT_NORMAL:
68686876
*type = GL_FLOAT;
68696877
*numParams = 3;
68706878
return true;
6871-
case GL_CURRENT_TEXTURE_COORDS:
6872-
*type = GL_FLOAT;
6873-
*numParams = 4;
6874-
return true;
6875-
case GL_MATRIX_MODE:
6876-
*type = GL_INT;
6877-
*numParams = 1;
6878-
return true;
68796879
}
68806880
}
68816881

src/libANGLE/Context_gles_1_0.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,12 @@ void Context::polygonOffsetx(GLfixed factor, GLfixed units)
359359

360360
void Context::popMatrix()
361361
{
362-
UNIMPLEMENTED();
362+
mGLState.gles1().popMatrix();
363363
}
364364

365365
void Context::pushMatrix()
366366
{
367-
UNIMPLEMENTED();
367+
mGLState.gles1().pushMatrix();
368368
}
369369

370370
void Context::rotatef(float angle, float x, float y, float z)

src/libANGLE/ErrorStrings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ ERRMSG(InvalidVertexAttrSize, "Vertex attribute size must be 1, 2, 3, or 4.");
128128
ERRMSG(InvalidWidth, "Invalid width.");
129129
ERRMSG(InvalidWrapModeTexture, "Invalid wrap mode for texture type.");
130130
ERRMSG(LevelNotZero, "Texture level must be zero.");
131+
ERRMSG(MatrixStackOverflow, "Current matrix stack is full.");
132+
ERRMSG(MatrixStackUnderflow, "Current matrix stack has only a single matrix.");
131133
ERRMSG(MismatchedByteCountType, "Buffer size does not align with data type.");
132134
ERRMSG(MismatchedFormat, "Format must match internal format.");
133135
ERRMSG(MismatchedTargetAndFormat, "Invalid texture target and format combination.");

src/libANGLE/GLES1State.cpp

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ bool TextureCoordF::operator==(const TextureCoordF &other) const
2626
}
2727

2828
GLES1State::GLES1State()
29-
: mVertexArrayEnabled(false),
29+
: mGLState(nullptr),
30+
mVertexArrayEnabled(false),
3031
mNormalArrayEnabled(false),
3132
mColorArrayEnabled(false),
3233
mPointSizeArrayEnabled(false),
@@ -59,8 +60,10 @@ GLES1State::GLES1State()
5960
GLES1State::~GLES1State() = default;
6061

6162
// Taken from the GLES 1.x spec which specifies all initial state values.
62-
void GLES1State::initialize(const Context *context)
63+
void GLES1State::initialize(const Context *context, const State *state)
6364
{
65+
mGLState = state;
66+
6467
const Caps &caps = context->getCaps();
6568

6669
mTexUnitEnables.resize(caps.maxMultitextureUnits);
@@ -97,12 +100,12 @@ void GLES1State::initialize(const Context *context)
97100

98101
mTextureEnvironments.resize(caps.maxMultitextureUnits);
99102

100-
mProjMatrices.resize(caps.maxProjectionMatrixStackDepth);
101-
mModelviewMatrices.resize(caps.maxModelviewMatrixStackDepth);
103+
mModelviewMatrices.push_back(angle::Mat4());
104+
mProjectionMatrices.push_back(angle::Mat4());
102105
mTextureMatrices.resize(caps.maxMultitextureUnits);
103-
for (auto &textureMatrixStack : mTextureMatrices)
106+
for (auto &stack : mTextureMatrices)
104107
{
105-
textureMatrixStack.resize(caps.maxTextureMatrixStackDepth);
108+
stack.push_back(angle::Mat4());
106109
}
107110

108111
mMaterial.ambient = {0.2f, 0.2f, 0.2f, 1.0f};
@@ -210,4 +213,48 @@ MatrixType GLES1State::getMatrixMode() const
210213
return mMatrixMode;
211214
}
212215

216+
void GLES1State::pushMatrix()
217+
{
218+
auto &stack = currentMatrixStack();
219+
stack.push_back(stack.back());
220+
}
221+
222+
void GLES1State::popMatrix()
223+
{
224+
auto &stack = currentMatrixStack();
225+
stack.pop_back();
226+
}
227+
228+
GLES1State::MatrixStack &GLES1State::currentMatrixStack()
229+
{
230+
switch (mMatrixMode)
231+
{
232+
case MatrixType::Modelview:
233+
return mModelviewMatrices;
234+
case MatrixType::Projection:
235+
return mProjectionMatrices;
236+
case MatrixType::Texture:
237+
return mTextureMatrices[mGLState->getActiveSampler()];
238+
default:
239+
UNREACHABLE();
240+
return mModelviewMatrices;
241+
}
242+
}
243+
244+
const GLES1State::MatrixStack &GLES1State::currentMatrixStack() const
245+
{
246+
switch (mMatrixMode)
247+
{
248+
case MatrixType::Modelview:
249+
return mModelviewMatrices;
250+
case MatrixType::Projection:
251+
return mProjectionMatrices;
252+
case MatrixType::Texture:
253+
return mTextureMatrices[mGLState->getActiveSampler()];
254+
default:
255+
UNREACHABLE();
256+
return mModelviewMatrices;
257+
}
258+
}
259+
213260
} // namespace gl

src/libANGLE/GLES1State.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212

1313
#include <unordered_set>
1414

15+
#include "common/FixedVector.h"
1516
#include "common/angleutils.h"
1617
#include "common/matrix_utils.h"
1718
#include "common/vector_utils.h"
19+
#include "libANGLE/Caps.h"
1820
#include "libANGLE/angletypes.h"
1921

2022
namespace gl
@@ -120,7 +122,7 @@ class GLES1State final : angle::NonCopyable
120122
GLES1State();
121123
~GLES1State();
122124

123-
void initialize(const Context *context);
125+
void initialize(const Context *context, const State *state);
124126

125127
void setAlphaFunc(AlphaTestFunc func, GLfloat ref);
126128
void setClientTextureUnit(unsigned int unit);
@@ -138,9 +140,19 @@ class GLES1State final : angle::NonCopyable
138140
void setMatrixMode(MatrixType mode);
139141
MatrixType getMatrixMode() const;
140142

143+
void pushMatrix();
144+
void popMatrix();
145+
146+
using MatrixStack = angle::FixedVector<angle::Mat4, Caps::GlobalMatrixStackDepth>;
147+
MatrixStack &currentMatrixStack();
148+
const MatrixStack &currentMatrixStack() const;
149+
141150
private:
142151
friend class State;
143152

153+
// Back pointer for reading from State.
154+
const State *mGLState;
155+
144156
// All initial state values come from the
145157
// OpenGL ES 1.1 spec.
146158
struct TextureEnables
@@ -181,9 +193,8 @@ class GLES1State final : angle::NonCopyable
181193
unsigned int mClientActiveTexture;
182194

183195
// Table 6.7
184-
using MatrixStack = std::vector<angle::Mat4>;
185196
MatrixType mMatrixMode;
186-
MatrixStack mProjMatrices;
197+
MatrixStack mProjectionMatrices;
187198
MatrixStack mModelviewMatrices;
188199
std::vector<MatrixStack> mTextureMatrices;
189200

src/libANGLE/State.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void State::initialize(const Context *context,
246246
// applies
247247
if (clientVersion < Version(2, 0))
248248
{
249-
mGLES1State.initialize(context);
249+
mGLES1State.initialize(context, this);
250250
}
251251
}
252252

src/libANGLE/validationES1.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,25 @@ bool ValidatePolygonOffsetx(Context *context, GLfixed factor, GLfixed units)
504504

505505
bool ValidatePopMatrix(Context *context)
506506
{
507-
UNIMPLEMENTED();
507+
ANGLE_VALIDATE_IS_GLES1(context);
508+
const auto &stack = context->getGLState().gles1().currentMatrixStack();
509+
if (stack.size() == 1)
510+
{
511+
ANGLE_VALIDATION_ERR(context, StackUnderflow(), MatrixStackUnderflow);
512+
return false;
513+
}
508514
return true;
509515
}
510516

511517
bool ValidatePushMatrix(Context *context)
512518
{
513-
UNIMPLEMENTED();
519+
ANGLE_VALIDATE_IS_GLES1(context);
520+
const auto &stack = context->getGLState().gles1().currentMatrixStack();
521+
if (stack.size() == stack.max_size())
522+
{
523+
ANGLE_VALIDATION_ERR(context, StackOverflow(), MatrixStackOverflow);
524+
return false;
525+
}
514526
return true;
515527
}
516528

src/tests/angle_end2end_tests.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
'<(angle_path)/src/tests/gl_tests/gles1/CurrentNormalTest.cpp',
5454
'<(angle_path)/src/tests/gl_tests/gles1/CurrentTextureCoordsTest.cpp',
5555
'<(angle_path)/src/tests/gl_tests/gles1/MatrixModeTest.cpp',
56+
'<(angle_path)/src/tests/gl_tests/gles1/MatrixStackTest.cpp',
5657
'<(angle_path)/src/tests/gl_tests/GLSLTest.cpp',
5758
'<(angle_path)/src/tests/gl_tests/ImageTest.cpp',
5859
'<(angle_path)/src/tests/gl_tests/IncompleteTextureTest.cpp',

0 commit comments

Comments
 (0)