1 // SwiftShader Software Renderer
\r
3 // Copyright(c) 2005-2013 TransGaming Inc.
\r
5 // All rights reserved. No part of this software may be copied, distributed, transmitted,
\r
6 // transcribed, stored in a retrieval system, translated into any human or computer
\r
7 // language by any means, or disclosed to third parties without the explicit written
\r
8 // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
\r
9 // or implied, including but not limited to any patent rights, are granted to you.
\r
12 // Context.h: Defines the Context class, managing all GL state and performing
\r
13 // rendering operations. It is the GLES2 specific implementation of EGLContext.
\r
15 #ifndef LIBGLESV2_CONTEXT_H_
\r
16 #define LIBGLESV2_CONTEXT_H_
\r
18 #include "libEGL/Context.hpp"
\r
19 #include "ResourceManager.h"
\r
20 #include "common/NameSpace.hpp"
\r
21 #include "common/Object.hpp"
\r
22 #include "common/Image.hpp"
\r
23 #include "Renderer/Sampler.hpp"
\r
24 #include "TransformFeedback.h"
\r
26 #include <GLES2/gl2.h>
\r
27 #include <GLES2/gl2ext.h>
\r
28 #include <GLES3/gl3.h>
\r
29 #include <EGL/egl.h>
\r
43 struct TranslatedAttribute;
\r
44 struct TranslatedIndexData;
\r
52 class Texture2DArray;
\r
53 class TextureCubeMap;
\r
54 class TextureExternal;
\r
57 class RenderbufferStorage;
\r
60 class StreamingIndexBuffer;
\r
61 class Stencilbuffer;
\r
62 class DepthStencilbuffer;
\r
63 class VertexDataManager;
\r
64 class IndexDataManager;
\r
73 MAX_VERTEX_ATTRIBS = VERTEX_ATTRIBUTES,
\r
74 MAX_UNIFORM_VECTORS = 256, // Device limit
\r
75 MAX_VERTEX_UNIFORM_VECTORS = VERTEX_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
\r
76 MAX_VARYING_VECTORS = 10,
\r
77 MAX_TEXTURE_IMAGE_UNITS = TEXTURE_IMAGE_UNITS,
\r
78 MAX_VERTEX_TEXTURE_IMAGE_UNITS = VERTEX_TEXTURE_IMAGE_UNITS,
\r
79 MAX_COMBINED_TEXTURE_IMAGE_UNITS = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS,
\r
80 MAX_FRAGMENT_UNIFORM_VECTORS = FRAGMENT_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
\r
81 MAX_DRAW_BUFFERS = RENDERTARGETS,
\r
82 MAX_ELEMENT_INDEX = 0x7FFFFFFF,
\r
83 MAX_ELEMENTS_INDICES = 0x7FFFFFFF,
\r
84 MAX_ELEMENTS_VERTICES = 0x7FFFFFFF,
\r
85 MAX_VERTEX_OUTPUT_VECTORS = 16,
\r
86 MAX_FRAGMENT_INPUT_VECTORS = 15,
\r
87 MIN_PROGRAM_TEXEL_OFFSET = -8,
\r
88 MAX_PROGRAM_TEXEL_OFFSET = 7,
\r
91 const GLenum compressedTextureFormats[] =
\r
95 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
\r
96 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
\r
97 GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE,
\r
98 GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE,
\r
100 #if (GL_ES_VERSION_3_0)
\r
101 GL_COMPRESSED_R11_EAC,
\r
102 GL_COMPRESSED_SIGNED_R11_EAC,
\r
103 GL_COMPRESSED_RG11_EAC,
\r
104 GL_COMPRESSED_SIGNED_RG11_EAC,
\r
105 GL_COMPRESSED_RGB8_ETC2,
\r
106 GL_COMPRESSED_SRGB8_ETC2,
\r
107 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
\r
108 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
\r
109 GL_COMPRESSED_RGBA8_ETC2_EAC,
\r
110 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
\r
111 GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
\r
112 GL_COMPRESSED_RGBA_ASTC_5x4_KHR,
\r
113 GL_COMPRESSED_RGBA_ASTC_5x5_KHR,
\r
114 GL_COMPRESSED_RGBA_ASTC_6x5_KHR,
\r
115 GL_COMPRESSED_RGBA_ASTC_6x6_KHR,
\r
116 GL_COMPRESSED_RGBA_ASTC_8x5_KHR,
\r
117 GL_COMPRESSED_RGBA_ASTC_8x6_KHR,
\r
118 GL_COMPRESSED_RGBA_ASTC_8x8_KHR,
\r
119 GL_COMPRESSED_RGBA_ASTC_10x5_KHR,
\r
120 GL_COMPRESSED_RGBA_ASTC_10x6_KHR,
\r
121 GL_COMPRESSED_RGBA_ASTC_10x8_KHR,
\r
122 GL_COMPRESSED_RGBA_ASTC_10x10_KHR,
\r
123 GL_COMPRESSED_RGBA_ASTC_12x10_KHR,
\r
124 GL_COMPRESSED_RGBA_ASTC_12x12_KHR,
\r
125 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
\r
126 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
\r
127 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
\r
128 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
\r
129 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
\r
130 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
\r
131 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
\r
132 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
\r
133 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
\r
134 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
\r
135 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
\r
136 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
\r
137 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
\r
138 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
\r
142 const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);
\r
144 const GLint multisampleCount[] = {4, 2, 1};
\r
145 const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]);
\r
146 const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0];
\r
148 const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
\r
149 const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
\r
150 const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;
\r
151 const float ALIASED_POINT_SIZE_RANGE_MAX = 8192.0f;
\r
152 const float MAX_TEXTURE_MAX_ANISOTROPY = 16.0f;
\r
156 QUERY_ANY_SAMPLES_PASSED,
\r
157 QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE,
\r
158 QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
\r
171 // Helper structure describing a single vertex attribute
\r
172 class VertexAttribute
\r
175 VertexAttribute() : mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mDivisor(0), mPointer(NULL), mArrayEnabled(false)
\r
177 mCurrentValue[0].f = 0.0f;
\r
178 mCurrentValue[1].f = 0.0f;
\r
179 mCurrentValue[2].f = 0.0f;
\r
180 mCurrentValue[3].f = 1.0f;
\r
181 mCurrentValueType = ValueUnion::FloatType;
\r
184 int typeSize() const
\r
188 case GL_BYTE: return mSize * sizeof(GLbyte);
\r
189 case GL_UNSIGNED_BYTE: return mSize * sizeof(GLubyte);
\r
190 case GL_SHORT: return mSize * sizeof(GLshort);
\r
191 case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort);
\r
192 case GL_INT: return mSize * sizeof(GLint);
\r
193 case GL_UNSIGNED_INT: return mSize * sizeof(GLuint);
\r
194 case GL_FIXED: return mSize * sizeof(GLfixed);
\r
195 case GL_FLOAT: return mSize * sizeof(GLfloat);
\r
196 default: UNREACHABLE(mType); return mSize * sizeof(GLfloat);
\r
200 GLsizei stride() const
\r
202 return mStride ? mStride : typeSize();
\r
205 inline float getCurrentValueBitsAsFloat(int i) const
\r
207 return mCurrentValue[i].f;
\r
210 inline float getCurrentValueF(int i) const
\r
212 switch(mCurrentValueType)
\r
214 case ValueUnion::FloatType: return mCurrentValue[i].f;
\r
215 case ValueUnion::IntType: return static_cast<float>(mCurrentValue[i].i);
\r
216 case ValueUnion::UIntType: return static_cast<float>(mCurrentValue[i].ui);
\r
217 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].f;
\r
221 inline GLint getCurrentValueI(int i) const
\r
223 switch(mCurrentValueType)
\r
225 case ValueUnion::FloatType: return static_cast<GLint>(mCurrentValue[i].f);
\r
226 case ValueUnion::IntType: return mCurrentValue[i].i;
\r
227 case ValueUnion::UIntType: return static_cast<GLint>(mCurrentValue[i].ui);
\r
228 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].i;
\r
232 inline GLuint getCurrentValueUI(int i) const
\r
234 switch(mCurrentValueType)
\r
236 case ValueUnion::FloatType: return static_cast<GLuint>(mCurrentValue[i].f);
\r
237 case ValueUnion::IntType: return static_cast<GLuint>(mCurrentValue[i].i);
\r
238 case ValueUnion::UIntType: return mCurrentValue[i].ui;
\r
239 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].ui;
\r
243 inline void setCurrentValue(const GLfloat *values)
\r
245 mCurrentValue[0].f = values[0];
\r
246 mCurrentValue[1].f = values[1];
\r
247 mCurrentValue[2].f = values[2];
\r
248 mCurrentValue[3].f = values[3];
\r
249 mCurrentValueType = ValueUnion::FloatType;
\r
252 inline void setCurrentValue(const GLint *values)
\r
254 mCurrentValue[0].i = values[0];
\r
255 mCurrentValue[1].i = values[1];
\r
256 mCurrentValue[2].i = values[2];
\r
257 mCurrentValue[3].i = values[3];
\r
258 mCurrentValueType = ValueUnion::IntType;
\r
261 inline void setCurrentValue(const GLuint *values)
\r
263 mCurrentValue[0].ui = values[0];
\r
264 mCurrentValue[1].ui = values[1];
\r
265 mCurrentValue[2].ui = values[2];
\r
266 mCurrentValue[3].ui = values[3];
\r
267 mCurrentValueType = ValueUnion::UIntType;
\r
270 // From glVertexAttribPointer
\r
274 GLsizei mStride; // 0 means natural stride
\r
275 GLuint mDivisor; // From glVertexAttribDivisor
\r
279 const void *mPointer;
\r
283 gl::BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called.
\r
285 bool mArrayEnabled; // From glEnable/DisableVertexAttribArray
\r
290 enum Type { FloatType, IntType, UIntType };
\r
297 ValueUnion mCurrentValue[4]; // From glVertexAttrib
\r
298 ValueUnion::Type mCurrentValueType;
\r
301 typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS];
\r
303 // Helper structure to store all raw state
\r
306 Color colorClearValue;
\r
307 GLclampf depthClearValue;
\r
308 int stencilClearValue;
\r
310 bool cullFaceEnabled;
\r
313 bool depthTestEnabled;
\r
316 GLenum sourceBlendRGB;
\r
317 GLenum destBlendRGB;
\r
318 GLenum sourceBlendAlpha;
\r
319 GLenum destBlendAlpha;
\r
320 GLenum blendEquationRGB;
\r
321 GLenum blendEquationAlpha;
\r
323 bool stencilTestEnabled;
\r
324 GLenum stencilFunc;
\r
326 GLuint stencilMask;
\r
327 GLenum stencilFail;
\r
328 GLenum stencilPassDepthFail;
\r
329 GLenum stencilPassDepthPass;
\r
330 GLuint stencilWritemask;
\r
331 GLenum stencilBackFunc;
\r
332 GLint stencilBackRef;
\r
333 GLuint stencilBackMask;
\r
334 GLenum stencilBackFail;
\r
335 GLenum stencilBackPassDepthFail;
\r
336 GLenum stencilBackPassDepthPass;
\r
337 GLuint stencilBackWritemask;
\r
338 bool polygonOffsetFillEnabled;
\r
339 GLfloat polygonOffsetFactor;
\r
340 GLfloat polygonOffsetUnits;
\r
341 bool sampleAlphaToCoverageEnabled;
\r
342 bool sampleCoverageEnabled;
\r
343 GLclampf sampleCoverageValue;
\r
344 bool sampleCoverageInvert;
\r
345 bool scissorTestEnabled;
\r
346 bool ditherEnabled;
\r
347 bool primitiveRestartFixedIndexEnabled;
\r
348 bool rasterizerDiscardEnabled;
\r
349 bool colorLogicOpEnabled;
\r
350 GLenum logicalOperation;
\r
354 GLenum generateMipmapHint;
\r
355 GLenum fragmentShaderDerivativeHint;
\r
359 GLsizei viewportWidth;
\r
360 GLsizei viewportHeight;
\r
366 GLsizei scissorWidth;
\r
367 GLsizei scissorHeight;
\r
370 bool colorMaskGreen;
\r
371 bool colorMaskBlue;
\r
372 bool colorMaskAlpha;
\r
375 unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0
\r
376 gl::BindingPointer<Buffer> arrayBuffer;
\r
377 gl::BindingPointer<Buffer> copyReadBuffer;
\r
378 gl::BindingPointer<Buffer> copyWriteBuffer;
\r
379 gl::BindingPointer<Buffer> pixelPackBuffer;
\r
380 gl::BindingPointer<Buffer> pixelUnpackBuffer;
\r
381 gl::BindingPointer<Buffer> genericUniformBuffer;
\r
382 BufferBinding uniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];
\r
384 GLuint readFramebuffer;
\r
385 GLuint drawFramebuffer;
\r
386 gl::BindingPointer<Renderbuffer> renderbuffer;
\r
387 GLuint currentProgram;
\r
388 GLuint vertexArray;
\r
389 GLuint transformFeedback;
\r
390 gl::BindingPointer<Sampler> sampler[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
\r
392 VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS];
\r
393 gl::BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_COMBINED_TEXTURE_IMAGE_UNITS];
\r
394 gl::BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT];
\r
396 egl::Image::UnpackInfo unpackInfo;
\r
397 GLint packAlignment;
\r
398 GLint packRowLength;
\r
399 GLint packImageHeight;
\r
400 GLint packSkipPixels;
\r
401 GLint packSkipRows;
\r
402 GLint packSkipImages;
\r
405 class Context : public egl::Context
\r
408 Context(const egl::Config *config, const Context *shareContext, EGLint clientVersion);
\r
410 virtual void makeCurrent(egl::Surface *surface);
\r
411 virtual EGLint getClientVersion() const;
\r
413 void markAllStateDirty();
\r
415 // State manipulation
\r
416 void setClearColor(float red, float green, float blue, float alpha);
\r
417 void setClearDepth(float depth);
\r
418 void setClearStencil(int stencil);
\r
420 void setCullFaceEnabled(bool enabled);
\r
421 bool isCullFaceEnabled() const;
\r
422 void setCullMode(GLenum mode);
\r
423 void setFrontFace(GLenum front);
\r
425 void setDepthTestEnabled(bool enabled);
\r
426 bool isDepthTestEnabled() const;
\r
427 void setDepthFunc(GLenum depthFunc);
\r
428 void setDepthRange(float zNear, float zFar);
\r
430 void setBlendEnabled(bool enabled);
\r
431 bool isBlendEnabled() const;
\r
432 void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
\r
433 void setBlendColor(float red, float green, float blue, float alpha);
\r
434 void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
\r
436 void setStencilTestEnabled(bool enabled);
\r
437 bool isStencilTestEnabled() const;
\r
438 void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
\r
439 void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
\r
440 void setStencilWritemask(GLuint stencilWritemask);
\r
441 void setStencilBackWritemask(GLuint stencilBackWritemask);
\r
442 void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
\r
443 void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);
\r
445 void setPolygonOffsetFillEnabled(bool enabled);
\r
446 bool isPolygonOffsetFillEnabled() const;
\r
447 void setPolygonOffsetParams(GLfloat factor, GLfloat units);
\r
449 void setSampleAlphaToCoverageEnabled(bool enabled);
\r
450 bool isSampleAlphaToCoverageEnabled() const;
\r
451 void setSampleCoverageEnabled(bool enabled);
\r
452 bool isSampleCoverageEnabled() const;
\r
453 void setSampleCoverageParams(GLclampf value, bool invert);
\r
455 void setDitherEnabled(bool enabled);
\r
456 bool isDitherEnabled() const;
\r
458 void setPrimitiveRestartFixedIndexEnabled(bool enabled);
\r
459 bool isPrimitiveRestartFixedIndexEnabled() const;
\r
461 void setRasterizerDiscardEnabled(bool enabled);
\r
462 bool isRasterizerDiscardEnabled() const;
\r
464 void setLineWidth(GLfloat width);
\r
466 void setGenerateMipmapHint(GLenum hint);
\r
467 void setFragmentShaderDerivativeHint(GLenum hint);
\r
469 void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
\r
471 void setScissorTestEnabled(bool enabled);
\r
472 bool isScissorTestEnabled() const;
\r
473 void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
\r
475 void setColorMask(bool red, bool green, bool blue, bool alpha);
\r
476 unsigned int getColorMask() const;
\r
477 void setDepthMask(bool mask);
\r
479 void setActiveSampler(unsigned int active);
\r
481 GLuint getReadFramebufferName() const;
\r
482 GLuint getDrawFramebufferName() const;
\r
483 GLuint getRenderbufferName() const;
\r
485 void setFramebufferReadBuffer(GLenum buf);
\r
486 void setFramebufferDrawBuffers(GLsizei n, const GLenum *bufs);
\r
487 GLuint getReadFramebufferColorIndex() const;
\r
489 GLuint getActiveQuery(GLenum target) const;
\r
491 GLuint getArrayBufferName() const;
\r
492 GLuint getElementArrayBufferName() const;
\r
494 void setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled);
\r
495 void setVertexAttribDivisor(unsigned int attribNum, GLuint divisor);
\r
496 const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;
\r
497 void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
\r
498 bool normalized, GLsizei stride, const void *pointer);
\r
499 const void *getVertexAttribPointer(unsigned int attribNum) const;
\r
501 const VertexAttributeArray &getVertexArrayAttributes();
\r
502 // Context attribute current values can be queried independently from VAO current values
\r
503 const VertexAttributeArray &getCurrentVertexAttributes();
\r
505 void setUnpackAlignment(GLint alignment);
\r
506 void setUnpackRowLength(GLint rowLength);
\r
507 void setUnpackImageHeight(GLint imageHeight);
\r
508 void setUnpackSkipPixels(GLint skipPixels);
\r
509 void setUnpackSkipRows(GLint skipRows);
\r
510 void setUnpackSkipImages(GLint skipImages);
\r
511 const egl::Image::UnpackInfo& getUnpackInfo() const;
\r
513 void setPackAlignment(GLint alignment);
\r
514 void setPackRowLength(GLint rowLength);
\r
515 void setPackImageHeight(GLint imageHeight);
\r
516 void setPackSkipPixels(GLint skipPixels);
\r
517 void setPackSkipRows(GLint skipRows);
\r
518 void setPackSkipImages(GLint skipImages);
\r
520 // These create and destroy methods are merely pass-throughs to
\r
521 // ResourceManager, which owns these object types
\r
522 GLuint createBuffer();
\r
523 GLuint createShader(GLenum type);
\r
524 GLuint createProgram();
\r
525 GLuint createTexture();
\r
526 GLuint createRenderbuffer();
\r
527 GLuint createSampler();
\r
528 GLsync createFenceSync(GLenum condition, GLbitfield flags);
\r
530 void deleteBuffer(GLuint buffer);
\r
531 void deleteShader(GLuint shader);
\r
532 void deleteProgram(GLuint program);
\r
533 void deleteTexture(GLuint texture);
\r
534 void deleteRenderbuffer(GLuint renderbuffer);
\r
535 void deleteSampler(GLuint sampler);
\r
536 void deleteFenceSync(GLsync fenceSync);
\r
538 // Framebuffers are owned by the Context, so these methods do not pass through
\r
539 GLuint createFramebuffer();
\r
540 void deleteFramebuffer(GLuint framebuffer);
\r
542 // Fences are owned by the Context
\r
543 GLuint createFence();
\r
544 void deleteFence(GLuint fence);
\r
546 // Queries are owned by the Context
\r
547 GLuint createQuery();
\r
548 void deleteQuery(GLuint query);
\r
550 // Vertex arrays are owned by the Context
\r
551 GLuint createVertexArray();
\r
552 void deleteVertexArray(GLuint array);
\r
554 // Transform feedbacks are owned by the Context
\r
555 GLuint createTransformFeedback();
\r
556 void deleteTransformFeedback(GLuint transformFeedback);
\r
558 void bindArrayBuffer(GLuint buffer);
\r
559 void bindElementArrayBuffer(GLuint buffer);
\r
560 void bindCopyReadBuffer(GLuint buffer);
\r
561 void bindCopyWriteBuffer(GLuint buffer);
\r
562 void bindPixelPackBuffer(GLuint buffer);
\r
563 void bindPixelUnpackBuffer(GLuint buffer);
\r
564 void bindTransformFeedbackBuffer(GLuint buffer);
\r
565 void bindTexture2D(GLuint texture);
\r
566 void bindTextureCubeMap(GLuint texture);
\r
567 void bindTextureExternal(GLuint texture);
\r
568 void bindTexture3D(GLuint texture);
\r
569 void bindTexture2DArray(GLuint texture);
\r
570 void bindReadFramebuffer(GLuint framebuffer);
\r
571 void bindDrawFramebuffer(GLuint framebuffer);
\r
572 void bindRenderbuffer(GLuint renderbuffer);
\r
573 void bindVertexArray(GLuint array);
\r
574 void bindGenericUniformBuffer(GLuint buffer);
\r
575 void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
\r
576 void bindGenericTransformFeedbackBuffer(GLuint buffer);
\r
577 void bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
\r
578 void bindTransformFeedback(GLuint transformFeedback);
\r
579 bool bindSampler(GLuint unit, GLuint sampler);
\r
580 void useProgram(GLuint program);
\r
582 void beginQuery(GLenum target, GLuint query);
\r
583 void endQuery(GLenum target);
\r
585 void setFramebufferZero(Framebuffer *framebuffer);
\r
587 void setRenderbufferStorage(RenderbufferStorage *renderbuffer);
\r
589 void setVertexAttrib(GLuint index, const GLfloat *values);
\r
590 void setVertexAttrib(GLuint index, const GLint *values);
\r
591 void setVertexAttrib(GLuint index, const GLuint *values);
\r
593 Buffer *getBuffer(GLuint handle) const;
\r
594 Fence *getFence(GLuint handle) const;
\r
595 FenceSync *getFenceSync(GLsync handle) const;
\r
596 Shader *getShader(GLuint handle) const;
\r
597 Program *getProgram(GLuint handle) const;
\r
598 virtual Texture *getTexture(GLuint handle) const;
\r
599 Framebuffer *getFramebuffer(GLuint handle) const;
\r
600 virtual Renderbuffer *getRenderbuffer(GLuint handle) const;
\r
601 Query *getQuery(GLuint handle) const;
\r
602 VertexArray *getVertexArray(GLuint array) const;
\r
603 VertexArray *getCurrentVertexArray() const;
\r
604 bool isVertexArray(GLuint array) const;
\r
605 TransformFeedback *getTransformFeedback(GLuint transformFeedback) const;
\r
606 TransformFeedback *getTransformFeedback() const;
\r
607 Sampler *getSampler(GLuint sampler) const;
\r
608 bool isSampler(GLuint sampler) const;
\r
610 Buffer *getArrayBuffer() const;
\r
611 Buffer *getElementArrayBuffer() const;
\r
612 Buffer *getCopyReadBuffer() const;
\r
613 Buffer *getCopyWriteBuffer() const;
\r
614 Buffer *getPixelPackBuffer() const;
\r
615 Buffer *getPixelUnpackBuffer() const;
\r
616 Buffer *getGenericUniformBuffer() const;
\r
617 bool getBuffer(GLenum target, es2::Buffer **buffer) const;
\r
618 Program *getCurrentProgram() const;
\r
619 Texture2D *getTexture2D() const;
\r
620 Texture3D *getTexture3D() const;
\r
621 Texture2DArray *getTexture2DArray() const;
\r
622 TextureCubeMap *getTextureCubeMap() const;
\r
623 TextureExternal *getTextureExternal() const;
\r
624 Texture *getSamplerTexture(unsigned int sampler, TextureType type) const;
\r
625 Framebuffer *getReadFramebuffer() const;
\r
626 Framebuffer *getDrawFramebuffer() const;
\r
628 bool getFloatv(GLenum pname, GLfloat *params) const;
\r
629 template<typename T> bool getIntegerv(GLenum pname, T *params) const;
\r
630 bool getBooleanv(GLenum pname, GLboolean *params) const;
\r
631 template<typename T> bool getTransformFeedbackiv(GLuint index, GLenum pname, T *param) const;
\r
632 template<typename T> bool getUniformBufferiv(GLuint index, GLenum pname, T *param) const;
\r
633 void samplerParameteri(GLuint sampler, GLenum pname, GLint param);
\r
634 void samplerParameterf(GLuint sampler, GLenum pname, GLfloat param);
\r
635 GLint getSamplerParameteri(GLuint sampler, GLenum pname);
\r
636 GLfloat getSamplerParameterf(GLuint sampler, GLenum pname);
\r
638 bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const;
\r
640 bool hasZeroDivisor() const;
\r
642 void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);
\r
643 void clear(GLbitfield mask);
\r
644 void clearColorBuffer(GLint drawbuffer, const GLint *value);
\r
645 void clearColorBuffer(GLint drawbuffer, const GLuint *value);
\r
646 void clearColorBuffer(GLint drawbuffer, const GLfloat *value);
\r
647 void clearDepthBuffer(const GLfloat value);
\r
648 void clearStencilBuffer(const GLint value);
\r
649 void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount = 1);
\r
650 void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount = 1);
\r
654 void recordInvalidEnum();
\r
655 void recordInvalidValue();
\r
656 void recordInvalidOperation();
\r
657 void recordOutOfMemory();
\r
658 void recordInvalidFramebufferOperation();
\r
662 static int getSupportedMultisampleCount(int requested);
\r
664 void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
\r
665 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
\r
668 virtual void bindTexImage(egl::Surface *surface);
\r
669 virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
\r
670 virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
\r
672 Device *getDevice();
\r
674 const GLubyte* getExtensions(GLuint index, GLuint* numExt = nullptr) const;
\r
677 virtual ~Context();
\r
679 void applyScissor(int width, int height);
\r
680 bool applyRenderTarget();
\r
681 void applyState(GLenum drawMode);
\r
682 GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count, GLsizei instanceId);
\r
683 GLenum applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
\r
684 void applyShaders();
\r
685 void applyTextures();
\r
686 void applyTextures(sw::SamplerType type);
\r
687 void applyTexture(sw::SamplerType type, int sampler, Texture *texture);
\r
688 void clearColorBuffer(GLint drawbuffer, void *value, sw::Format format);
\r
690 void detachBuffer(GLuint buffer);
\r
691 void detachTexture(GLuint texture);
\r
692 void detachFramebuffer(GLuint framebuffer);
\r
693 void detachRenderbuffer(GLuint renderbuffer);
\r
694 void detachSampler(GLuint sampler);
\r
696 bool cullSkipsDraw(GLenum drawMode);
\r
697 bool isTriangleMode(GLenum drawMode);
\r
699 Query *createQuery(GLuint handle, GLenum type);
\r
701 const EGLint clientVersion;
\r
702 const egl::Config *const mConfig;
\r
706 gl::BindingPointer<Texture2D> mTexture2DZero;
\r
707 gl::BindingPointer<Texture3D> mTexture3DZero;
\r
708 gl::BindingPointer<Texture2DArray> mTexture2DArrayZero;
\r
709 gl::BindingPointer<TextureCubeMap> mTextureCubeMapZero;
\r
710 gl::BindingPointer<TextureExternal> mTextureExternalZero;
\r
712 gl::NameSpace<Framebuffer> mFramebufferNameSpace;
\r
713 gl::NameSpace<Fence, 0> mFenceNameSpace;
\r
714 gl::NameSpace<Query> mQueryNameSpace;
\r
715 gl::NameSpace<VertexArray> mVertexArrayNameSpace;
\r
716 gl::NameSpace<TransformFeedback> mTransformFeedbackNameSpace;
\r
718 VertexDataManager *mVertexDataManager;
\r
719 IndexDataManager *mIndexDataManager;
\r
723 bool mInvalidValue;
\r
724 bool mInvalidOperation;
\r
726 bool mInvalidFramebufferOperation;
\r
728 bool mHasBeenCurrent;
\r
730 unsigned int mAppliedProgramSerial;
\r
732 // state caching flags
\r
733 bool mDepthStateDirty;
\r
734 bool mMaskStateDirty;
\r
735 bool mBlendStateDirty;
\r
736 bool mStencilStateDirty;
\r
737 bool mPolygonOffsetStateDirty;
\r
738 bool mSampleStateDirty;
\r
739 bool mFrontFaceDirty;
\r
740 bool mDitherStateDirty;
\r
743 ResourceManager *mResourceManager;
\r
747 #endif // INCLUDE_CONTEXT_H_
\r