blob: 92949d90a564140c4062002b872343432b4a704a [file] [log] [blame]
keunyoungb85b2752013-03-08 12:28:03 -08001/*
2* Copyright (C) 2011 The Android Open Source Project
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16#ifndef _GL_CLIENT_STATE_H_
17#define _GL_CLIENT_STATE_H_
18
19#define GL_API
20#ifndef ANDROID
21#define GL_APIENTRY
22#define GL_APIENTRYP
23#endif
24
Lingfeng Yang74e29292017-01-10 14:54:38 -080025#include "TextureSharedData.h"
26
keunyoungb85b2752013-03-08 12:28:03 -080027#include <GLES/gl.h>
28#include <GLES/glext.h>
29#include <GLES2/gl2.h>
30#include <GLES2/gl2ext.h>
31
32#include <stdio.h>
33#include <stdlib.h>
34#include "ErrorLog.h"
35#include "codec_defs.h"
36
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070037#include <vector>
Lingfeng Yang74e29292017-01-10 14:54:38 -080038#include <map>
Lingfeng Yange00ec9d2016-09-16 08:54:03 -070039#include <set>
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070040
41// Tracking framebuffer objects:
42// which framebuffer is bound,
43// and which texture names
44// are currently bound to which attachment points.
45struct FboProps {
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070046 GLuint name;
47 bool previouslyBound;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -080048 std::vector<GLuint> colorAttachmenti_textures;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070049 GLuint depthAttachment_texture;
50 GLuint stencilAttachment_texture;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -080051 GLuint depthstencilAttachment_texture;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070052
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -080053 std::vector<bool> colorAttachmenti_hasTex;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070054 bool depthAttachment_hasTexObj;
55 bool stencilAttachment_hasTexObj;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -080056 bool depthstencilAttachment_hasTexObj;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070057
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -080058 std::vector<GLuint> colorAttachmenti_rbos;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070059 GLuint depthAttachment_rbo;
60 GLuint stencilAttachment_rbo;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -080061 GLuint depthstencilAttachment_rbo;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070062
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -080063 std::vector<bool> colorAttachmenti_hasRbo;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070064 bool depthAttachment_hasRbo;
65 bool stencilAttachment_hasRbo;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -080066 bool depthstencilAttachment_hasRbo;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070067};
68
69// Same for Rbo's
70struct RboProps {
71 GLenum target;
72 GLuint name;
Lingfeng Yang69066602016-04-12 09:29:11 -070073 GLenum format;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -080074 GLsizei multisamples;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -070075 bool previouslyBound;
76};
77
Lingfeng Yang69066602016-04-12 09:29:11 -070078// Enum for describing whether a framebuffer attachment
79// is a texture or renderbuffer.
80enum FboAttachmentType {
81 FBO_ATTACHMENT_RENDERBUFFER = 0,
82 FBO_ATTACHMENT_TEXTURE = 1,
83 FBO_ATTACHMENT_NONE = 2
84};
85
86// Tracking FBO format
87struct FboFormatInfo {
88 FboAttachmentType type;
89 GLenum rb_format;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -080090 GLsizei rb_multisamples;
91
Lingfeng Yang69066602016-04-12 09:29:11 -070092 GLint tex_internalformat;
93 GLenum tex_format;
94 GLenum tex_type;
Lingfeng Yang74e29292017-01-10 14:54:38 -080095 GLsizei tex_multisamples;
Lingfeng Yang69066602016-04-12 09:29:11 -070096};
97
keunyoungb85b2752013-03-08 12:28:03 -080098class GLClientState {
99public:
100 typedef enum {
101 VERTEX_LOCATION = 0,
102 NORMAL_LOCATION = 1,
103 COLOR_LOCATION = 2,
104 POINTSIZE_LOCATION = 3,
105 TEXCOORD0_LOCATION = 4,
106 TEXCOORD1_LOCATION = 5,
107 TEXCOORD2_LOCATION = 6,
108 TEXCOORD3_LOCATION = 7,
109 TEXCOORD4_LOCATION = 8,
110 TEXCOORD5_LOCATION = 9,
111 TEXCOORD6_LOCATION = 10,
112 TEXCOORD7_LOCATION = 11,
113 MATRIXINDEX_LOCATION = 12,
114 WEIGHT_LOCATION = 13,
115 LAST_LOCATION = 14
116 } StateLocation;
117
118 typedef struct {
119 GLint enabled;
120 GLint size;
121 GLenum type;
122 GLsizei stride;
123 void *data;
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800124 GLuint reloffset;
keunyoungb85b2752013-03-08 12:28:03 -0800125 GLuint bufferObject;
126 GLenum glConst;
127 unsigned int elementSize;
128 bool enableDirty; // true if any enable state has changed since last draw
129 bool normalized;
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800130 GLuint divisor;
131 bool isInt;
132 int bindingindex;
keunyoungb85b2752013-03-08 12:28:03 -0800133 } VertexAttribState;
134
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800135 struct BufferBinding {
136 GLintptr offset;
137 GLintptr stride;
138 GLintptr effectiveStride;
139 GLsizeiptr size;
140 GLuint buffer;
141 GLuint divisor;
142 };
143
144 typedef std::vector<VertexAttribState> VertexAttribStateVector;
145 typedef std::vector<BufferBinding> VertexAttribBindingVector;
146
147 struct VAOState {
148 VAOState(GLuint ibo, int nLoc, int nBindings) :
149 element_array_buffer_binding(ibo),
150 attribState(nLoc),
151 bindingState(nBindings) { }
152 VertexAttribStateVector attribState;
153 VertexAttribBindingVector bindingState;
154 GLuint element_array_buffer_binding;
155 };
156
157 typedef std::map<GLuint, VAOState> VAOStateMap;
158 struct VAOStateRef {
159 VAOStateRef() { }
160 VAOStateRef(
161 VAOStateMap::iterator iter) : it(iter) { }
162 VertexAttribState& operator[](size_t k) { return it->second.attribState[k]; }
163 BufferBinding& bufferBinding(size_t k) { return it->second.bindingState[k]; }
164 VertexAttribBindingVector& bufferBindings() { return it->second.bindingState; }
165 const VertexAttribBindingVector& bufferBindings_const() const { return it->second.bindingState; }
166 GLuint vaoId() const { return it->first; }
167 GLuint& iboId() { return it->second.element_array_buffer_binding; }
168 VAOStateMap::iterator it;
169 };
170
keunyoungb85b2752013-03-08 12:28:03 -0800171 typedef struct {
172 int unpack_alignment;
Lingfeng Yang74e29292017-01-10 14:54:38 -0800173
174 int unpack_row_length;
175 int unpack_image_height;
176 int unpack_skip_pixels;
177 int unpack_skip_rows;
178 int unpack_skip_images;
179
keunyoungb85b2752013-03-08 12:28:03 -0800180 int pack_alignment;
Lingfeng Yang74e29292017-01-10 14:54:38 -0800181
182 int pack_row_length;
183 int pack_skip_pixels;
184 int pack_skip_rows;
keunyoungb85b2752013-03-08 12:28:03 -0800185 } PixelStoreState;
186
187 enum {
Lingfeng Yang74e29292017-01-10 14:54:38 -0800188 MAX_TEXTURE_UNITS = 256,
keunyoungb85b2752013-03-08 12:28:03 -0800189 };
190
191public:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800192 GLClientState();
193 GLClientState(int majorVersion, int minorVersion);
keunyoungb85b2752013-03-08 12:28:03 -0800194 ~GLClientState();
195 int nLocations() { return m_nLocations; }
196 const PixelStoreState *pixelStoreState() { return &m_pixelStore; }
197 int setPixelStore(GLenum param, GLint value);
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800198 GLuint currentVertexArrayObject() const { return m_currVaoState.vaoId(); }
199 GLuint currentArrayVbo() { return m_arrayBuffer; }
200 GLuint currentIndexVbo() { return m_currVaoState.iboId(); }
keunyoungb85b2752013-03-08 12:28:03 -0800201 void enable(int location, int state);
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800202 // Vertex array objects and vertex attributes
203 void addVertexArrayObjects(GLsizei n, GLuint* arrays);
204 void removeVertexArrayObjects(GLsizei n, const GLuint* arrays);
205 void addVertexArrayObject(GLuint name);
206 void removeVertexArrayObject(GLuint name);
207 void setVertexArrayObject(GLuint vao);
208 bool isVertexArrayObject(GLuint vao) const;
209 void setVertexAttribState(int location, int size, GLenum type, GLboolean normalized, GLsizei stride, const void *data, bool isInt = false);
210 void setVertexBindingDivisor(int bindingindex, GLuint divisor);
211 const BufferBinding& getCurrAttributeBindingInfo(int attribindex);
212 void setVertexAttribBinding(int attribindex, int bindingindex);
213 void setVertexAttribFormat(int location, int size, GLenum type, GLboolean normalized, GLuint reloffset, bool isInt = false);
214 const VertexAttribState& getState(int location);
215 const VertexAttribState& getStateAndEnableDirty(int location, bool *enableChanged);
keunyoungb85b2752013-03-08 12:28:03 -0800216 int getLocation(GLenum loc);
217 void setActiveTexture(int texUnit) {m_activeTexture = texUnit; };
218 int getActiveTexture() const { return m_activeTexture; }
Lingfeng Yangb0176982016-03-01 21:27:49 -0800219 void setMaxVertexAttribs(int val) {
220 m_maxVertexAttribs = val;
221 m_maxVertexAttribsDirty = false;
222 }
keunyoungb85b2752013-03-08 12:28:03 -0800223
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800224 void unBindBuffer(GLuint id);
bohub0f0cdf2014-11-06 18:08:07 -0800225
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800226 int bindBuffer(GLenum target, GLuint id);
227 void bindIndexedBuffer(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size, GLintptr stride, GLintptr effectiveStride);
228 int getMaxIndexedBufferBindings(GLenum target) const;
keunyoungb85b2752013-03-08 12:28:03 -0800229
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800230 int getBuffer(GLenum target);
231
Lingfeng Yang74e29292017-01-10 14:54:38 -0800232 size_t pixelDataSize(GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, int pack) const;
233 size_t pboNeededDataSize(GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, int pack) const;
234 size_t clearBufferNumElts(GLenum buffer) const;
keunyoungb85b2752013-03-08 12:28:03 -0800235
236 void setCurrentProgram(GLint program) { m_currentProgram = program; }
237 GLint currentProgram() const { return m_currentProgram; }
238
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800239 struct UniformBlockInfoKey {
240 GLuint program;
241 GLuint uniformBlockIndex;
242 };
243 struct UniformBlockInfoKeyCompare {
244 bool operator() (const UniformBlockInfoKey& a,
245 const UniformBlockInfoKey& b) const {
246 if (a.program != b.program) return a.program < b.program;
247 if (a.uniformBlockIndex != b.uniformBlockIndex) return a.uniformBlockIndex < b.uniformBlockIndex;
248 return false;
249 }
250 };
251 struct UniformBlockUniformInfo {
252 size_t numActiveUniforms;
253 };
254
255 typedef std::map<UniformBlockInfoKey, UniformBlockUniformInfo, UniformBlockInfoKeyCompare> UniformBlockInfoMap;
256 UniformBlockInfoMap m_uniformBlockInfoMap;
257
Lingfeng Yange6556dc2017-01-09 12:04:12 -0800258 void setNumActiveUniformsInUniformBlock(GLuint program, GLuint uniformBlockIndex, GLint numActiveUniforms);
259 size_t numActiveUniformsInUniformBlock(GLuint program, GLuint uniformBlockIndex) const;
keunyoungb85b2752013-03-08 12:28:03 -0800260 /* OES_EGL_image_external
261 *
262 * These functions manipulate GL state which interacts with the
263 * OES_EGL_image_external extension, to support client-side emulation on
264 * top of host implementations that don't have it.
265 *
266 * Most of these calls should only be used with TEXTURE_2D or
267 * TEXTURE_EXTERNAL_OES texture targets; TEXTURE_CUBE_MAP or other extension
268 * targets should bypass this. An exception is bindTexture(), which should
269 * see all glBindTexture() calls for any target.
270 */
271
272 // glActiveTexture(GL_TEXTURE0 + i)
273 // Sets the active texture unit. Up to MAX_TEXTURE_UNITS are supported.
274 GLenum setActiveTextureUnit(GLenum texture);
275 GLenum getActiveTextureUnit() const;
276
277 // glEnable(GL_TEXTURE_(2D|EXTERNAL_OES))
278 void enableTextureTarget(GLenum target);
279
280 // glDisable(GL_TEXTURE_(2D|EXTERNAL_OES))
281 void disableTextureTarget(GLenum target);
282
283 // Implements the target priority logic:
284 // * Return GL_TEXTURE_EXTERNAL_OES if enabled, else
285 // * Return GL_TEXTURE_2D if enabled, else
286 // * Return the allDisabled value.
287 // For some cases passing GL_TEXTURE_2D for allDisabled makes callee code
288 // simpler; for other cases passing a recognizable enum like GL_ZERO or
289 // GL_INVALID_ENUM is appropriate.
290 GLenum getPriorityEnabledTarget(GLenum allDisabled) const;
291
292 // glBindTexture(GL_TEXTURE_*, ...)
293 // Set the target binding of the active texture unit to texture. Returns
294 // GL_NO_ERROR on success or GL_INVALID_OPERATION if the texture has
295 // previously been bound to a different target. If firstUse is not NULL,
296 // it is set to indicate whether this is the first use of the texture.
297 // For accurate error detection, bindTexture should be called for *all*
298 // targets, not just 2D and EXTERNAL_OES.
299 GLenum bindTexture(GLenum target, GLuint texture, GLboolean* firstUse);
Lingfeng Yang74e29292017-01-10 14:54:38 -0800300 void setBoundEGLImage(GLenum target, GLeglImageOES image);
keunyoungb85b2752013-03-08 12:28:03 -0800301
302 // Return the texture currently bound to GL_TEXTURE_(2D|EXTERNAL_OES).
303 GLuint getBoundTexture(GLenum target) const;
Lingfeng Yang74e29292017-01-10 14:54:38 -0800304 // Other publicly-visible texture queries
305 GLenum queryTexLastBoundTarget(GLuint name) const;
306 GLenum queryTexFormat(GLuint name) const;
307 GLint queryTexInternalFormat(GLuint name) const;
308 GLsizei queryTexWidth(GLsizei level, GLuint name) const;
309 GLsizei queryTexHeight(GLsizei level, GLuint name) const;
310 GLsizei queryTexDepth(GLsizei level, GLuint name) const;
311 bool queryTexEGLImageBacked(GLuint name) const;
keunyoungb85b2752013-03-08 12:28:03 -0800312
Lingfeng Yange00ec9d2016-09-16 08:54:03 -0700313 // For AMD GPUs, it is easy for the emulator to segfault
314 // (esp. in dEQP) when a cube map is defined using glCopyTexImage2D
315 // and uses GL_LUMINANCE as internal format.
316 // In particular, the segfault happens when negative components of
317 // cube maps are defined before positive ones,
318 // This procedure checks internal state to see if we have defined
319 // the positive component of a cube map already. If not, it returns
320 // which positive component needs to be defined first.
321 // If there is no need for the extra definition, 0 is returned.
322 GLenum copyTexImageLuminanceCubeMapAMDWorkaround(GLenum target, GLint level,
323 GLenum internalformat);
324
Lingfeng Yang69066602016-04-12 09:29:11 -0700325 // Tracks the format of the currently bound texture.
326 // This is to pass dEQP tests for fbo completeness.
327 void setBoundTextureInternalFormat(GLenum target, GLint format);
328 void setBoundTextureFormat(GLenum target, GLenum format);
329 void setBoundTextureType(GLenum target, GLenum type);
Lingfeng Yang74e29292017-01-10 14:54:38 -0800330 void setBoundTextureDims(GLenum target, GLsizei level, GLsizei width, GLsizei height, GLsizei depth);
331 void setBoundTextureSamples(GLenum target, GLsizei samples);
332
333 // glTexStorage2D disallows any change in texture format after it is set for a particular texture.
334 void setBoundTextureImmutableFormat(GLenum target);
335 bool isBoundTextureImmutableFormat(GLenum target) const;
Lingfeng Yang69066602016-04-12 09:29:11 -0700336
keunyoungb85b2752013-03-08 12:28:03 -0800337 // glDeleteTextures(...)
338 // Remove references to the to-be-deleted textures.
339 void deleteTextures(GLsizei n, const GLuint* textures);
340
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700341 // Render buffer objects
342 void addRenderbuffers(GLsizei n, GLuint* renderbuffers);
343 void removeRenderbuffers(GLsizei n, const GLuint* renderbuffers);
344 bool usedRenderbufferName(GLuint name) const;
345 void bindRenderbuffer(GLenum target, GLuint name);
346 GLuint boundRenderbuffer() const;
Lingfeng Yang69066602016-04-12 09:29:11 -0700347 void setBoundRenderbufferFormat(GLenum format);
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800348 void setBoundRenderbufferSamples(GLsizei samples);
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700349
350 // Frame buffer objects
351 void addFramebuffers(GLsizei n, GLuint* framebuffers);
352 void removeFramebuffers(GLsizei n, const GLuint* framebuffers);
353 bool usedFramebufferName(GLuint name) const;
354 void bindFramebuffer(GLenum target, GLuint name);
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800355 void setCheckFramebufferStatus(GLenum target, GLenum status);
356 GLenum getCheckFramebufferStatus(GLenum target) const;
357 GLuint boundFramebuffer(GLenum target) const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700358
359 // Texture object -> FBO
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800360 void attachTextureObject(GLenum target, GLenum attachment, GLuint texture);
361 GLuint getFboAttachmentTextureId(GLenum target, GLenum attachment) const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700362
363 // RBO -> FBO
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800364 void detachRbo(GLuint renderbuffer);
365 void detachRboFromFbo(GLenum target, GLenum attachment, GLuint renderbuffer);
366 void attachRbo(GLenum target, GLenum attachment, GLuint renderbuffer);
367 GLuint getFboAttachmentRboId(GLenum target, GLenum attachment) const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700368
369 // FBO attachments in general
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800370 bool attachmentHasObject(GLenum target, GLenum attachment) const;
371 GLuint objectOfAttachment(GLenum target, GLenum attachment) const;
372
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700373
Lingfeng Yang74e29292017-01-10 14:54:38 -0800374 void setTextureData(SharedTextureDataMap* sharedTexData);
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700375 // set eglsurface property on default framebuffer
376 // if coming from eglMakeCurrent
377 void fromMakeCurrent();
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800378 // set indexed buffer state.
379 // We need to query the underlying OpenGL to get
380 // accurate values for indexed buffers
381 // and # render targets.
382 void initFromCaps(
383 int max_transform_feedback_separate_attribs,
384 int max_uniform_buffer_bindings,
385 int max_atomic_counter_buffer_bindings,
386 int max_shader_storage_buffer_bindings,
387 int max_vertex_attrib_bindings,
388 int max_color_attachments,
389 int max_draw_buffers);
390 bool needsInitFromCaps() const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700391
Lingfeng Yang69066602016-04-12 09:29:11 -0700392 // Queries the format backing the current framebuffer.
393 // Type differs depending on whether the attachment
394 // is a texture or renderbuffer.
395 void getBoundFramebufferFormat(
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800396 GLenum target,
397 GLenum attachment,
398 FboFormatInfo* res_info) const;
399 FboAttachmentType getBoundFramebufferAttachmentType(
400 GLenum target,
401 GLenum attachment) const;
402 int getMaxColorAttachments() const;
403 int getMaxDrawBuffers() const;
keunyoungb85b2752013-03-08 12:28:03 -0800404private:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800405 void init();
406 bool m_initialized;
keunyoungb85b2752013-03-08 12:28:03 -0800407 PixelStoreState m_pixelStore;
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800408
409 // GL_ARRAY_BUFFER_BINDING is separate from VAO state
410 GLuint m_arrayBuffer;
411 VAOStateMap m_vaoMap;
412 VAOStateRef m_currVaoState;
413
414 // Other buffer id's, other targets
415 GLuint m_copyReadBuffer;
416 GLuint m_copyWriteBuffer;
417
418 GLuint m_pixelPackBuffer;
419 GLuint m_pixelUnpackBuffer;
420
421 GLuint m_transformFeedbackBuffer;
422 GLuint m_uniformBuffer;
423
424 GLuint m_atomicCounterBuffer;
425 GLuint m_dispatchIndirectBuffer;
426 GLuint m_drawIndirectBuffer;
427 GLuint m_shaderStorageBuffer;
428
429 bool m_transformFeedbackActiveUnpaused;
430
431 int m_max_transform_feedback_separate_attribs;
432 int m_max_uniform_buffer_bindings;
433 int m_max_atomic_counter_buffer_bindings;
434 int m_max_shader_storage_buffer_bindings;
435 int m_max_vertex_attrib_bindings;
436 std::vector<BufferBinding> m_indexedTransformFeedbackBuffers;
437 std::vector<BufferBinding> m_indexedUniformBuffers;
438 std::vector<BufferBinding> m_indexedAtomicCounterBuffers;
439 std::vector<BufferBinding> m_indexedShaderStorageBuffers;
440
Lingfeng Yang74e29292017-01-10 14:54:38 -0800441 int m_glesMajorVersion;
442 int m_glesMinorVersion;
Lingfeng Yangb0176982016-03-01 21:27:49 -0800443 int m_maxVertexAttribs;
444 bool m_maxVertexAttribsDirty;
keunyoungb85b2752013-03-08 12:28:03 -0800445 int m_nLocations;
keunyoungb85b2752013-03-08 12:28:03 -0800446 int m_activeTexture;
447 GLint m_currentProgram;
448
keunyoungb85b2752013-03-08 12:28:03 -0800449 enum TextureTarget {
450 TEXTURE_2D = 0,
451 TEXTURE_EXTERNAL = 1,
Lingfeng Yang74e29292017-01-10 14:54:38 -0800452 TEXTURE_CUBE_MAP = 2,
453 TEXTURE_2D_ARRAY = 3,
454 TEXTURE_3D = 4,
455 TEXTURE_2D_MULTISAMPLE = 5,
keunyoungb85b2752013-03-08 12:28:03 -0800456 TEXTURE_TARGET_COUNT
457 };
458 struct TextureUnit {
459 unsigned int enables;
460 GLuint texture[TEXTURE_TARGET_COUNT];
461 };
keunyoungb85b2752013-03-08 12:28:03 -0800462 struct TextureState {
463 TextureUnit unit[MAX_TEXTURE_UNITS];
464 TextureUnit* activeUnit;
Lingfeng Yang74e29292017-01-10 14:54:38 -0800465 // Initialized from shared group.
466 SharedTextureDataMap* textureRecs;
keunyoungb85b2752013-03-08 12:28:03 -0800467 };
468 TextureState m_tex;
469
Lingfeng Yange00ec9d2016-09-16 08:54:03 -0700470 // State tracking of cube map definitions.
471 // Currently used only for driver workarounds
472 // when using GL_LUMINANCE and defining cube maps with
473 // glCopyTexImage2D.
474 struct CubeMapDef {
475 GLuint id;
476 GLenum target;
477 GLint level;
478 GLenum internalformat;
479 };
480 struct CubeMapDefCompare {
481 bool operator() (const CubeMapDef& a,
482 const CubeMapDef& b) const {
483 if (a.id != b.id) return a.id < b.id;
484 if (a.target != b.target) return a.target < b.target;
485 if (a.level != b.level) return a.level < b.level;
486 if (a.internalformat != b.internalformat)
487 return a.internalformat < b.internalformat;
488 return false;
489 }
490 };
491 std::set<CubeMapDef, CubeMapDefCompare> m_cubeMapDefs;
492 void writeCopyTexImageState(GLenum target, GLint level,
493 GLenum internalformat);
494 GLenum copyTexImageNeededTarget(GLenum target, GLint level,
495 GLenum internalformat);
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700496
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800497 int m_max_color_attachments;
498 int m_max_draw_buffers;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700499 struct RboState {
500 GLuint boundRenderbuffer;
501 size_t boundRenderbufferIndex;
502 std::vector<RboProps> rboData;
503 };
504 RboState mRboState;
505 void addFreshRenderbuffer(GLuint name);
506 void setBoundRenderbufferIndex();
507 size_t getRboIndex(GLuint name) const;
508 RboProps& boundRboProps();
509 const RboProps& boundRboProps_const() const;
510
511 struct FboState {
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800512 GLuint boundDrawFramebuffer;
513 GLuint boundReadFramebuffer;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700514 size_t boundFramebufferIndex;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800515 std::map<GLuint, FboProps> fboData;
516 GLenum drawFboCheckStatus;
517 GLenum readFboCheckStatus;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700518 };
519 FboState mFboState;
520 void addFreshFramebuffer(GLuint name);
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800521 FboProps& boundFboProps(GLenum target);
522 const FboProps& boundFboProps_const(GLenum target) const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700523
Lingfeng Yang69066602016-04-12 09:29:11 -0700524 // Querying framebuffer format
525 GLenum queryRboFormat(GLuint name) const;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800526 GLsizei queryRboSamples(GLuint name) const;
Lingfeng Yang69066602016-04-12 09:29:11 -0700527 GLenum queryTexType(GLuint name) const;
Lingfeng Yang74e29292017-01-10 14:54:38 -0800528 GLsizei queryTexSamples(GLuint name) const;
Lingfeng Yang69066602016-04-12 09:29:11 -0700529
keunyoungb85b2752013-03-08 12:28:03 -0800530 static int compareTexId(const void* pid, const void* prec);
531 TextureRec* addTextureRec(GLuint id, GLenum target);
Lingfeng Yang74e29292017-01-10 14:54:38 -0800532 TextureRec* getTextureRec(GLuint id) const;
keunyoungb85b2752013-03-08 12:28:03 -0800533
534public:
535 void getClientStatePointer(GLenum pname, GLvoid** params);
536
537 template <class T>
538 int getVertexAttribParameter(GLuint index, GLenum param, T *ptr)
539 {
540 bool handled = true;
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800541 const VertexAttribState& vertexAttrib = getState(index);
542 const BufferBinding& vertexAttribBufferBinding =
543 m_currVaoState.bufferBindings_const()[vertexAttrib.bindingindex];
keunyoungb85b2752013-03-08 12:28:03 -0800544
545 switch(param) {
546 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800547 *ptr = (T)(vertexAttribBufferBinding.buffer);
keunyoungb85b2752013-03-08 12:28:03 -0800548 break;
549 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800550 *ptr = (T)(vertexAttrib.enabled);
551 break;
552#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD
553 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
554 *ptr = (T)(vertexAttrib.isInt);
keunyoungb85b2752013-03-08 12:28:03 -0800555 break;
556 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800557 *ptr = (T)(vertexAttrib.size);
keunyoungb85b2752013-03-08 12:28:03 -0800558 break;
559 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800560 *ptr = (T)(vertexAttribBufferBinding.stride);
keunyoungb85b2752013-03-08 12:28:03 -0800561 break;
562 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800563 *ptr = (T)(vertexAttrib.type);
keunyoungb85b2752013-03-08 12:28:03 -0800564 break;
565 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800566 *ptr = (T)(vertexAttrib.normalized);
keunyoungb85b2752013-03-08 12:28:03 -0800567 break;
568 case GL_CURRENT_VERTEX_ATTRIB:
569 handled = false;
570 break;
571 default:
572 handled = false;
573 ERR("unknown vertex-attrib parameter param %d\n", param);
574 }
575 return handled;
576 }
577
578 template <class T>
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800579 bool getClientStateParameter(GLenum param, T* out)
keunyoungb85b2752013-03-08 12:28:03 -0800580 {
581 bool isClientStateParam = false;
582 switch (param) {
583 case GL_CLIENT_ACTIVE_TEXTURE: {
584 GLint tex = getActiveTexture() + GL_TEXTURE0;
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800585 *out = tex;
keunyoungb85b2752013-03-08 12:28:03 -0800586 isClientStateParam = true;
587 break;
588 }
589 case GL_VERTEX_ARRAY_SIZE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800590 const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION);
591 *out = state.size;
keunyoungb85b2752013-03-08 12:28:03 -0800592 isClientStateParam = true;
593 break;
594 }
595 case GL_VERTEX_ARRAY_TYPE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800596 const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION);
597 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800598 isClientStateParam = true;
599 break;
600 }
601 case GL_VERTEX_ARRAY_STRIDE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800602 const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION);
603 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800604 isClientStateParam = true;
605 break;
606 }
607 case GL_COLOR_ARRAY_SIZE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800608 const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION);
609 *out = state.size;
keunyoungb85b2752013-03-08 12:28:03 -0800610 isClientStateParam = true;
611 break;
612 }
613 case GL_COLOR_ARRAY_TYPE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800614 const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION);
615 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800616 isClientStateParam = true;
617 break;
618 }
619 case GL_COLOR_ARRAY_STRIDE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800620 const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION);
621 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800622 isClientStateParam = true;
623 break;
624 }
625 case GL_NORMAL_ARRAY_TYPE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800626 const GLClientState::VertexAttribState& state = getState(GLClientState::NORMAL_LOCATION);
627 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800628 isClientStateParam = true;
629 break;
630 }
631 case GL_NORMAL_ARRAY_STRIDE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800632 const GLClientState::VertexAttribState& state = getState(GLClientState::NORMAL_LOCATION);
633 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800634 isClientStateParam = true;
635 break;
636 }
637 case GL_TEXTURE_COORD_ARRAY_SIZE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800638 const GLClientState::VertexAttribState& state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION);
639 *out = state.size;
keunyoungb85b2752013-03-08 12:28:03 -0800640 isClientStateParam = true;
641 break;
642 }
643 case GL_TEXTURE_COORD_ARRAY_TYPE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800644 const GLClientState::VertexAttribState& state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION);
645 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800646 isClientStateParam = true;
647 break;
648 }
649 case GL_TEXTURE_COORD_ARRAY_STRIDE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800650 const GLClientState::VertexAttribState& state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION);
651 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800652 isClientStateParam = true;
653 break;
654 }
655 case GL_POINT_SIZE_ARRAY_TYPE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800656 const GLClientState::VertexAttribState& state = getState(GLClientState::POINTSIZE_LOCATION);
657 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800658 isClientStateParam = true;
659 break;
660 }
661 case GL_POINT_SIZE_ARRAY_STRIDE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800662 const GLClientState::VertexAttribState& state = getState(GLClientState::POINTSIZE_LOCATION);
663 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800664 isClientStateParam = true;
665 break;
666 }
667 case GL_MATRIX_INDEX_ARRAY_SIZE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800668 const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION);
669 *out = state.size;
keunyoungb85b2752013-03-08 12:28:03 -0800670 isClientStateParam = true;
671 break;
672 }
673 case GL_MATRIX_INDEX_ARRAY_TYPE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800674 const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION);
675 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800676 isClientStateParam = true;
677 break;
678 }
679 case GL_MATRIX_INDEX_ARRAY_STRIDE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800680 const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION);
681 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800682 isClientStateParam = true;
683 break;
684 }
685 case GL_WEIGHT_ARRAY_SIZE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800686 const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION);
687 *out = state.size;
keunyoungb85b2752013-03-08 12:28:03 -0800688 isClientStateParam = true;
689 break;
690 }
691 case GL_WEIGHT_ARRAY_TYPE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800692 const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION);
693 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800694 isClientStateParam = true;
695 break;
696 }
697 case GL_WEIGHT_ARRAY_STRIDE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800698 const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION);
699 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800700 isClientStateParam = true;
701 break;
702 }
703 case GL_VERTEX_ARRAY_BUFFER_BINDING: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800704 const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION);
705 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800706 isClientStateParam = true;
707 break;
708 }
709 case GL_NORMAL_ARRAY_BUFFER_BINDING: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800710 const GLClientState::VertexAttribState& state = getState(GLClientState::NORMAL_LOCATION);
711 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800712 isClientStateParam = true;
713 break;
714 }
715 case GL_COLOR_ARRAY_BUFFER_BINDING: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800716 const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION);
717 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800718 isClientStateParam = true;
719 break;
720 }
721 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800722 const GLClientState::VertexAttribState& state = getState(getActiveTexture()+GLClientState::TEXCOORD0_LOCATION);
723 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800724 isClientStateParam = true;
725 break;
726 }
727 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800728 const GLClientState::VertexAttribState& state = getState(GLClientState::POINTSIZE_LOCATION);
729 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800730 isClientStateParam = true;
731 break;
732 }
733 case GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800734 const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION);
735 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800736 isClientStateParam = true;
737 break;
738 }
739 case GL_WEIGHT_ARRAY_BUFFER_BINDING_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800740 const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION);
741 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800742 isClientStateParam = true;
743 break;
744 }
745 case GL_ARRAY_BUFFER_BINDING: {
746 int buffer = getBuffer(GL_ARRAY_BUFFER);
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800747 *out = buffer;
keunyoungb85b2752013-03-08 12:28:03 -0800748 isClientStateParam = true;
749 break;
750 }
751 case GL_ELEMENT_ARRAY_BUFFER_BINDING: {
752 int buffer = getBuffer(GL_ELEMENT_ARRAY_BUFFER);
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800753 *out = buffer;
keunyoungb85b2752013-03-08 12:28:03 -0800754 isClientStateParam = true;
755 break;
756 }
Lingfeng Yangb0176982016-03-01 21:27:49 -0800757 case GL_MAX_VERTEX_ATTRIBS: {
758 if (m_maxVertexAttribsDirty) {
759 isClientStateParam = false;
760 } else {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800761 *out = m_maxVertexAttribs;
Lingfeng Yangb0176982016-03-01 21:27:49 -0800762 isClientStateParam = true;
763 }
764 break;
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800765 }
keunyoungb85b2752013-03-08 12:28:03 -0800766 }
767 return isClientStateParam;
768 }
769
770};
771#endif