Commit 4a09c1a2 by Lingfeng Yang Committed by Commit Bot

GLES1: Entry points for lighting and materials

- glLight*/glMaterial and their queries - Use new packed enums in these entry points, except for lightmodel which stays GLenum to be consistent with other generic glGet's - State.cpp: New glGet* queries related to light model and light/normal rescale enablement - GLES1State.cpp: Functions to get/set lighting/material state - Validation for lighting/materials + Add a few convenience methods to random_utils for sampling non-negative floats and a sampler for random booleans BUG=angleproject:2306 Change-Id: If7ba0c0a0dc75f88fbaa986b904f1ea96ee6512e Reviewed-on: https://chromium-review.googlesource.com/1065502 Commit-Queue: Lingfeng Yang <lfy@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 2b0cdcc1
......@@ -136,6 +136,18 @@
"glGetBufferPointervRobustANGLE": {
"target": "BufferBinding"
},
"glGetLightfv": {
"pname" : "LightParameter"
},
"glGetLightxv": {
"pname" : "LightParameter"
},
"glGetMaterialfv": {
"pname" : "MaterialParameter"
},
"glGetMaterialxv": {
"pname" : "MaterialParameter"
},
"glGetQueryiv": {
"target": "QueryType"
},
......@@ -178,6 +190,18 @@
"glGetTexParameterxv": {
"target": "TextureType"
},
"glLightf" : {
"pname" : "LightParameter"
},
"glLightfv" : {
"pname" : "LightParameter"
},
"glLightx" : {
"pname" : "LightParameter"
},
"glLightxv" : {
"pname" : "LightParameter"
},
"glMapBuffer": {
"target": "BufferBinding"
},
......@@ -190,6 +214,18 @@
"glMapBufferRangeEXT": {
"target": "BufferBinding"
},
"glMaterialf": {
"pname": "MaterialParameter"
},
"glMaterialfv": {
"pname": "MaterialParameter"
},
"glMaterialx": {
"pname": "MaterialParameter"
},
"glMaterialxv": {
"pname": "MaterialParameter"
},
"glMatrixMode": {
"mode": "MatrixType"
},
......
......@@ -21,6 +21,15 @@ struct Color
const T *data() const { return &red; }
T *ptr() { return &red; }
static Color fromData(const T *data) { return Color(data[0], data[1], data[2], data[3]); }
void writeData(T *data) const
{
data[0] = red;
data[1] = green;
data[2] = blue;
data[3] = alpha;
}
T red;
T green;
T blue;
......
......@@ -1682,6 +1682,9 @@ void Context::getIntegervImpl(GLenum pname, GLint *params)
case GL_MAX_TEXTURE_STACK_DEPTH:
*params = mCaps.maxTextureMatrixStackDepth;
break;
case GL_MAX_LIGHTS:
*params = mCaps.maxLights;
break;
// GLES1 emulation: Vertex attribute queries
case GL_VERTEX_ARRAY_BUFFER_BINDING:
case GL_NORMAL_ARRAY_BUFFER_BINDING:
......@@ -7058,6 +7061,7 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
case GL_MAX_MODELVIEW_STACK_DEPTH:
case GL_MAX_PROJECTION_STACK_DEPTH:
case GL_MAX_TEXTURE_STACK_DEPTH:
case GL_MAX_LIGHTS:
case GL_VERTEX_ARRAY_STRIDE:
case GL_NORMAL_ARRAY_STRIDE:
case GL_COLOR_ARRAY_STRIDE:
......@@ -7085,6 +7089,7 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
return true;
case GL_CURRENT_COLOR:
case GL_CURRENT_TEXTURE_COORDS:
case GL_LIGHT_MODEL_AMBIENT:
*type = GL_FLOAT;
*numParams = 4;
return true;
......@@ -7098,6 +7103,10 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
*type = GL_FLOAT;
*numParams = 16;
return true;
case GL_LIGHT_MODEL_TWO_SIDE:
*type = GL_BOOL;
*numParams = 1;
return true;
}
}
......
......@@ -12,6 +12,7 @@
#include "common/utilities.h"
#include "libANGLE/GLES1Renderer.h"
#include "libANGLE/queryutils.h"
namespace
{
......@@ -157,24 +158,36 @@ void Context::getFixedv(GLenum pname, GLfixed *params)
UNIMPLEMENTED();
}
void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
void Context::getLightfv(GLenum light, LightParameter pname, GLfloat *params)
{
UNIMPLEMENTED();
GetLightParameters(&mGLState.gles1(), light, pname, params);
}
void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
void Context::getLightxv(GLenum light, LightParameter pname, GLfixed *params)
{
UNIMPLEMENTED();
GLfloat paramsf[4];
getLightfv(light, pname, paramsf);
for (unsigned int i = 0; i < GetLightParameterCount(pname); i++)
{
params[i] = FloatToFixed(paramsf[i]);
}
}
void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
void Context::getMaterialfv(GLenum face, MaterialParameter pname, GLfloat *params)
{
UNIMPLEMENTED();
GetMaterialParameters(&mGLState.gles1(), face, pname, params);
}
void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
void Context::getMaterialxv(GLenum face, MaterialParameter pname, GLfixed *params)
{
UNIMPLEMENTED();
GLfloat paramsf[4];
getMaterialfv(face, pname, paramsf);
for (unsigned int i = 0; i < GetMaterialParameterCount(pname); i++)
{
params[i] = FloatToFixed(paramsf[i]);
}
}
void Context::getTexEnvfv(GLenum env, GLenum pname, GLfloat *params)
......@@ -199,42 +212,56 @@ void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *param
void Context::lightModelf(GLenum pname, GLfloat param)
{
UNIMPLEMENTED();
SetLightModelParameters(&mGLState.gles1(), pname, &param);
}
void Context::lightModelfv(GLenum pname, const GLfloat *params)
{
UNIMPLEMENTED();
SetLightModelParameters(&mGLState.gles1(), pname, params);
}
void Context::lightModelx(GLenum pname, GLfixed param)
{
UNIMPLEMENTED();
lightModelf(pname, FixedToFloat(param));
}
void Context::lightModelxv(GLenum pname, const GLfixed *param)
{
UNIMPLEMENTED();
GLfloat paramsf[4];
for (unsigned int i = 0; i < GetLightModelParameterCount(pname); i++)
{
paramsf[i] = FixedToFloat(param[i]);
}
lightModelfv(pname, paramsf);
}
void Context::lightf(GLenum light, GLenum pname, GLfloat param)
void Context::lightf(GLenum light, LightParameter pname, GLfloat param)
{
UNIMPLEMENTED();
SetLightParameters(&mGLState.gles1(), light, pname, &param);
}
void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
void Context::lightfv(GLenum light, LightParameter pname, const GLfloat *params)
{
UNIMPLEMENTED();
SetLightParameters(&mGLState.gles1(), light, pname, params);
}
void Context::lightx(GLenum light, GLenum pname, GLfixed param)
void Context::lightx(GLenum light, LightParameter pname, GLfixed param)
{
UNIMPLEMENTED();
lightf(light, pname, FixedToFloat(param));
}
void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
void Context::lightxv(GLenum light, LightParameter pname, const GLfixed *params)
{
UNIMPLEMENTED();
GLfloat paramsf[4];
for (unsigned int i = 0; i < GetLightParameterCount(pname); i++)
{
paramsf[i] = FixedToFloat(params[i]);
}
lightfv(light, pname, paramsf);
}
void Context::lineWidthx(GLfixed width)
......@@ -262,24 +289,31 @@ void Context::logicOp(GLenum opcode)
UNIMPLEMENTED();
}
void Context::materialf(GLenum face, GLenum pname, GLfloat param)
void Context::materialf(GLenum face, MaterialParameter pname, GLfloat param)
{
UNIMPLEMENTED();
SetMaterialParameters(&mGLState.gles1(), face, pname, &param);
}
void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
void Context::materialfv(GLenum face, MaterialParameter pname, const GLfloat *params)
{
UNIMPLEMENTED();
SetMaterialParameters(&mGLState.gles1(), face, pname, params);
}
void Context::materialx(GLenum face, GLenum pname, GLfixed param)
void Context::materialx(GLenum face, MaterialParameter pname, GLfixed param)
{
UNIMPLEMENTED();
materialf(face, pname, FixedToFloat(param));
}
void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
void Context::materialxv(GLenum face, MaterialParameter pname, const GLfixed *param)
{
UNIMPLEMENTED();
GLfloat paramsf[4];
for (unsigned int i = 0; i < GetMaterialParameterCount(pname); i++)
{
paramsf[i] = FixedToFloat(param[i]);
}
materialfv(face, pname, paramsf);
}
void Context::matrixMode(MatrixType mode)
......
......@@ -34,10 +34,10 @@
void getClipPlanef(GLenum plane, GLfloat *equation); \
void getClipPlanex(GLenum plane, GLfixed *equation); \
void getFixedv(GLenum pname, GLfixed *params); \
void getLightfv(GLenum light, GLenum pname, GLfloat *params); \
void getLightxv(GLenum light, GLenum pname, GLfixed *params); \
void getMaterialfv(GLenum face, GLenum pname, GLfloat *params); \
void getMaterialxv(GLenum face, GLenum pname, GLfixed *params); \
void getLightfv(GLenum light, LightParameter pnamePacked, GLfloat *params); \
void getLightxv(GLenum light, LightParameter pnamePacked, GLfixed *params); \
void getMaterialfv(GLenum face, MaterialParameter pnamePacked, GLfloat *params); \
void getMaterialxv(GLenum face, MaterialParameter pnamePacked, GLfixed *params); \
void getTexEnvfv(GLenum target, GLenum pname, GLfloat *params); \
void getTexEnviv(GLenum target, GLenum pname, GLint *params); \
void getTexEnvxv(GLenum target, GLenum pname, GLfixed *params); \
......@@ -46,19 +46,19 @@
void lightModelfv(GLenum pname, const GLfloat *params); \
void lightModelx(GLenum pname, GLfixed param); \
void lightModelxv(GLenum pname, const GLfixed *param); \
void lightf(GLenum light, GLenum pname, GLfloat param); \
void lightfv(GLenum light, GLenum pname, const GLfloat *params); \
void lightx(GLenum light, GLenum pname, GLfixed param); \
void lightxv(GLenum light, GLenum pname, const GLfixed *params); \
void lightf(GLenum light, LightParameter pnamePacked, GLfloat param); \
void lightfv(GLenum light, LightParameter pnamePacked, const GLfloat *params); \
void lightx(GLenum light, LightParameter pnamePacked, GLfixed param); \
void lightxv(GLenum light, LightParameter pnamePacked, const GLfixed *params); \
void lineWidthx(GLfixed width); \
void loadIdentity(); \
void loadMatrixf(const GLfloat *m); \
void loadMatrixx(const GLfixed *m); \
void logicOp(GLenum opcode); \
void materialf(GLenum face, GLenum pname, GLfloat param); \
void materialfv(GLenum face, GLenum pname, const GLfloat *params); \
void materialx(GLenum face, GLenum pname, GLfixed param); \
void materialxv(GLenum face, GLenum pname, const GLfixed *param); \
void materialf(GLenum face, MaterialParameter pnamePacked, GLfloat param); \
void materialfv(GLenum face, MaterialParameter pnamePacked, const GLfloat *params); \
void materialx(GLenum face, MaterialParameter pnamePacked, GLfixed param); \
void materialxv(GLenum face, MaterialParameter pnamePacked, const GLfixed *param); \
void matrixMode(MatrixType modePacked); \
void multMatrixf(const GLfloat *m); \
void multMatrixx(const GLfixed *m); \
......
......@@ -94,6 +94,11 @@ ERRMSG(InvalidFramebufferLayer,
ERRMSG(InvalidImageUnit,
"Image unit cannot be greater than or equal to the value of MAX_IMAGE_UNITS.");
ERRMSG(InvalidInternalFormat, "Invalid internal format.");
ERRMSG(InvalidLight, "Invalid light.");
ERRMSG(InvalidLightModelParameter, "Invalid light model parameter.");
ERRMSG(InvalidLightParameter, "Invalid light parameter.");
ERRMSG(InvalidMaterialFace, "Invalid material face.");
ERRMSG(InvalidMaterialParameter, "Invalid material parameter.");
ERRMSG(InvalidMatrixMode, "Invalid matrix mode.");
ERRMSG(InvalidMemoryBarrierBit, "Invalid memory barrier bit.");
ERRMSG(InvalidMipLevel, "Level of detail outside of range.");
......@@ -139,6 +144,8 @@ ERRMSG(InvalidVertexPointerType, "Invalid type for built-in vertex attribute.");
ERRMSG(InvalidWidth, "Invalid width.");
ERRMSG(InvalidWrapModeTexture, "Invalid wrap mode for texture type.");
ERRMSG(LevelNotZero, "Texture level must be zero.");
ERRMSG(LightParameterOutOfRange, "Light parameter out of range.");
ERRMSG(MaterialParameterOutOfRange, "Material parameter out of range.");
ERRMSG(MatrixStackOverflow, "Current matrix stack is full.");
ERRMSG(MatrixStackUnderflow, "Current matrix stack has only a single matrix.");
ERRMSG(MismatchedByteCountType, "Buffer size does not align with data type.");
......
......@@ -240,6 +240,11 @@ GLES1State::MatrixStack &GLES1State::currentMatrixStack()
}
}
const angle::Mat4 &GLES1State::getModelviewMatrix() const
{
return mModelviewMatrices.back();
}
const GLES1State::MatrixStack &GLES1State::currentMatrixStack() const
{
switch (mMatrixMode)
......@@ -323,4 +328,39 @@ bool GLES1State::isTextureTargetEnabled(unsigned int unit, const TextureType typ
return mTexUnitEnables[unit].test(type);
}
LightModelParameters &GLES1State::lightModelParameters()
{
return mLightModel;
}
const LightModelParameters &GLES1State::lightModelParameters() const
{
return mLightModel;
}
LightParameters &GLES1State::lightParameters(unsigned int light)
{
return mLights[light];
}
const LightParameters &GLES1State::lightParameters(unsigned int light) const
{
return mLights[light];
}
MaterialParameters &GLES1State::materialParameters()
{
return mMaterial;
}
const MaterialParameters &GLES1State::materialParameters() const
{
return mMaterial;
}
bool GLES1State::isColorMaterialEnabled() const
{
return mColorMaterialEnabled;
}
} // namespace gl
......@@ -149,6 +149,8 @@ class GLES1State final : angle::NonCopyable
MatrixStack &currentMatrixStack();
const MatrixStack &currentMatrixStack() const;
const angle::Mat4 &getModelviewMatrix() const;
void loadMatrix(const angle::Mat4 &m);
void multMatrix(const angle::Mat4 &m);
......@@ -157,6 +159,16 @@ class GLES1State final : angle::NonCopyable
bool isTexCoordArrayEnabled(unsigned int unit) const;
bool isTextureTargetEnabled(unsigned int unit, const TextureType type) const;
LightModelParameters &lightModelParameters();
const LightModelParameters &lightModelParameters() const;
LightParameters &lightParameters(unsigned int light);
const LightParameters &lightParameters(unsigned int light) const;
MaterialParameters &materialParameters();
const MaterialParameters &materialParameters() const;
bool isColorMaterialEnabled() const;
private:
friend class State;
friend class GLES1Renderer;
......
......@@ -786,7 +786,28 @@ void State::setEnableFeature(GLenum feature, bool enabled)
case GL_TEXTURE_CUBE_MAP:
mGLES1State.mTexUnitEnables[mActiveSampler].set(TextureType::CubeMap, enabled);
break;
case GL_LIGHTING:
mGLES1State.mLightingEnabled = enabled;
break;
case GL_LIGHT0:
case GL_LIGHT1:
case GL_LIGHT2:
case GL_LIGHT3:
case GL_LIGHT4:
case GL_LIGHT5:
case GL_LIGHT6:
case GL_LIGHT7:
mGLES1State.mLights[feature - GL_LIGHT0].enabled = enabled;
break;
case GL_NORMALIZE:
mGLES1State.mNormalizeEnabled = enabled;
break;
case GL_RESCALE_NORMAL:
mGLES1State.mRescaleNormalEnabled = enabled;
break;
case GL_COLOR_MATERIAL:
mGLES1State.mColorMaterialEnabled = enabled;
break;
default:
UNREACHABLE();
}
......@@ -856,6 +877,23 @@ bool State::getEnableFeature(GLenum feature) const
return mGLES1State.mTexUnitEnables[mActiveSampler].test(TextureType::_2D);
case GL_TEXTURE_CUBE_MAP:
return mGLES1State.mTexUnitEnables[mActiveSampler].test(TextureType::CubeMap);
case GL_LIGHTING:
return mGLES1State.mLightingEnabled;
case GL_LIGHT0:
case GL_LIGHT1:
case GL_LIGHT2:
case GL_LIGHT3:
case GL_LIGHT4:
case GL_LIGHT5:
case GL_LIGHT6:
case GL_LIGHT7:
return mGLES1State.mLights[feature - GL_LIGHT0].enabled;
case GL_NORMALIZE:
return mGLES1State.mNormalizeEnabled;
case GL_RESCALE_NORMAL:
return mGLES1State.mRescaleNormalEnabled;
case GL_COLOR_MATERIAL:
return mGLES1State.mColorMaterialEnabled;
default:
UNREACHABLE();
return false;
......@@ -1899,7 +1937,9 @@ void State::getBooleanv(GLenum pname, GLboolean *params)
case GL_PROGRAM_CACHE_ENABLED_ANGLE:
*params = mProgramBinaryCacheEnabled ? GL_TRUE : GL_FALSE;
break;
case GL_LIGHT_MODEL_TWO_SIDE:
*params = IsLightModelTwoSided(&mGLES1State);
break;
default:
UNREACHABLE();
break;
......@@ -1993,6 +2033,9 @@ void State::getFloatv(GLenum pname, GLfloat *params)
memcpy(params, mGLES1State.mTextureMatrices[mActiveSampler].back().data(),
16 * sizeof(GLfloat));
break;
case GL_LIGHT_MODEL_AMBIENT:
GetLightModelParameters(&mGLES1State, pname, params);
break;
default:
UNREACHABLE();
break;
......
......@@ -15,6 +15,7 @@
#include "libANGLE/Context.h"
#include "libANGLE/Fence.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/GLES1State.h"
#include "libANGLE/Program.h"
#include "libANGLE/Renderbuffer.h"
#include "libANGLE/Sampler.h"
......@@ -1746,6 +1747,282 @@ ClientVertexArrayType ParamToVertexArrayType(GLenum param)
}
}
void SetLightModelParameters(GLES1State *state, GLenum pname, const GLfloat *params)
{
LightModelParameters &lightModel = state->lightModelParameters();
switch (pname)
{
case GL_LIGHT_MODEL_AMBIENT:
lightModel.color = ColorF::fromData(params);
break;
case GL_LIGHT_MODEL_TWO_SIDE:
lightModel.twoSided = *params == 1.0f ? true : false;
break;
default:
break;
}
}
void GetLightModelParameters(const GLES1State *state, GLenum pname, GLfloat *params)
{
const LightModelParameters &lightModel = state->lightModelParameters();
switch (pname)
{
case GL_LIGHT_MODEL_TWO_SIDE:
*params = lightModel.twoSided ? 1.0f : 0.0f;
break;
case GL_LIGHT_MODEL_AMBIENT:
lightModel.color.writeData(params);
break;
default:
break;
}
}
bool IsLightModelTwoSided(const GLES1State *state)
{
return state->lightModelParameters().twoSided;
}
void SetLightParameters(GLES1State *state,
GLenum light,
LightParameter pname,
const GLfloat *params)
{
uint32_t lightIndex = light - GL_LIGHT0;
LightParameters &lightParams = state->lightParameters(lightIndex);
switch (pname)
{
case LightParameter::Ambient:
lightParams.ambient = ColorF::fromData(params);
break;
case LightParameter::Diffuse:
lightParams.diffuse = ColorF::fromData(params);
break;
case LightParameter::Specular:
lightParams.specular = ColorF::fromData(params);
break;
case LightParameter::Position:
{
angle::Mat4 mv = state->getModelviewMatrix();
angle::Vector4 transformedPos =
mv.product(angle::Vector4(params[0], params[1], params[2], params[3]));
lightParams.position[0] = transformedPos[0];
lightParams.position[1] = transformedPos[1];
lightParams.position[2] = transformedPos[2];
lightParams.position[3] = transformedPos[3];
}
break;
case LightParameter::SpotDirection:
{
angle::Mat4 mv = state->getModelviewMatrix();
angle::Vector4 transformedPos =
mv.product(angle::Vector4(params[0], params[1], params[2], 0.0f));
lightParams.direction[0] = transformedPos[0];
lightParams.direction[1] = transformedPos[1];
lightParams.direction[2] = transformedPos[2];
}
break;
case LightParameter::SpotExponent:
lightParams.spotlightExponent = *params;
break;
case LightParameter::SpotCutoff:
lightParams.spotlightCutoffAngle = *params;
break;
case LightParameter::ConstantAttenuation:
lightParams.attenuationConst = *params;
break;
case LightParameter::LinearAttenuation:
lightParams.attenuationLinear = *params;
break;
case LightParameter::QuadraticAttenuation:
lightParams.attenuationQuadratic = *params;
break;
default:
return;
}
}
void GetLightParameters(const GLES1State *state,
GLenum light,
LightParameter pname,
GLfloat *params)
{
uint32_t lightIndex = light - GL_LIGHT0;
const LightParameters &lightParams = state->lightParameters(lightIndex);
switch (pname)
{
case LightParameter::Ambient:
lightParams.ambient.writeData(params);
break;
case LightParameter::Diffuse:
lightParams.diffuse.writeData(params);
break;
case LightParameter::Specular:
lightParams.specular.writeData(params);
break;
case LightParameter::Position:
memcpy(params, lightParams.position.data(), 4 * sizeof(GLfloat));
break;
case LightParameter::SpotDirection:
memcpy(params, lightParams.direction.data(), 3 * sizeof(GLfloat));
break;
case LightParameter::SpotExponent:
*params = lightParams.spotlightExponent;
break;
case LightParameter::SpotCutoff:
*params = lightParams.spotlightCutoffAngle;
break;
case LightParameter::ConstantAttenuation:
*params = lightParams.attenuationConst;
break;
case LightParameter::LinearAttenuation:
*params = lightParams.attenuationLinear;
break;
case LightParameter::QuadraticAttenuation:
*params = lightParams.attenuationQuadratic;
break;
default:
break;
}
}
void SetMaterialParameters(GLES1State *state,
GLenum face,
MaterialParameter pname,
const GLfloat *params)
{
MaterialParameters &material = state->materialParameters();
switch (pname)
{
case MaterialParameter::Ambient:
material.ambient = ColorF::fromData(params);
break;
case MaterialParameter::Diffuse:
material.diffuse = ColorF::fromData(params);
break;
case MaterialParameter::AmbientAndDiffuse:
material.ambient = ColorF::fromData(params);
material.diffuse = ColorF::fromData(params);
break;
case MaterialParameter::Specular:
material.specular = ColorF::fromData(params);
break;
case MaterialParameter::Emission:
material.emissive = ColorF::fromData(params);
break;
case MaterialParameter::Shininess:
material.specularExponent = *params;
break;
default:
return;
}
}
void GetMaterialParameters(const GLES1State *state,
GLenum face,
MaterialParameter pname,
GLfloat *params)
{
const ColorF &currentColor = state->getCurrentColor();
const MaterialParameters &material = state->materialParameters();
const bool colorMaterialEnabled = state->isColorMaterialEnabled();
switch (pname)
{
case MaterialParameter::Ambient:
if (colorMaterialEnabled)
{
currentColor.writeData(params);
}
else
{
material.ambient.writeData(params);
}
break;
case MaterialParameter::Diffuse:
if (colorMaterialEnabled)
{
currentColor.writeData(params);
}
else
{
material.diffuse.writeData(params);
}
break;
case MaterialParameter::Specular:
material.specular.writeData(params);
break;
case MaterialParameter::Emission:
material.emissive.writeData(params);
break;
case MaterialParameter::Shininess:
*params = material.specularExponent;
break;
default:
return;
}
}
unsigned int GetLightModelParameterCount(GLenum pname)
{
switch (pname)
{
case GL_LIGHT_MODEL_AMBIENT:
return 4;
case GL_LIGHT_MODEL_TWO_SIDE:
return 1;
default:
UNREACHABLE();
return 0;
}
}
unsigned int GetLightParameterCount(LightParameter pname)
{
switch (pname)
{
case LightParameter::Ambient:
case LightParameter::Diffuse:
case LightParameter::Specular:
case LightParameter::Position:
return 4;
case LightParameter::SpotDirection:
return 3;
case LightParameter::SpotExponent:
case LightParameter::SpotCutoff:
case LightParameter::ConstantAttenuation:
case LightParameter::LinearAttenuation:
case LightParameter::QuadraticAttenuation:
return 1;
default:
UNREACHABLE();
return 0;
}
}
unsigned int GetMaterialParameterCount(MaterialParameter pname)
{
switch (pname)
{
case MaterialParameter::Ambient:
case MaterialParameter::Diffuse:
case MaterialParameter::Specular:
case MaterialParameter::Emission:
return 4;
case MaterialParameter::Shininess:
return 1;
default:
UNREACHABLE();
return 0;
}
}
} // namespace gl
namespace egl
......
......@@ -22,6 +22,7 @@ class Context;
class Error;
class Sync;
class Framebuffer;
class GLES1State;
class Program;
class Renderbuffer;
class Sampler;
......@@ -144,9 +145,36 @@ void QueryProgramInterfaceiv(const Program *program,
GLenum programInterface,
GLenum pname,
GLint *params);
// GLES1 emulation
ClientVertexArrayType ParamToVertexArrayType(GLenum param);
void SetLightParameters(GLES1State *state,
GLenum light,
LightParameter pname,
const GLfloat *params);
void GetLightParameters(const GLES1State *state,
GLenum light,
LightParameter pname,
GLfloat *params);
void SetLightModelParameters(GLES1State *state, GLenum pname, const GLfloat *params);
void GetLightModelParameters(const GLES1State *state, GLenum pname, GLfloat *params);
bool IsLightModelTwoSided(const GLES1State *state);
void SetMaterialParameters(GLES1State *state,
GLenum face,
MaterialParameter pname,
const GLfloat *params);
void GetMaterialParameters(const GLES1State *state,
GLenum face,
MaterialParameter pname,
GLfloat *params);
unsigned int GetLightModelParameterCount(GLenum pname);
unsigned int GetLightParameterCount(LightParameter pname);
unsigned int GetMaterialParameterCount(MaterialParameter pname);
} // namespace gl
namespace egl
......
......@@ -59,10 +59,10 @@ bool ValidateGetBufferParameteriv(Context *context, GLenum target, GLenum pname,
bool ValidateGetClipPlanef(Context *context, GLenum plane, GLfloat *equation);
bool ValidateGetClipPlanex(Context *context, GLenum plane, GLfixed *equation);
bool ValidateGetFixedv(Context *context, GLenum pname, GLfixed *params);
bool ValidateGetLightfv(Context *context, GLenum light, GLenum pname, GLfloat *params);
bool ValidateGetLightxv(Context *context, GLenum light, GLenum pname, GLfixed *params);
bool ValidateGetMaterialfv(Context *context, GLenum face, GLenum pname, GLfloat *params);
bool ValidateGetMaterialxv(Context *context, GLenum face, GLenum pname, GLfixed *params);
bool ValidateGetLightfv(Context *context, GLenum light, LightParameter pname, GLfloat *params);
bool ValidateGetLightxv(Context *context, GLenum light, LightParameter pname, GLfixed *params);
bool ValidateGetMaterialfv(Context *context, GLenum face, MaterialParameter pname, GLfloat *params);
bool ValidateGetMaterialxv(Context *context, GLenum face, MaterialParameter pname, GLfixed *params);
bool ValidateGetPointerv(Context *context, GLenum pname, void **params);
bool ValidateGetTexEnvfv(Context *context, GLenum target, GLenum pname, GLfloat *params);
bool ValidateGetTexEnviv(Context *context, GLenum target, GLenum pname, GLint *params);
......@@ -72,19 +72,25 @@ bool ValidateLightModelf(Context *context, GLenum pname, GLfloat param);
bool ValidateLightModelfv(Context *context, GLenum pname, const GLfloat *params);
bool ValidateLightModelx(Context *context, GLenum pname, GLfixed param);
bool ValidateLightModelxv(Context *context, GLenum pname, const GLfixed *param);
bool ValidateLightf(Context *context, GLenum light, GLenum pname, GLfloat param);
bool ValidateLightfv(Context *context, GLenum light, GLenum pname, const GLfloat *params);
bool ValidateLightx(Context *context, GLenum light, GLenum pname, GLfixed param);
bool ValidateLightxv(Context *context, GLenum light, GLenum pname, const GLfixed *params);
bool ValidateLightf(Context *context, GLenum light, LightParameter pname, GLfloat param);
bool ValidateLightfv(Context *context, GLenum light, LightParameter pname, const GLfloat *params);
bool ValidateLightx(Context *context, GLenum light, LightParameter pname, GLfixed param);
bool ValidateLightxv(Context *context, GLenum light, LightParameter pname, const GLfixed *params);
bool ValidateLineWidthx(Context *context, GLfixed width);
bool ValidateLoadIdentity(Context *context);
bool ValidateLoadMatrixf(Context *context, const GLfloat *m);
bool ValidateLoadMatrixx(Context *context, const GLfixed *m);
bool ValidateLogicOp(Context *context, GLenum opcode);
bool ValidateMaterialf(Context *context, GLenum face, GLenum pname, GLfloat param);
bool ValidateMaterialfv(Context *context, GLenum face, GLenum pname, const GLfloat *params);
bool ValidateMaterialx(Context *context, GLenum face, GLenum pname, GLfixed param);
bool ValidateMaterialxv(Context *context, GLenum face, GLenum pname, const GLfixed *param);
bool ValidateMaterialf(Context *context, GLenum face, MaterialParameter pname, GLfloat param);
bool ValidateMaterialfv(Context *context,
GLenum face,
MaterialParameter pname,
const GLfloat *params);
bool ValidateMaterialx(Context *context, GLenum face, MaterialParameter pname, GLfixed param);
bool ValidateMaterialxv(Context *context,
GLenum face,
MaterialParameter pname,
const GLfixed *param);
bool ValidateMatrixMode(Context *context, MatrixType mode);
bool ValidateMultMatrixf(Context *context, const GLfloat *m);
bool ValidateMultMatrixx(Context *context, const GLfixed *m);
......
......@@ -799,6 +799,18 @@ bool ValidCap(const Context *context, GLenum cap, bool queryOnly)
case GL_COLOR_ARRAY:
case GL_TEXTURE_COORD_ARRAY:
case GL_TEXTURE_2D:
case GL_LIGHTING:
case GL_LIGHT0:
case GL_LIGHT1:
case GL_LIGHT2:
case GL_LIGHT3:
case GL_LIGHT4:
case GL_LIGHT5:
case GL_LIGHT6:
case GL_LIGHT7:
case GL_NORMALIZE:
case GL_RESCALE_NORMAL:
case GL_COLOR_MATERIAL:
return context->getClientVersion() < Version(2, 0);
case GL_POINT_SIZE_ARRAY_OES:
return context->getClientVersion() < Version(2, 0) &&
......
......@@ -408,11 +408,12 @@ void GL_APIENTRY GetLightfv(GLenum light, GLenum pname, GLfloat *params)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::GetLightfv>(light, pname, params);
LightParameter pnamePacked = FromGLenum<LightParameter>(pname);
context->gatherParams<EntryPoint::GetLightfv>(light, pnamePacked, params);
if (context->skipValidation() || ValidateGetLightfv(context, light, pname, params))
if (context->skipValidation() || ValidateGetLightfv(context, light, pnamePacked, params))
{
context->getLightfv(light, pname, params);
context->getLightfv(light, pnamePacked, params);
}
}
}
......@@ -425,11 +426,12 @@ void GL_APIENTRY GetLightxv(GLenum light, GLenum pname, GLfixed *params)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::GetLightxv>(light, pname, params);
LightParameter pnamePacked = FromGLenum<LightParameter>(pname);
context->gatherParams<EntryPoint::GetLightxv>(light, pnamePacked, params);
if (context->skipValidation() || ValidateGetLightxv(context, light, pname, params))
if (context->skipValidation() || ValidateGetLightxv(context, light, pnamePacked, params))
{
context->getLightxv(light, pname, params);
context->getLightxv(light, pnamePacked, params);
}
}
}
......@@ -442,11 +444,12 @@ void GL_APIENTRY GetMaterialfv(GLenum face, GLenum pname, GLfloat *params)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::GetMaterialfv>(face, pname, params);
MaterialParameter pnamePacked = FromGLenum<MaterialParameter>(pname);
context->gatherParams<EntryPoint::GetMaterialfv>(face, pnamePacked, params);
if (context->skipValidation() || ValidateGetMaterialfv(context, face, pname, params))
if (context->skipValidation() || ValidateGetMaterialfv(context, face, pnamePacked, params))
{
context->getMaterialfv(face, pname, params);
context->getMaterialfv(face, pnamePacked, params);
}
}
}
......@@ -459,11 +462,12 @@ void GL_APIENTRY GetMaterialxv(GLenum face, GLenum pname, GLfixed *params)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::GetMaterialxv>(face, pname, params);
MaterialParameter pnamePacked = FromGLenum<MaterialParameter>(pname);
context->gatherParams<EntryPoint::GetMaterialxv>(face, pnamePacked, params);
if (context->skipValidation() || ValidateGetMaterialxv(context, face, pname, params))
if (context->skipValidation() || ValidateGetMaterialxv(context, face, pnamePacked, params))
{
context->getMaterialxv(face, pname, params);
context->getMaterialxv(face, pnamePacked, params);
}
}
}
......@@ -625,11 +629,12 @@ void GL_APIENTRY Lightf(GLenum light, GLenum pname, GLfloat param)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::Lightf>(light, pname, param);
LightParameter pnamePacked = FromGLenum<LightParameter>(pname);
context->gatherParams<EntryPoint::Lightf>(light, pnamePacked, param);
if (context->skipValidation() || ValidateLightf(context, light, pname, param))
if (context->skipValidation() || ValidateLightf(context, light, pnamePacked, param))
{
context->lightf(light, pname, param);
context->lightf(light, pnamePacked, param);
}
}
}
......@@ -642,11 +647,12 @@ void GL_APIENTRY Lightfv(GLenum light, GLenum pname, const GLfloat *params)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::Lightfv>(light, pname, params);
LightParameter pnamePacked = FromGLenum<LightParameter>(pname);
context->gatherParams<EntryPoint::Lightfv>(light, pnamePacked, params);
if (context->skipValidation() || ValidateLightfv(context, light, pname, params))
if (context->skipValidation() || ValidateLightfv(context, light, pnamePacked, params))
{
context->lightfv(light, pname, params);
context->lightfv(light, pnamePacked, params);
}
}
}
......@@ -658,11 +664,12 @@ void GL_APIENTRY Lightx(GLenum light, GLenum pname, GLfixed param)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::Lightx>(light, pname, param);
LightParameter pnamePacked = FromGLenum<LightParameter>(pname);
context->gatherParams<EntryPoint::Lightx>(light, pnamePacked, param);
if (context->skipValidation() || ValidateLightx(context, light, pname, param))
if (context->skipValidation() || ValidateLightx(context, light, pnamePacked, param))
{
context->lightx(light, pname, param);
context->lightx(light, pnamePacked, param);
}
}
}
......@@ -675,11 +682,12 @@ void GL_APIENTRY Lightxv(GLenum light, GLenum pname, const GLfixed *params)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::Lightxv>(light, pname, params);
LightParameter pnamePacked = FromGLenum<LightParameter>(pname);
context->gatherParams<EntryPoint::Lightxv>(light, pnamePacked, params);
if (context->skipValidation() || ValidateLightxv(context, light, pname, params))
if (context->skipValidation() || ValidateLightxv(context, light, pnamePacked, params))
{
context->lightxv(light, pname, params);
context->lightxv(light, pnamePacked, params);
}
}
}
......@@ -771,11 +779,12 @@ void GL_APIENTRY Materialf(GLenum face, GLenum pname, GLfloat param)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::Materialf>(face, pname, param);
MaterialParameter pnamePacked = FromGLenum<MaterialParameter>(pname);
context->gatherParams<EntryPoint::Materialf>(face, pnamePacked, param);
if (context->skipValidation() || ValidateMaterialf(context, face, pname, param))
if (context->skipValidation() || ValidateMaterialf(context, face, pnamePacked, param))
{
context->materialf(face, pname, param);
context->materialf(face, pnamePacked, param);
}
}
}
......@@ -788,11 +797,12 @@ void GL_APIENTRY Materialfv(GLenum face, GLenum pname, const GLfloat *params)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::Materialfv>(face, pname, params);
MaterialParameter pnamePacked = FromGLenum<MaterialParameter>(pname);
context->gatherParams<EntryPoint::Materialfv>(face, pnamePacked, params);
if (context->skipValidation() || ValidateMaterialfv(context, face, pname, params))
if (context->skipValidation() || ValidateMaterialfv(context, face, pnamePacked, params))
{
context->materialfv(face, pname, params);
context->materialfv(face, pnamePacked, params);
}
}
}
......@@ -804,11 +814,12 @@ void GL_APIENTRY Materialx(GLenum face, GLenum pname, GLfixed param)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::Materialx>(face, pname, param);
MaterialParameter pnamePacked = FromGLenum<MaterialParameter>(pname);
context->gatherParams<EntryPoint::Materialx>(face, pnamePacked, param);
if (context->skipValidation() || ValidateMaterialx(context, face, pname, param))
if (context->skipValidation() || ValidateMaterialx(context, face, pnamePacked, param))
{
context->materialx(face, pname, param);
context->materialx(face, pnamePacked, param);
}
}
}
......@@ -821,11 +832,12 @@ void GL_APIENTRY Materialxv(GLenum face, GLenum pname, const GLfixed *param)
Context *context = GetValidGlobalContext();
if (context)
{
context->gatherParams<EntryPoint::Materialxv>(face, pname, param);
MaterialParameter pnamePacked = FromGLenum<MaterialParameter>(pname);
context->gatherParams<EntryPoint::Materialxv>(face, pnamePacked, param);
if (context->skipValidation() || ValidateMaterialxv(context, face, pname, param))
if (context->skipValidation() || ValidateMaterialxv(context, face, pnamePacked, param))
{
context->materialxv(face, pname, param);
context->materialxv(face, pnamePacked, param);
}
}
}
......
......@@ -55,11 +55,13 @@
'<(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/MaterialsTest.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',
'<(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/TextureTargetEnableTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/VertexPointerTest.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.
//
// MaterialsTest.cpp: Tests basic usage of glMaterial*.
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "random_utils.h"
#include <stdint.h>
#include <vector>
using namespace angle;
class MaterialsTest : public ANGLETest
{
protected:
MaterialsTest()
{
setWindowWidth(32);
setWindowHeight(32);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
};
// Check that the initial material state is correct.
TEST_P(MaterialsTest, InitialState)
{
const GLColor32F kAmbientInitial(0.2f, 0.2f, 0.2f, 1.0f);
const GLColor32F kDiffuseInitial(0.8f, 0.8f, 0.8f, 1.0f);
const GLColor32F kSpecularInitial(0.0f, 0.0f, 0.0f, 1.0f);
const GLColor32F kEmissiveInitial(0.0f, 0.0f, 0.0f, 1.0f);
const float kShininessInitial = 0.0f;
GLColor32F actualColor;
float actualShininess;
std::vector<GLenum> pnames = {
GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION,
};
std::vector<GLColor32F> colors = {
kAmbientInitial, kDiffuseInitial, kSpecularInitial, kEmissiveInitial,
};
for (size_t i = 0; i < pnames.size(); i++)
{
glGetMaterialfv(GL_FRONT_AND_BACK, pnames[i], &actualColor.R);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(colors[i], actualColor);
}
glGetMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &actualShininess);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(kShininessInitial, actualShininess);
}
// Check for invalid parameter names.
TEST_P(MaterialsTest, InvalidParameter)
{
glGetMaterialfv(GL_FRONT_AND_BACK, 0, nullptr);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
glGetMaterialfv(GL_FRONT, GL_AMBIENT, nullptr);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
glGetMaterialfv(GL_BACK, GL_AMBIENT, nullptr);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
}
// Check that material parameters can be set.
TEST_P(MaterialsTest, SetParameters)
{
const GLColor32F kAmbientTestValue(1.0f, 1.0f, 1.0f, 1.0f);
const GLColor32F kDiffuseTestValue(0.0f, 0.0f, 0.0f, 0.0f);
const GLColor32F kSpecularTestValue(0.5f, 0.5f, 0.5f, 0.5f);
const GLColor32F kEmissiveTestValue(0.4f, 0.4f, 0.4f, 0.4f);
const float kShininessTestValue = 1.0f;
std::vector<GLenum> pnames = {
GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION,
};
std::vector<GLColor32F> colors = {
kAmbientTestValue, kDiffuseTestValue, kSpecularTestValue, kEmissiveTestValue,
};
GLColor32F actualColor;
float actualShininess;
for (size_t i = 0; i < pnames.size(); i++)
{
glMaterialfv(GL_FRONT_AND_BACK, pnames[i], &colors[i].R);
EXPECT_GL_NO_ERROR();
glGetMaterialfv(GL_FRONT_AND_BACK, pnames[i], &actualColor.R);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(colors[i], actualColor);
}
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, kShininessTestValue);
EXPECT_GL_NO_ERROR();
glGetMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &actualShininess);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(kShininessTestValue, actualShininess);
}
ANGLE_INSTANTIATE_TEST(MaterialsTest, ES1_D3D11(), ES1_OPENGL(), ES1_OPENGLES());
......@@ -37,6 +37,12 @@ void RNG::reseed(unsigned int newSeed)
mGenerator.seed(newSeed);
}
bool RNG::randomBool(float probTrue)
{
std::bernoulli_distribution dist(probTrue);
return dist(mGenerator);
}
int RNG::randomInt()
{
std::uniform_int_distribution<int> intDistribution;
......@@ -67,6 +73,13 @@ float RNG::randomFloatBetween(float min, float max)
return floatDistribution(mGenerator);
}
float RNG::randomFloatNonnegative()
{
std::uniform_real_distribution<float> floatDistribution(0.0f,
std::numeric_limits<float>::max());
return floatDistribution(mGenerator);
}
float RNG::randomNegativeOneToOne()
{
return randomFloatBetween(-1.0f, 1.0f);
......
......@@ -29,11 +29,13 @@ class ANGLE_EXPORT RNG
void reseed(unsigned int newSeed);
bool randomBool(float probTrue = 0.5f);
int randomInt();
int randomIntBetween(int min, int max);
unsigned int randomUInt();
float randomFloat();
float randomFloatBetween(float min, float max);
float randomFloatNonnegative();
float randomNegativeOneToOne();
private:
......@@ -57,4 +59,4 @@ inline void FillVectorWithRandomUBytes(std::vector<uint8_t> *data)
} // namespace angle
#endif // UTIL_RANDOM_UTILS_H
#endif // UTIL_RANDOM_UTILS_H
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