blob: e3865e7c847eda8c8ab48d768cbf7bf4b0e2cab3 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Context.h: Defines the Context class, managing all GL state and performing
16// rendering operations. It is the GLES2 specific implementation of EGLContext.
17
18#ifndef LIBGLESV2_CONTEXT_H_
19#define LIBGLESV2_CONTEXT_H_
20
21#include "ResourceManager.h"
22#include "Buffer.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"
28
29#include <GLES2/gl2.h>
30#include <GLES2/gl2ext.h>
31#include <GLES3/gl3.h>
32#include <EGL/egl.h>
33
34#include <map>
35#include <string>
36
37namespace egl
38{
39class Display;
40class Surface;
41class Config;
42}
43
44namespace es2
45{
46struct TranslatedAttribute;
47struct TranslatedIndexData;
48
49class Device;
50class Shader;
51class Program;
52class Texture;
53class Texture2D;
54class Texture3D;
55class Texture2DArray;
56class TextureCubeMap;
57class TextureExternal;
58class Framebuffer;
59class Renderbuffer;
60class RenderbufferStorage;
61class Colorbuffer;
62class Depthbuffer;
63class StreamingIndexBuffer;
64class Stencilbuffer;
65class DepthStencilbuffer;
66class VertexDataManager;
67class IndexDataManager;
68class Fence;
69class FenceSync;
70class Query;
71class Sampler;
72class VertexArray;
73class TransformFeedback;
74
75enum
76{
Nicolas Capensf0aef1a2016-05-18 14:44:21 -040077 MAX_VERTEX_ATTRIBS = sw::MAX_VERTEX_INPUTS,
Nicolas Capens0bac2852016-05-07 06:09:58 -040078 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,
Nicolas Capense7e70d02016-06-07 14:40:12 -040090 MIN_PROGRAM_TEXEL_OFFSET = sw::MIN_PROGRAM_TEXEL_OFFSET,
Meng-Lin Wu2337a192016-06-01 13:54:07 -040091 MAX_PROGRAM_TEXEL_OFFSET = sw::MAX_PROGRAM_TEXEL_OFFSET,
Nicolas Capens0bac2852016-05-07 06:09:58 -040092 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,
106};
107
108const GLenum compressedTextureFormats[] =
109{
110 GL_ETC1_RGB8_OES,
111#if (S3TC_SUPPORT)
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,
116#endif
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,
156#endif
157};
158
159const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);
160
161const GLint multisampleCount[] = {4, 2, 1};
162const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]);
163const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0];
164
165const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
166const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
167const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;
168const float ALIASED_POINT_SIZE_RANGE_MAX = 8192.0f;
169const float MAX_TEXTURE_MAX_ANISOTROPY = 16.0f;
170
171enum QueryType
172{
173 QUERY_ANY_SAMPLES_PASSED,
174 QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE,
175 QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
176
177 QUERY_TYPE_COUNT
178};
179
180struct Color
181{
182 float red;
183 float green;
184 float blue;
185 float alpha;
186};
187
188// Helper structure describing a single vertex attribute
189class VertexAttribute
190{
191public:
192 VertexAttribute() : mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mDivisor(0), mPointer(nullptr), mArrayEnabled(false)
193 {
194 mCurrentValue[0].f = 0.0f;
195 mCurrentValue[1].f = 0.0f;
196 mCurrentValue[2].f = 0.0f;
197 mCurrentValue[3].f = 1.0f;
Alexis Hetu6125b662016-12-13 11:18:54 -0500198 mCurrentValueType = GL_FLOAT;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400199 }
200
201 int typeSize() const
202 {
203 switch(mType)
204 {
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);
Alexis Hetu70085ba2016-05-13 22:40:02 -0400213 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);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400216 default: UNREACHABLE(mType); return mSize * sizeof(GLfloat);
217 }
218 }
219
Alexis Hetu6125b662016-12-13 11:18:54 -0500220 GLenum currentValueType() const
221 {
222 return mCurrentValueType;
223 }
224
Nicolas Capens0bac2852016-05-07 06:09:58 -0400225 GLsizei stride() const
226 {
227 return mStride ? mStride : typeSize();
228 }
229
230 inline float getCurrentValueBitsAsFloat(int i) const
231 {
232 return mCurrentValue[i].f;
233 }
234
235 inline float getCurrentValueF(int i) const
236 {
237 switch(mCurrentValueType)
238 {
Alexis Hetu6125b662016-12-13 11:18:54 -0500239 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);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400242 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].f;
243 }
244 }
245
246 inline GLint getCurrentValueI(int i) const
247 {
248 switch(mCurrentValueType)
249 {
Alexis Hetu6125b662016-12-13 11:18:54 -0500250 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);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400253 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].i;
254 }
255 }
256
257 inline GLuint getCurrentValueUI(int i) const
258 {
259 switch(mCurrentValueType)
260 {
Alexis Hetu6125b662016-12-13 11:18:54 -0500261 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;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400264 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].ui;
265 }
266 }
267
268 inline void setCurrentValue(const GLfloat *values)
269 {
270 mCurrentValue[0].f = values[0];
271 mCurrentValue[1].f = values[1];
272 mCurrentValue[2].f = values[2];
273 mCurrentValue[3].f = values[3];
Alexis Hetu6125b662016-12-13 11:18:54 -0500274 mCurrentValueType = GL_FLOAT;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400275 }
276
277 inline void setCurrentValue(const GLint *values)
278 {
279 mCurrentValue[0].i = values[0];
280 mCurrentValue[1].i = values[1];
281 mCurrentValue[2].i = values[2];
282 mCurrentValue[3].i = values[3];
Alexis Hetu6125b662016-12-13 11:18:54 -0500283 mCurrentValueType = GL_INT;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400284 }
285
286 inline void setCurrentValue(const GLuint *values)
287 {
288 mCurrentValue[0].ui = values[0];
289 mCurrentValue[1].ui = values[1];
290 mCurrentValue[2].ui = values[2];
291 mCurrentValue[3].ui = values[3];
Alexis Hetu6125b662016-12-13 11:18:54 -0500292 mCurrentValueType = GL_UNSIGNED_INT;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400293 }
294
295 // From glVertexAttribPointer
296 GLenum mType;
297 GLint mSize;
298 bool mNormalized;
299 GLsizei mStride; // 0 means natural stride
300 GLuint mDivisor; // From glVertexAttribDivisor
301
302 union
303 {
304 const void *mPointer;
305 intptr_t mOffset;
306 };
307
308 gl::BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called.
309
310 bool mArrayEnabled; // From glEnable/DisableVertexAttribArray
311
312private:
313 union ValueUnion
314 {
Nicolas Capens0bac2852016-05-07 06:09:58 -0400315 float f;
316 GLint i;
317 GLuint ui;
318 };
319
320 ValueUnion mCurrentValue[4]; // From glVertexAttrib
Alexis Hetu6125b662016-12-13 11:18:54 -0500321 GLenum mCurrentValueType;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400322};
323
324typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS];
325
326// Helper structure to store all raw state
327struct State
328{
329 Color colorClearValue;
330 GLclampf depthClearValue;
331 int stencilClearValue;
332
333 bool cullFaceEnabled;
334 GLenum cullMode;
335 GLenum frontFace;
336 bool depthTestEnabled;
337 GLenum depthFunc;
338 bool blendEnabled;
339 GLenum sourceBlendRGB;
340 GLenum destBlendRGB;
341 GLenum sourceBlendAlpha;
342 GLenum destBlendAlpha;
343 GLenum blendEquationRGB;
344 GLenum blendEquationAlpha;
345 Color blendColor;
346 bool stencilTestEnabled;
347 GLenum stencilFunc;
348 GLint stencilRef;
349 GLuint stencilMask;
350 GLenum stencilFail;
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;
369 bool ditherEnabled;
370 bool primitiveRestartFixedIndexEnabled;
371 bool rasterizerDiscardEnabled;
372 bool colorLogicOpEnabled;
373 GLenum logicalOperation;
374
375 GLfloat lineWidth;
376
377 GLenum generateMipmapHint;
378 GLenum fragmentShaderDerivativeHint;
379
380 GLint viewportX;
381 GLint viewportY;
382 GLsizei viewportWidth;
383 GLsizei viewportHeight;
384 float zNear;
385 float zFar;
386
387 GLint scissorX;
388 GLint scissorY;
389 GLsizei scissorWidth;
390 GLsizei scissorHeight;
391
392 bool colorMaskRed;
393 bool colorMaskGreen;
394 bool colorMaskBlue;
395 bool colorMaskAlpha;
396 bool depthMask;
397
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];
406
407 GLuint readFramebuffer;
408 GLuint drawFramebuffer;
409 gl::BindingPointer<Renderbuffer> renderbuffer;
410 GLuint currentProgram;
411 GLuint vertexArray;
412 GLuint transformFeedback;
413 gl::BindingPointer<Sampler> sampler[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
414
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];
418
419 egl::Image::UnpackInfo unpackInfo;
420 GLint packAlignment;
421 GLint packRowLength;
422 GLint packImageHeight;
423 GLint packSkipPixels;
424 GLint packSkipRows;
425 GLint packSkipImages;
426};
427
428class Context : public egl::Context
429{
430public:
Alexis Hetucc5c4642016-06-08 15:04:56 -0400431 Context(egl::Display *display, const Context *shareContext, EGLint clientVersion);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400432
433 virtual void makeCurrent(egl::Surface *surface);
434 virtual EGLint getClientVersion() const;
435
436 void markAllStateDirty();
437
438 // State manipulation
439 void setClearColor(float red, float green, float blue, float alpha);
440 void setClearDepth(float depth);
441 void setClearStencil(int stencil);
442
443 void setCullFaceEnabled(bool enabled);
444 bool isCullFaceEnabled() const;
445 void setCullMode(GLenum mode);
446 void setFrontFace(GLenum front);
447
448 void setDepthTestEnabled(bool enabled);
449 bool isDepthTestEnabled() const;
450 void setDepthFunc(GLenum depthFunc);
451 void setDepthRange(float zNear, float zFar);
452
453 void setBlendEnabled(bool enabled);
454 bool isBlendEnabled() const;
455 void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
456 void setBlendColor(float red, float green, float blue, float alpha);
457 void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
458
459 void setStencilTestEnabled(bool enabled);
460 bool isStencilTestEnabled() const;
461 void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
462 void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
463 void setStencilWritemask(GLuint stencilWritemask);
464 void setStencilBackWritemask(GLuint stencilBackWritemask);
465 void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
466 void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);
467
468 void setPolygonOffsetFillEnabled(bool enabled);
469 bool isPolygonOffsetFillEnabled() const;
470 void setPolygonOffsetParams(GLfloat factor, GLfloat units);
471
472 void setSampleAlphaToCoverageEnabled(bool enabled);
473 bool isSampleAlphaToCoverageEnabled() const;
474 void setSampleCoverageEnabled(bool enabled);
475 bool isSampleCoverageEnabled() const;
476 void setSampleCoverageParams(GLclampf value, bool invert);
477
478 void setDitherEnabled(bool enabled);
479 bool isDitherEnabled() const;
480
481 void setPrimitiveRestartFixedIndexEnabled(bool enabled);
482 bool isPrimitiveRestartFixedIndexEnabled() const;
483
484 void setRasterizerDiscardEnabled(bool enabled);
485 bool isRasterizerDiscardEnabled() const;
486
487 void setLineWidth(GLfloat width);
488
489 void setGenerateMipmapHint(GLenum hint);
490 void setFragmentShaderDerivativeHint(GLenum hint);
491
492 void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
493
494 void setScissorTestEnabled(bool enabled);
495 bool isScissorTestEnabled() const;
496 void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
497
498 void setColorMask(bool red, bool green, bool blue, bool alpha);
499 unsigned int getColorMask() const;
500 void setDepthMask(bool mask);
501
502 void setActiveSampler(unsigned int active);
503
504 GLuint getReadFramebufferName() const;
505 GLuint getDrawFramebufferName() const;
506 GLuint getRenderbufferName() const;
507
508 void setFramebufferReadBuffer(GLenum buf);
509 void setFramebufferDrawBuffers(GLsizei n, const GLenum *bufs);
510 GLuint getReadFramebufferColorIndex() const;
511
512 GLuint getActiveQuery(GLenum target) const;
513
514 GLuint getArrayBufferName() const;
515 GLuint getElementArrayBufferName() const;
516
517 void setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled);
518 void setVertexAttribDivisor(unsigned int attribNum, GLuint divisor);
519 const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;
520 void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
521 bool normalized, GLsizei stride, const void *pointer);
522 const void *getVertexAttribPointer(unsigned int attribNum) const;
523
524 const VertexAttributeArray &getVertexArrayAttributes();
525 // Context attribute current values can be queried independently from VAO current values
526 const VertexAttributeArray &getCurrentVertexAttributes();
527
528 void setUnpackAlignment(GLint alignment);
529 void setUnpackRowLength(GLint rowLength);
530 void setUnpackImageHeight(GLint imageHeight);
531 void setUnpackSkipPixels(GLint skipPixels);
532 void setUnpackSkipRows(GLint skipRows);
533 void setUnpackSkipImages(GLint skipImages);
534 const egl::Image::UnpackInfo& getUnpackInfo() const;
535
536 void setPackAlignment(GLint alignment);
537 void setPackRowLength(GLint rowLength);
538 void setPackImageHeight(GLint imageHeight);
539 void setPackSkipPixels(GLint skipPixels);
540 void setPackSkipRows(GLint skipRows);
541 void setPackSkipImages(GLint skipImages);
542
543 // These create and destroy methods are merely pass-throughs to
544 // ResourceManager, which owns these object types
545 GLuint createBuffer();
546 GLuint createShader(GLenum type);
547 GLuint createProgram();
548 GLuint createTexture();
549 GLuint createRenderbuffer();
550 GLuint createSampler();
551 GLsync createFenceSync(GLenum condition, GLbitfield flags);
552
553 void deleteBuffer(GLuint buffer);
554 void deleteShader(GLuint shader);
555 void deleteProgram(GLuint program);
556 void deleteTexture(GLuint texture);
557 void deleteRenderbuffer(GLuint renderbuffer);
558 void deleteSampler(GLuint sampler);
559 void deleteFenceSync(GLsync fenceSync);
560
561 // Framebuffers are owned by the Context, so these methods do not pass through
562 GLuint createFramebuffer();
563 void deleteFramebuffer(GLuint framebuffer);
564
565 // Fences are owned by the Context
566 GLuint createFence();
567 void deleteFence(GLuint fence);
568
569 // Queries are owned by the Context
570 GLuint createQuery();
571 void deleteQuery(GLuint query);
572
573 // Vertex arrays are owned by the Context
574 GLuint createVertexArray();
575 void deleteVertexArray(GLuint array);
576
577 // Transform feedbacks are owned by the Context
578 GLuint createTransformFeedback();
579 void deleteTransformFeedback(GLuint transformFeedback);
580
581 void bindArrayBuffer(GLuint buffer);
582 void bindElementArrayBuffer(GLuint buffer);
583 void bindCopyReadBuffer(GLuint buffer);
584 void bindCopyWriteBuffer(GLuint buffer);
585 void bindPixelPackBuffer(GLuint buffer);
586 void bindPixelUnpackBuffer(GLuint buffer);
587 void bindTransformFeedbackBuffer(GLuint buffer);
588 void bindTexture2D(GLuint texture);
589 void bindTextureCubeMap(GLuint texture);
590 void bindTextureExternal(GLuint texture);
591 void bindTexture3D(GLuint texture);
592 void bindTexture2DArray(GLuint texture);
593 void bindReadFramebuffer(GLuint framebuffer);
594 void bindDrawFramebuffer(GLuint framebuffer);
595 void bindRenderbuffer(GLuint renderbuffer);
596 void bindVertexArray(GLuint array);
597 void bindGenericUniformBuffer(GLuint buffer);
598 void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
599 void bindGenericTransformFeedbackBuffer(GLuint buffer);
600 void bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
601 void bindTransformFeedback(GLuint transformFeedback);
602 bool bindSampler(GLuint unit, GLuint sampler);
603 void useProgram(GLuint program);
604
605 void beginQuery(GLenum target, GLuint query);
606 void endQuery(GLenum target);
607
608 void setFramebufferZero(Framebuffer *framebuffer);
609
610 void setRenderbufferStorage(RenderbufferStorage *renderbuffer);
611
612 void setVertexAttrib(GLuint index, const GLfloat *values);
613 void setVertexAttrib(GLuint index, const GLint *values);
614 void setVertexAttrib(GLuint index, const GLuint *values);
615
616 Buffer *getBuffer(GLuint handle) const;
617 Fence *getFence(GLuint handle) const;
618 FenceSync *getFenceSync(GLsync handle) const;
619 Shader *getShader(GLuint handle) const;
620 Program *getProgram(GLuint handle) const;
621 virtual Texture *getTexture(GLuint handle) const;
622 Framebuffer *getFramebuffer(GLuint handle) const;
623 virtual Renderbuffer *getRenderbuffer(GLuint handle) const;
624 Query *getQuery(GLuint handle) const;
625 VertexArray *getVertexArray(GLuint array) const;
626 VertexArray *getCurrentVertexArray() const;
627 bool isVertexArray(GLuint array) const;
628 TransformFeedback *getTransformFeedback(GLuint transformFeedback) const;
629 TransformFeedback *getTransformFeedback() const;
630 Sampler *getSampler(GLuint sampler) const;
631 bool isSampler(GLuint sampler) const;
632
633 Buffer *getArrayBuffer() const;
634 Buffer *getElementArrayBuffer() const;
635 Buffer *getCopyReadBuffer() const;
636 Buffer *getCopyWriteBuffer() const;
637 Buffer *getPixelPackBuffer() const;
638 Buffer *getPixelUnpackBuffer() const;
639 Buffer *getGenericUniformBuffer() const;
Alexis Hetu53f48092016-06-17 14:08:06 -0400640 const GLvoid* getPixels(const GLvoid* data) const;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400641 bool getBuffer(GLenum target, es2::Buffer **buffer) const;
642 Program *getCurrentProgram() const;
643 Texture2D *getTexture2D() const;
644 Texture3D *getTexture3D() const;
645 Texture2DArray *getTexture2DArray() const;
646 TextureCubeMap *getTextureCubeMap() const;
647 TextureExternal *getTextureExternal() const;
648 Texture *getSamplerTexture(unsigned int sampler, TextureType type) const;
649 Framebuffer *getReadFramebuffer() const;
650 Framebuffer *getDrawFramebuffer() const;
651
652 bool getFloatv(GLenum pname, GLfloat *params) const;
653 template<typename T> bool getIntegerv(GLenum pname, T *params) const;
654 bool getBooleanv(GLenum pname, GLboolean *params) const;
655 template<typename T> bool getTransformFeedbackiv(GLuint index, GLenum pname, T *param) const;
656 template<typename T> bool getUniformBufferiv(GLuint index, GLenum pname, T *param) const;
657 void samplerParameteri(GLuint sampler, GLenum pname, GLint param);
658 void samplerParameterf(GLuint sampler, GLenum pname, GLfloat param);
659 GLint getSamplerParameteri(GLuint sampler, GLenum pname);
660 GLfloat getSamplerParameterf(GLuint sampler, GLenum pname);
661
662 bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const;
663
664 bool hasZeroDivisor() const;
665
666 void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);
667 void clear(GLbitfield mask);
668 void clearColorBuffer(GLint drawbuffer, const GLint *value);
669 void clearColorBuffer(GLint drawbuffer, const GLuint *value);
670 void clearColorBuffer(GLint drawbuffer, const GLfloat *value);
671 void clearDepthBuffer(const GLfloat value);
672 void clearStencilBuffer(const GLint value);
673 void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount = 1);
674 void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount = 1);
675 void finish();
676 void flush();
677
678 void recordInvalidEnum();
679 void recordInvalidValue();
680 void recordInvalidOperation();
681 void recordOutOfMemory();
682 void recordInvalidFramebufferOperation();
683
684 GLenum getError();
685
686 static int getSupportedMultisampleCount(int requested);
687
688 void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
689 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
Alexis Hetub9dda642016-10-06 11:25:32 -0400690 GLbitfield mask, bool filter, bool allowPartialDepthStencilBlit);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400691
692 virtual void bindTexImage(egl::Surface *surface);
693 virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
694 virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
Nicolas Capens58df2f62016-06-07 14:48:56 -0400695 egl::Image *getSharedImage(GLeglImageOES image);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400696
697 Device *getDevice();
698
699 const GLubyte* getExtensions(GLuint index, GLuint* numExt = nullptr) const;
700
701private:
702 virtual ~Context();
703
704 void applyScissor(int width, int height);
705 bool applyRenderTarget();
706 void applyState(GLenum drawMode);
707 GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count, GLsizei instanceId);
708 GLenum applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
709 void applyShaders();
710 void applyTextures();
711 void applyTextures(sw::SamplerType type);
712 void applyTexture(sw::SamplerType type, int sampler, Texture *texture);
713 void clearColorBuffer(GLint drawbuffer, void *value, sw::Format format);
714
715 void detachBuffer(GLuint buffer);
716 void detachTexture(GLuint texture);
717 void detachFramebuffer(GLuint framebuffer);
718 void detachRenderbuffer(GLuint renderbuffer);
719 void detachSampler(GLuint sampler);
720
721 bool cullSkipsDraw(GLenum drawMode);
722 bool isTriangleMode(GLenum drawMode);
723
724 Query *createQuery(GLuint handle, GLenum type);
725
726 const EGLint clientVersion;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400727
728 State mState;
729
730 gl::BindingPointer<Texture2D> mTexture2DZero;
731 gl::BindingPointer<Texture3D> mTexture3DZero;
732 gl::BindingPointer<Texture2DArray> mTexture2DArrayZero;
733 gl::BindingPointer<TextureCubeMap> mTextureCubeMapZero;
734 gl::BindingPointer<TextureExternal> mTextureExternalZero;
735
736 gl::NameSpace<Framebuffer> mFramebufferNameSpace;
737 gl::NameSpace<Fence, 0> mFenceNameSpace;
738 gl::NameSpace<Query> mQueryNameSpace;
739 gl::NameSpace<VertexArray> mVertexArrayNameSpace;
740 gl::NameSpace<TransformFeedback> mTransformFeedbackNameSpace;
741
742 VertexDataManager *mVertexDataManager;
743 IndexDataManager *mIndexDataManager;
744
745 // Recorded errors
746 bool mInvalidEnum;
747 bool mInvalidValue;
748 bool mInvalidOperation;
749 bool mOutOfMemory;
750 bool mInvalidFramebufferOperation;
751
752 bool mHasBeenCurrent;
753
754 unsigned int mAppliedProgramSerial;
755
756 // state caching flags
757 bool mDepthStateDirty;
758 bool mMaskStateDirty;
759 bool mBlendStateDirty;
760 bool mStencilStateDirty;
761 bool mPolygonOffsetStateDirty;
762 bool mSampleStateDirty;
763 bool mFrontFaceDirty;
764 bool mDitherStateDirty;
765
766 Device *device;
767 ResourceManager *mResourceManager;
768};
769}
770
771#endif // INCLUDE_CONTEXT_H_