1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 // Context.h: Defines the Context class, managing all GL state and performing
16 // rendering operations. It is the GLES2 specific implementation of EGLContext.
18 #ifndef LIBGLESV2_CONTEXT_H_
19 #define LIBGLESV2_CONTEXT_H_
21 #include "ResourceManager.h"
23 #include "libEGL/Context.hpp"
24 #include "common/NameSpace.hpp"
25 #include "common/Object.hpp"
26 #include "common/Image.hpp"
27 #include "Renderer/Sampler.hpp"
29 #include <GLES2/gl2.h>
30 #include <GLES2/gl2ext.h>
31 #include <GLES3/gl3.h>
46 struct TranslatedAttribute;
47 struct TranslatedIndexData;
57 class TextureExternal;
60 class RenderbufferStorage;
63 class StreamingIndexBuffer;
65 class DepthStencilbuffer;
66 class VertexDataManager;
67 class IndexDataManager;
73 class TransformFeedback;
77 MAX_VERTEX_ATTRIBS = sw::VERTEX_ATTRIBUTES,
78 MAX_UNIFORM_VECTORS = 256, // Device limit
79 MAX_VERTEX_UNIFORM_VECTORS = sw::VERTEX_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
80 MAX_VARYING_VECTORS = 10,
81 MAX_TEXTURE_IMAGE_UNITS = sw::TEXTURE_IMAGE_UNITS,
82 MAX_VERTEX_TEXTURE_IMAGE_UNITS = sw::VERTEX_TEXTURE_IMAGE_UNITS,
83 MAX_COMBINED_TEXTURE_IMAGE_UNITS = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS,
84 MAX_FRAGMENT_UNIFORM_VECTORS = sw::FRAGMENT_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
85 MAX_ELEMENT_INDEX = 0x7FFFFFFF,
86 MAX_ELEMENTS_INDICES = 0x7FFFFFFF,
87 MAX_ELEMENTS_VERTICES = 0x7FFFFFFF,
88 MAX_VERTEX_OUTPUT_VECTORS = 16,
89 MAX_FRAGMENT_INPUT_VECTORS = 15,
90 MIN_PROGRAM_TEXEL_OFFSET = -8,
91 MAX_PROGRAM_TEXEL_OFFSET = 7,
92 MAX_DRAW_BUFFERS = sw::RENDERTARGETS,
93 MAX_COLOR_ATTACHMENTS = MAX(MAX_DRAW_BUFFERS, 8),
94 MAX_FRAGMENT_UNIFORM_BLOCKS = sw::MAX_FRAGMENT_UNIFORM_BLOCKS,
95 MAX_VERTEX_UNIFORM_BLOCKS = sw::MAX_VERTEX_UNIFORM_BLOCKS,
96 MAX_FRAGMENT_UNIFORM_COMPONENTS = sw::FRAGMENT_UNIFORM_VECTORS * 4,
97 MAX_VERTEX_UNIFORM_COMPONENTS = sw::VERTEX_UNIFORM_VECTORS * 4,
98 MAX_UNIFORM_BLOCK_SIZE = sw::MAX_UNIFORM_BLOCK_SIZE,
99 MAX_FRAGMENT_UNIFORM_BLOCKS_COMPONENTS = sw::MAX_FRAGMENT_UNIFORM_BLOCKS * MAX_UNIFORM_BLOCK_SIZE / 4,
100 MAX_VERTEX_UNIFORM_BLOCKS_COMPONENTS = MAX_VERTEX_UNIFORM_BLOCKS * MAX_UNIFORM_BLOCK_SIZE / 4,
101 MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = MAX_FRAGMENT_UNIFORM_BLOCKS_COMPONENTS + MAX_FRAGMENT_UNIFORM_COMPONENTS,
102 MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = MAX_VERTEX_UNIFORM_BLOCKS_COMPONENTS + MAX_VERTEX_UNIFORM_COMPONENTS,
103 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 4,
104 MAX_UNIFORM_BUFFER_BINDINGS = sw::MAX_UNIFORM_BUFFER_BINDINGS,
105 UNIFORM_BUFFER_OFFSET_ALIGNMENT = 1,
108 const GLenum compressedTextureFormats[] =
112 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
113 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
114 GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE,
115 GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE,
117 #if (GL_ES_VERSION_3_0)
118 GL_COMPRESSED_R11_EAC,
119 GL_COMPRESSED_SIGNED_R11_EAC,
120 GL_COMPRESSED_RG11_EAC,
121 GL_COMPRESSED_SIGNED_RG11_EAC,
122 GL_COMPRESSED_RGB8_ETC2,
123 GL_COMPRESSED_SRGB8_ETC2,
124 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
125 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
126 GL_COMPRESSED_RGBA8_ETC2_EAC,
127 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
128 GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
129 GL_COMPRESSED_RGBA_ASTC_5x4_KHR,
130 GL_COMPRESSED_RGBA_ASTC_5x5_KHR,
131 GL_COMPRESSED_RGBA_ASTC_6x5_KHR,
132 GL_COMPRESSED_RGBA_ASTC_6x6_KHR,
133 GL_COMPRESSED_RGBA_ASTC_8x5_KHR,
134 GL_COMPRESSED_RGBA_ASTC_8x6_KHR,
135 GL_COMPRESSED_RGBA_ASTC_8x8_KHR,
136 GL_COMPRESSED_RGBA_ASTC_10x5_KHR,
137 GL_COMPRESSED_RGBA_ASTC_10x6_KHR,
138 GL_COMPRESSED_RGBA_ASTC_10x8_KHR,
139 GL_COMPRESSED_RGBA_ASTC_10x10_KHR,
140 GL_COMPRESSED_RGBA_ASTC_12x10_KHR,
141 GL_COMPRESSED_RGBA_ASTC_12x12_KHR,
142 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
143 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
144 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
145 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
146 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
147 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
148 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
149 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
150 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
151 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
152 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
153 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
154 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
155 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
159 const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);
161 const GLint multisampleCount[] = {4, 2, 1};
162 const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]);
163 const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0];
165 const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
166 const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
167 const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;
168 const float ALIASED_POINT_SIZE_RANGE_MAX = 8192.0f;
169 const float MAX_TEXTURE_MAX_ANISOTROPY = 16.0f;
173 QUERY_ANY_SAMPLES_PASSED,
174 QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE,
175 QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
188 // Helper structure describing a single vertex attribute
189 class VertexAttribute
192 VertexAttribute() : mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mDivisor(0), mPointer(nullptr), mArrayEnabled(false)
194 mCurrentValue[0].f = 0.0f;
195 mCurrentValue[1].f = 0.0f;
196 mCurrentValue[2].f = 0.0f;
197 mCurrentValue[3].f = 1.0f;
198 mCurrentValueType = ValueUnion::FloatType;
205 case GL_BYTE: return mSize * sizeof(GLbyte);
206 case GL_UNSIGNED_BYTE: return mSize * sizeof(GLubyte);
207 case GL_SHORT: return mSize * sizeof(GLshort);
208 case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort);
209 case GL_INT: return mSize * sizeof(GLint);
210 case GL_UNSIGNED_INT: return mSize * sizeof(GLuint);
211 case GL_FIXED: return mSize * sizeof(GLfixed);
212 case GL_FLOAT: return mSize * sizeof(GLfloat);
213 default: UNREACHABLE(mType); return mSize * sizeof(GLfloat);
217 GLsizei stride() const
219 return mStride ? mStride : typeSize();
222 inline float getCurrentValueBitsAsFloat(int i) const
224 return mCurrentValue[i].f;
227 inline float getCurrentValueF(int i) const
229 switch(mCurrentValueType)
231 case ValueUnion::FloatType: return mCurrentValue[i].f;
232 case ValueUnion::IntType: return static_cast<float>(mCurrentValue[i].i);
233 case ValueUnion::UIntType: return static_cast<float>(mCurrentValue[i].ui);
234 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].f;
238 inline GLint getCurrentValueI(int i) const
240 switch(mCurrentValueType)
242 case ValueUnion::FloatType: return static_cast<GLint>(mCurrentValue[i].f);
243 case ValueUnion::IntType: return mCurrentValue[i].i;
244 case ValueUnion::UIntType: return static_cast<GLint>(mCurrentValue[i].ui);
245 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].i;
249 inline GLuint getCurrentValueUI(int i) const
251 switch(mCurrentValueType)
253 case ValueUnion::FloatType: return static_cast<GLuint>(mCurrentValue[i].f);
254 case ValueUnion::IntType: return static_cast<GLuint>(mCurrentValue[i].i);
255 case ValueUnion::UIntType: return mCurrentValue[i].ui;
256 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].ui;
260 inline void setCurrentValue(const GLfloat *values)
262 mCurrentValue[0].f = values[0];
263 mCurrentValue[1].f = values[1];
264 mCurrentValue[2].f = values[2];
265 mCurrentValue[3].f = values[3];
266 mCurrentValueType = ValueUnion::FloatType;
269 inline void setCurrentValue(const GLint *values)
271 mCurrentValue[0].i = values[0];
272 mCurrentValue[1].i = values[1];
273 mCurrentValue[2].i = values[2];
274 mCurrentValue[3].i = values[3];
275 mCurrentValueType = ValueUnion::IntType;
278 inline void setCurrentValue(const GLuint *values)
280 mCurrentValue[0].ui = values[0];
281 mCurrentValue[1].ui = values[1];
282 mCurrentValue[2].ui = values[2];
283 mCurrentValue[3].ui = values[3];
284 mCurrentValueType = ValueUnion::UIntType;
287 // From glVertexAttribPointer
291 GLsizei mStride; // 0 means natural stride
292 GLuint mDivisor; // From glVertexAttribDivisor
296 const void *mPointer;
300 gl::BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called.
302 bool mArrayEnabled; // From glEnable/DisableVertexAttribArray
307 enum Type { FloatType, IntType, UIntType };
314 ValueUnion mCurrentValue[4]; // From glVertexAttrib
315 ValueUnion::Type mCurrentValueType;
318 typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS];
320 // Helper structure to store all raw state
323 Color colorClearValue;
324 GLclampf depthClearValue;
325 int stencilClearValue;
327 bool cullFaceEnabled;
330 bool depthTestEnabled;
333 GLenum sourceBlendRGB;
335 GLenum sourceBlendAlpha;
336 GLenum destBlendAlpha;
337 GLenum blendEquationRGB;
338 GLenum blendEquationAlpha;
340 bool stencilTestEnabled;
345 GLenum stencilPassDepthFail;
346 GLenum stencilPassDepthPass;
347 GLuint stencilWritemask;
348 GLenum stencilBackFunc;
349 GLint stencilBackRef;
350 GLuint stencilBackMask;
351 GLenum stencilBackFail;
352 GLenum stencilBackPassDepthFail;
353 GLenum stencilBackPassDepthPass;
354 GLuint stencilBackWritemask;
355 bool polygonOffsetFillEnabled;
356 GLfloat polygonOffsetFactor;
357 GLfloat polygonOffsetUnits;
358 bool sampleAlphaToCoverageEnabled;
359 bool sampleCoverageEnabled;
360 GLclampf sampleCoverageValue;
361 bool sampleCoverageInvert;
362 bool scissorTestEnabled;
364 bool primitiveRestartFixedIndexEnabled;
365 bool rasterizerDiscardEnabled;
366 bool colorLogicOpEnabled;
367 GLenum logicalOperation;
371 GLenum generateMipmapHint;
372 GLenum fragmentShaderDerivativeHint;
376 GLsizei viewportWidth;
377 GLsizei viewportHeight;
383 GLsizei scissorWidth;
384 GLsizei scissorHeight;
392 unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0
393 gl::BindingPointer<Buffer> arrayBuffer;
394 gl::BindingPointer<Buffer> copyReadBuffer;
395 gl::BindingPointer<Buffer> copyWriteBuffer;
396 gl::BindingPointer<Buffer> pixelPackBuffer;
397 gl::BindingPointer<Buffer> pixelUnpackBuffer;
398 gl::BindingPointer<Buffer> genericUniformBuffer;
399 BufferBinding uniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];
401 GLuint readFramebuffer;
402 GLuint drawFramebuffer;
403 gl::BindingPointer<Renderbuffer> renderbuffer;
404 GLuint currentProgram;
406 GLuint transformFeedback;
407 gl::BindingPointer<Sampler> sampler[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
409 VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS];
410 gl::BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_COMBINED_TEXTURE_IMAGE_UNITS];
411 gl::BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT];
413 egl::Image::UnpackInfo unpackInfo;
416 GLint packImageHeight;
417 GLint packSkipPixels;
419 GLint packSkipImages;
422 class Context : public egl::Context
425 Context(const egl::Config *config, const Context *shareContext, EGLint clientVersion);
427 virtual void makeCurrent(egl::Surface *surface);
428 virtual EGLint getClientVersion() const;
430 void markAllStateDirty();
432 // State manipulation
433 void setClearColor(float red, float green, float blue, float alpha);
434 void setClearDepth(float depth);
435 void setClearStencil(int stencil);
437 void setCullFaceEnabled(bool enabled);
438 bool isCullFaceEnabled() const;
439 void setCullMode(GLenum mode);
440 void setFrontFace(GLenum front);
442 void setDepthTestEnabled(bool enabled);
443 bool isDepthTestEnabled() const;
444 void setDepthFunc(GLenum depthFunc);
445 void setDepthRange(float zNear, float zFar);
447 void setBlendEnabled(bool enabled);
448 bool isBlendEnabled() const;
449 void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
450 void setBlendColor(float red, float green, float blue, float alpha);
451 void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
453 void setStencilTestEnabled(bool enabled);
454 bool isStencilTestEnabled() const;
455 void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
456 void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
457 void setStencilWritemask(GLuint stencilWritemask);
458 void setStencilBackWritemask(GLuint stencilBackWritemask);
459 void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
460 void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);
462 void setPolygonOffsetFillEnabled(bool enabled);
463 bool isPolygonOffsetFillEnabled() const;
464 void setPolygonOffsetParams(GLfloat factor, GLfloat units);
466 void setSampleAlphaToCoverageEnabled(bool enabled);
467 bool isSampleAlphaToCoverageEnabled() const;
468 void setSampleCoverageEnabled(bool enabled);
469 bool isSampleCoverageEnabled() const;
470 void setSampleCoverageParams(GLclampf value, bool invert);
472 void setDitherEnabled(bool enabled);
473 bool isDitherEnabled() const;
475 void setPrimitiveRestartFixedIndexEnabled(bool enabled);
476 bool isPrimitiveRestartFixedIndexEnabled() const;
478 void setRasterizerDiscardEnabled(bool enabled);
479 bool isRasterizerDiscardEnabled() const;
481 void setLineWidth(GLfloat width);
483 void setGenerateMipmapHint(GLenum hint);
484 void setFragmentShaderDerivativeHint(GLenum hint);
486 void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
488 void setScissorTestEnabled(bool enabled);
489 bool isScissorTestEnabled() const;
490 void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
492 void setColorMask(bool red, bool green, bool blue, bool alpha);
493 unsigned int getColorMask() const;
494 void setDepthMask(bool mask);
496 void setActiveSampler(unsigned int active);
498 GLuint getReadFramebufferName() const;
499 GLuint getDrawFramebufferName() const;
500 GLuint getRenderbufferName() const;
502 void setFramebufferReadBuffer(GLenum buf);
503 void setFramebufferDrawBuffers(GLsizei n, const GLenum *bufs);
504 GLuint getReadFramebufferColorIndex() const;
506 GLuint getActiveQuery(GLenum target) const;
508 GLuint getArrayBufferName() const;
509 GLuint getElementArrayBufferName() const;
511 void setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled);
512 void setVertexAttribDivisor(unsigned int attribNum, GLuint divisor);
513 const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;
514 void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
515 bool normalized, GLsizei stride, const void *pointer);
516 const void *getVertexAttribPointer(unsigned int attribNum) const;
518 const VertexAttributeArray &getVertexArrayAttributes();
519 // Context attribute current values can be queried independently from VAO current values
520 const VertexAttributeArray &getCurrentVertexAttributes();
522 void setUnpackAlignment(GLint alignment);
523 void setUnpackRowLength(GLint rowLength);
524 void setUnpackImageHeight(GLint imageHeight);
525 void setUnpackSkipPixels(GLint skipPixels);
526 void setUnpackSkipRows(GLint skipRows);
527 void setUnpackSkipImages(GLint skipImages);
528 const egl::Image::UnpackInfo& getUnpackInfo() const;
530 void setPackAlignment(GLint alignment);
531 void setPackRowLength(GLint rowLength);
532 void setPackImageHeight(GLint imageHeight);
533 void setPackSkipPixels(GLint skipPixels);
534 void setPackSkipRows(GLint skipRows);
535 void setPackSkipImages(GLint skipImages);
537 // These create and destroy methods are merely pass-throughs to
538 // ResourceManager, which owns these object types
539 GLuint createBuffer();
540 GLuint createShader(GLenum type);
541 GLuint createProgram();
542 GLuint createTexture();
543 GLuint createRenderbuffer();
544 GLuint createSampler();
545 GLsync createFenceSync(GLenum condition, GLbitfield flags);
547 void deleteBuffer(GLuint buffer);
548 void deleteShader(GLuint shader);
549 void deleteProgram(GLuint program);
550 void deleteTexture(GLuint texture);
551 void deleteRenderbuffer(GLuint renderbuffer);
552 void deleteSampler(GLuint sampler);
553 void deleteFenceSync(GLsync fenceSync);
555 // Framebuffers are owned by the Context, so these methods do not pass through
556 GLuint createFramebuffer();
557 void deleteFramebuffer(GLuint framebuffer);
559 // Fences are owned by the Context
560 GLuint createFence();
561 void deleteFence(GLuint fence);
563 // Queries are owned by the Context
564 GLuint createQuery();
565 void deleteQuery(GLuint query);
567 // Vertex arrays are owned by the Context
568 GLuint createVertexArray();
569 void deleteVertexArray(GLuint array);
571 // Transform feedbacks are owned by the Context
572 GLuint createTransformFeedback();
573 void deleteTransformFeedback(GLuint transformFeedback);
575 void bindArrayBuffer(GLuint buffer);
576 void bindElementArrayBuffer(GLuint buffer);
577 void bindCopyReadBuffer(GLuint buffer);
578 void bindCopyWriteBuffer(GLuint buffer);
579 void bindPixelPackBuffer(GLuint buffer);
580 void bindPixelUnpackBuffer(GLuint buffer);
581 void bindTransformFeedbackBuffer(GLuint buffer);
582 void bindTexture2D(GLuint texture);
583 void bindTextureCubeMap(GLuint texture);
584 void bindTextureExternal(GLuint texture);
585 void bindTexture3D(GLuint texture);
586 void bindTexture2DArray(GLuint texture);
587 void bindReadFramebuffer(GLuint framebuffer);
588 void bindDrawFramebuffer(GLuint framebuffer);
589 void bindRenderbuffer(GLuint renderbuffer);
590 void bindVertexArray(GLuint array);
591 void bindGenericUniformBuffer(GLuint buffer);
592 void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
593 void bindGenericTransformFeedbackBuffer(GLuint buffer);
594 void bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
595 void bindTransformFeedback(GLuint transformFeedback);
596 bool bindSampler(GLuint unit, GLuint sampler);
597 void useProgram(GLuint program);
599 void beginQuery(GLenum target, GLuint query);
600 void endQuery(GLenum target);
602 void setFramebufferZero(Framebuffer *framebuffer);
604 void setRenderbufferStorage(RenderbufferStorage *renderbuffer);
606 void setVertexAttrib(GLuint index, const GLfloat *values);
607 void setVertexAttrib(GLuint index, const GLint *values);
608 void setVertexAttrib(GLuint index, const GLuint *values);
610 Buffer *getBuffer(GLuint handle) const;
611 Fence *getFence(GLuint handle) const;
612 FenceSync *getFenceSync(GLsync handle) const;
613 Shader *getShader(GLuint handle) const;
614 Program *getProgram(GLuint handle) const;
615 virtual Texture *getTexture(GLuint handle) const;
616 Framebuffer *getFramebuffer(GLuint handle) const;
617 virtual Renderbuffer *getRenderbuffer(GLuint handle) const;
618 Query *getQuery(GLuint handle) const;
619 VertexArray *getVertexArray(GLuint array) const;
620 VertexArray *getCurrentVertexArray() const;
621 bool isVertexArray(GLuint array) const;
622 TransformFeedback *getTransformFeedback(GLuint transformFeedback) const;
623 TransformFeedback *getTransformFeedback() const;
624 Sampler *getSampler(GLuint sampler) const;
625 bool isSampler(GLuint sampler) const;
627 Buffer *getArrayBuffer() const;
628 Buffer *getElementArrayBuffer() const;
629 Buffer *getCopyReadBuffer() const;
630 Buffer *getCopyWriteBuffer() const;
631 Buffer *getPixelPackBuffer() const;
632 Buffer *getPixelUnpackBuffer() const;
633 Buffer *getGenericUniformBuffer() const;
634 bool getBuffer(GLenum target, es2::Buffer **buffer) const;
635 Program *getCurrentProgram() const;
636 Texture2D *getTexture2D() const;
637 Texture3D *getTexture3D() const;
638 Texture2DArray *getTexture2DArray() const;
639 TextureCubeMap *getTextureCubeMap() const;
640 TextureExternal *getTextureExternal() const;
641 Texture *getSamplerTexture(unsigned int sampler, TextureType type) const;
642 Framebuffer *getReadFramebuffer() const;
643 Framebuffer *getDrawFramebuffer() const;
645 bool getFloatv(GLenum pname, GLfloat *params) const;
646 template<typename T> bool getIntegerv(GLenum pname, T *params) const;
647 bool getBooleanv(GLenum pname, GLboolean *params) const;
648 template<typename T> bool getTransformFeedbackiv(GLuint index, GLenum pname, T *param) const;
649 template<typename T> bool getUniformBufferiv(GLuint index, GLenum pname, T *param) const;
650 void samplerParameteri(GLuint sampler, GLenum pname, GLint param);
651 void samplerParameterf(GLuint sampler, GLenum pname, GLfloat param);
652 GLint getSamplerParameteri(GLuint sampler, GLenum pname);
653 GLfloat getSamplerParameterf(GLuint sampler, GLenum pname);
655 bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const;
657 bool hasZeroDivisor() const;
659 void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);
660 void clear(GLbitfield mask);
661 void clearColorBuffer(GLint drawbuffer, const GLint *value);
662 void clearColorBuffer(GLint drawbuffer, const GLuint *value);
663 void clearColorBuffer(GLint drawbuffer, const GLfloat *value);
664 void clearDepthBuffer(const GLfloat value);
665 void clearStencilBuffer(const GLint value);
666 void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount = 1);
667 void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount = 1);
671 void recordInvalidEnum();
672 void recordInvalidValue();
673 void recordInvalidOperation();
674 void recordOutOfMemory();
675 void recordInvalidFramebufferOperation();
679 static int getSupportedMultisampleCount(int requested);
681 void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
682 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
685 virtual void bindTexImage(egl::Surface *surface);
686 virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
687 virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
691 const GLubyte* getExtensions(GLuint index, GLuint* numExt = nullptr) const;
696 void applyScissor(int width, int height);
697 bool applyRenderTarget();
698 void applyState(GLenum drawMode);
699 GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count, GLsizei instanceId);
700 GLenum applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
702 void applyTextures();
703 void applyTextures(sw::SamplerType type);
704 void applyTexture(sw::SamplerType type, int sampler, Texture *texture);
705 void clearColorBuffer(GLint drawbuffer, void *value, sw::Format format);
707 void detachBuffer(GLuint buffer);
708 void detachTexture(GLuint texture);
709 void detachFramebuffer(GLuint framebuffer);
710 void detachRenderbuffer(GLuint renderbuffer);
711 void detachSampler(GLuint sampler);
713 bool cullSkipsDraw(GLenum drawMode);
714 bool isTriangleMode(GLenum drawMode);
716 Query *createQuery(GLuint handle, GLenum type);
718 const EGLint clientVersion;
719 const egl::Config *const mConfig;
723 gl::BindingPointer<Texture2D> mTexture2DZero;
724 gl::BindingPointer<Texture3D> mTexture3DZero;
725 gl::BindingPointer<Texture2DArray> mTexture2DArrayZero;
726 gl::BindingPointer<TextureCubeMap> mTextureCubeMapZero;
727 gl::BindingPointer<TextureExternal> mTextureExternalZero;
729 gl::NameSpace<Framebuffer> mFramebufferNameSpace;
730 gl::NameSpace<Fence, 0> mFenceNameSpace;
731 gl::NameSpace<Query> mQueryNameSpace;
732 gl::NameSpace<VertexArray> mVertexArrayNameSpace;
733 gl::NameSpace<TransformFeedback> mTransformFeedbackNameSpace;
735 VertexDataManager *mVertexDataManager;
736 IndexDataManager *mIndexDataManager;
741 bool mInvalidOperation;
743 bool mInvalidFramebufferOperation;
745 bool mHasBeenCurrent;
747 unsigned int mAppliedProgramSerial;
749 // state caching flags
750 bool mDepthStateDirty;
751 bool mMaskStateDirty;
752 bool mBlendStateDirty;
753 bool mStencilStateDirty;
754 bool mPolygonOffsetStateDirty;
755 bool mSampleStateDirty;
756 bool mFrontFaceDirty;
757 bool mDitherStateDirty;
760 ResourceManager *mResourceManager;
764 #endif // INCLUDE_CONTEXT_H_