Commit bb5ce5cc by Lingfeng Yang Committed by Commit Bot

GLES1: Built-in matrix operations

glRotate glTranslate glScale glFrustum glPerspective glOrtho BUG=angleproject:2306 Change-Id: Ia9321d52f5824ef7c15b56d94e23ff3b1fbc3151 Reviewed-on: https://chromium-review.googlesource.com/1002915 Commit-Queue: Lingfeng Yang <lfy@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 56c8577b
......@@ -125,19 +125,16 @@ void Context::fogxv(GLenum pname, const GLfixed *param)
UNIMPLEMENTED();
}
void Context::frustumf(GLfloat left,
GLfloat right,
GLfloat bottom,
GLfloat top,
GLfloat zNear,
GLfloat zFar)
void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
{
UNIMPLEMENTED();
mGLState.gles1().multMatrix(angle::Mat4::Frustum(l, r, b, t, n, f));
}
void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
{
UNIMPLEMENTED();
mGLState.gles1().multMatrix(angle::Mat4::Frustum(FixedToFloat(l), FixedToFloat(r),
FixedToFloat(b), FixedToFloat(t),
FixedToFloat(n), FixedToFloat(f)));
}
void Context::getClipPlanef(GLenum plane, GLfloat *equation)
......@@ -332,12 +329,14 @@ void Context::orthof(GLfloat left,
GLfloat zNear,
GLfloat zFar)
{
UNIMPLEMENTED();
mGLState.gles1().multMatrix(angle::Mat4::Ortho(left, right, bottom, top, zNear, zFar));
}
void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
{
UNIMPLEMENTED();
mGLState.gles1().multMatrix(angle::Mat4::Ortho(FixedToFloat(l), FixedToFloat(r),
FixedToFloat(b), FixedToFloat(t),
FixedToFloat(n), FixedToFloat(f)));
}
void Context::pointParameterf(GLenum pname, GLfloat param)
......@@ -387,12 +386,13 @@ void Context::pushMatrix()
void Context::rotatef(float angle, float x, float y, float z)
{
UNIMPLEMENTED();
mGLState.gles1().multMatrix(angle::Mat4::Rotate(angle, angle::Vector3(x, y, z)));
}
void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
{
UNIMPLEMENTED();
mGLState.gles1().multMatrix(angle::Mat4::Rotate(
FixedToFloat(angle), angle::Vector3(FixedToFloat(x), FixedToFloat(y), FixedToFloat(z))));
}
void Context::sampleCoveragex(GLclampx value, GLboolean invert)
......@@ -402,12 +402,13 @@ void Context::sampleCoveragex(GLclampx value, GLboolean invert)
void Context::scalef(float x, float y, float z)
{
UNIMPLEMENTED();
mGLState.gles1().multMatrix(angle::Mat4::Scale(angle::Vector3(x, y, z)));
}
void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
{
UNIMPLEMENTED();
mGLState.gles1().multMatrix(
angle::Mat4::Scale(angle::Vector3(FixedToFloat(x), FixedToFloat(y), FixedToFloat(z))));
}
void Context::shadeModel(GLenum mode)
......@@ -462,12 +463,13 @@ void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *pa
void Context::translatef(float x, float y, float z)
{
UNIMPLEMENTED();
mGLState.gles1().multMatrix(angle::Mat4::Translate(angle::Vector3(x, y, z)));
}
void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
{
UNIMPLEMENTED();
mGLState.gles1().multMatrix(
angle::Mat4::Translate(angle::Vector3(FixedToFloat(x), FixedToFloat(y), FixedToFloat(z))));
}
void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *ptr)
......
......@@ -100,6 +100,9 @@ ERRMSG(InvalidNameCharacters, "Name contains invalid characters.");
ERRMSG(InvalidPname, "Invalid pname.");
ERRMSG(InvalidPrecision, "Invalid or unsupported precision type.");
ERRMSG(InvalidProgramName, "Program object expected.");
ERRMSG(InvalidProjectionMatrix,
"Invalid projection matrix. Left/right, top/bottom, near/far intervals cannot be zero, and "
"near/far cannot be less than zero.");
ERRMSG(InvalidQueryId, "Invalid query Id.");
ERRMSG(InvalidQueryTarget, "Invalid query target.");
ERRMSG(InvalidQueryType, "Invalid query type.");
......
......@@ -173,7 +173,11 @@ bool ValidateFrustumf(Context *context,
GLfloat n,
GLfloat f)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
if (l == r || b == t || n == f || n <= 0.0f || f <= 0.0f)
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProjectionMatrix);
}
return true;
}
......@@ -185,7 +189,11 @@ bool ValidateFrustumx(Context *context,
GLfixed n,
GLfixed f)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
if (l == r || b == t || n == f || n <= 0 || f <= 0)
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProjectionMatrix);
}
return true;
}
......@@ -444,7 +452,11 @@ bool ValidateOrthof(Context *context,
GLfloat n,
GLfloat f)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
if (l == r || b == t || n == f || n <= 0.0f || f <= 0.0f)
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProjectionMatrix);
}
return true;
}
......@@ -456,7 +468,11 @@ bool ValidateOrthox(Context *context,
GLfixed n,
GLfixed f)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
if (l == r || b == t || n == f || n <= 0 || f <= 0)
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProjectionMatrix);
}
return true;
}
......@@ -528,13 +544,13 @@ bool ValidatePushMatrix(Context *context)
bool ValidateRotatef(Context *context, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
return true;
}
bool ValidateRotatex(Context *context, GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
return true;
}
......@@ -546,13 +562,13 @@ bool ValidateSampleCoveragex(Context *context, GLclampx value, GLboolean invert)
bool ValidateScalef(Context *context, GLfloat x, GLfloat y, GLfloat z)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
return true;
}
bool ValidateScalex(Context *context, GLfixed x, GLfixed y, GLfixed z)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
return true;
}
......@@ -625,13 +641,13 @@ bool ValidateTexParameterxv(Context *context,
bool ValidateTranslatef(Context *context, GLfloat x, GLfloat y, GLfloat z)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
return true;
}
bool ValidateTranslatex(Context *context, GLfixed x, GLfixed y, GLfixed z)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
return true;
}
......
......@@ -52,6 +52,7 @@
'<(angle_path)/src/tests/gl_tests/gles1/CurrentColorTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/CurrentNormalTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/CurrentTextureCoordsTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/MatrixBuiltinsTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/MatrixLoadTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/MatrixModeTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/MatrixMultTest.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.
//
// MatrixBuiltinsTest.cpp: Tests basic usage of builtin matrix operations.
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "common/matrix_utils.h"
#include "random_utils.h"
#include <stdint.h>
using namespace angle;
class MatrixBuiltinsTest : public ANGLETest
{
protected:
MatrixBuiltinsTest()
{
setWindowWidth(32);
setWindowHeight(32);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
};
// Test rotation and check the matrix for closeness to a rotation matrix.
TEST_P(MatrixBuiltinsTest, Rotate)
{
constexpr float angle = 90.0f;
constexpr float x = 1.0f;
constexpr float y = 1.0f;
constexpr float z = 1.0f;
angle::Mat4 testMatrix = angle::Mat4::Rotate(angle, angle::Vector3(x, y, z));
glRotatef(angle, x, y, z);
EXPECT_GL_NO_ERROR();
angle::Mat4 outputMatrix;
glGetFloatv(GL_MODELVIEW_MATRIX, outputMatrix.data());
EXPECT_GL_NO_ERROR();
EXPECT_TRUE(testMatrix.nearlyEqual(0.00001f, outputMatrix));
}
// Test translation and check the matrix for closeness to a translation matrix.
TEST_P(MatrixBuiltinsTest, Translate)
{
constexpr float x = 1.0f;
constexpr float y = 1.0f;
constexpr float z = 1.0f;
angle::Mat4 testMatrix = angle::Mat4::Translate(angle::Vector3(x, y, z));
glTranslatef(1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, 1.0f);
EXPECT_GL_NO_ERROR();
angle::Mat4 outputMatrix;
glGetFloatv(GL_MODELVIEW_MATRIX, outputMatrix.data());
EXPECT_GL_NO_ERROR();
EXPECT_TRUE(testMatrix.nearlyEqual(0.00001f, outputMatrix));
}
// Test scale and check the matrix for closeness to a scale matrix.
TEST_P(MatrixBuiltinsTest, Scale)
{
constexpr float x = 3.0f;
constexpr float y = 9.0f;
constexpr float z = 27.0f;
angle::Mat4 testMatrix = angle::Mat4::Scale(angle::Vector3(x, y, z));
glScalef(3.0f, 3.0f, 3.0f);
glScalef(1.0f, 3.0f, 3.0f);
glScalef(1.0f, 1.0f, 3.0f);
EXPECT_GL_NO_ERROR();
angle::Mat4 outputMatrix;
glGetFloatv(GL_MODELVIEW_MATRIX, outputMatrix.data());
EXPECT_GL_NO_ERROR();
EXPECT_TRUE(testMatrix.nearlyEqual(0.00001f, outputMatrix));
}
// Test frustum projection and check the matrix values.
TEST_P(MatrixBuiltinsTest, Frustum)
{
constexpr float l = -1.0f;
constexpr float r = 1.0f;
constexpr float b = -1.0f;
constexpr float t = 1.0f;
constexpr float n = 0.1f;
constexpr float f = 1.0f;
angle::Mat4 testMatrix = angle::Mat4::Frustum(l, r, b, t, n, f);
glFrustumf(l, r, b, t, n, f);
EXPECT_GL_NO_ERROR();
angle::Mat4 outputMatrix;
glGetFloatv(GL_MODELVIEW_MATRIX, outputMatrix.data());
EXPECT_GL_NO_ERROR();
EXPECT_TRUE(testMatrix.nearlyEqual(0.00001f, outputMatrix));
}
// Test orthographic projection and check the matrix values.
TEST_P(MatrixBuiltinsTest, Ortho)
{
constexpr float l = -1.0f;
constexpr float r = 1.0f;
constexpr float b = -1.0f;
constexpr float t = 1.0f;
constexpr float n = 0.1f;
constexpr float f = 1.0f;
angle::Mat4 testMatrix = angle::Mat4::Ortho(l, r, b, t, n, f);
glOrthof(l, r, b, t, n, f);
EXPECT_GL_NO_ERROR();
angle::Mat4 outputMatrix;
glGetFloatv(GL_MODELVIEW_MATRIX, outputMatrix.data());
EXPECT_GL_NO_ERROR();
EXPECT_TRUE(testMatrix.nearlyEqual(0.00001f, outputMatrix));
}
// Test that GL_INVALID_VALUE is issued if potential divide by zero situations happen for
// glFrustumf.
TEST_P(MatrixBuiltinsTest, FrustumNegative)
{
glFrustumf(1.0f, 1.0f, 0.0f, 1.0f, 0.1f, 1.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glFrustumf(0.0f, 1.0f, 1.0f, 1.0f, 0.1f, 1.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glFrustumf(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glFrustumf(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glFrustumf(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glFrustumf(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
}
// Test that GL_INVALID_VALUE is issued if potential divide by zero situations happen for glOrthof.
TEST_P(MatrixBuiltinsTest, OrthoNegative)
{
glOrthof(1.0f, 1.0f, 0.0f, 1.0f, 0.1f, 1.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glOrthof(0.0f, 1.0f, 1.0f, 1.0f, 0.1f, 1.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glOrthof(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glOrthof(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glOrthof(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
}
ANGLE_INSTANTIATE_TEST(MatrixBuiltinsTest, 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