Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a43994c

Browse files
741gCommit Bot
authored andcommitted
GLES1: glColor4(f|ub|x)
BUG=angleproject:2306 Change-Id: I4a57732d4c470c821a3847a7ee012cf3ccbba197 Reviewed-on: https://chromium-review.googlesource.com/986454 Commit-Queue: Lingfeng Yang <[email protected]> Reviewed-by: Geoff Lang <[email protected]>
1 parent 489243f commit a43994c

File tree

8 files changed

+113
-6
lines changed

8 files changed

+113
-6
lines changed

src/libANGLE/Context.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6397,6 +6397,10 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
63976397
*type = GL_INT;
63986398
*numParams = 1;
63996399
return true;
6400+
case GL_CURRENT_COLOR:
6401+
*type = GL_FLOAT;
6402+
*numParams = 4;
6403+
return true;
64006404
}
64016405
}
64026406

src/libANGLE/Context_gles_1_0.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,20 @@ void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5151

5252
void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5353
{
54-
UNIMPLEMENTED();
54+
mGLState.gles1().setCurrentColor({red, green, blue, alpha});
5555
}
5656

5757
void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5858
{
59-
UNIMPLEMENTED();
59+
mGLState.gles1().setCurrentColor(
60+
{normalizedToFloat<uint8_t>(red), normalizedToFloat<uint8_t>(green),
61+
normalizedToFloat<uint8_t>(blue), normalizedToFloat<uint8_t>(alpha)});
6062
}
6163

6264
void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
6365
{
64-
UNIMPLEMENTED();
66+
mGLState.gles1().setCurrentColor(
67+
{FixedToFloat(red), FixedToFloat(green), FixedToFloat(blue), FixedToFloat(alpha)});
6568
}
6669

6770
void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *ptr)

src/libANGLE/GLES1State.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,14 @@ unsigned int GLES1State::getClientTextureUnit() const
159159
return mClientActiveTexture;
160160
}
161161

162+
void GLES1State::setCurrentColor(ColorF color)
163+
{
164+
mCurrentColor = color;
165+
}
166+
167+
const ColorF &GLES1State::getCurrentColor() const
168+
{
169+
return mCurrentColor;
170+
}
171+
162172
} // namespace gl

src/libANGLE/GLES1State.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class GLES1State final : angle::NonCopyable
121121
void setAlphaFunc(AlphaTestFunc func, GLfloat ref);
122122
void setClientTextureUnit(unsigned int unit);
123123
unsigned int getClientTextureUnit() const;
124+
void setCurrentColor(ColorF color);
125+
const ColorF &getCurrentColor() const;
124126

125127
private:
126128
friend class State;

src/libANGLE/State.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,15 @@ void State::getFloatv(GLenum pname, GLfloat *params)
19301930
case GL_ALPHA_TEST_REF:
19311931
*params = mGLES1State.mAlphaTestRef;
19321932
break;
1933+
case GL_CURRENT_COLOR:
1934+
{
1935+
const auto &color = mGLES1State.mCurrentColor;
1936+
params[0] = color.red;
1937+
params[1] = color.green;
1938+
params[2] = color.blue;
1939+
params[3] = color.alpha;
1940+
break;
1941+
}
19331942
default:
19341943
UNREACHABLE();
19351944
break;

src/libANGLE/validationES1.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ bool ValidateClipPlanex(Context *context, GLenum plane, const GLfixed *equation)
9797

9898
bool ValidateColor4f(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
9999
{
100-
UNIMPLEMENTED();
100+
ANGLE_VALIDATE_IS_GLES1(context);
101101
return true;
102102
}
103103

104104
bool ValidateColor4ub(Context *context, GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
105105
{
106-
UNIMPLEMENTED();
106+
ANGLE_VALIDATE_IS_GLES1(context);
107107
return true;
108108
}
109109

110110
bool ValidateColor4x(Context *context, GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
111111
{
112-
UNIMPLEMENTED();
112+
ANGLE_VALIDATE_IS_GLES1(context);
113113
return true;
114114
}
115115

src/tests/angle_end2end_tests.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
'<(angle_path)/src/tests/gl_tests/GeometryShaderTest.cpp',
5050
'<(angle_path)/src/tests/gl_tests/gles1/AlphaFuncTest.cpp',
5151
'<(angle_path)/src/tests/gl_tests/gles1/ClientActiveTextureTest.cpp',
52+
'<(angle_path)/src/tests/gl_tests/gles1/CurrentColorTest.cpp',
5253
'<(angle_path)/src/tests/gl_tests/GLSLTest.cpp',
5354
'<(angle_path)/src/tests/gl_tests/ImageTest.cpp',
5455
'<(angle_path)/src/tests/gl_tests/IncompleteTextureTest.cpp',
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//
2+
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
//
6+
7+
// CurrentColorTest.cpp: Tests basic usage of glClientActiveTexture.
8+
9+
#include "test_utils/ANGLETest.h"
10+
#include "test_utils/gl_raii.h"
11+
12+
#include "random_utils.h"
13+
14+
#include <stdint.h>
15+
16+
using namespace angle;
17+
18+
class CurrentColorTest : public ANGLETest
19+
{
20+
protected:
21+
CurrentColorTest()
22+
{
23+
setWindowWidth(32);
24+
setWindowHeight(32);
25+
setConfigRedBits(8);
26+
setConfigGreenBits(8);
27+
setConfigBlueBits(8);
28+
setConfigAlphaBits(8);
29+
setConfigDepthBits(24);
30+
}
31+
};
32+
33+
// State query: Checks the initial state is correct.
34+
TEST_P(CurrentColorTest, InitialState)
35+
{
36+
const GLColor32F kFloatWhite(1.0f, 1.0f, 1.0f, 1.0f);
37+
GLColor32F actualColor;
38+
glGetFloatv(GL_CURRENT_COLOR, &actualColor.R);
39+
EXPECT_GL_NO_ERROR();
40+
EXPECT_EQ(kFloatWhite, actualColor);
41+
}
42+
43+
// Set test: Checks that the current color is properly set and retrieved.
44+
TEST_P(CurrentColorTest, Set)
45+
{
46+
float epsilon = 0.00001f;
47+
48+
glColor4f(0.1f, 0.2f, 0.3f, 0.4f);
49+
EXPECT_GL_NO_ERROR();
50+
51+
GLColor32F floatColor;
52+
glGetFloatv(GL_CURRENT_COLOR, &floatColor.R);
53+
EXPECT_GL_NO_ERROR();
54+
55+
EXPECT_EQ(GLColor32F(0.1f, 0.2f, 0.3f, 0.4f), floatColor);
56+
57+
glColor4ub(0xff, 0x0, 0x55, 0x33);
58+
59+
glGetFloatv(GL_CURRENT_COLOR, &floatColor.R);
60+
EXPECT_GL_NO_ERROR();
61+
62+
EXPECT_NEAR(1.0f, floatColor.R, epsilon);
63+
EXPECT_NEAR(0.0f, floatColor.G, epsilon);
64+
EXPECT_NEAR(1.0f / 3.0f, floatColor.B, epsilon);
65+
EXPECT_NEAR(0.2f, floatColor.A, epsilon);
66+
67+
glColor4x(0x10000, 0x0, 0x3333, 0x5555);
68+
69+
glGetFloatv(GL_CURRENT_COLOR, &floatColor.R);
70+
EXPECT_GL_NO_ERROR();
71+
72+
EXPECT_NEAR(1.0f, floatColor.R, epsilon);
73+
EXPECT_NEAR(0.0f, floatColor.G, epsilon);
74+
EXPECT_NEAR(0.2f, floatColor.B, epsilon);
75+
EXPECT_NEAR(1.0f / 3.0f, floatColor.A, epsilon);
76+
}
77+
78+
ANGLE_INSTANTIATE_TEST(CurrentColorTest, ES1_D3D11(), ES1_OPENGL(), ES1_OPENGLES());

0 commit comments

Comments
 (0)