Commit a0cfa873 by Lingfeng Yang Committed by Commit Bot

GLES1: Shade model API

+ add sample BUG=angleproject:2306 Change-Id: Ie0c391618ec2b771cc99b96db02b9008a86272b9 Reviewed-on: https://chromium-review.googlesource.com/1079992 Commit-Queue: Lingfeng Yang <lfy@google.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 32749b94
...@@ -191,6 +191,12 @@ angle_sample("gles1_simple_lighting") { ...@@ -191,6 +191,12 @@ angle_sample("gles1_simple_lighting") {
] ]
} }
angle_sample("gles1_flat_shading") {
sources = [
"gles1/FlatShading.cpp",
]
}
group("all") { group("all") {
testonly = true testonly = true
deps = [ deps = [
......
//
// 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.
//
// Based on Hello_Triangle.c from
// Book: OpenGL(R) ES 2.0 Programming Guide
// Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner
// ISBN-10: 0321502795
// ISBN-13: 9780321502797
// Publisher: Addison-Wesley Professional
// URLs: http://safari.informit.com/9780321563835
// http://www.opengles-book.com
#include "SampleApplication.h"
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <algorithm>
class FlatShadingSample : public SampleApplication
{
public:
FlatShadingSample(EGLint displayType)
: SampleApplication("FlatShadingSample", 1280, 720, 1, 0, displayType)
{
}
virtual bool initialize()
{
glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
mRotDeg = 0.0f;
return true;
}
virtual void destroy() {}
virtual void draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLfloat vertices[] = {
-0.5f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f,
0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f,
};
GLfloat colors[] = {
1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
};
GLuint indices[] = {
0, 1, 2, 2, 3, 0,
4, 1, 0, 4, 2, 1, 4, 3, 2, 4, 0, 3,
};
glEnable(GL_DEPTH_TEST);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glColorPointer(4, GL_FLOAT, 0, colors);
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 6; j++)
{
if ((i + j * 6) % 2 == 0)
{
glShadeModel(GL_FLAT);
}
else
{
glShadeModel(GL_SMOOTH);
}
glPushMatrix();
glTranslatef(-0.7f + i * 0.3f, -0.7f + j * 0.3f, 0.0f);
glRotatef(mRotDeg + (5.0f * (6.0f * i + j)), 0.0f, 1.0f, 0.0f);
glRotatef(20.0f + (10.0f * (6.0f * i + j)), 1.0f, 0.0f, 0.0f);
GLfloat scale = 0.2f;
glScalef(scale, scale, scale);
glDrawElements(GL_TRIANGLES, sizeof(indices) / sizeof(GLuint), GL_UNSIGNED_INT,
indices);
glPopMatrix();
}
}
mRotDeg += 0.1f;
}
private:
float mRotDeg;
};
int main(int argc, char **argv)
{
EGLint displayType = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE;
if (argc > 1)
{
displayType = GetDisplayTypeFromArg(argv[1]);
}
FlatShadingSample app(displayType);
return app.run();
}
...@@ -262,6 +262,9 @@ ...@@ -262,6 +262,9 @@
"glQueryCounterEXT": { "glQueryCounterEXT": {
"target": "QueryType" "target": "QueryType"
}, },
"glShadeModel": {
"mode": "ShadingModel"
},
"glTexImage2D": { "glTexImage2D": {
"target": "TextureTarget" "target": "TextureTarget"
}, },
......
...@@ -7091,6 +7091,7 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu ...@@ -7091,6 +7091,7 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
case GL_POINT_SIZE_ARRAY_STRIDE_OES: case GL_POINT_SIZE_ARRAY_STRIDE_OES:
case GL_POINT_SIZE_ARRAY_TYPE_OES: case GL_POINT_SIZE_ARRAY_TYPE_OES:
case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES: case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
case GL_SHADE_MODEL:
*type = GL_INT; *type = GL_INT;
*numParams = 1; *numParams = 1;
return true; return true;
......
...@@ -451,9 +451,9 @@ void Context::scalex(GLfixed x, GLfixed y, GLfixed z) ...@@ -451,9 +451,9 @@ void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
angle::Mat4::Scale(angle::Vector3(FixedToFloat(x), FixedToFloat(y), FixedToFloat(z)))); angle::Mat4::Scale(angle::Vector3(FixedToFloat(x), FixedToFloat(y), FixedToFloat(z))));
} }
void Context::shadeModel(GLenum mode) void Context::shadeModel(ShadingModel model)
{ {
UNIMPLEMENTED(); mGLState.gles1().setShadeModel(model);
} }
void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *ptr) void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *ptr)
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
void sampleCoveragex(GLclampx value, GLboolean invert); \ void sampleCoveragex(GLclampx value, GLboolean invert); \
void scalef(GLfloat x, GLfloat y, GLfloat z); \ void scalef(GLfloat x, GLfloat y, GLfloat z); \
void scalex(GLfixed x, GLfixed y, GLfixed z); \ void scalex(GLfixed x, GLfixed y, GLfixed z); \
void shadeModel(GLenum mode); \ void shadeModel(ShadingModel modePacked); \
void texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer); \ void texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer); \
void texEnvf(GLenum target, GLenum pname, GLfloat param); \ void texEnvf(GLenum target, GLenum pname, GLfloat param); \
void texEnvfv(GLenum target, GLenum pname, const GLfloat *params); \ void texEnvfv(GLenum target, GLenum pname, const GLfloat *params); \
......
...@@ -127,6 +127,7 @@ ERRMSG(InvalidSampleMaskNumber, ...@@ -127,6 +127,7 @@ ERRMSG(InvalidSampleMaskNumber,
ERRMSG(InvalidSampler, "Sampler is not valid"); ERRMSG(InvalidSampler, "Sampler is not valid");
ERRMSG(InvalidShaderName, "Shader object expected."); ERRMSG(InvalidShaderName, "Shader object expected.");
ERRMSG(InvalidShaderType, "Invalid shader type."); ERRMSG(InvalidShaderType, "Invalid shader type.");
ERRMSG(InvalidShadingModel, "Invalid shading model.");
ERRMSG(InvalidStencil, "Invalid stencil."); ERRMSG(InvalidStencil, "Invalid stencil.");
ERRMSG(InvalidStencilBitMask, "Invalid stencil bit mask."); ERRMSG(InvalidStencilBitMask, "Invalid stencil bit mask.");
ERRMSG(InvalidTarget, "Invalid target."); ERRMSG(InvalidTarget, "Invalid target.");
......
...@@ -363,4 +363,9 @@ bool GLES1State::isColorMaterialEnabled() const ...@@ -363,4 +363,9 @@ bool GLES1State::isColorMaterialEnabled() const
return mColorMaterialEnabled; return mColorMaterialEnabled;
} }
void GLES1State::setShadeModel(ShadingModel model)
{
mShadeModel = model;
}
} // namespace gl } // namespace gl
...@@ -169,6 +169,8 @@ class GLES1State final : angle::NonCopyable ...@@ -169,6 +169,8 @@ class GLES1State final : angle::NonCopyable
const MaterialParameters &materialParameters() const; const MaterialParameters &materialParameters() const;
bool isColorMaterialEnabled() const; bool isColorMaterialEnabled() const;
void setShadeModel(ShadingModel model);
private: private:
friend class State; friend class State;
friend class GLES1Renderer; friend class GLES1Renderer;
......
...@@ -2413,6 +2413,9 @@ Error State::getIntegerv(const Context *context, GLenum pname, GLint *params) ...@@ -2413,6 +2413,9 @@ Error State::getIntegerv(const Context *context, GLenum pname, GLint *params)
case GL_MATRIX_MODE: case GL_MATRIX_MODE:
*params = ToGLenum(mGLES1State.mMatrixMode); *params = ToGLenum(mGLES1State.mMatrixMode);
break; break;
case GL_SHADE_MODEL:
*params = ToGLenum(mGLES1State.mShadeModel);
break;
default: default:
UNREACHABLE(); UNREACHABLE();
break; break;
......
...@@ -862,10 +862,18 @@ bool ValidateScalex(Context *context, GLfixed x, GLfixed y, GLfixed z) ...@@ -862,10 +862,18 @@ bool ValidateScalex(Context *context, GLfixed x, GLfixed y, GLfixed z)
return true; return true;
} }
bool ValidateShadeModel(Context *context, GLenum mode) bool ValidateShadeModel(Context *context, ShadingModel mode)
{ {
UNIMPLEMENTED(); ANGLE_VALIDATE_IS_GLES1(context);
switch (mode)
{
case ShadingModel::Flat:
case ShadingModel::Smooth:
return true; return true;
default:
ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidShadingModel);
return false;
}
} }
bool ValidateTexCoordPointer(Context *context, bool ValidateTexCoordPointer(Context *context,
......
...@@ -137,7 +137,7 @@ bool ValidateRotatex(Context *context, GLfixed angle, GLfixed x, GLfixed y, GLfi ...@@ -137,7 +137,7 @@ bool ValidateRotatex(Context *context, GLfixed angle, GLfixed x, GLfixed y, GLfi
bool ValidateSampleCoveragex(Context *context, GLclampx value, GLboolean invert); bool ValidateSampleCoveragex(Context *context, GLclampx value, GLboolean invert);
bool ValidateScalef(Context *context, GLfloat x, GLfloat y, GLfloat z); bool ValidateScalef(Context *context, GLfloat x, GLfloat y, GLfloat z);
bool ValidateScalex(Context *context, GLfixed x, GLfixed y, GLfixed z); bool ValidateScalex(Context *context, GLfixed x, GLfixed y, GLfixed z);
bool ValidateShadeModel(Context *context, GLenum mode); bool ValidateShadeModel(Context *context, ShadingModel mode);
bool ValidateTexCoordPointer(Context *context, bool ValidateTexCoordPointer(Context *context,
GLint size, GLint size,
GLenum type, GLenum type,
......
...@@ -1246,11 +1246,12 @@ void GL_APIENTRY ShadeModel(GLenum mode) ...@@ -1246,11 +1246,12 @@ void GL_APIENTRY ShadeModel(GLenum mode)
Context *context = GetValidGlobalContext(); Context *context = GetValidGlobalContext();
if (context) if (context)
{ {
context->gatherParams<EntryPoint::ShadeModel>(mode); ShadingModel modePacked = FromGLenum<ShadingModel>(mode);
context->gatherParams<EntryPoint::ShadeModel>(modePacked);
if (context->skipValidation() || ValidateShadeModel(context, mode)) if (context->skipValidation() || ValidateShadeModel(context, modePacked))
{ {
context->shadeModel(mode); context->shadeModel(modePacked);
} }
} }
} }
......
...@@ -12778,11 +12778,12 @@ void GL_APIENTRY ShadeModelContextANGLE(GLeglContext ctx, GLenum mode) ...@@ -12778,11 +12778,12 @@ void GL_APIENTRY ShadeModelContextANGLE(GLeglContext ctx, GLenum mode)
if (context) if (context)
{ {
ASSERT(context == GetValidGlobalContext()); ASSERT(context == GetValidGlobalContext());
context->gatherParams<EntryPoint::ShadeModel>(mode); ShadingModel modePacked = FromGLenum<ShadingModel>(mode);
context->gatherParams<EntryPoint::ShadeModel>(modePacked);
if (context->skipValidation() || ValidateShadeModel(context, mode)) if (context->skipValidation() || ValidateShadeModel(context, modePacked))
{ {
context->shadeModel(mode); context->shadeModel(modePacked);
} }
} }
} }
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
'<(angle_path)/src/tests/gl_tests/gles1/MatrixMultTest.cpp', '<(angle_path)/src/tests/gl_tests/gles1/MatrixMultTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/MatrixStackTest.cpp', '<(angle_path)/src/tests/gl_tests/gles1/MatrixStackTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/LightsTest.cpp', '<(angle_path)/src/tests/gl_tests/gles1/LightsTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/ShadeModelTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/TextureTargetEnableTest.cpp', '<(angle_path)/src/tests/gl_tests/gles1/TextureTargetEnableTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/VertexPointerTest.cpp', '<(angle_path)/src/tests/gl_tests/gles1/VertexPointerTest.cpp',
'<(angle_path)/src/tests/gl_tests/GLSLTest.cpp', '<(angle_path)/src/tests/gl_tests/GLSLTest.cpp',
......
//
// 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.
//
// ShadeModelTest.cpp: Tests the shade model API.
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "random_utils.h"
#include <stdint.h>
using namespace angle;
class ShadeModelTest : public ANGLETest
{
protected:
ShadeModelTest()
{
setWindowWidth(32);
setWindowHeight(32);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
};
// Checks that the initial state is correct.
TEST_P(ShadeModelTest, InitialState)
{
GLint shadeModel = 0;
glGetIntegerv(GL_SHADE_MODEL, &shadeModel);
EXPECT_GL_NO_ERROR();
EXPECT_GLENUM_EQ(GL_SMOOTH, shadeModel);
}
// Negative test for shade model.
TEST_P(ShadeModelTest, Negative)
{
glShadeModel(GL_TEXTURE_2D);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
}
// Checks that the state can be set.
TEST_P(ShadeModelTest, Set)
{
glShadeModel(GL_FLAT);
EXPECT_GL_NO_ERROR();
GLint shadeModel;
glGetIntegerv(GL_SHADE_MODEL, &shadeModel);
EXPECT_GL_NO_ERROR();
EXPECT_GLENUM_EQ(GL_FLAT, shadeModel);
glShadeModel(GL_SMOOTH);
EXPECT_GL_NO_ERROR();
glGetIntegerv(GL_SHADE_MODEL, &shadeModel);
EXPECT_GL_NO_ERROR();
EXPECT_GLENUM_EQ(GL_SMOOTH, shadeModel);
}
ANGLE_INSTANTIATE_TEST(ShadeModelTest, ES1_D3D11(), ES1_OPENGL(), ES1_OPENGLES());
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