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>
45 struct TranslatedAttribute;
46 struct TranslatedIndexData;
56 class TextureExternal;
59 class RenderbufferStorage;
62 class StreamingIndexBuffer;
64 class DepthStencilbuffer;
65 class VertexDataManager;
66 class IndexDataManager;
72 class TransformFeedback;
76 MAX_VERTEX_ATTRIBS = sw::MAX_VERTEX_INPUTS,
77 MAX_UNIFORM_VECTORS = 256, // Device limit
78 MAX_VERTEX_UNIFORM_VECTORS = sw::VERTEX_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
79 MAX_VARYING_VECTORS = MIN(sw::MAX_FRAGMENT_INPUTS, sw::MAX_VERTEX_OUTPUTS),
80 MAX_TEXTURE_IMAGE_UNITS = sw::TEXTURE_IMAGE_UNITS,
81 MAX_VERTEX_TEXTURE_IMAGE_UNITS = sw::VERTEX_TEXTURE_IMAGE_UNITS,
82 MAX_COMBINED_TEXTURE_IMAGE_UNITS = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS,
83 MAX_FRAGMENT_UNIFORM_VECTORS = sw::FRAGMENT_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
84 MAX_ELEMENT_INDEX = 0x7FFFFFFF,
85 MAX_ELEMENTS_INDICES = 0x7FFFFFFF,
86 MAX_ELEMENTS_VERTICES = 0x7FFFFFFF,
87 MAX_VERTEX_OUTPUT_VECTORS = 16,
88 MAX_FRAGMENT_INPUT_VECTORS = 15,
89 MIN_PROGRAM_TEXEL_OFFSET = sw::MIN_PROGRAM_TEXEL_OFFSET,
90 MAX_PROGRAM_TEXEL_OFFSET = sw::MAX_PROGRAM_TEXEL_OFFSET,
91 MAX_DRAW_BUFFERS = sw::RENDERTARGETS,
92 MAX_COLOR_ATTACHMENTS = MAX(MAX_DRAW_BUFFERS, 8),
93 MAX_FRAGMENT_UNIFORM_BLOCKS = sw::MAX_FRAGMENT_UNIFORM_BLOCKS,
94 MAX_VERTEX_UNIFORM_BLOCKS = sw::MAX_VERTEX_UNIFORM_BLOCKS,
95 MAX_FRAGMENT_UNIFORM_COMPONENTS = sw::FRAGMENT_UNIFORM_VECTORS * 4,
96 MAX_VERTEX_UNIFORM_COMPONENTS = sw::VERTEX_UNIFORM_VECTORS * 4,
97 MAX_UNIFORM_BLOCK_SIZE = sw::MAX_UNIFORM_BLOCK_SIZE,
98 MAX_FRAGMENT_UNIFORM_BLOCKS_COMPONENTS = sw::MAX_FRAGMENT_UNIFORM_BLOCKS * MAX_UNIFORM_BLOCK_SIZE / 4,
99 MAX_VERTEX_UNIFORM_BLOCKS_COMPONENTS = MAX_VERTEX_UNIFORM_BLOCKS * MAX_UNIFORM_BLOCK_SIZE / 4,
100 MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = MAX_FRAGMENT_UNIFORM_BLOCKS_COMPONENTS + MAX_FRAGMENT_UNIFORM_COMPONENTS,
101 MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = MAX_VERTEX_UNIFORM_BLOCKS_COMPONENTS + MAX_VERTEX_UNIFORM_COMPONENTS,
102 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 4,
103 MAX_UNIFORM_BUFFER_BINDINGS = sw::MAX_UNIFORM_BUFFER_BINDINGS,
104 UNIFORM_BUFFER_OFFSET_ALIGNMENT = 1,
105 NUM_PROGRAM_BINARY_FORMATS = 0,
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 = GL_FLOAT;
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 case GL_HALF_FLOAT: return mSize * sizeof(GLhalf);
214 case GL_INT_2_10_10_10_REV: return sizeof(GLint);
215 case GL_UNSIGNED_INT_2_10_10_10_REV: return sizeof(GLuint);
216 default: UNREACHABLE(mType); return mSize * sizeof(GLfloat);
220 GLenum currentValueType() const
222 return mCurrentValueType;
225 GLsizei stride() const
227 return mStride ? mStride : typeSize();
230 inline float getCurrentValueBitsAsFloat(int i) const
232 return mCurrentValue[i].f;
235 inline float getCurrentValueF(int i) const
237 switch(mCurrentValueType)
239 case GL_FLOAT: return mCurrentValue[i].f;
240 case GL_INT: return static_cast<float>(mCurrentValue[i].i);
241 case GL_UNSIGNED_INT: return static_cast<float>(mCurrentValue[i].ui);
242 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].f;
246 inline GLint getCurrentValueI(int i) const
248 switch(mCurrentValueType)
250 case GL_FLOAT: return static_cast<GLint>(mCurrentValue[i].f);
251 case GL_INT: return mCurrentValue[i].i;
252 case GL_UNSIGNED_INT: return static_cast<GLint>(mCurrentValue[i].ui);
253 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].i;
257 inline GLuint getCurrentValueUI(int i) const
259 switch(mCurrentValueType)
261 case GL_FLOAT: return static_cast<GLuint>(mCurrentValue[i].f);
262 case GL_INT: return static_cast<GLuint>(mCurrentValue[i].i);
263 case GL_UNSIGNED_INT: return mCurrentValue[i].ui;
264 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].ui;
268 inline void setCurrentValue(const GLfloat *values)
270 mCurrentValue[0].f = values[0];
271 mCurrentValue[1].f = values[1];
272 mCurrentValue[2].f = values[2];
273 mCurrentValue[3].f = values[3];
274 mCurrentValueType = GL_FLOAT;
277 inline void setCurrentValue(const GLint *values)
279 mCurrentValue[0].i = values[0];
280 mCurrentValue[1].i = values[1];
281 mCurrentValue[2].i = values[2];
282 mCurrentValue[3].i = values[3];
283 mCurrentValueType = GL_INT;
286 inline void setCurrentValue(const GLuint *values)
288 mCurrentValue[0].ui = values[0];
289 mCurrentValue[1].ui = values[1];
290 mCurrentValue[2].ui = values[2];
291 mCurrentValue[3].ui = values[3];
292 mCurrentValueType = GL_UNSIGNED_INT;
295 // From glVertexAttribPointer
299 GLsizei mStride; // 0 means natural stride
300 GLuint mDivisor; // From glVertexAttribDivisor
304 const void *mPointer;
308 gl::BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called.
310 bool mArrayEnabled; // From glEnable/DisableVertexAttribArray
320 ValueUnion mCurrentValue[4]; // From glVertexAttrib
321 GLenum mCurrentValueType;
324 typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS];
326 // Helper structure to store all raw state
329 Color colorClearValue;
330 GLclampf depthClearValue;
331 int stencilClearValue;
333 bool cullFaceEnabled;
336 bool depthTestEnabled;
339 GLenum sourceBlendRGB;
341 GLenum sourceBlendAlpha;
342 GLenum destBlendAlpha;
343 GLenum blendEquationRGB;
344 GLenum blendEquationAlpha;
346 bool stencilTestEnabled;
351 GLenum stencilPassDepthFail;
352 GLenum stencilPassDepthPass;
353 GLuint stencilWritemask;
354 GLenum stencilBackFunc;
355 GLint stencilBackRef;
356 GLuint stencilBackMask;
357 GLenum stencilBackFail;
358 GLenum stencilBackPassDepthFail;
359 GLenum stencilBackPassDepthPass;
360 GLuint stencilBackWritemask;
361 bool polygonOffsetFillEnabled;
362 GLfloat polygonOffsetFactor;
363 GLfloat polygonOffsetUnits;
364 bool sampleAlphaToCoverageEnabled;
365 bool sampleCoverageEnabled;
366 GLclampf sampleCoverageValue;
367 bool sampleCoverageInvert;
368 bool scissorTestEnabled;
370 bool primitiveRestartFixedIndexEnabled;
371 bool rasterizerDiscardEnabled;
372 bool colorLogicOpEnabled;
373 GLenum logicalOperation;
377 GLenum generateMipmapHint;
378 GLenum fragmentShaderDerivativeHint;
382 GLsizei viewportWidth;
383 GLsizei viewportHeight;
389 GLsizei scissorWidth;
390 GLsizei scissorHeight;
398 unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0
399 gl::BindingPointer<Buffer> arrayBuffer;
400 gl::BindingPointer<Buffer> copyReadBuffer;
401 gl::BindingPointer<Buffer> copyWriteBuffer;
402 gl::BindingPointer<Buffer> pixelPackBuffer;
403 gl::BindingPointer<Buffer> pixelUnpackBuffer;
404 gl::BindingPointer<Buffer> genericUniformBuffer;
405 BufferBinding uniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];
407 GLuint readFramebuffer;
408 GLuint drawFramebuffer;
409 gl::BindingPointer<Renderbuffer> renderbuffer;
410 GLuint currentProgram;
412 GLuint transformFeedback;
413 gl::BindingPointer<Sampler> sampler[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
415 VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS];
416 gl::BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_COMBINED_TEXTURE_IMAGE_UNITS];
417 gl::BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT];
419 egl::Image::UnpackInfo unpackInfo;
422 GLint packImageHeight;
423 GLint packSkipPixels;
425 GLint packSkipImages;
428 class [[clang::lto_visibility_public]] Context : public egl::Context
431 Context(egl::Display *display, const Context *shareContext, EGLint clientVersion, const egl::Config *config);
433 void makeCurrent(gl::Surface *surface) override;
434 EGLint getClientVersion() const override;
435 EGLint getConfigID() const override;
437 void markAllStateDirty();
439 // State manipulation
440 void setClearColor(float red, float green, float blue, float alpha);
441 void setClearDepth(float depth);
442 void setClearStencil(int stencil);
444 void setCullFaceEnabled(bool enabled);
445 bool isCullFaceEnabled() const;
446 void setCullMode(GLenum mode);
447 void setFrontFace(GLenum front);
449 void setDepthTestEnabled(bool enabled);
450 bool isDepthTestEnabled() const;
451 void setDepthFunc(GLenum depthFunc);
452 void setDepthRange(float zNear, float zFar);
454 void setBlendEnabled(bool enabled);
455 bool isBlendEnabled() const;
456 void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
457 void setBlendColor(float red, float green, float blue, float alpha);
458 void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
460 void setStencilTestEnabled(bool enabled);
461 bool isStencilTestEnabled() const;
462 void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
463 void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
464 void setStencilWritemask(GLuint stencilWritemask);
465 void setStencilBackWritemask(GLuint stencilBackWritemask);
466 void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
467 void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);
469 void setPolygonOffsetFillEnabled(bool enabled);
470 bool isPolygonOffsetFillEnabled() const;
471 void setPolygonOffsetParams(GLfloat factor, GLfloat units);
473 void setSampleAlphaToCoverageEnabled(bool enabled);
474 bool isSampleAlphaToCoverageEnabled() const;
475 void setSampleCoverageEnabled(bool enabled);
476 bool isSampleCoverageEnabled() const;
477 void setSampleCoverageParams(GLclampf value, bool invert);
479 void setDitherEnabled(bool enabled);
480 bool isDitherEnabled() const;
482 void setPrimitiveRestartFixedIndexEnabled(bool enabled);
483 bool isPrimitiveRestartFixedIndexEnabled() const;
485 void setRasterizerDiscardEnabled(bool enabled);
486 bool isRasterizerDiscardEnabled() const;
488 void setLineWidth(GLfloat width);
490 void setGenerateMipmapHint(GLenum hint);
491 void setFragmentShaderDerivativeHint(GLenum hint);
493 void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
495 void setScissorTestEnabled(bool enabled);
496 bool isScissorTestEnabled() const;
497 void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
499 void setColorMask(bool red, bool green, bool blue, bool alpha);
500 unsigned int getColorMask() const;
501 void setDepthMask(bool mask);
503 void setActiveSampler(unsigned int active);
505 GLuint getReadFramebufferName() const;
506 GLuint getDrawFramebufferName() const;
507 GLuint getRenderbufferName() const;
509 void setFramebufferReadBuffer(GLenum buf);
510 void setFramebufferDrawBuffers(GLsizei n, const GLenum *bufs);
511 GLuint getReadFramebufferColorIndex() const;
513 GLuint getActiveQuery(GLenum target) const;
515 GLuint getArrayBufferName() const;
516 GLuint getElementArrayBufferName() const;
518 void setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled);
519 void setVertexAttribDivisor(unsigned int attribNum, GLuint divisor);
520 const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;
521 void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
522 bool normalized, GLsizei stride, const void *pointer);
523 const void *getVertexAttribPointer(unsigned int attribNum) const;
525 const VertexAttributeArray &getVertexArrayAttributes();
526 // Context attribute current values can be queried independently from VAO current values
527 const VertexAttributeArray &getCurrentVertexAttributes();
529 void setUnpackAlignment(GLint alignment);
530 void setUnpackRowLength(GLint rowLength);
531 void setUnpackImageHeight(GLint imageHeight);
532 void setUnpackSkipPixels(GLint skipPixels);
533 void setUnpackSkipRows(GLint skipRows);
534 void setUnpackSkipImages(GLint skipImages);
535 const egl::Image::UnpackInfo& getUnpackInfo() const;
537 void setPackAlignment(GLint alignment);
538 void setPackRowLength(GLint rowLength);
539 void setPackImageHeight(GLint imageHeight);
540 void setPackSkipPixels(GLint skipPixels);
541 void setPackSkipRows(GLint skipRows);
542 void setPackSkipImages(GLint skipImages);
544 // These create and destroy methods are merely pass-throughs to
545 // ResourceManager, which owns these object types
546 GLuint createBuffer();
547 GLuint createShader(GLenum type);
548 GLuint createProgram();
549 GLuint createTexture();
550 GLuint createRenderbuffer();
551 GLuint createSampler();
552 GLsync createFenceSync(GLenum condition, GLbitfield flags);
554 void deleteBuffer(GLuint buffer);
555 void deleteShader(GLuint shader);
556 void deleteProgram(GLuint program);
557 void deleteTexture(GLuint texture);
558 void deleteRenderbuffer(GLuint renderbuffer);
559 void deleteSampler(GLuint sampler);
560 void deleteFenceSync(GLsync fenceSync);
562 // Framebuffers are owned by the Context, so these methods do not pass through
563 GLuint createFramebuffer();
564 void deleteFramebuffer(GLuint framebuffer);
566 // Fences are owned by the Context
567 GLuint createFence();
568 void deleteFence(GLuint fence);
570 // Queries are owned by the Context
571 GLuint createQuery();
572 void deleteQuery(GLuint query);
574 // Vertex arrays are owned by the Context
575 GLuint createVertexArray();
576 void deleteVertexArray(GLuint array);
578 // Transform feedbacks are owned by the Context
579 GLuint createTransformFeedback();
580 void deleteTransformFeedback(GLuint transformFeedback);
582 void bindArrayBuffer(GLuint buffer);
583 void bindElementArrayBuffer(GLuint buffer);
584 void bindCopyReadBuffer(GLuint buffer);
585 void bindCopyWriteBuffer(GLuint buffer);
586 void bindPixelPackBuffer(GLuint buffer);
587 void bindPixelUnpackBuffer(GLuint buffer);
588 void bindTransformFeedbackBuffer(GLuint buffer);
589 void bindTexture2D(GLuint texture);
590 void bindTextureCubeMap(GLuint texture);
591 void bindTextureExternal(GLuint texture);
592 void bindTexture3D(GLuint texture);
593 void bindTexture2DArray(GLuint texture);
594 void bindReadFramebuffer(GLuint framebuffer);
595 void bindDrawFramebuffer(GLuint framebuffer);
596 void bindRenderbuffer(GLuint renderbuffer);
597 void bindVertexArray(GLuint array);
598 void bindGenericUniformBuffer(GLuint buffer);
599 void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
600 void bindGenericTransformFeedbackBuffer(GLuint buffer);
601 void bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
602 void bindTransformFeedback(GLuint transformFeedback);
603 bool bindSampler(GLuint unit, GLuint sampler);
604 void useProgram(GLuint program);
606 void beginQuery(GLenum target, GLuint query);
607 void endQuery(GLenum target);
609 void setFramebufferZero(Framebuffer *framebuffer);
611 void setRenderbufferStorage(RenderbufferStorage *renderbuffer);
613 void setVertexAttrib(GLuint index, const GLfloat *values);
614 void setVertexAttrib(GLuint index, const GLint *values);
615 void setVertexAttrib(GLuint index, const GLuint *values);
617 Buffer *getBuffer(GLuint handle) const;
618 Fence *getFence(GLuint handle) const;
619 FenceSync *getFenceSync(GLsync handle) const;
620 Shader *getShader(GLuint handle) const;
621 Program *getProgram(GLuint handle) const;
622 virtual Texture *getTexture(GLuint handle) const;
623 Framebuffer *getFramebuffer(GLuint handle) const;
624 virtual Renderbuffer *getRenderbuffer(GLuint handle) const;
625 Query *getQuery(GLuint handle) const;
626 VertexArray *getVertexArray(GLuint array) const;
627 VertexArray *getCurrentVertexArray() const;
628 bool isVertexArray(GLuint array) const;
629 TransformFeedback *getTransformFeedback(GLuint transformFeedback) const;
630 TransformFeedback *getTransformFeedback() const;
631 Sampler *getSampler(GLuint sampler) const;
632 bool isSampler(GLuint sampler) const;
634 Buffer *getArrayBuffer() const;
635 Buffer *getElementArrayBuffer() const;
636 Buffer *getCopyReadBuffer() const;
637 Buffer *getCopyWriteBuffer() const;
638 Buffer *getPixelPackBuffer() const;
639 Buffer *getPixelUnpackBuffer() const;
640 Buffer *getGenericUniformBuffer() const;
641 const GLvoid* getPixels(const GLvoid* data) const;
642 bool getBuffer(GLenum target, es2::Buffer **buffer) const;
643 Program *getCurrentProgram() const;
644 Texture2D *getTexture2D() const;
645 Texture3D *getTexture3D() const;
646 Texture2DArray *getTexture2DArray() const;
647 TextureCubeMap *getTextureCubeMap() const;
648 TextureExternal *getTextureExternal() const;
649 Texture *getSamplerTexture(unsigned int sampler, TextureType type) const;
650 Framebuffer *getReadFramebuffer() const;
651 Framebuffer *getDrawFramebuffer() const;
653 bool getFloatv(GLenum pname, GLfloat *params) const;
654 template<typename T> bool getIntegerv(GLenum pname, T *params) const;
655 bool getBooleanv(GLenum pname, GLboolean *params) const;
656 template<typename T> bool getTransformFeedbackiv(GLuint index, GLenum pname, T *param) const;
657 template<typename T> bool getUniformBufferiv(GLuint index, GLenum pname, T *param) const;
658 void samplerParameteri(GLuint sampler, GLenum pname, GLint param);
659 void samplerParameterf(GLuint sampler, GLenum pname, GLfloat param);
660 GLint getSamplerParameteri(GLuint sampler, GLenum pname);
661 GLfloat getSamplerParameterf(GLuint sampler, GLenum pname);
663 bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const;
665 bool hasZeroDivisor() const;
667 void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount = 1);
668 void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount = 1);
669 void blit(sw::Surface *source, const sw::SliceRect &sRect, sw::Surface *dest, const sw::SliceRect &dRect) override;
670 void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);
671 void clear(GLbitfield mask);
672 void clearColorBuffer(GLint drawbuffer, const GLint *value);
673 void clearColorBuffer(GLint drawbuffer, const GLuint *value);
674 void clearColorBuffer(GLint drawbuffer, const GLfloat *value);
675 void clearDepthBuffer(const GLfloat value);
676 void clearStencilBuffer(const GLint value);
677 void finish() override;
680 void recordInvalidEnum();
681 void recordInvalidValue();
682 void recordInvalidOperation();
683 void recordOutOfMemory();
684 void recordInvalidFramebufferOperation();
688 static int getSupportedMultisampleCount(int requested);
690 void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
691 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
692 GLbitfield mask, bool filter, bool allowPartialDepthStencilBlit);
694 void bindTexImage(gl::Surface *surface) override;
695 EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel) override;
696 egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel) override;
697 egl::Image *getSharedImage(GLeglImageOES image);
701 const GLubyte *getExtensions(GLuint index, GLuint *numExt = nullptr) const;
706 void applyScissor(int width, int height);
707 bool applyRenderTarget();
708 void applyState(GLenum drawMode);
709 GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count, GLsizei instanceId);
710 GLenum applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
712 void applyTextures();
713 void applyTextures(sw::SamplerType type);
714 void applyTexture(sw::SamplerType type, int sampler, Texture *texture);
715 void clearColorBuffer(GLint drawbuffer, void *value, sw::Format format);
717 void detachBuffer(GLuint buffer);
718 void detachTexture(GLuint texture);
719 void detachFramebuffer(GLuint framebuffer);
720 void detachRenderbuffer(GLuint renderbuffer);
721 void detachSampler(GLuint sampler);
723 bool cullSkipsDraw(GLenum drawMode);
724 bool isTriangleMode(GLenum drawMode);
726 Query *createQuery(GLuint handle, GLenum type);
728 const EGLint clientVersion;
729 const egl::Config *const config;
733 gl::BindingPointer<Texture2D> mTexture2DZero;
734 gl::BindingPointer<Texture3D> mTexture3DZero;
735 gl::BindingPointer<Texture2DArray> mTexture2DArrayZero;
736 gl::BindingPointer<TextureCubeMap> mTextureCubeMapZero;
737 gl::BindingPointer<TextureExternal> mTextureExternalZero;
739 gl::NameSpace<Framebuffer> mFramebufferNameSpace;
740 gl::NameSpace<Fence, 0> mFenceNameSpace;
741 gl::NameSpace<Query> mQueryNameSpace;
742 gl::NameSpace<VertexArray> mVertexArrayNameSpace;
743 gl::NameSpace<TransformFeedback> mTransformFeedbackNameSpace;
745 VertexDataManager *mVertexDataManager;
746 IndexDataManager *mIndexDataManager;
751 bool mInvalidOperation;
753 bool mInvalidFramebufferOperation;
755 bool mHasBeenCurrent;
757 unsigned int mAppliedProgramSerial;
759 // state caching flags
760 bool mDepthStateDirty;
761 bool mMaskStateDirty;
762 bool mBlendStateDirty;
763 bool mStencilStateDirty;
764 bool mPolygonOffsetStateDirty;
765 bool mSampleStateDirty;
766 bool mFrontFaceDirty;
767 bool mDitherStateDirty;
770 ResourceManager *mResourceManager;
774 #endif // INCLUDE_CONTEXT_H_