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
53 class Texture2DArray;
\r
54 class TextureCubeMap;
\r
55 class TextureExternal;
\r
58 class RenderbufferStorage;
\r
61 class StreamingIndexBuffer;
\r
62 class Stencilbuffer;
\r
63 class DepthStencilbuffer;
\r
64 class VertexDataManager;
\r
65 class IndexDataManager;
\r
74 MAX_VERTEX_ATTRIBS = VERTEX_ATTRIBUTES,
\r
75 MAX_UNIFORM_VECTORS = 256, // Device limit
\r
76 MAX_VERTEX_UNIFORM_VECTORS = VERTEX_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
\r
77 MAX_VARYING_VECTORS = 10,
\r
78 MAX_TEXTURE_IMAGE_UNITS = TEXTURE_IMAGE_UNITS,
\r
79 MAX_VERTEX_TEXTURE_IMAGE_UNITS = VERTEX_TEXTURE_IMAGE_UNITS,
\r
80 MAX_COMBINED_TEXTURE_IMAGE_UNITS = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS,
\r
81 MAX_FRAGMENT_UNIFORM_VECTORS = FRAGMENT_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
\r
82 MAX_DRAW_BUFFERS = 1,
\r
83 MAX_ELEMENT_INDEX = 0x7FFFFFFF,
\r
84 MAX_ELEMENTS_INDICES = 0x7FFFFFFF,
\r
85 MAX_ELEMENTS_VERTICES = 0x7FFFFFFF,
\r
86 MAX_VERTEX_OUTPUT_VECTORS = 16,
\r
87 MAX_FRAGMENT_INPUT_VECTORS = 15,
\r
88 MIN_PROGRAM_TEXEL_OFFSET = -8,
\r
89 MAX_PROGRAM_TEXEL_OFFSET = 7,
\r
92 const GLenum compressedTextureFormats[] =
\r
96 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
\r
97 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
\r
98 GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE,
\r
99 GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE,
\r
101 #if (GL_ES_VERSION_3_0)
\r
102 GL_COMPRESSED_R11_EAC,
\r
103 GL_COMPRESSED_SIGNED_R11_EAC,
\r
104 GL_COMPRESSED_RG11_EAC,
\r
105 GL_COMPRESSED_SIGNED_RG11_EAC,
\r
106 GL_COMPRESSED_RGB8_ETC2,
\r
107 GL_COMPRESSED_SRGB8_ETC2,
\r
108 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
\r
109 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
\r
110 GL_COMPRESSED_RGBA8_ETC2_EAC,
\r
111 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
\r
115 const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);
\r
117 const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
\r
118 const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
\r
119 const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;
\r
120 const float ALIASED_POINT_SIZE_RANGE_MAX = 8192.0f;
\r
121 const float MAX_TEXTURE_MAX_ANISOTROPY = 16.0f;
\r
125 QUERY_ANY_SAMPLES_PASSED,
\r
126 QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE,
\r
127 QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
\r
140 // Helper structure describing a single vertex attribute
\r
141 class VertexAttribute
\r
144 VertexAttribute() : mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mDivisor(0), mPointer(NULL), mArrayEnabled(false)
\r
146 mCurrentValue[0].f = 0.0f;
\r
147 mCurrentValue[1].f = 0.0f;
\r
148 mCurrentValue[2].f = 0.0f;
\r
149 mCurrentValue[3].f = 1.0f;
\r
150 mCurrentValueType = ValueUnion::FloatType;
\r
153 int typeSize() const
\r
157 case GL_BYTE: return mSize * sizeof(GLbyte);
\r
158 case GL_UNSIGNED_BYTE: return mSize * sizeof(GLubyte);
\r
159 case GL_SHORT: return mSize * sizeof(GLshort);
\r
160 case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort);
\r
161 case GL_FIXED: return mSize * sizeof(GLfixed);
\r
162 case GL_FLOAT: return mSize * sizeof(GLfloat);
\r
163 default: UNREACHABLE(mType); return mSize * sizeof(GLfloat);
\r
167 GLsizei stride() const
\r
169 return mStride ? mStride : typeSize();
\r
172 inline float getCurrentValue(int i) const
\r
174 switch(mCurrentValueType)
\r
176 case ValueUnion::FloatType: return mCurrentValue[i].f;
\r
177 case ValueUnion::IntType: return static_cast<float>(mCurrentValue[i].i);
\r
178 case ValueUnion::UIntType: return static_cast<float>(mCurrentValue[i].ui);
\r
179 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].f;
\r
183 inline GLint getCurrentValueI(int i) const
\r
185 switch(mCurrentValueType)
\r
187 case ValueUnion::FloatType: return static_cast<GLint>(mCurrentValue[i].f);
\r
188 case ValueUnion::IntType: return mCurrentValue[i].i;
\r
189 case ValueUnion::UIntType: return static_cast<GLint>(mCurrentValue[i].ui);
\r
190 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].i;
\r
194 inline GLuint getCurrentValueUI(int i) const
\r
196 switch(mCurrentValueType)
\r
198 case ValueUnion::FloatType: return static_cast<GLuint>(mCurrentValue[i].f);
\r
199 case ValueUnion::IntType: return static_cast<GLuint>(mCurrentValue[i].i);
\r
200 case ValueUnion::UIntType: return mCurrentValue[i].ui;
\r
201 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].ui;
\r
205 inline void setCurrentValue(const GLfloat *values)
\r
207 mCurrentValue[0].f = values[0];
\r
208 mCurrentValue[1].f = values[1];
\r
209 mCurrentValue[2].f = values[2];
\r
210 mCurrentValue[3].f = values[3];
\r
211 mCurrentValueType = ValueUnion::FloatType;
\r
214 inline void setCurrentValue(const GLint *values)
\r
216 mCurrentValue[0].i = values[0];
\r
217 mCurrentValue[1].i = values[1];
\r
218 mCurrentValue[2].i = values[2];
\r
219 mCurrentValue[3].i = values[3];
\r
220 mCurrentValueType = ValueUnion::IntType;
\r
223 inline void setCurrentValue(const GLuint *values)
\r
225 mCurrentValue[0].ui = values[0];
\r
226 mCurrentValue[1].ui = values[1];
\r
227 mCurrentValue[2].ui = values[2];
\r
228 mCurrentValue[3].ui = values[3];
\r
229 mCurrentValueType = ValueUnion::UIntType;
\r
232 // From glVertexAttribPointer
\r
236 GLsizei mStride; // 0 means natural stride
\r
237 GLuint mDivisor; // From glVertexAttribDivisor
\r
241 const void *mPointer;
\r
245 gl::BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called.
\r
247 bool mArrayEnabled; // From glEnable/DisableVertexAttribArray
\r
252 enum Type { FloatType, IntType, UIntType };
\r
259 ValueUnion mCurrentValue[4]; // From glVertexAttrib
\r
260 ValueUnion::Type mCurrentValueType;
\r
263 typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS];
\r
265 // Helper structure to store all raw state
\r
268 Color colorClearValue;
\r
269 GLclampf depthClearValue;
\r
270 int stencilClearValue;
\r
272 bool cullFaceEnabled;
\r
275 bool depthTestEnabled;
\r
278 GLenum sourceBlendRGB;
\r
279 GLenum destBlendRGB;
\r
280 GLenum sourceBlendAlpha;
\r
281 GLenum destBlendAlpha;
\r
282 GLenum blendEquationRGB;
\r
283 GLenum blendEquationAlpha;
\r
285 bool stencilTestEnabled;
\r
286 GLenum stencilFunc;
\r
288 GLuint stencilMask;
\r
289 GLenum stencilFail;
\r
290 GLenum stencilPassDepthFail;
\r
291 GLenum stencilPassDepthPass;
\r
292 GLuint stencilWritemask;
\r
293 GLenum stencilBackFunc;
\r
294 GLint stencilBackRef;
\r
295 GLuint stencilBackMask;
\r
296 GLenum stencilBackFail;
\r
297 GLenum stencilBackPassDepthFail;
\r
298 GLenum stencilBackPassDepthPass;
\r
299 GLuint stencilBackWritemask;
\r
300 bool polygonOffsetFillEnabled;
\r
301 GLfloat polygonOffsetFactor;
\r
302 GLfloat polygonOffsetUnits;
\r
303 bool sampleAlphaToCoverageEnabled;
\r
304 bool sampleCoverageEnabled;
\r
305 GLclampf sampleCoverageValue;
\r
306 bool sampleCoverageInvert;
\r
307 bool scissorTestEnabled;
\r
308 bool ditherEnabled;
\r
309 bool primitiveRestartFixedIndexEnabled;
\r
310 bool rasterizerDiscardEnabled;
\r
311 bool colorLogicOpEnabled;
\r
312 GLenum logicalOperation;
\r
316 GLenum generateMipmapHint;
\r
317 GLenum fragmentShaderDerivativeHint;
\r
321 GLsizei viewportWidth;
\r
322 GLsizei viewportHeight;
\r
328 GLsizei scissorWidth;
\r
329 GLsizei scissorHeight;
\r
332 bool colorMaskGreen;
\r
333 bool colorMaskBlue;
\r
334 bool colorMaskAlpha;
\r
337 unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0
\r
338 gl::BindingPointer<Buffer> arrayBuffer;
\r
339 gl::BindingPointer<Buffer> copyReadBuffer;
\r
340 gl::BindingPointer<Buffer> copyWriteBuffer;
\r
341 gl::BindingPointer<Buffer> pixelPackBuffer;
\r
342 gl::BindingPointer<Buffer> pixelUnpackBuffer;
\r
343 gl::BindingPointer<Buffer> genericUniformBuffer;
\r
344 gl::BindingPointer<Buffer> uniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];
\r
346 GLuint readFramebuffer;
\r
347 GLuint drawFramebuffer;
\r
348 GLuint readFramebufferColorIndex;
\r
349 GLuint drawFramebufferColorIndices[MAX_COLOR_ATTACHMENTS];
\r
350 gl::BindingPointer<Renderbuffer> renderbuffer;
\r
351 GLuint currentProgram;
\r
352 GLuint vertexArray;
\r
353 GLuint transformFeedback;
\r
354 gl::BindingPointer<Sampler> sampler[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
\r
356 VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS];
\r
357 gl::BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_COMBINED_TEXTURE_IMAGE_UNITS];
\r
358 gl::BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT];
\r
360 egl::Image::UnpackInfo unpackInfo;
\r
361 GLint packAlignment;
\r
362 GLint packRowLength;
\r
363 GLint packSkipPixels;
\r
364 GLint packSkipRows;
\r
367 class Context : public egl::Context
\r
370 Context(const egl::Config *config, const Context *shareContext, EGLint clientVersion);
\r
372 virtual void makeCurrent(egl::Surface *surface);
\r
373 virtual EGLint getClientVersion() const;
\r
375 void markAllStateDirty();
\r
377 // State manipulation
\r
378 void setClearColor(float red, float green, float blue, float alpha);
\r
379 void setClearDepth(float depth);
\r
380 void setClearStencil(int stencil);
\r
382 void setCullFaceEnabled(bool enabled);
\r
383 bool isCullFaceEnabled() const;
\r
384 void setCullMode(GLenum mode);
\r
385 void setFrontFace(GLenum front);
\r
387 void setDepthTestEnabled(bool enabled);
\r
388 bool isDepthTestEnabled() const;
\r
389 void setDepthFunc(GLenum depthFunc);
\r
390 void setDepthRange(float zNear, float zFar);
\r
392 void setBlendEnabled(bool enabled);
\r
393 bool isBlendEnabled() const;
\r
394 void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
\r
395 void setBlendColor(float red, float green, float blue, float alpha);
\r
396 void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
\r
398 void setStencilTestEnabled(bool enabled);
\r
399 bool isStencilTestEnabled() const;
\r
400 void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
\r
401 void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
\r
402 void setStencilWritemask(GLuint stencilWritemask);
\r
403 void setStencilBackWritemask(GLuint stencilBackWritemask);
\r
404 void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
\r
405 void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);
\r
407 void setPolygonOffsetFillEnabled(bool enabled);
\r
408 bool isPolygonOffsetFillEnabled() const;
\r
409 void setPolygonOffsetParams(GLfloat factor, GLfloat units);
\r
411 void setSampleAlphaToCoverageEnabled(bool enabled);
\r
412 bool isSampleAlphaToCoverageEnabled() const;
\r
413 void setSampleCoverageEnabled(bool enabled);
\r
414 bool isSampleCoverageEnabled() const;
\r
415 void setSampleCoverageParams(GLclampf value, bool invert);
\r
417 void setDitherEnabled(bool enabled);
\r
418 bool isDitherEnabled() const;
\r
420 void setPrimitiveRestartFixedIndexEnabled(bool enabled);
\r
421 bool isPrimitiveRestartFixedIndexEnabled() const;
\r
423 void setRasterizerDiscardEnabled(bool enabled);
\r
424 bool isRasterizerDiscardEnabled() const;
\r
426 void setLineWidth(GLfloat width);
\r
428 void setGenerateMipmapHint(GLenum hint);
\r
429 void setFragmentShaderDerivativeHint(GLenum hint);
\r
431 void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
\r
433 void setScissorTestEnabled(bool enabled);
\r
434 bool isScissorTestEnabled() const;
\r
435 void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
\r
437 void setColorMask(bool red, bool green, bool blue, bool alpha);
\r
438 unsigned int getColorMask() const;
\r
439 void setDepthMask(bool mask);
\r
441 void setActiveSampler(unsigned int active);
\r
443 GLuint getReadFramebufferName() const;
\r
444 GLuint getDrawFramebufferName() const;
\r
445 GLuint getRenderbufferName() const;
\r
447 void setReadFramebufferColorIndex(GLuint index);
\r
448 void setDrawFramebufferColorIndices(GLsizei n, const GLenum *bufs);
\r
449 GLuint getReadFramebufferColorIndex() const;
\r
451 GLuint getActiveQuery(GLenum target) const;
\r
453 GLuint getArrayBufferName() const;
\r
454 GLuint getElementArrayBufferName() const;
\r
456 void setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled);
\r
457 void setVertexAttribDivisor(unsigned int attribNum, GLuint divisor);
\r
458 const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;
\r
459 void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
\r
460 bool normalized, GLsizei stride, const void *pointer);
\r
461 const void *getVertexAttribPointer(unsigned int attribNum) const;
\r
463 const VertexAttributeArray &getVertexArrayAttributes();
\r
464 // Context attribute current values can be queried independently from VAO current values
\r
465 const VertexAttributeArray &getCurrentVertexAttributes();
\r
467 void setUnpackAlignment(GLint alignment);
\r
468 void setUnpackRowLength(GLint rowLength);
\r
469 void setUnpackImageHeight(GLint imageHeight);
\r
470 void setUnpackSkipPixels(GLint skipPixels);
\r
471 void setUnpackSkipRows(GLint skipRows);
\r
472 void setUnpackSkipImages(GLint skipImages);
\r
473 const egl::Image::UnpackInfo& getUnpackInfo() const;
\r
475 void setPackAlignment(GLint alignment);
\r
476 void setPackRowLength(GLint rowLength);
\r
477 void setPackSkipPixels(GLint skipPixels);
\r
478 void setPackSkipRows(GLint skipRows);
\r
480 // These create and destroy methods are merely pass-throughs to
\r
481 // ResourceManager, which owns these object types
\r
482 GLuint createBuffer();
\r
483 GLuint createShader(GLenum type);
\r
484 GLuint createProgram();
\r
485 GLuint createTexture();
\r
486 GLuint createRenderbuffer();
\r
487 GLuint createSampler();
\r
488 GLsync createFenceSync(GLenum condition, GLbitfield flags);
\r
490 void deleteBuffer(GLuint buffer);
\r
491 void deleteShader(GLuint shader);
\r
492 void deleteProgram(GLuint program);
\r
493 void deleteTexture(GLuint texture);
\r
494 void deleteRenderbuffer(GLuint renderbuffer);
\r
495 void deleteSampler(GLuint sampler);
\r
496 void deleteFenceSync(GLsync fenceSync);
\r
498 // Framebuffers are owned by the Context, so these methods do not pass through
\r
499 GLuint createFramebuffer();
\r
500 void deleteFramebuffer(GLuint framebuffer);
\r
502 // Fences are owned by the Context
\r
503 GLuint createFence();
\r
504 void deleteFence(GLuint fence);
\r
506 // Queries are owned by the Context
\r
507 GLuint createQuery();
\r
508 void deleteQuery(GLuint query);
\r
510 // Vertex arrays are owned by the Context
\r
511 GLuint createVertexArray();
\r
512 void deleteVertexArray(GLuint array);
\r
514 // Transform feedbacks are owned by the Context
\r
515 GLuint createTransformFeedback();
\r
516 void deleteTransformFeedback(GLuint transformFeedback);
\r
518 void bindArrayBuffer(GLuint buffer);
\r
519 void bindElementArrayBuffer(GLuint buffer);
\r
520 void bindCopyReadBuffer(GLuint buffer);
\r
521 void bindCopyWriteBuffer(GLuint buffer);
\r
522 void bindPixelPackBuffer(GLuint buffer);
\r
523 void bindPixelUnpackBuffer(GLuint buffer);
\r
524 void bindTransformFeedbackBuffer(GLuint buffer);
\r
525 void bindTexture2D(GLuint texture);
\r
526 void bindTextureCubeMap(GLuint texture);
\r
527 void bindTextureExternal(GLuint texture);
\r
528 void bindTexture3D(GLuint texture);
\r
529 void bindTexture2DArray(GLuint texture);
\r
530 void bindReadFramebuffer(GLuint framebuffer);
\r
531 void bindDrawFramebuffer(GLuint framebuffer);
\r
532 void bindRenderbuffer(GLuint renderbuffer);
\r
533 bool bindVertexArray(GLuint array);
\r
534 void bindGenericUniformBuffer(GLuint buffer);
\r
535 void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
\r
536 void bindGenericTransformFeedbackBuffer(GLuint buffer);
\r
537 void bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
\r
538 bool bindTransformFeedback(GLuint transformFeedback);
\r
539 bool bindSampler(GLuint unit, GLuint sampler);
\r
540 void useProgram(GLuint program);
\r
542 void beginQuery(GLenum target, GLuint query);
\r
543 void endQuery(GLenum target);
\r
545 void setFramebufferZero(Framebuffer *framebuffer);
\r
547 void setRenderbufferStorage(RenderbufferStorage *renderbuffer);
\r
549 void setVertexAttrib(GLuint index, const GLfloat *values);
\r
550 void setVertexAttrib(GLuint index, const GLint *values);
\r
551 void setVertexAttrib(GLuint index, const GLuint *values);
\r
553 Buffer *getBuffer(GLuint handle) const;
\r
554 Fence *getFence(GLuint handle) const;
\r
555 FenceSync *getFenceSync(GLsync handle) const;
\r
556 Shader *getShader(GLuint handle) const;
\r
557 Program *getProgram(GLuint handle) const;
\r
558 virtual Texture *getTexture(GLuint handle) const;
\r
559 Framebuffer *getFramebuffer(GLuint handle) const;
\r
560 virtual Renderbuffer *getRenderbuffer(GLuint handle) const;
\r
561 Query *getQuery(GLuint handle) const;
\r
562 VertexArray *getVertexArray(GLuint array) const;
\r
563 VertexArray *getCurrentVertexArray() const;
\r
564 TransformFeedback *getTransformFeedback(GLuint transformFeedback) const;
\r
565 TransformFeedback *getTransformFeedback() const;
\r
566 Sampler *getSampler(GLuint sampler) const;
\r
567 bool isSampler(GLuint sampler) const;
\r
569 Buffer *getArrayBuffer() const;
\r
570 Buffer *getElementArrayBuffer() const;
\r
571 Buffer *getCopyReadBuffer() const;
\r
572 Buffer *getCopyWriteBuffer() const;
\r
573 Buffer *getPixelPackBuffer() const;
\r
574 Buffer *getPixelUnpackBuffer() const;
\r
575 Buffer *getGenericUniformBuffer() const;
\r
576 bool getBuffer(GLenum target, es2::Buffer **buffer) const;
\r
577 Program *getCurrentProgram() const;
\r
578 Texture2D *getTexture2D() const;
\r
579 Texture3D *getTexture3D() const;
\r
580 Texture2DArray *getTexture2DArray() const;
\r
581 TextureCubeMap *getTextureCubeMap() const;
\r
582 TextureExternal *getTextureExternal() const;
\r
583 Texture *getSamplerTexture(unsigned int sampler, TextureType type) const;
\r
584 Framebuffer *getReadFramebuffer() const;
\r
585 Framebuffer *getDrawFramebuffer() const;
\r
587 bool getFloatv(GLenum pname, GLfloat *params) const;
\r
588 template<typename T> bool getIntegerv(GLenum pname, T *params) const;
\r
589 bool getBooleanv(GLenum pname, GLboolean *params) const;
\r
590 template<typename T> bool getTransformFeedbackiv(GLuint xfb, GLenum pname, T *param) const;
\r
591 void samplerParameteri(GLuint sampler, GLenum pname, GLint param);
\r
592 void samplerParameterf(GLuint sampler, GLenum pname, GLfloat param);
\r
593 GLint getSamplerParameteri(GLuint sampler, GLenum pname);
\r
594 GLfloat getSamplerParameterf(GLuint sampler, GLenum pname);
\r
596 bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const;
\r
598 bool hasZeroDivisor() const;
\r
600 void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);
\r
601 void clear(GLbitfield mask);
\r
602 void clearColorBuffer(GLint drawbuffer, const GLint *value);
\r
603 void clearColorBuffer(GLint drawbuffer, const GLuint *value);
\r
604 void clearColorBuffer(GLint drawbuffer, const GLfloat *value);
\r
605 void clearDepthBuffer(GLint drawbuffer, const GLfloat *value);
\r
606 void clearStencilBuffer(GLint drawbuffer, const GLint *value);
\r
607 void clearDepthStencilBuffer(GLint drawbuffer, GLfloat depth, GLint stencil);
\r
608 void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount = 1);
\r
609 void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount = 1);
\r
613 void recordInvalidEnum();
\r
614 void recordInvalidValue();
\r
615 void recordInvalidOperation();
\r
616 void recordOutOfMemory();
\r
617 void recordInvalidFramebufferOperation();
\r
621 static int getSupportedMultiSampleDepth(sw::Format format, int requested);
\r
623 void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
\r
624 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
\r
627 virtual void bindTexImage(egl::Surface *surface);
\r
628 virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
\r
629 virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
\r
631 Device *getDevice();
\r
633 const GLubyte* getExtensions(GLuint index, GLuint* numExt = nullptr) const;
\r
636 virtual ~Context();
\r
638 egl::Image *getScissoredImage(GLint drawbuffer, int &x0, int &y0, int &width, int &height, bool depthStencil);
\r
639 void applyScissor(int width, int height);
\r
640 bool applyRenderTarget();
\r
641 void applyState(GLenum drawMode);
\r
642 GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count, GLsizei instanceId);
\r
643 GLenum applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
\r
644 void applyShaders();
\r
645 void applyTextures();
\r
646 void applyTextures(sw::SamplerType type);
\r
647 void applyTexture(sw::SamplerType type, int sampler, Texture *texture);
\r
649 void detachBuffer(GLuint buffer);
\r
650 void detachTexture(GLuint texture);
\r
651 void detachFramebuffer(GLuint framebuffer);
\r
652 void detachRenderbuffer(GLuint renderbuffer);
\r
653 void detachSampler(GLuint sampler);
\r
655 bool cullSkipsDraw(GLenum drawMode);
\r
656 bool isTriangleMode(GLenum drawMode);
\r
658 Query *createQuery(GLuint handle, GLenum type);
\r
660 const EGLint clientVersion;
\r
661 const egl::Config *const mConfig;
\r
665 gl::BindingPointer<Texture2D> mTexture2DZero;
\r
666 gl::BindingPointer<Texture3D> mTexture3DZero;
\r
667 gl::BindingPointer<Texture2DArray> mTexture2DArrayZero;
\r
668 gl::BindingPointer<TextureCubeMap> mTextureCubeMapZero;
\r
669 gl::BindingPointer<TextureExternal> mTextureExternalZero;
\r
671 typedef std::map<GLint, Framebuffer*> FramebufferMap;
\r
672 FramebufferMap mFramebufferMap;
\r
673 gl::NameSpace mFramebufferNameSpace;
\r
675 typedef std::map<GLint, Fence*> FenceMap;
\r
676 FenceMap mFenceMap;
\r
677 gl::NameSpace mFenceNameSpace;
\r
679 typedef std::map<GLint, Query*> QueryMap;
\r
680 QueryMap mQueryMap;
\r
681 gl::NameSpace mQueryNameSpace;
\r
683 typedef std::map<GLint, VertexArray*> VertexArrayMap;
\r
684 VertexArrayMap mVertexArrayMap;
\r
685 gl::NameSpace mVertexArrayNameSpace;
\r
687 typedef std::map<GLint, TransformFeedback*> TransformFeedbackMap;
\r
688 TransformFeedbackMap mTransformFeedbackMap;
\r
689 gl::NameSpace mTransformFeedbackNameSpace;
\r
691 VertexDataManager *mVertexDataManager;
\r
692 IndexDataManager *mIndexDataManager;
\r
696 bool mInvalidValue;
\r
697 bool mInvalidOperation;
\r
699 bool mInvalidFramebufferOperation;
\r
701 bool mHasBeenCurrent;
\r
703 unsigned int mAppliedProgramSerial;
\r
705 // state caching flags
\r
706 bool mDepthStateDirty;
\r
707 bool mMaskStateDirty;
\r
708 bool mPixelPackingStateDirty;
\r
709 bool mBlendStateDirty;
\r
710 bool mStencilStateDirty;
\r
711 bool mPolygonOffsetStateDirty;
\r
712 bool mSampleStateDirty;
\r
713 bool mFrontFaceDirty;
\r
714 bool mDitherStateDirty;
\r
717 ResourceManager *mResourceManager;
\r
721 #endif // INCLUDE_CONTEXT_H_
\r