1 //
2 // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // Context.h: Defines the gl::Context class, managing all GL state and performing
8 // rendering operations. It is the GLES2 specific implementation of EGLContext.
9
10 #ifndef LIBANGLE_CONTEXT_H_
11 #define LIBANGLE_CONTEXT_H_
12
13 #include <set>
14 #include <string>
15
16 #include "angle_gl.h"
17 #include "common/MemoryBuffer.h"
18 #include "common/angleutils.h"
19 #include "libANGLE/Caps.h"
20 #include "libANGLE/Constants.h"
21 #include "libANGLE/ContextState.h"
22 #include "libANGLE/Error.h"
23 #include "libANGLE/HandleAllocator.h"
24 #include "libANGLE/PackedGLEnums.h"
25 #include "libANGLE/RefCountObject.h"
26 #include "libANGLE/ResourceMap.h"
27 #include "libANGLE/VertexAttribute.h"
28 #include "libANGLE/Workarounds.h"
29 #include "libANGLE/angletypes.h"
30
31 namespace rx
32 {
33 class ContextImpl;
34 class EGLImplFactory;
35 }
36
37 namespace egl
38 {
39 class AttributeMap;
40 class Surface;
41 struct Config;
42 class Thread;
43 }
44
45 namespace gl
46 {
47 class Buffer;
48 class Compiler;
49 class FenceNV;
50 class Sync;
51 class Framebuffer;
52 class MemoryProgramCache;
53 class Program;
54 class Query;
55 class Renderbuffer;
56 class Sampler;
57 class Shader;
58 class Texture;
59 class TransformFeedback;
60 class VertexArray;
61 struct VertexAttribute;
62 class ProgramPipeline;
63
64 class Context final : public ValidationContext
65 {
66 public:
67 Context(rx::EGLImplFactory *implFactory,
68 const egl::Config *config,
69 const Context *shareContext,
70 TextureManager *shareTextures,
71 MemoryProgramCache *memoryProgramCache,
72 const egl::AttributeMap &attribs,
73 const egl::DisplayExtensions &displayExtensions);
74
75 egl::Error onDestroy(const egl::Display *display);
76 ~Context() override;
77
78 egl::Error makeCurrent(egl::Display *display, egl::Surface *surface);
79 egl::Error releaseSurface(const egl::Display *display);
80
81 // These create and destroy methods are merely pass-throughs to
82 // ResourceManager, which owns these object types
83 GLuint createBuffer();
84 GLuint createShader(GLenum type);
85 GLuint createProgram();
86 GLuint createTexture();
87 GLuint createRenderbuffer();
88 GLuint createPaths(GLsizei range);
89 GLuint createProgramPipeline();
90 GLuint createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings);
91
92 void deleteBuffer(GLuint buffer);
93 void deleteShader(GLuint shader);
94 void deleteProgram(GLuint program);
95 void deleteTexture(GLuint texture);
96 void deleteRenderbuffer(GLuint renderbuffer);
97 void deletePaths(GLuint first, GLsizei range);
98 void deleteProgramPipeline(GLuint pipeline);
99
100 // CHROMIUM_path_rendering
101 bool hasPathData(GLuint path) const;
102 bool hasPath(GLuint path) const;
103 void setPathCommands(GLuint path,
104 GLsizei numCommands,
105 const GLubyte *commands,
106 GLsizei numCoords,
107 GLenum coordType,
108 const void *coords);
109 void setPathParameterf(GLuint path, GLenum pname, GLfloat value);
110 void getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const;
111 void setPathStencilFunc(GLenum func, GLint ref, GLuint mask);
112
113 // Framebuffers are owned by the Context, so these methods do not pass through
114 GLuint createFramebuffer();
115 void deleteFramebuffer(GLuint framebuffer);
116
117 // NV Fences are owned by the Context.
118 GLuint createFenceNV();
119 void deleteFenceNV(GLuint fence);
120
121 void bindTexture(GLenum target, GLuint handle);
122 void bindReadFramebuffer(GLuint framebufferHandle);
123 void bindDrawFramebuffer(GLuint framebufferHandle);
124 void bindVertexArray(GLuint vertexArrayHandle);
125 void bindVertexBuffer(GLuint bindingIndex,
126 GLuint bufferHandle,
127 GLintptr offset,
128 GLsizei stride);
129 void bindSampler(GLuint textureUnit, GLuint samplerHandle);
130 void bindImageTexture(GLuint unit,
131 GLuint texture,
132 GLint level,
133 GLboolean layered,
134 GLint layer,
135 GLenum access,
136 GLenum format);
137 void useProgram(GLuint program);
138 void useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program);
139 void bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle);
140 void bindProgramPipeline(GLuint pipelineHandle);
141
142 void beginQuery(GLenum target, GLuint query);
143 void endQuery(GLenum target);
144 void queryCounter(GLuint id, GLenum target);
145 void getQueryiv(GLenum target, GLenum pname, GLint *params);
146 void getQueryObjectiv(GLuint id, GLenum pname, GLint *params);
147 void getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params);
148 void getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params);
149 void getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params);
150
151 void vertexAttribDivisor(GLuint index, GLuint divisor);
152 void vertexBindingDivisor(GLuint bindingIndex, GLuint divisor);
153
154 void getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params);
155 void getFramebufferAttachmentParameteriv(GLenum target,
156 GLenum attachment,
157 GLenum pname,
158 GLint *params);
159 void getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params);
160
161 void getTexParameterfv(GLenum target, GLenum pname, GLfloat *params);
162 void getTexParameteriv(GLenum target, GLenum pname, GLint *params);
163 void getTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params);
164 void getTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params);
165 void texParameterf(GLenum target, GLenum pname, GLfloat param);
166 void texParameterfv(GLenum target, GLenum pname, const GLfloat *params);
167 void texParameteri(GLenum target, GLenum pname, GLint param);
168 void texParameteriv(GLenum target, GLenum pname, const GLint *params);
169
170 void samplerParameteri(GLuint sampler, GLenum pname, GLint param);
171 void samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param);
172 void samplerParameterf(GLuint sampler, GLenum pname, GLfloat param);
173 void samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param);
174
175 void getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params);
176 void getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params);
177
178 void programParameteri(GLuint program, GLenum pname, GLint value);
179
180 GLuint getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name);
181 void getProgramResourceName(GLuint program,
182 GLenum programInterface,
183 GLuint index,
184 GLsizei bufSize,
185 GLsizei *length,
186 GLchar *name);
187 GLint getProgramResourceLocation(GLuint program, GLenum programInterface, const GLchar *name);
188 void getProgramResourceiv(GLuint program,
189 GLenum programInterface,
190 GLuint index,
191 GLsizei propCount,
192 const GLenum *props,
193 GLsizei bufSize,
194 GLsizei *length,
195 GLint *params);
196
197 void getProgramInterfaceiv(GLuint program,
198 GLenum programInterface,
199 GLenum pname,
200 GLint *params);
201
202 Buffer *getBuffer(GLuint handle) const;
203 FenceNV *getFenceNV(GLuint handle);
204 Sync *getSync(GLsync handle) const;
205 Texture *getTexture(GLuint handle) const;
206 Framebuffer *getFramebuffer(GLuint handle) const;
207 Renderbuffer *getRenderbuffer(GLuint handle) const;
208 VertexArray *getVertexArray(GLuint handle) const;
209 Sampler *getSampler(GLuint handle) const;
210 Query *getQuery(GLuint handle, bool create, GLenum type);
211 Query *getQuery(GLuint handle) const;
212 TransformFeedback *getTransformFeedback(GLuint handle) const;
213 ProgramPipeline *getProgramPipeline(GLuint handle) const;
214
215 void objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
216 void objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label);
217 void getObjectLabel(GLenum identifier,
218 GLuint name,
219 GLsizei bufSize,
220 GLsizei *length,
221 GLchar *label) const;
222 void getObjectPtrLabel(const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label) const;
223
224 Texture *getTargetTexture(GLenum target) const;
225 Texture *getSamplerTexture(unsigned int sampler, GLenum type) const;
226
227 Compiler *getCompiler() const;
228
229 bool isSampler(GLuint samplerName) const;
230
231 bool isVertexArrayGenerated(GLuint vertexArray);
232 bool isTransformFeedbackGenerated(GLuint vertexArray);
233
234 void getBooleanv(GLenum pname, GLboolean *params);
235 void getBooleanvImpl(GLenum pname, GLboolean *params);
236 void getFloatv(GLenum pname, GLfloat *params);
237 void getFloatvImpl(GLenum pname, GLfloat *params);
238 void getIntegerv(GLenum pname, GLint *params);
239 void getIntegervImpl(GLenum pname, GLint *params);
240 void getInteger64vImpl(GLenum pname, GLint64 *params);
241 void getPointerv(GLenum pname, void **params) const;
242 void getBooleani_v(GLenum target, GLuint index, GLboolean *data);
243 void getIntegeri_v(GLenum target, GLuint index, GLint *data);
244 void getInteger64i_v(GLenum target, GLuint index, GLint64 *data);
245
246 void activeShaderProgram(GLuint pipeline, GLuint program);
247 void activeTexture(GLenum texture);
248 void blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
249 void blendEquation(GLenum mode);
250 void blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
251 void blendFunc(GLenum sfactor, GLenum dfactor);
252 void blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
253 void clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
254 void clearDepthf(GLfloat depth);
255 void clearStencil(GLint s);
256 void colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
257 void cullFace(CullFaceMode mode);
258 void depthFunc(GLenum func);
259 void depthMask(GLboolean flag);
260 void depthRangef(GLfloat zNear, GLfloat zFar);
261 void disable(GLenum cap);
262 void disableVertexAttribArray(GLuint index);
263 void enable(GLenum cap);
264 void enableVertexAttribArray(GLuint index);
265 void frontFace(GLenum mode);
266 void hint(GLenum target, GLenum mode);
267 void lineWidth(GLfloat width);
268 void pixelStorei(GLenum pname, GLint param);
269 void polygonOffset(GLfloat factor, GLfloat units);
270 void sampleCoverage(GLfloat value, GLboolean invert);
271 void sampleMaski(GLuint maskNumber, GLbitfield mask);
272 void scissor(GLint x, GLint y, GLsizei width, GLsizei height);
273 void stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
274 void stencilMaskSeparate(GLenum face, GLuint mask);
275 void stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
276 void vertexAttrib1f(GLuint index, GLfloat x);
277 void vertexAttrib1fv(GLuint index, const GLfloat *values);
278 void vertexAttrib2f(GLuint index, GLfloat x, GLfloat y);
279 void vertexAttrib2fv(GLuint index, const GLfloat *values);
280 void vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z);
281 void vertexAttrib3fv(GLuint index, const GLfloat *values);
282 void vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
283 void vertexAttrib4fv(GLuint index, const GLfloat *values);
284 void vertexAttribFormat(GLuint attribIndex,
285 GLint size,
286 GLenum type,
287 GLboolean normalized,
288 GLuint relativeOffset);
289 void vertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type, GLuint relativeOffset);
290 void vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex);
291 void vertexAttribPointer(GLuint index,
292 GLint size,
293 GLenum type,
294 GLboolean normalized,
295 GLsizei stride,
296 const void *ptr);
297 void vertexAttribIPointer(GLuint index,
298 GLint size,
299 GLenum type,
300 GLsizei stride,
301 const void *pointer);
302 void viewport(GLint x, GLint y, GLsizei width, GLsizei height);
303
304 void vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w);
305 void vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
306 void vertexAttribI4iv(GLuint index, const GLint *v);
307 void vertexAttribI4uiv(GLuint index, const GLuint *v);
308 void getVertexAttribiv(GLuint index, GLenum pname, GLint *params);
309 void getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params);
310 void getVertexAttribIiv(GLuint index, GLenum pname, GLint *params);
311 void getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params);
312 void getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer);
313
314 void debugMessageControl(GLenum source,
315 GLenum type,
316 GLenum severity,
317 GLsizei count,
318 const GLuint *ids,
319 GLboolean enabled);
320 void debugMessageInsert(GLenum source,
321 GLenum type,
322 GLuint id,
323 GLenum severity,
324 GLsizei length,
325 const GLchar *buf);
326 void debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam);
327 GLuint getDebugMessageLog(GLuint count,
328 GLsizei bufSize,
329 GLenum *sources,
330 GLenum *types,
331 GLuint *ids,
332 GLenum *severities,
333 GLsizei *lengths,
334 GLchar *messageLog);
335 void pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message);
336 void popDebugGroup();
337
338 void clear(GLbitfield mask);
339 void clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values);
340 void clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values);
341 void clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values);
342 void clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
343
344 void drawArrays(GLenum mode, GLint first, GLsizei count);
345 void drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount);
346
347 void drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices);
348 void drawElementsInstanced(GLenum mode,
349 GLsizei count,
350 GLenum type,
351 const void *indices,
352 GLsizei instances);
353 void drawRangeElements(GLenum mode,
354 GLuint start,
355 GLuint end,
356 GLsizei count,
357 GLenum type,
358 const void *indices);
359 void drawArraysIndirect(GLenum mode, const void *indirect);
360 void drawElementsIndirect(GLenum mode, GLenum type, const void *indirect);
361
362 void blitFramebuffer(GLint srcX0,
363 GLint srcY0,
364 GLint srcX1,
365 GLint srcY1,
366 GLint dstX0,
367 GLint dstY0,
368 GLint dstX1,
369 GLint dstY1,
370 GLbitfield mask,
371 GLenum filter);
372
373 void readPixels(GLint x,
374 GLint y,
375 GLsizei width,
376 GLsizei height,
377 GLenum format,
378 GLenum type,
379 void *pixels);
380
381 void copyTexImage2D(GLenum target,
382 GLint level,
383 GLenum internalformat,
384 GLint x,
385 GLint y,
386 GLsizei width,
387 GLsizei height,
388 GLint border);
389
390 void copyTexSubImage2D(GLenum target,
391 GLint level,
392 GLint xoffset,
393 GLint yoffset,
394 GLint x,
395 GLint y,
396 GLsizei width,
397 GLsizei height);
398
399 void copyTexSubImage3D(GLenum target,
400 GLint level,
401 GLint xoffset,
402 GLint yoffset,
403 GLint zoffset,
404 GLint x,
405 GLint y,
406 GLsizei width,
407 GLsizei height);
408
409 void framebufferTexture2D(GLenum target,
410 GLenum attachment,
411 GLenum textarget,
412 GLuint texture,
413 GLint level);
414
415 void framebufferRenderbuffer(GLenum target,
416 GLenum attachment,
417 GLenum renderbuffertarget,
418 GLuint renderbuffer);
419
420 void framebufferTextureLayer(GLenum target,
421 GLenum attachment,
422 GLuint texture,
423 GLint level,
424 GLint layer);
425 void framebufferTextureMultiviewLayeredANGLE(GLenum target,
426 GLenum attachment,
427 GLuint texture,
428 GLint level,
429 GLint baseViewIndex,
430 GLsizei numViews);
431 void framebufferTextureMultiviewSideBySideANGLE(GLenum target,
432 GLenum attachment,
433 GLuint texture,
434 GLint level,
435 GLsizei numViews,
436 const GLint *viewportOffsets);
437
438 void drawBuffers(GLsizei n, const GLenum *bufs);
439 void readBuffer(GLenum mode);
440
441 void discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments);
442 void invalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments);
443 void invalidateSubFramebuffer(GLenum target,
444 GLsizei numAttachments,
445 const GLenum *attachments,
446 GLint x,
447 GLint y,
448 GLsizei width,
449 GLsizei height);
450
451 void texImage2D(GLenum target,
452 GLint level,
453 GLint internalformat,
454 GLsizei width,
455 GLsizei height,
456 GLint border,
457 GLenum format,
458 GLenum type,
459 const void *pixels);
460 void texImage3D(GLenum target,
461 GLint level,
462 GLint internalformat,
463 GLsizei width,
464 GLsizei height,
465 GLsizei depth,
466 GLint border,
467 GLenum format,
468 GLenum type,
469 const void *pixels);
470 void texSubImage2D(GLenum target,
471 GLint level,
472 GLint xoffset,
473 GLint yoffset,
474 GLsizei width,
475 GLsizei height,
476 GLenum format,
477 GLenum type,
478 const void *pixels);
479 void texSubImage3D(GLenum target,
480 GLint level,
481 GLint xoffset,
482 GLint yoffset,
483 GLint zoffset,
484 GLsizei width,
485 GLsizei height,
486 GLsizei depth,
487 GLenum format,
488 GLenum type,
489 const void *pixels);
490 void compressedTexImage2D(GLenum target,
491 GLint level,
492 GLenum internalformat,
493 GLsizei width,
494 GLsizei height,
495 GLint border,
496 GLsizei imageSize,
497 const void *data);
498 void compressedTexImage3D(GLenum target,
499 GLint level,
500 GLenum internalformat,
501 GLsizei width,
502 GLsizei height,
503 GLsizei depth,
504 GLint border,
505 GLsizei imageSize,
506 const void *data);
507 void compressedTexSubImage2D(GLenum target,
508 GLint level,
509 GLint xoffset,
510 GLint yoffset,
511 GLsizei width,
512 GLsizei height,
513 GLenum format,
514 GLsizei imageSize,
515 const void *data);
516 void compressedTexSubImage3D(GLenum target,
517 GLint level,
518 GLint xoffset,
519 GLint yoffset,
520 GLint zoffset,
521 GLsizei width,
522 GLsizei height,
523 GLsizei depth,
524 GLenum format,
525 GLsizei imageSize,
526 const void *data);
527 void copyTextureCHROMIUM(GLuint sourceId,
528 GLint sourceLevel,
529 GLenum destTarget,
530 GLuint destId,
531 GLint destLevel,
532 GLint internalFormat,
533 GLenum destType,
534 GLboolean unpackFlipY,
535 GLboolean unpackPremultiplyAlpha,
536 GLboolean unpackUnmultiplyAlpha);
537 void copySubTextureCHROMIUM(GLuint sourceId,
538 GLint sourceLevel,
539 GLenum destTarget,
540 GLuint destId,
541 GLint destLevel,
542 GLint xoffset,
543 GLint yoffset,
544 GLint x,
545 GLint y,
546 GLsizei width,
547 GLsizei height,
548 GLboolean unpackFlipY,
549 GLboolean unpackPremultiplyAlpha,
550 GLboolean unpackUnmultiplyAlpha);
551 void compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId);
552
553 void generateMipmap(GLenum target);
554
555 void flush();
556 void finish();
557
558 void getBufferPointerv(BufferBinding target, GLenum pname, void **params);
559 void *mapBuffer(BufferBinding target, GLenum access);
560 GLboolean unmapBuffer(BufferBinding target);
561 void *mapBufferRange(BufferBinding target,
562 GLintptr offset,
563 GLsizeiptr length,
564 GLbitfield access);
565 void flushMappedBufferRange(BufferBinding target, GLintptr offset, GLsizeiptr length);
566
567 void beginTransformFeedback(GLenum primitiveMode);
568
569 bool hasActiveTransformFeedback(GLuint program) const;
570
571 void insertEventMarker(GLsizei length, const char *marker);
572 void pushGroupMarker(GLsizei length, const char *marker);
573 void popGroupMarker();
574
575 void bindUniformLocation(GLuint program, GLint location, const GLchar *name);
576 void renderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
577 void renderbufferStorageMultisample(GLenum target,
578 GLsizei samples,
579 GLenum internalformat,
580 GLsizei width,
581 GLsizei height);
582
583 void getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
584
585 // CHROMIUM_framebuffer_mixed_samples
586 void setCoverageModulation(GLenum components);
587
588 // CHROMIUM_path_rendering
589 void loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix);
590 void loadPathRenderingIdentityMatrix(GLenum matrixMode);
591 void stencilFillPath(GLuint path, GLenum fillMode, GLuint mask);
592 void stencilStrokePath(GLuint path, GLint reference, GLuint mask);
593 void coverFillPath(GLuint path, GLenum coverMode);
594 void coverStrokePath(GLuint path, GLenum coverMode);
595 void stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode);
596 void stencilThenCoverStrokePath(GLuint path, GLint reference, GLuint mask, GLenum coverMode);
597 void coverFillPathInstanced(GLsizei numPaths,
598 GLenum pathNameType,
599 const void *paths,
600 GLuint pathBase,
601 GLenum coverMode,
602 GLenum transformType,
603 const GLfloat *transformValues);
604 void coverStrokePathInstanced(GLsizei numPaths,
605 GLenum pathNameType,
606 const void *paths,
607 GLuint pathBase,
608 GLenum coverMode,
609 GLenum transformType,
610 const GLfloat *transformValues);
611 void stencilFillPathInstanced(GLsizei numPaths,
612 GLenum pathNameType,
613 const void *paths,
614 GLuint pathBAse,
615 GLenum fillMode,
616 GLuint mask,
617 GLenum transformType,
618 const GLfloat *transformValues);
619 void stencilStrokePathInstanced(GLsizei numPaths,
620 GLenum pathNameType,
621 const void *paths,
622 GLuint pathBase,
623 GLint reference,
624 GLuint mask,
625 GLenum transformType,
626 const GLfloat *transformValues);
627 void stencilThenCoverFillPathInstanced(GLsizei numPaths,
628 GLenum pathNameType,
629 const void *paths,
630 GLuint pathBase,
631 GLenum fillMode,
632 GLuint mask,
633 GLenum coverMode,
634 GLenum transformType,
635 const GLfloat *transformValues);
636 void stencilThenCoverStrokePathInstanced(GLsizei numPaths,
637 GLenum pathNameType,
638 const void *paths,
639 GLuint pathBase,
640 GLint reference,
641 GLuint mask,
642 GLenum coverMode,
643 GLenum transformType,
644 const GLfloat *transformValues);
645 void bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name);
646 void programPathFragmentInputGen(GLuint program,
647 GLint location,
648 GLenum genMode,
649 GLint components,
650 const GLfloat *coeffs);
651
652 void bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage);
653 void bufferSubData(BufferBinding target, GLintptr offset, GLsizeiptr size, const void *data);
654 void attachShader(GLuint program, GLuint shader);
655 void bindAttribLocation(GLuint program, GLuint index, const GLchar *name);
656 void bindBuffer(BufferBinding target, GLuint buffer);
657 void bindBufferBase(BufferBinding target, GLuint index, GLuint buffer);
658 void bindBufferRange(BufferBinding target,
659 GLuint index,
660 GLuint buffer,
661 GLintptr offset,
662 GLsizeiptr size);
663 void bindFramebuffer(GLenum target, GLuint framebuffer);
664 void bindRenderbuffer(GLenum target, GLuint renderbuffer);
665
666 void texStorage2DMultisample(GLenum target,
667 GLsizei samples,
668 GLenum internalformat,
669 GLsizei width,
670 GLsizei height,
671 GLboolean fixedsamplelocations);
672
673 void getMultisamplefv(GLenum pname, GLuint index, GLfloat *val);
674
675 void copyBufferSubData(BufferBinding readTarget,
676 BufferBinding writeTarget,
677 GLintptr readOffset,
678 GLintptr writeOffset,
679 GLsizeiptr size);
680
681 GLenum checkFramebufferStatus(GLenum target);
682 void compileShader(GLuint shader);
683 void deleteBuffers(GLsizei n, const GLuint *buffers);
684 void deleteFramebuffers(GLsizei n, const GLuint *framebuffers);
685 void deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers);
686 void deleteTextures(GLsizei n, const GLuint *textures);
687 void detachShader(GLuint program, GLuint shader);
688 void genBuffers(GLsizei n, GLuint *buffers);
689 void genFramebuffers(GLsizei n, GLuint *framebuffers);
690 void genRenderbuffers(GLsizei n, GLuint *renderbuffers);
691 void genTextures(GLsizei n, GLuint *textures);
692 void getActiveAttrib(GLuint program,
693 GLuint index,
694 GLsizei bufsize,
695 GLsizei *length,
696 GLint *size,
697 GLenum *type,
698 GLchar *name);
699 void getActiveUniform(GLuint program,
700 GLuint index,
701 GLsizei bufsize,
702 GLsizei *length,
703 GLint *size,
704 GLenum *type,
705 GLchar *name);
706 void getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders);
707 GLint getAttribLocation(GLuint program, const GLchar *name);
708 void getProgramiv(GLuint program, GLenum pname, GLint *params);
709 void getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params);
710 void getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog);
711 void getProgramPipelineInfoLog(GLuint pipeline,
712 GLsizei bufSize,
713 GLsizei *length,
714 GLchar *infoLog);
715 void getShaderiv(GLuint shader, GLenum pname, GLint *params);
716 void getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog);
717 void getShaderPrecisionFormat(GLenum shadertype,
718 GLenum precisiontype,
719 GLint *range,
720 GLint *precision);
721 void getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source);
722 void getUniformfv(GLuint program, GLint location, GLfloat *params);
723 void getUniformiv(GLuint program, GLint location, GLint *params);
724 GLint getUniformLocation(GLuint program, const GLchar *name);
725 GLboolean isBuffer(GLuint buffer);
726 GLboolean isEnabled(GLenum cap);
727 GLboolean isFramebuffer(GLuint framebuffer);
728 GLboolean isProgram(GLuint program);
729 GLboolean isRenderbuffer(GLuint renderbuffer);
730 GLboolean isShader(GLuint shader);
731 GLboolean isTexture(GLuint texture);
732 void linkProgram(GLuint program);
733 void releaseShaderCompiler();
734 void shaderBinary(GLsizei n,
735 const GLuint *shaders,
736 GLenum binaryformat,
737 const void *binary,
738 GLsizei length);
739 void shaderSource(GLuint shader,
740 GLsizei count,
741 const GLchar *const *string,
742 const GLint *length);
743 void stencilFunc(GLenum func, GLint ref, GLuint mask);
744 void stencilMask(GLuint mask);
745 void stencilOp(GLenum fail, GLenum zfail, GLenum zpass);
746 void uniform1f(GLint location, GLfloat x);
747 void uniform1fv(GLint location, GLsizei count, const GLfloat *v);
748 void uniform1i(GLint location, GLint x);
749 void uniform1iv(GLint location, GLsizei count, const GLint *v);
750 void uniform2f(GLint location, GLfloat x, GLfloat y);
751 void uniform2fv(GLint location, GLsizei count, const GLfloat *v);
752 void uniform2i(GLint location, GLint x, GLint y);
753 void uniform2iv(GLint location, GLsizei count, const GLint *v);
754 void uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z);
755 void uniform3fv(GLint location, GLsizei count, const GLfloat *v);
756 void uniform3i(GLint location, GLint x, GLint y, GLint z);
757 void uniform3iv(GLint location, GLsizei count, const GLint *v);
758 void uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
759 void uniform4fv(GLint location, GLsizei count, const GLfloat *v);
760 void uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w);
761 void uniform4iv(GLint location, GLsizei count, const GLint *v);
762 void uniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
763 void uniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
764 void uniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
765 void validateProgram(GLuint program);
766 void validateProgramPipeline(GLuint pipeline);
767
768 void genQueries(GLsizei n, GLuint *ids);
769 void deleteQueries(GLsizei n, const GLuint *ids);
770 GLboolean isQuery(GLuint id);
771
772 void uniform1ui(GLint location, GLuint v0);
773 void uniform2ui(GLint location, GLuint v0, GLuint v1);
774 void uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2);
775 void uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
776 void uniform1uiv(GLint location, GLsizei count, const GLuint *value);
777 void uniform2uiv(GLint location, GLsizei count, const GLuint *value);
778 void uniform3uiv(GLint location, GLsizei count, const GLuint *value);
779 void uniform4uiv(GLint location, GLsizei count, const GLuint *value);
780
781 void uniformMatrix2x3fv(GLint location,
782 GLsizei count,
783 GLboolean transpose,
784 const GLfloat *value);
785 void uniformMatrix3x2fv(GLint location,
786 GLsizei count,
787 GLboolean transpose,
788 const GLfloat *value);
789 void uniformMatrix2x4fv(GLint location,
790 GLsizei count,
791 GLboolean transpose,
792 const GLfloat *value);
793 void uniformMatrix4x2fv(GLint location,
794 GLsizei count,
795 GLboolean transpose,
796 const GLfloat *value);
797 void uniformMatrix3x4fv(GLint location,
798 GLsizei count,
799 GLboolean transpose,
800 const GLfloat *value);
801 void uniformMatrix4x3fv(GLint location,
802 GLsizei count,
803 GLboolean transpose,
804 const GLfloat *value);
805
806 void deleteVertexArrays(GLsizei n, const GLuint *arrays);
807 void genVertexArrays(GLsizei n, GLuint *arrays);
808 bool isVertexArray(GLuint array);
809
810 void endTransformFeedback();
811 void transformFeedbackVaryings(GLuint program,
812 GLsizei count,
813 const GLchar *const *varyings,
814 GLenum bufferMode);
815 void getTransformFeedbackVarying(GLuint program,
816 GLuint index,
817 GLsizei bufSize,
818 GLsizei *length,
819 GLsizei *size,
820 GLenum *type,
821 GLchar *name);
822
823 void deleteTransformFeedbacks(GLsizei n, const GLuint *ids);
824 void genTransformFeedbacks(GLsizei n, GLuint *ids);
825 bool isTransformFeedback(GLuint id);
826 void pauseTransformFeedback();
827 void resumeTransformFeedback();
828
829 void getProgramBinary(GLuint program,
830 GLsizei bufSize,
831 GLsizei *length,
832 GLenum *binaryFormat,
833 void *binary);
834 void programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length);
835
836 void getUniformuiv(GLuint program, GLint location, GLuint *params);
837 GLint getFragDataLocation(GLuint program, const GLchar *name);
838 void getUniformIndices(GLuint program,
839 GLsizei uniformCount,
840 const GLchar *const *uniformNames,
841 GLuint *uniformIndices);
842 void getActiveUniformsiv(GLuint program,
843 GLsizei uniformCount,
844 const GLuint *uniformIndices,
845 GLenum pname,
846 GLint *params);
847 GLuint getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName);
848 void getActiveUniformBlockiv(GLuint program,
849 GLuint uniformBlockIndex,
850 GLenum pname,
851 GLint *params);
852 void getActiveUniformBlockName(GLuint program,
853 GLuint uniformBlockIndex,
854 GLsizei bufSize,
855 GLsizei *length,
856 GLchar *uniformBlockName);
857 void uniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
858
859 GLsync fenceSync(GLenum condition, GLbitfield flags);
860 GLboolean isSync(GLsync sync);
861 void deleteSync(GLsync sync);
862 GLenum clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout);
863 void waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout);
864 void getInteger64v(GLenum pname, GLint64 *params);
865
866 void getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params);
867 void genSamplers(GLsizei count, GLuint *samplers);
868 void deleteSamplers(GLsizei count, const GLuint *samplers);
869 void getInternalformativ(GLenum target,
870 GLenum internalformat,
871 GLenum pname,
872 GLsizei bufSize,
873 GLint *params);
874
875 void programUniform1i(GLuint program, GLint location, GLint v0);
876 void programUniform2i(GLuint program, GLint location, GLint v0, GLint v1);
877 void programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
878 void programUniform4i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
879 void programUniform1ui(GLuint program, GLint location, GLuint v0);
880 void programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1);
881 void programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
882 void programUniform4ui(GLuint program,
883 GLint location,
884 GLuint v0,
885 GLuint v1,
886 GLuint v2,
887 GLuint v3);
888 void programUniform1f(GLuint program, GLint location, GLfloat v0);
889 void programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1);
890 void programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
891 void programUniform4f(GLuint program,
892 GLint location,
893 GLfloat v0,
894 GLfloat v1,
895 GLfloat v2,
896 GLfloat v3);
897 void programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value);
898 void programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value);
899 void programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value);
900 void programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value);
901 void programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value);
902 void programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value);
903 void programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value);
904 void programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value);
905 void programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value);
906 void programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value);
907 void programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value);
908 void programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value);
909
910 void programUniformMatrix2fv(GLuint program,
911 GLint location,
912 GLsizei count,
913 GLboolean transpose,
914 const GLfloat *value);
915
916 void programUniformMatrix3fv(GLuint program,
917 GLint location,
918 GLsizei count,
919 GLboolean transpose,
920 const GLfloat *value);
921
922 void programUniformMatrix4fv(GLuint program,
923 GLint location,
924 GLsizei count,
925 GLboolean transpose,
926 const GLfloat *value);
927
928 void programUniformMatrix2x3fv(GLuint program,
929 GLint location,
930 GLsizei count,
931 GLboolean transpose,
932 const GLfloat *value);
933
934 void programUniformMatrix3x2fv(GLuint program,
935 GLint location,
936 GLsizei count,
937 GLboolean transpose,
938 const GLfloat *value);
939
940 void programUniformMatrix2x4fv(GLuint program,
941 GLint location,
942 GLsizei count,
943 GLboolean transpose,
944 const GLfloat *value);
945
946 void programUniformMatrix4x2fv(GLuint program,
947 GLint location,
948 GLsizei count,
949 GLboolean transpose,
950 const GLfloat *value);
951
952 void programUniformMatrix3x4fv(GLuint program,
953 GLint location,
954 GLsizei count,
955 GLboolean transpose,
956 const GLfloat *value);
957
958 void programUniformMatrix4x3fv(GLuint program,
959 GLint location,
960 GLsizei count,
961 GLboolean transpose,
962 const GLfloat *value);
963
964 void deleteProgramPipelines(GLsizei n, const GLuint *pipelines);
965 void genProgramPipelines(GLsizei n, GLuint *pipelines);
966 GLboolean isProgramPipeline(GLuint pipeline);
967
968 // Consumes the error.
969 void handleError(const Error &error) override;
970
971 GLenum getError();
972 void markContextLost();
973 bool isContextLost();
974 GLenum getResetStatus();
975 bool isResetNotificationEnabled();
976
977 const egl::Config *getConfig() const;
978 EGLenum getClientType() const;
979 EGLenum getRenderBuffer() const;
980
981 const GLubyte *getString(GLenum name) const;
982 const GLubyte *getStringi(GLenum name, GLuint index) const;
983
984 size_t getExtensionStringCount() const;
985
986 bool isExtensionRequestable(const char *name);
987 void requestExtension(const char *name);
988 size_t getRequestableExtensionStringCount() const;
989
getImplementation()990 rx::ContextImpl *getImplementation() const { return mImplementation.get(); }
991 const Workarounds &getWorkarounds() const;
992
993 void getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params);
994 void framebufferParameteri(GLenum target, GLenum pname, GLint param);
995
996 Error getScratchBuffer(size_t requestedSizeBytes, angle::MemoryBuffer **scratchBufferOut) const;
997 Error getZeroFilledBuffer(size_t requstedSizeBytes, angle::MemoryBuffer **zeroBufferOut) const;
998
999 void dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ);
1000 void dispatchComputeIndirect(GLintptr indirect);
1001
getMemoryProgramCache()1002 MemoryProgramCache *getMemoryProgramCache() const { return mMemoryProgramCache; }
1003
1004 template <EntryPoint EP, typename... ParamsT>
1005 void gatherParams(ParamsT &&... params);
1006
1007 void texStorage2D(GLenum target,
1008 GLsizei levels,
1009 GLenum internalFormat,
1010 GLsizei width,
1011 GLsizei height);
1012 void texStorage3D(GLenum target,
1013 GLsizei levels,
1014 GLenum internalFormat,
1015 GLsizei width,
1016 GLsizei height,
1017 GLsizei depth);
1018
1019 void memoryBarrier(GLbitfield barriers);
1020 void memoryBarrierByRegion(GLbitfield barriers);
1021
1022 // Notification for a state change in a Texture.
1023 void onTextureChange(const Texture *texture);
1024
getCurrentDisplay()1025 egl::Display *getCurrentDisplay() const { return mCurrentDisplay; }
getCurrentDrawSurface()1026 egl::Surface *getCurrentDrawSurface() const { return mCurrentSurface; }
getCurrentReadSurface()1027 egl::Surface *getCurrentReadSurface() const { return mCurrentSurface; }
1028
isRobustResourceInitEnabled()1029 bool isRobustResourceInitEnabled() const { return mGLState.isRobustResourceInitEnabled(); }
1030
1031 private:
1032 Error prepareForDraw();
1033 void syncRendererState();
1034 void syncRendererState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask);
1035 void syncStateForReadPixels();
1036 void syncStateForTexImage();
1037 void syncStateForClear();
1038 void syncStateForBlit();
1039 VertexArray *checkVertexArrayAllocation(GLuint vertexArrayHandle);
1040 TransformFeedback *checkTransformFeedbackAllocation(GLuint transformFeedback);
1041
1042 void detachBuffer(GLuint buffer);
1043 void detachTexture(GLuint texture);
1044 void detachFramebuffer(GLuint framebuffer);
1045 void detachRenderbuffer(GLuint renderbuffer);
1046 void detachVertexArray(GLuint vertexArray);
1047 void detachTransformFeedback(GLuint transformFeedback);
1048 void detachSampler(GLuint sampler);
1049 void detachProgramPipeline(GLuint pipeline);
1050
1051 void initRendererString();
1052 void initVersionStrings();
1053 void initExtensionStrings();
1054
1055 void initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit);
1056 void updateCaps();
1057 void initWorkarounds();
1058
1059 LabeledObject *getLabeledObject(GLenum identifier, GLuint name) const;
1060 LabeledObject *getLabeledObjectFromPtr(const void *ptr) const;
1061
1062 std::unique_ptr<rx::ContextImpl> mImplementation;
1063
1064 // Caps to use for validation
1065 Caps mCaps;
1066 TextureCapsMap mTextureCaps;
1067 Extensions mExtensions;
1068 Limitations mLimitations;
1069
1070 // Shader compiler. Lazily initialized hence the mutable value.
1071 mutable BindingPointer<Compiler> mCompiler;
1072
1073 State mGLState;
1074
1075 const egl::Config *mConfig;
1076 EGLenum mClientType;
1077
1078 TextureMap mZeroTextures;
1079
1080 ResourceMap<FenceNV> mFenceNVMap;
1081 HandleAllocator mFenceNVHandleAllocator;
1082
1083 ResourceMap<Query> mQueryMap;
1084 HandleAllocator mQueryHandleAllocator;
1085
1086 ResourceMap<VertexArray> mVertexArrayMap;
1087 HandleAllocator mVertexArrayHandleAllocator;
1088
1089 ResourceMap<TransformFeedback> mTransformFeedbackMap;
1090 HandleAllocator mTransformFeedbackHandleAllocator;
1091
1092 const char *mVersionString;
1093 const char *mShadingLanguageString;
1094 const char *mRendererString;
1095 const char *mExtensionString;
1096 std::vector<const char *> mExtensionStrings;
1097 const char *mRequestableExtensionString;
1098 std::vector<const char *> mRequestableExtensionStrings;
1099
1100 // Recorded errors
1101 typedef std::set<GLenum> ErrorSet;
1102 ErrorSet mErrors;
1103
1104 // Current/lost context flags
1105 bool mHasBeenCurrent;
1106 bool mContextLost;
1107 GLenum mResetStatus;
1108 bool mContextLostForced;
1109 GLenum mResetStrategy;
1110 bool mRobustAccess;
1111 egl::Surface *mCurrentSurface;
1112 egl::Display *mCurrentDisplay;
1113 Framebuffer *mSurfacelessFramebuffer;
1114 bool mWebGLContext;
1115 MemoryProgramCache *mMemoryProgramCache;
1116
1117 State::DirtyBits mTexImageDirtyBits;
1118 State::DirtyObjects mTexImageDirtyObjects;
1119 State::DirtyBits mReadPixelsDirtyBits;
1120 State::DirtyObjects mReadPixelsDirtyObjects;
1121 State::DirtyBits mClearDirtyBits;
1122 State::DirtyObjects mClearDirtyObjects;
1123 State::DirtyBits mBlitDirtyBits;
1124 State::DirtyObjects mBlitDirtyObjects;
1125
1126 Workarounds mWorkarounds;
1127
1128 // Not really a property of context state. The size and contexts change per-api-call.
1129 mutable angle::ScratchBuffer mScratchBuffer;
1130 mutable angle::ScratchBuffer mZeroFilledBuffer;
1131 };
1132
1133 template <EntryPoint EP, typename... ArgsT>
gatherParams(ArgsT &&...args)1134 ANGLE_INLINE void Context::gatherParams(ArgsT &&... args)
1135 {
1136 static_assert(sizeof(EntryPointParamType<EP>) <= kParamsBufferSize,
1137 "Params struct too large, please increase kParamsBufferSize.");
1138
1139 mSavedArgsType = &EntryPointParamType<EP>::TypeInfo;
1140
1141 // Skip doing any work for ParamsBase/Invalid type.
1142 if (!EntryPointParamType<EP>::TypeInfo.isValid())
1143 {
1144 return;
1145 }
1146
1147 EntryPointParamType<EP> *objBuffer =
1148 reinterpret_cast<EntryPointParamType<EP> *>(mParamsBuffer.data());
1149 EntryPointParamType<EP>::template Factory<EP>(objBuffer, this, std::forward<ArgsT>(args)...);
1150 }
1151
1152 } // namespace gl
1153
1154 #endif // LIBANGLE_CONTEXT_H_
1155