Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // Context.h: Defines the Context class, managing all GL state and performing |
| 16 | // rendering operations. It is the GLES2 specific implementation of EGLContext. |
| 17 | |
| 18 | #ifndef LIBGLES_CM_CONTEXT_H_ |
| 19 | #define LIBGLES_CM_CONTEXT_H_ |
| 20 | |
| 21 | #include "libEGL/Context.hpp" |
| 22 | #include "ResourceManager.h" |
| 23 | #include "common/NameSpace.hpp" |
| 24 | #include "common/Object.hpp" |
| 25 | #include "common/Image.hpp" |
| 26 | #include "Renderer/Sampler.hpp" |
| 27 | #include "common/MatrixStack.hpp" |
| 28 | |
| 29 | #include <GLES/gl.h> |
| 30 | #include <GLES/glext.h> |
| 31 | #include <EGL/egl.h> |
| 32 | |
| 33 | #include <map> |
| 34 | #include <string> |
| 35 | |
| 36 | namespace egl |
| 37 | { |
| 38 | class Display; |
| 39 | class Surface; |
| 40 | class Config; |
| 41 | } |
| 42 | |
| 43 | namespace es1 |
| 44 | { |
| 45 | struct TranslatedAttribute; |
| 46 | struct TranslatedIndexData; |
| 47 | |
| 48 | class Device; |
| 49 | class Buffer; |
| 50 | class Texture; |
| 51 | class Texture2D; |
| 52 | class TextureExternal; |
| 53 | class Framebuffer; |
| 54 | class Renderbuffer; |
| 55 | class RenderbufferStorage; |
| 56 | class Colorbuffer; |
| 57 | class Depthbuffer; |
| 58 | class StreamingIndexBuffer; |
| 59 | class Stencilbuffer; |
| 60 | class DepthStencilbuffer; |
| 61 | class VertexDataManager; |
| 62 | class IndexDataManager; |
| 63 | |
| 64 | enum |
| 65 | { |
Nicolas Capens | f0aef1a | 2016-05-18 14:44:21 -0400 | [diff] [blame] | 66 | MAX_VERTEX_ATTRIBS = sw::MAX_VERTEX_INPUTS, |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 67 | MAX_VARYING_VECTORS = 10, |
| 68 | MAX_TEXTURE_UNITS = 2, |
| 69 | MAX_DRAW_BUFFERS = 1, |
| 70 | MAX_LIGHTS = 8, |
| 71 | MAX_CLIP_PLANES = sw::MAX_CLIP_PLANES, |
| 72 | |
| 73 | MAX_MODELVIEW_STACK_DEPTH = 32, |
| 74 | MAX_PROJECTION_STACK_DEPTH = 2, |
| 75 | MAX_TEXTURE_STACK_DEPTH = 2, |
| 76 | }; |
| 77 | |
| 78 | const GLenum compressedTextureFormats[] = |
| 79 | { |
| 80 | GL_ETC1_RGB8_OES, |
| 81 | #if (S3TC_SUPPORT) |
| 82 | GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 83 | GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, |
| 84 | #endif |
| 85 | }; |
| 86 | |
| 87 | const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]); |
| 88 | |
| 89 | const GLint multisampleCount[] = {4, 2, 1}; |
| 90 | const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]); |
| 91 | const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0]; |
| 92 | |
| 93 | const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f; |
| 94 | const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f; |
| 95 | const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f; |
| 96 | const float ALIASED_POINT_SIZE_RANGE_MAX = 8192.0f; |
| 97 | const float SMOOTH_LINE_WIDTH_RANGE_MIN = 1.0f; |
| 98 | const float SMOOTH_LINE_WIDTH_RANGE_MAX = 1.0f; |
| 99 | const float SMOOTH_POINT_SIZE_RANGE_MIN = 0.125f; |
| 100 | const float SMOOTH_POINT_SIZE_RANGE_MAX = 8192.0f; |
| 101 | const float MAX_TEXTURE_MAX_ANISOTROPY = 16.0f; |
| 102 | |
| 103 | struct Color |
| 104 | { |
| 105 | float red; |
| 106 | float green; |
| 107 | float blue; |
| 108 | float alpha; |
| 109 | }; |
| 110 | |
| 111 | struct Point |
| 112 | { |
| 113 | float x; |
| 114 | float y; |
| 115 | float z; |
| 116 | float w; |
| 117 | }; |
| 118 | |
| 119 | struct Vector |
| 120 | { |
| 121 | float x; |
| 122 | float y; |
| 123 | float z; |
| 124 | }; |
| 125 | |
| 126 | struct Attenuation |
| 127 | { |
| 128 | float constant; |
| 129 | float linear; |
| 130 | float quadratic; |
| 131 | }; |
| 132 | |
| 133 | struct Light |
| 134 | { |
| 135 | bool enabled; |
| 136 | Color ambient; |
| 137 | Color diffuse; |
| 138 | Color specular; |
| 139 | Point position; |
| 140 | Vector direction; |
| 141 | Attenuation attenuation; |
| 142 | float spotExponent; |
| 143 | float spotCutoffAngle; |
| 144 | }; |
| 145 | |
| 146 | // Helper structure describing a single vertex attribute |
| 147 | class VertexAttribute |
| 148 | { |
| 149 | public: |
| 150 | VertexAttribute() : mType(GL_FLOAT), mSize(4), mNormalized(false), mStride(0), mPointer(nullptr), mArrayEnabled(false) |
| 151 | { |
| 152 | mCurrentValue[0] = 0.0f; |
| 153 | mCurrentValue[1] = 0.0f; |
| 154 | mCurrentValue[2] = 0.0f; |
| 155 | mCurrentValue[3] = 1.0f; |
| 156 | } |
| 157 | |
| 158 | int typeSize() const |
| 159 | { |
| 160 | switch(mType) |
| 161 | { |
| 162 | case GL_BYTE: return mSize * sizeof(GLbyte); |
| 163 | case GL_UNSIGNED_BYTE: return mSize * sizeof(GLubyte); |
| 164 | case GL_SHORT: return mSize * sizeof(GLshort); |
| 165 | case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort); |
| 166 | case GL_FIXED: return mSize * sizeof(GLfixed); |
| 167 | case GL_FLOAT: return mSize * sizeof(GLfloat); |
| 168 | default: UNREACHABLE(mType); return mSize * sizeof(GLfloat); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | GLsizei stride() const |
| 173 | { |
| 174 | return mStride ? mStride : typeSize(); |
| 175 | } |
| 176 | |
| 177 | // From glVertexAttribPointer |
| 178 | GLenum mType; |
| 179 | GLint mSize; |
| 180 | bool mNormalized; |
| 181 | GLsizei mStride; // 0 means natural stride |
| 182 | |
| 183 | union |
| 184 | { |
| 185 | const void *mPointer; |
| 186 | intptr_t mOffset; |
| 187 | }; |
| 188 | |
| 189 | gl::BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called. |
| 190 | |
| 191 | bool mArrayEnabled; // From glEnable/DisableVertexAttribArray |
| 192 | float mCurrentValue[4]; // From glVertexAttrib |
| 193 | }; |
| 194 | |
| 195 | typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS]; |
| 196 | |
| 197 | struct TextureUnit |
| 198 | { |
| 199 | Color color; |
| 200 | GLenum environmentMode; |
| 201 | GLenum combineRGB; |
| 202 | GLenum combineAlpha; |
| 203 | GLenum src0RGB; |
| 204 | GLenum src0Alpha; |
| 205 | GLenum src1RGB; |
| 206 | GLenum src1Alpha; |
| 207 | GLenum src2RGB; |
| 208 | GLenum src2Alpha; |
| 209 | GLenum operand0RGB; |
| 210 | GLenum operand0Alpha; |
| 211 | GLenum operand1RGB; |
| 212 | GLenum operand1Alpha; |
| 213 | GLenum operand2RGB; |
| 214 | GLenum operand2Alpha; |
| 215 | }; |
| 216 | |
| 217 | // Helper structure to store all raw state |
| 218 | struct State |
| 219 | { |
| 220 | Color colorClearValue; |
| 221 | GLclampf depthClearValue; |
| 222 | int stencilClearValue; |
| 223 | |
| 224 | bool cullFaceEnabled; |
| 225 | GLenum cullMode; |
| 226 | GLenum frontFace; |
| 227 | bool depthTestEnabled; |
| 228 | GLenum depthFunc; |
| 229 | bool blendEnabled; |
| 230 | GLenum sourceBlendRGB; |
| 231 | GLenum destBlendRGB; |
| 232 | GLenum sourceBlendAlpha; |
| 233 | GLenum destBlendAlpha; |
| 234 | GLenum blendEquationRGB; |
| 235 | GLenum blendEquationAlpha; |
| 236 | bool stencilTestEnabled; |
| 237 | GLenum stencilFunc; |
| 238 | GLint stencilRef; |
| 239 | GLuint stencilMask; |
| 240 | GLenum stencilFail; |
| 241 | GLenum stencilPassDepthFail; |
| 242 | GLenum stencilPassDepthPass; |
| 243 | GLuint stencilWritemask; |
| 244 | bool polygonOffsetFillEnabled; |
| 245 | GLfloat polygonOffsetFactor; |
| 246 | GLfloat polygonOffsetUnits; |
| 247 | bool sampleAlphaToCoverageEnabled; |
| 248 | bool sampleCoverageEnabled; |
| 249 | GLclampf sampleCoverageValue; |
| 250 | bool sampleCoverageInvert; |
| 251 | bool scissorTestEnabled; |
| 252 | bool ditherEnabled; |
| 253 | GLenum shadeModel; |
| 254 | |
| 255 | GLfloat lineWidth; |
| 256 | |
| 257 | GLenum generateMipmapHint; |
| 258 | GLenum perspectiveCorrectionHint; |
| 259 | GLenum fogHint; |
| 260 | |
| 261 | GLint viewportX; |
| 262 | GLint viewportY; |
| 263 | GLsizei viewportWidth; |
| 264 | GLsizei viewportHeight; |
| 265 | float zNear; |
| 266 | float zFar; |
| 267 | |
| 268 | GLint scissorX; |
| 269 | GLint scissorY; |
| 270 | GLsizei scissorWidth; |
| 271 | GLsizei scissorHeight; |
| 272 | |
| 273 | bool colorMaskRed; |
| 274 | bool colorMaskGreen; |
| 275 | bool colorMaskBlue; |
| 276 | bool colorMaskAlpha; |
| 277 | bool depthMask; |
| 278 | |
| 279 | unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0 |
| 280 | gl::BindingPointer<Buffer> arrayBuffer; |
| 281 | gl::BindingPointer<Buffer> elementArrayBuffer; |
| 282 | GLuint framebuffer; |
| 283 | gl::BindingPointer<Renderbuffer> renderbuffer; |
| 284 | |
| 285 | VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS]; |
| 286 | gl::BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_TEXTURE_UNITS]; |
| 287 | |
| 288 | GLint unpackAlignment; |
| 289 | GLint packAlignment; |
| 290 | |
| 291 | TextureUnit textureUnit[MAX_TEXTURE_UNITS]; |
| 292 | }; |
| 293 | |
| 294 | class Context : public egl::Context |
| 295 | { |
| 296 | public: |
Alexis Hetu | cc5c464 | 2016-06-08 15:04:56 -0400 | [diff] [blame^] | 297 | Context(egl::Display *display, const Context *shareContext); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 298 | |
| 299 | virtual void makeCurrent(egl::Surface *surface); |
| 300 | virtual int getClientVersion() const; |
| 301 | virtual void finish(); |
| 302 | |
| 303 | void markAllStateDirty(); |
| 304 | |
| 305 | // State manipulation |
| 306 | void setClearColor(float red, float green, float blue, float alpha); |
| 307 | void setClearDepth(float depth); |
| 308 | void setClearStencil(int stencil); |
| 309 | |
| 310 | void setCullFaceEnabled(bool enabled); |
| 311 | bool isCullFaceEnabled() const; |
| 312 | void setCullMode(GLenum mode); |
| 313 | void setFrontFace(GLenum front); |
| 314 | |
| 315 | void setDepthTestEnabled(bool enabled); |
| 316 | bool isDepthTestEnabled() const; |
| 317 | void setDepthFunc(GLenum depthFunc); |
| 318 | void setDepthRange(float zNear, float zFar); |
| 319 | |
| 320 | void setAlphaTestEnabled(bool enabled); |
| 321 | bool isAlphaTestEnabled() const; |
| 322 | void setAlphaFunc(GLenum alphaFunc, GLclampf reference); |
| 323 | |
| 324 | void setBlendEnabled(bool enabled); |
| 325 | bool isBlendEnabled() const; |
| 326 | void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha); |
| 327 | void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation); |
| 328 | |
| 329 | void setStencilTestEnabled(bool enabled); |
| 330 | bool isStencilTestEnabled() const; |
| 331 | void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask); |
| 332 | void setStencilWritemask(GLuint stencilWritemask); |
| 333 | void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass); |
| 334 | |
| 335 | void setPolygonOffsetFillEnabled(bool enabled); |
| 336 | bool isPolygonOffsetFillEnabled() const; |
| 337 | void setPolygonOffsetParams(GLfloat factor, GLfloat units); |
| 338 | |
| 339 | void setSampleAlphaToCoverageEnabled(bool enabled); |
| 340 | bool isSampleAlphaToCoverageEnabled() const; |
| 341 | void setSampleCoverageEnabled(bool enabled); |
| 342 | bool isSampleCoverageEnabled() const; |
| 343 | void setSampleCoverageParams(GLclampf value, bool invert); |
| 344 | |
| 345 | void setShadeModel(GLenum mode); |
| 346 | void setDitherEnabled(bool enabled); |
| 347 | bool isDitherEnabled() const; |
| 348 | void setLightingEnabled(bool enabled); |
| 349 | bool isLightingEnabled() const; |
| 350 | void setLightEnabled(int index, bool enable); |
| 351 | bool isLightEnabled(int index) const; |
| 352 | void setLightAmbient(int index, float r, float g, float b, float a); |
| 353 | void setLightDiffuse(int index, float r, float g, float b, float a); |
| 354 | void setLightSpecular(int index, float r, float g, float b, float a); |
| 355 | void setLightPosition(int index, float x, float y, float z, float w); |
| 356 | void setLightDirection(int index, float x, float y, float z); |
| 357 | void setLightAttenuationConstant(int index, float constant); |
| 358 | void setLightAttenuationLinear(int index, float linear); |
| 359 | void setLightAttenuationQuadratic(int index, float quadratic); |
| 360 | void setSpotLightExponent(int index, float exponent); |
| 361 | void setSpotLightCutoff(int index, float cutoff); |
| 362 | |
| 363 | void setGlobalAmbient(float red, float green, float blue, float alpha); |
| 364 | void setMaterialAmbient(float red, float green, float blue, float alpha); |
| 365 | void setMaterialDiffuse(float red, float green, float blue, float alpha); |
| 366 | void setMaterialSpecular(float red, float green, float blue, float alpha); |
| 367 | void setMaterialEmission(float red, float green, float blue, float alpha); |
| 368 | void setMaterialShininess(float shininess); |
| 369 | void setLightModelTwoSide(bool enable); |
| 370 | |
| 371 | void setFogEnabled(bool enabled); |
| 372 | bool isFogEnabled() const; |
| 373 | void setFogMode(GLenum mode); |
| 374 | void setFogDensity(float fogDensity); |
| 375 | void setFogStart(float fogStart); |
| 376 | void setFogEnd(float fogEnd); |
| 377 | void setFogColor(float r, float g, float b, float a); |
| 378 | |
| 379 | void setTexture2Denabled(bool enabled); |
| 380 | bool isTexture2Denabled() const; |
| 381 | void setTextureExternalEnabled(bool enabled); |
| 382 | bool isTextureExternalEnabled() const; |
| 383 | void clientActiveTexture(GLenum texture); |
| 384 | GLenum getClientActiveTexture() const; |
| 385 | unsigned int getActiveTexture() const; |
| 386 | |
| 387 | void setTextureEnvMode(GLenum texEnvMode); |
| 388 | void setTextureEnvColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); |
| 389 | void setCombineRGB(GLenum combineRGB); |
| 390 | void setCombineAlpha(GLenum combineAlpha); |
| 391 | void setOperand0RGB(GLenum operand); |
| 392 | void setOperand1RGB(GLenum operand); |
| 393 | void setOperand2RGB(GLenum operand); |
| 394 | void setOperand0Alpha(GLenum operand); |
| 395 | void setOperand1Alpha(GLenum operand); |
| 396 | void setOperand2Alpha(GLenum operand); |
| 397 | void setSrc0RGB(GLenum src); |
| 398 | void setSrc1RGB(GLenum src); |
| 399 | void setSrc2RGB(GLenum src); |
| 400 | void setSrc0Alpha(GLenum src); |
| 401 | void setSrc1Alpha(GLenum src); |
| 402 | void setSrc2Alpha(GLenum src); |
| 403 | |
| 404 | void setLineWidth(GLfloat width); |
| 405 | |
| 406 | void setGenerateMipmapHint(GLenum hint); |
| 407 | void setPerspectiveCorrectionHint(GLenum hint); |
| 408 | void setFogHint(GLenum hint); |
| 409 | |
| 410 | void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height); |
| 411 | |
| 412 | void setScissorTestEnabled(bool enabled); |
| 413 | bool isScissorTestEnabled() const; |
| 414 | void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height); |
| 415 | |
| 416 | void setColorMask(bool red, bool green, bool blue, bool alpha); |
| 417 | void setDepthMask(bool mask); |
| 418 | |
| 419 | void setActiveSampler(unsigned int active); |
| 420 | |
| 421 | GLuint getFramebufferName() const; |
| 422 | GLuint getRenderbufferName() const; |
| 423 | |
| 424 | GLuint getArrayBufferName() const; |
| 425 | |
| 426 | void setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled); |
| 427 | const VertexAttribute &getVertexAttribState(unsigned int attribNum); |
| 428 | void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type, |
| 429 | bool normalized, GLsizei stride, const void *pointer); |
| 430 | const void *getVertexAttribPointer(unsigned int attribNum) const; |
| 431 | |
| 432 | const VertexAttributeArray &getVertexAttributes(); |
| 433 | |
| 434 | void setUnpackAlignment(GLint alignment); |
| 435 | GLint getUnpackAlignment() const; |
| 436 | |
| 437 | void setPackAlignment(GLint alignment); |
| 438 | GLint getPackAlignment() const; |
| 439 | |
| 440 | // These create and destroy methods are merely pass-throughs to |
| 441 | // ResourceManager, which owns these object types |
| 442 | GLuint createBuffer(); |
| 443 | GLuint createTexture(); |
| 444 | GLuint createRenderbuffer(); |
| 445 | |
| 446 | void deleteBuffer(GLuint buffer); |
| 447 | void deleteTexture(GLuint texture); |
| 448 | void deleteRenderbuffer(GLuint renderbuffer); |
| 449 | |
| 450 | // Framebuffers are owned by the Context, so these methods do not pass through |
| 451 | GLuint createFramebuffer(); |
| 452 | void deleteFramebuffer(GLuint framebuffer); |
| 453 | |
| 454 | void bindArrayBuffer(GLuint buffer); |
| 455 | void bindElementArrayBuffer(GLuint buffer); |
| 456 | void bindTexture2D(GLuint texture); |
| 457 | void bindTextureExternal(GLuint texture); |
| 458 | void bindFramebuffer(GLuint framebuffer); |
| 459 | void bindRenderbuffer(GLuint renderbuffer); |
| 460 | |
| 461 | void setFramebufferZero(Framebuffer *framebuffer); |
| 462 | |
| 463 | void setRenderbufferStorage(RenderbufferStorage *renderbuffer); |
| 464 | |
| 465 | void setVertexAttrib(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); |
| 466 | |
| 467 | Buffer *getBuffer(GLuint handle); |
| 468 | virtual Texture *getTexture(GLuint handle); |
| 469 | Framebuffer *getFramebuffer(GLuint handle); |
| 470 | virtual Renderbuffer *getRenderbuffer(GLuint handle); |
| 471 | |
| 472 | Buffer *getArrayBuffer(); |
| 473 | Buffer *getElementArrayBuffer(); |
| 474 | Texture2D *getTexture2D(); |
| 475 | TextureExternal *getTextureExternal(); |
| 476 | Texture *getSamplerTexture(unsigned int sampler, TextureType type); |
| 477 | Framebuffer *getFramebuffer(); |
| 478 | |
| 479 | bool getFloatv(GLenum pname, GLfloat *params); |
| 480 | bool getIntegerv(GLenum pname, GLint *params); |
| 481 | bool getBooleanv(GLenum pname, GLboolean *params); |
| 482 | bool getPointerv(GLenum pname, const GLvoid **params); |
| 483 | |
| 484 | int getQueryParameterNum(GLenum pname); |
| 485 | bool isQueryParameterInt(GLenum pname); |
| 486 | bool isQueryParameterFloat(GLenum pname); |
| 487 | bool isQueryParameterBool(GLenum pname); |
| 488 | bool isQueryParameterPointer(GLenum pname); |
| 489 | |
| 490 | void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels); |
| 491 | void clear(GLbitfield mask); |
| 492 | void drawArrays(GLenum mode, GLint first, GLsizei count); |
| 493 | void drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices); |
| 494 | void drawTexture(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height); |
| 495 | void flush(); |
| 496 | |
| 497 | void recordInvalidEnum(); |
| 498 | void recordInvalidValue(); |
| 499 | void recordInvalidOperation(); |
| 500 | void recordOutOfMemory(); |
| 501 | void recordInvalidFramebufferOperation(); |
| 502 | void recordMatrixStackOverflow(); |
| 503 | void recordMatrixStackUnderflow(); |
| 504 | |
| 505 | GLenum getError(); |
| 506 | |
| 507 | static int getSupportedMultisampleCount(int requested); |
| 508 | |
| 509 | virtual void bindTexImage(egl::Surface *surface); |
| 510 | virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel); |
| 511 | virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel); |
Nicolas Capens | 58df2f6 | 2016-06-07 14:48:56 -0400 | [diff] [blame] | 512 | egl::Image *getSharedImage(GLeglImageOES image); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 513 | |
| 514 | Device *getDevice(); |
| 515 | |
| 516 | void setMatrixMode(GLenum mode); |
| 517 | void loadIdentity(); |
| 518 | void load(const GLfloat *m); |
| 519 | void pushMatrix(); |
| 520 | void popMatrix(); |
| 521 | void rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); |
| 522 | void translate(GLfloat x, GLfloat y, GLfloat z); |
| 523 | void scale(GLfloat x, GLfloat y, GLfloat z); |
| 524 | void multiply(const GLfloat *m); |
| 525 | void frustum(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); |
| 526 | void ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); |
| 527 | |
| 528 | void setClipPlane(int index, const float plane[4]); |
| 529 | void setClipPlaneEnabled(int index, bool enable); |
| 530 | bool isClipPlaneEnabled(int index) const; |
| 531 | |
| 532 | void setColorLogicOpEnabled(bool enable); |
| 533 | bool isColorLogicOpEnabled() const; |
| 534 | void setLogicalOperation(GLenum logicOp); |
| 535 | |
| 536 | void setPointSmoothEnabled(bool enable); |
| 537 | bool isPointSmoothEnabled() const; |
| 538 | |
| 539 | void setLineSmoothEnabled(bool enable); |
| 540 | bool isLineSmoothEnabled() const; |
| 541 | |
| 542 | void setColorMaterialEnabled(bool enable); |
| 543 | bool isColorMaterialEnabled() const; |
| 544 | |
| 545 | void setNormalizeEnabled(bool enable); |
| 546 | bool isNormalizeEnabled() const; |
| 547 | |
| 548 | void setRescaleNormalEnabled(bool enable); |
| 549 | bool isRescaleNormalEnabled() const; |
| 550 | |
| 551 | void setVertexArrayEnabled(bool enable); |
| 552 | bool isVertexArrayEnabled() const; |
| 553 | |
| 554 | void setNormalArrayEnabled(bool enable); |
| 555 | bool isNormalArrayEnabled() const; |
| 556 | |
| 557 | void setColorArrayEnabled(bool enable); |
| 558 | bool isColorArrayEnabled() const; |
| 559 | |
| 560 | void setPointSizeArrayEnabled(bool enable); |
| 561 | bool isPointSizeArrayEnabled() const; |
| 562 | |
| 563 | void setTextureCoordArrayEnabled(bool enable); |
| 564 | bool isTextureCoordArrayEnabled() const; |
| 565 | |
| 566 | void setMultisampleEnabled(bool enable); |
| 567 | bool isMultisampleEnabled() const; |
| 568 | |
| 569 | void setSampleAlphaToOneEnabled(bool enable); |
| 570 | bool isSampleAlphaToOneEnabled() const; |
| 571 | |
| 572 | void setPointSpriteEnabled(bool enable); |
| 573 | bool isPointSpriteEnabled() const; |
| 574 | void setPointSizeMin(float min); |
| 575 | void setPointSizeMax(float max); |
| 576 | void setPointDistanceAttenuation(float a, float b, float c); |
| 577 | void setPointFadeThresholdSize(float threshold); |
| 578 | |
| 579 | private: |
| 580 | virtual ~Context(); |
| 581 | |
| 582 | bool applyRenderTarget(); |
| 583 | void applyState(GLenum drawMode); |
| 584 | GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count); |
| 585 | GLenum applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo); |
| 586 | void applyTextures(); |
| 587 | void applyTexture(int sampler, Texture *texture); |
| 588 | |
| 589 | void detachBuffer(GLuint buffer); |
| 590 | void detachTexture(GLuint texture); |
| 591 | void detachFramebuffer(GLuint framebuffer); |
| 592 | void detachRenderbuffer(GLuint renderbuffer); |
| 593 | |
| 594 | bool cullSkipsDraw(GLenum drawMode); |
| 595 | bool isTriangleMode(GLenum drawMode); |
| 596 | |
| 597 | State mState; |
| 598 | |
| 599 | gl::BindingPointer<Texture2D> mTexture2DZero; |
| 600 | gl::BindingPointer<TextureExternal> mTextureExternalZero; |
| 601 | |
| 602 | gl::NameSpace<Framebuffer> mFramebufferNameSpace; |
| 603 | |
| 604 | VertexDataManager *mVertexDataManager; |
| 605 | IndexDataManager *mIndexDataManager; |
| 606 | |
| 607 | bool lightingEnabled; |
| 608 | Light light[MAX_LIGHTS]; |
| 609 | Color globalAmbient; |
| 610 | Color materialAmbient; |
| 611 | Color materialDiffuse; |
| 612 | Color materialSpecular; |
| 613 | Color materialEmission; |
| 614 | GLfloat materialShininess; |
| 615 | bool lightModelTwoSide; |
| 616 | |
| 617 | // Recorded errors |
| 618 | bool mInvalidEnum; |
| 619 | bool mInvalidValue; |
| 620 | bool mInvalidOperation; |
| 621 | bool mOutOfMemory; |
| 622 | bool mInvalidFramebufferOperation; |
| 623 | bool mMatrixStackOverflow; |
| 624 | bool mMatrixStackUnderflow; |
| 625 | |
| 626 | bool mHasBeenCurrent; |
| 627 | |
| 628 | // state caching flags |
| 629 | bool mDepthStateDirty; |
| 630 | bool mMaskStateDirty; |
| 631 | bool mBlendStateDirty; |
| 632 | bool mStencilStateDirty; |
| 633 | bool mPolygonOffsetStateDirty; |
| 634 | bool mSampleStateDirty; |
| 635 | bool mFrontFaceDirty; |
| 636 | bool mDitherStateDirty; |
| 637 | |
| 638 | sw::MatrixStack ¤tMatrixStack(); |
| 639 | GLenum matrixMode; |
| 640 | sw::MatrixStack modelViewStack; |
| 641 | sw::MatrixStack projectionStack; |
| 642 | sw::MatrixStack textureStack0; |
| 643 | sw::MatrixStack textureStack1; |
| 644 | |
| 645 | bool texture2Denabled[MAX_TEXTURE_UNITS]; |
| 646 | bool textureExternalEnabled[MAX_TEXTURE_UNITS]; |
| 647 | GLenum clientTexture; |
| 648 | |
| 649 | int clipFlags; |
| 650 | |
| 651 | bool alphaTestEnabled; |
| 652 | GLenum alphaTestFunc; |
| 653 | float alphaTestRef; |
| 654 | |
| 655 | bool fogEnabled; |
| 656 | GLenum fogMode; |
| 657 | float fogDensity; |
| 658 | float fogStart; |
| 659 | float fogEnd; |
| 660 | Color fogColor; |
| 661 | |
| 662 | bool lineSmoothEnabled; |
| 663 | bool colorMaterialEnabled; |
| 664 | bool normalizeEnabled; |
| 665 | bool rescaleNormalEnabled; |
| 666 | bool multisampleEnabled; |
| 667 | bool sampleAlphaToOneEnabled; |
| 668 | |
| 669 | bool pointSpriteEnabled; |
| 670 | bool pointSmoothEnabled; |
| 671 | float pointSizeMin; |
| 672 | float pointSizeMax; |
| 673 | Attenuation pointDistanceAttenuation; |
| 674 | float pointFadeThresholdSize; |
| 675 | |
| 676 | bool colorLogicOpEnabled; |
| 677 | GLenum logicalOperation; |
| 678 | |
| 679 | Device *device; |
| 680 | ResourceManager *mResourceManager; |
| 681 | }; |
| 682 | } |
| 683 | |
| 684 | #endif // INCLUDE_CONTEXT_H_ |