Hash :
461b09a8
Author :
Date :
2018-04-23T09:02:09
GLES1: Renderer (minimal) This is the renderer code for GLES1 that delivers basic vertex attributes, matrices, and allows texturing for unit 0 only (more units mean implementing the multitexturing pipeline). + Sample + Update test expectations for GLES1 conformance tests BUG=angleproject:2554 BUG=angleproject:2306 Change-Id: I398edc764f982fbfc4c5e0f9d6bfef1e91aec47c Reviewed-on: https://chromium-review.googlesource.com/1057356 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Lingfeng Yang <lfy@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
//
// 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.
//
// GLES1State.cpp: Implements the GLES1State class, tracking state
// for GLES1 contexts.
#include "libANGLE/GLES1State.h"
#include "libANGLE/Context.h"
namespace gl
{
TextureCoordF::TextureCoordF() = default;
TextureCoordF::TextureCoordF(float _s, float _t, float _r, float _q) : s(_s), t(_t), r(_r), q(_q)
{
}
bool TextureCoordF::operator==(const TextureCoordF &other) const
{
return s == other.s && t == other.t && r == other.r && q == other.q;
}
GLES1State::GLES1State()
: mGLState(nullptr),
mVertexArrayEnabled(false),
mNormalArrayEnabled(false),
mColorArrayEnabled(false),
mPointSizeArrayEnabled(false),
mLineSmoothEnabled(false),
mPointSmoothEnabled(false),
mPointSpriteEnabled(false),
mAlphaTestEnabled(false),
mLogicOpEnabled(false),
mLightingEnabled(false),
mFogEnabled(false),
mRescaleNormalEnabled(false),
mNormalizeEnabled(false),
mColorMaterialEnabled(false),
mReflectionMapEnabled(false),
mCurrentColor({0.0f, 0.0f, 0.0f, 0.0f}),
mCurrentNormal({0.0f, 0.0f, 0.0f}),
mClientActiveTexture(0),
mMatrixMode(MatrixType::Modelview),
mShadeModel(ShadingModel::Smooth),
mAlphaTestFunc(AlphaTestFunc::AlwaysPass),
mAlphaTestRef(0.0f),
mLogicOp(LogicalOperation::Copy),
mLineSmoothHint(HintSetting::DontCare),
mPointSmoothHint(HintSetting::DontCare),
mPerspectiveCorrectionHint(HintSetting::DontCare),
mFogHint(HintSetting::DontCare)
{
}
GLES1State::~GLES1State() = default;
// Taken from the GLES 1.x spec which specifies all initial state values.
void GLES1State::initialize(const Context *context, const State *state)
{
mGLState = state;
const Caps &caps = context->getCaps();
mTexUnitEnables.resize(caps.maxMultitextureUnits);
for (auto &enables : mTexUnitEnables)
{
enables.reset();
}
mVertexArrayEnabled = false;
mNormalArrayEnabled = false;
mColorArrayEnabled = false;
mPointSizeArrayEnabled = false;
mTexCoordArrayEnabled.resize(caps.maxMultitextureUnits, false);
mLineSmoothEnabled = false;
mPointSmoothEnabled = false;
mPointSpriteEnabled = false;
mLogicOpEnabled = false;
mAlphaTestEnabled = false;
mLightingEnabled = false;
mFogEnabled = false;
mRescaleNormalEnabled = false;
mNormalizeEnabled = false;
mColorMaterialEnabled = false;
mReflectionMapEnabled = false;
mMatrixMode = MatrixType::Modelview;
mCurrentColor = {1.0f, 1.0f, 1.0f, 1.0f};
mCurrentNormal = {0.0f, 0.0f, 1.0f};
mCurrentTextureCoords.resize(caps.maxMultitextureUnits);
mClientActiveTexture = 0;
mTextureEnvironments.resize(caps.maxMultitextureUnits);
mModelviewMatrices.push_back(angle::Mat4());
mProjectionMatrices.push_back(angle::Mat4());
mTextureMatrices.resize(caps.maxMultitextureUnits);
for (auto &stack : mTextureMatrices)
{
stack.push_back(angle::Mat4());
}
mMaterial.ambient = {0.2f, 0.2f, 0.2f, 1.0f};
mMaterial.diffuse = {0.8f, 0.8f, 0.8f, 1.0f};
mMaterial.specular = {0.0f, 0.0f, 0.0f, 1.0f};
mMaterial.emissive = {0.0f, 0.0f, 0.0f, 1.0f};
mMaterial.specularExponent = 0.0f;
mLightModel.color = {0.2f, 0.2f, 0.2f, 1.0f};
mLightModel.twoSided = false;
mLights.resize(caps.maxLights);
// GL_LIGHT0 is special and has default state that avoids all-black renderings.
mLights[0].diffuse = {1.0f, 1.0f, 1.0f, 1.0f};
mLights[0].specular = {1.0f, 1.0f, 1.0f, 1.0f};
mFog.mode = FogMode::Exp;
mFog.density = 1.0f;
mFog.start = 0.0f;
mFog.end = 1.0f;
mFog.color = {0.0f, 0.0f, 0.0f, 0.0f};
mShadeModel = ShadingModel::Smooth;
mAlphaTestFunc = AlphaTestFunc::AlwaysPass;
mAlphaTestRef = 0.0f;
mLogicOp = LogicalOperation::Copy;
mClipPlaneEnabled.resize(caps.maxClipPlanes, false);
mClipPlanes.resize(caps.maxClipPlanes, angle::Vector4(0.0f, 0.0f, 0.0f, 0.0f));
mPointParameters.pointSizeMin = 0.1f;
mPointParameters.pointSizeMax = 100.0f;
mPointParameters.pointFadeThresholdSize = 0.1f;
mPointParameters.pointDistanceAttenuation[0] = 1.0f;
mPointParameters.pointDistanceAttenuation[1] = 0.0f;
mPointParameters.pointDistanceAttenuation[2] = 0.0f;
mPointParameters.pointSize = 1.0f;
mLineSmoothHint = HintSetting::DontCare;
mPointSmoothHint = HintSetting::DontCare;
mPerspectiveCorrectionHint = HintSetting::DontCare;
mFogHint = HintSetting::DontCare;
}
void GLES1State::setAlphaFunc(AlphaTestFunc func, GLfloat ref)
{
mAlphaTestFunc = func;
mAlphaTestRef = ref;
}
void GLES1State::setClientTextureUnit(unsigned int unit)
{
mClientActiveTexture = unit;
}
unsigned int GLES1State::getClientTextureUnit() const
{
return mClientActiveTexture;
}
void GLES1State::setCurrentColor(const ColorF &color)
{
mCurrentColor = color;
}
const ColorF &GLES1State::getCurrentColor() const
{
return mCurrentColor;
}
void GLES1State::setCurrentNormal(const angle::Vector3 &normal)
{
mCurrentNormal = normal;
}
const angle::Vector3 &GLES1State::getCurrentNormal() const
{
return mCurrentNormal;
}
void GLES1State::setCurrentTextureCoords(unsigned int unit, const TextureCoordF &coords)
{
mCurrentTextureCoords[unit] = coords;
}
const TextureCoordF &GLES1State::getCurrentTextureCoords(unsigned int unit) const
{
return mCurrentTextureCoords[unit];
}
void GLES1State::setMatrixMode(MatrixType mode)
{
mMatrixMode = mode;
}
MatrixType GLES1State::getMatrixMode() const
{
return mMatrixMode;
}
void GLES1State::pushMatrix()
{
auto &stack = currentMatrixStack();
stack.push_back(stack.back());
}
void GLES1State::popMatrix()
{
auto &stack = currentMatrixStack();
stack.pop_back();
}
GLES1State::MatrixStack &GLES1State::currentMatrixStack()
{
switch (mMatrixMode)
{
case MatrixType::Modelview:
return mModelviewMatrices;
case MatrixType::Projection:
return mProjectionMatrices;
case MatrixType::Texture:
return mTextureMatrices[mGLState->getActiveSampler()];
default:
UNREACHABLE();
return mModelviewMatrices;
}
}
const GLES1State::MatrixStack &GLES1State::currentMatrixStack() const
{
switch (mMatrixMode)
{
case MatrixType::Modelview:
return mModelviewMatrices;
case MatrixType::Projection:
return mProjectionMatrices;
case MatrixType::Texture:
return mTextureMatrices[mGLState->getActiveSampler()];
default:
UNREACHABLE();
return mModelviewMatrices;
}
}
void GLES1State::loadMatrix(const angle::Mat4 &m)
{
currentMatrixStack().back() = m;
}
void GLES1State::multMatrix(const angle::Mat4 &m)
{
angle::Mat4 currentMatrix = currentMatrixStack().back();
currentMatrixStack().back() = currentMatrix.product(m);
}
void GLES1State::setClientStateEnabled(ClientVertexArrayType clientState, bool enable)
{
switch (clientState)
{
case ClientVertexArrayType::Vertex:
mVertexArrayEnabled = enable;
break;
case ClientVertexArrayType::Normal:
mNormalArrayEnabled = enable;
break;
case ClientVertexArrayType::Color:
mColorArrayEnabled = enable;
break;
case ClientVertexArrayType::PointSize:
mPointSizeArrayEnabled = enable;
break;
case ClientVertexArrayType::TextureCoord:
mTexCoordArrayEnabled[mClientActiveTexture] = enable;
break;
default:
UNREACHABLE();
break;
}
}
bool GLES1State::isClientStateEnabled(ClientVertexArrayType clientState) const
{
switch (clientState)
{
case ClientVertexArrayType::Vertex:
return mVertexArrayEnabled;
case ClientVertexArrayType::Normal:
return mNormalArrayEnabled;
case ClientVertexArrayType::Color:
return mColorArrayEnabled;
case ClientVertexArrayType::PointSize:
return mPointSizeArrayEnabled;
case ClientVertexArrayType::TextureCoord:
return mTexCoordArrayEnabled[mClientActiveTexture];
default:
UNREACHABLE();
return false;
}
}
bool GLES1State::isTexCoordArrayEnabled(unsigned int unit) const
{
ASSERT(unit < mTexCoordArrayEnabled.size());
return mTexCoordArrayEnabled[unit];
}
bool GLES1State::isTextureTargetEnabled(unsigned int unit, const TextureType type) const
{
return mTexUnitEnables[unit].test(type);
}
} // namespace gl