blob: 4b2494784b959984dc8f8f0b487931fa6442a267 [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;
Lingfeng Yangb3dc29f2017-01-09 13:25:31 -0800260
261 typedef std::map<GLuint, GLuint> ProgramPipelineMap;
262 typedef ProgramPipelineMap::iterator ProgramPipelineIterator;
263 void associateProgramWithPipeline(GLuint program, GLuint pipeline);
264 ProgramPipelineIterator programPipelineBegin();
265 ProgramPipelineIterator programPipelineEnd();
266
keunyoungb85b2752013-03-08 12:28:03 -0800267 /* OES_EGL_image_external
268 *
269 * These functions manipulate GL state which interacts with the
270 * OES_EGL_image_external extension, to support client-side emulation on
271 * top of host implementations that don't have it.
272 *
273 * Most of these calls should only be used with TEXTURE_2D or
274 * TEXTURE_EXTERNAL_OES texture targets; TEXTURE_CUBE_MAP or other extension
275 * targets should bypass this. An exception is bindTexture(), which should
276 * see all glBindTexture() calls for any target.
277 */
278
279 // glActiveTexture(GL_TEXTURE0 + i)
280 // Sets the active texture unit. Up to MAX_TEXTURE_UNITS are supported.
281 GLenum setActiveTextureUnit(GLenum texture);
282 GLenum getActiveTextureUnit() const;
283
284 // glEnable(GL_TEXTURE_(2D|EXTERNAL_OES))
285 void enableTextureTarget(GLenum target);
286
287 // glDisable(GL_TEXTURE_(2D|EXTERNAL_OES))
288 void disableTextureTarget(GLenum target);
289
290 // Implements the target priority logic:
291 // * Return GL_TEXTURE_EXTERNAL_OES if enabled, else
292 // * Return GL_TEXTURE_2D if enabled, else
293 // * Return the allDisabled value.
294 // For some cases passing GL_TEXTURE_2D for allDisabled makes callee code
295 // simpler; for other cases passing a recognizable enum like GL_ZERO or
296 // GL_INVALID_ENUM is appropriate.
297 GLenum getPriorityEnabledTarget(GLenum allDisabled) const;
298
299 // glBindTexture(GL_TEXTURE_*, ...)
300 // Set the target binding of the active texture unit to texture. Returns
301 // GL_NO_ERROR on success or GL_INVALID_OPERATION if the texture has
302 // previously been bound to a different target. If firstUse is not NULL,
303 // it is set to indicate whether this is the first use of the texture.
304 // For accurate error detection, bindTexture should be called for *all*
305 // targets, not just 2D and EXTERNAL_OES.
306 GLenum bindTexture(GLenum target, GLuint texture, GLboolean* firstUse);
Lingfeng Yang74e29292017-01-10 14:54:38 -0800307 void setBoundEGLImage(GLenum target, GLeglImageOES image);
keunyoungb85b2752013-03-08 12:28:03 -0800308
309 // Return the texture currently bound to GL_TEXTURE_(2D|EXTERNAL_OES).
310 GLuint getBoundTexture(GLenum target) const;
Lingfeng Yang74e29292017-01-10 14:54:38 -0800311 // Other publicly-visible texture queries
312 GLenum queryTexLastBoundTarget(GLuint name) const;
313 GLenum queryTexFormat(GLuint name) const;
314 GLint queryTexInternalFormat(GLuint name) const;
315 GLsizei queryTexWidth(GLsizei level, GLuint name) const;
316 GLsizei queryTexHeight(GLsizei level, GLuint name) const;
317 GLsizei queryTexDepth(GLsizei level, GLuint name) const;
318 bool queryTexEGLImageBacked(GLuint name) const;
keunyoungb85b2752013-03-08 12:28:03 -0800319
Lingfeng Yange00ec9d2016-09-16 08:54:03 -0700320 // For AMD GPUs, it is easy for the emulator to segfault
321 // (esp. in dEQP) when a cube map is defined using glCopyTexImage2D
322 // and uses GL_LUMINANCE as internal format.
323 // In particular, the segfault happens when negative components of
324 // cube maps are defined before positive ones,
325 // This procedure checks internal state to see if we have defined
326 // the positive component of a cube map already. If not, it returns
327 // which positive component needs to be defined first.
328 // If there is no need for the extra definition, 0 is returned.
329 GLenum copyTexImageLuminanceCubeMapAMDWorkaround(GLenum target, GLint level,
330 GLenum internalformat);
331
Lingfeng Yang69066602016-04-12 09:29:11 -0700332 // Tracks the format of the currently bound texture.
333 // This is to pass dEQP tests for fbo completeness.
334 void setBoundTextureInternalFormat(GLenum target, GLint format);
335 void setBoundTextureFormat(GLenum target, GLenum format);
336 void setBoundTextureType(GLenum target, GLenum type);
Lingfeng Yang74e29292017-01-10 14:54:38 -0800337 void setBoundTextureDims(GLenum target, GLsizei level, GLsizei width, GLsizei height, GLsizei depth);
338 void setBoundTextureSamples(GLenum target, GLsizei samples);
339
340 // glTexStorage2D disallows any change in texture format after it is set for a particular texture.
341 void setBoundTextureImmutableFormat(GLenum target);
342 bool isBoundTextureImmutableFormat(GLenum target) const;
Lingfeng Yang69066602016-04-12 09:29:11 -0700343
keunyoungb85b2752013-03-08 12:28:03 -0800344 // glDeleteTextures(...)
345 // Remove references to the to-be-deleted textures.
346 void deleteTextures(GLsizei n, const GLuint* textures);
347
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700348 // Render buffer objects
349 void addRenderbuffers(GLsizei n, GLuint* renderbuffers);
350 void removeRenderbuffers(GLsizei n, const GLuint* renderbuffers);
351 bool usedRenderbufferName(GLuint name) const;
352 void bindRenderbuffer(GLenum target, GLuint name);
353 GLuint boundRenderbuffer() const;
Lingfeng Yang69066602016-04-12 09:29:11 -0700354 void setBoundRenderbufferFormat(GLenum format);
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800355 void setBoundRenderbufferSamples(GLsizei samples);
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700356
357 // Frame buffer objects
358 void addFramebuffers(GLsizei n, GLuint* framebuffers);
359 void removeFramebuffers(GLsizei n, const GLuint* framebuffers);
360 bool usedFramebufferName(GLuint name) const;
361 void bindFramebuffer(GLenum target, GLuint name);
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800362 void setCheckFramebufferStatus(GLenum target, GLenum status);
363 GLenum getCheckFramebufferStatus(GLenum target) const;
364 GLuint boundFramebuffer(GLenum target) const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700365
366 // Texture object -> FBO
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800367 void attachTextureObject(GLenum target, GLenum attachment, GLuint texture);
368 GLuint getFboAttachmentTextureId(GLenum target, GLenum attachment) const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700369
370 // RBO -> FBO
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800371 void detachRbo(GLuint renderbuffer);
372 void detachRboFromFbo(GLenum target, GLenum attachment, GLuint renderbuffer);
373 void attachRbo(GLenum target, GLenum attachment, GLuint renderbuffer);
374 GLuint getFboAttachmentRboId(GLenum target, GLenum attachment) const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700375
376 // FBO attachments in general
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800377 bool attachmentHasObject(GLenum target, GLenum attachment) const;
378 GLuint objectOfAttachment(GLenum target, GLenum attachment) const;
379
Lingfeng Yang4a66b312017-01-09 13:27:49 -0800380 // Transform feedback state
381 void setTransformFeedbackActiveUnpaused(bool activeUnpaused);
382 bool getTransformFeedbackActiveUnpaused() const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700383
Lingfeng Yang74e29292017-01-10 14:54:38 -0800384 void setTextureData(SharedTextureDataMap* sharedTexData);
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700385 // set eglsurface property on default framebuffer
386 // if coming from eglMakeCurrent
387 void fromMakeCurrent();
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800388 // set indexed buffer state.
389 // We need to query the underlying OpenGL to get
390 // accurate values for indexed buffers
391 // and # render targets.
392 void initFromCaps(
393 int max_transform_feedback_separate_attribs,
394 int max_uniform_buffer_bindings,
395 int max_atomic_counter_buffer_bindings,
396 int max_shader_storage_buffer_bindings,
397 int max_vertex_attrib_bindings,
398 int max_color_attachments,
399 int max_draw_buffers);
400 bool needsInitFromCaps() const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700401
Lingfeng Yang69066602016-04-12 09:29:11 -0700402 // Queries the format backing the current framebuffer.
403 // Type differs depending on whether the attachment
404 // is a texture or renderbuffer.
405 void getBoundFramebufferFormat(
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800406 GLenum target,
407 GLenum attachment,
408 FboFormatInfo* res_info) const;
409 FboAttachmentType getBoundFramebufferAttachmentType(
410 GLenum target,
411 GLenum attachment) const;
412 int getMaxColorAttachments() const;
413 int getMaxDrawBuffers() const;
keunyoungb85b2752013-03-08 12:28:03 -0800414private:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800415 void init();
416 bool m_initialized;
keunyoungb85b2752013-03-08 12:28:03 -0800417 PixelStoreState m_pixelStore;
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800418
419 // GL_ARRAY_BUFFER_BINDING is separate from VAO state
420 GLuint m_arrayBuffer;
421 VAOStateMap m_vaoMap;
422 VAOStateRef m_currVaoState;
423
424 // Other buffer id's, other targets
425 GLuint m_copyReadBuffer;
426 GLuint m_copyWriteBuffer;
427
428 GLuint m_pixelPackBuffer;
429 GLuint m_pixelUnpackBuffer;
430
431 GLuint m_transformFeedbackBuffer;
432 GLuint m_uniformBuffer;
433
434 GLuint m_atomicCounterBuffer;
435 GLuint m_dispatchIndirectBuffer;
436 GLuint m_drawIndirectBuffer;
437 GLuint m_shaderStorageBuffer;
438
439 bool m_transformFeedbackActiveUnpaused;
440
441 int m_max_transform_feedback_separate_attribs;
442 int m_max_uniform_buffer_bindings;
443 int m_max_atomic_counter_buffer_bindings;
444 int m_max_shader_storage_buffer_bindings;
445 int m_max_vertex_attrib_bindings;
446 std::vector<BufferBinding> m_indexedTransformFeedbackBuffers;
447 std::vector<BufferBinding> m_indexedUniformBuffers;
448 std::vector<BufferBinding> m_indexedAtomicCounterBuffers;
449 std::vector<BufferBinding> m_indexedShaderStorageBuffers;
450
Lingfeng Yang74e29292017-01-10 14:54:38 -0800451 int m_glesMajorVersion;
452 int m_glesMinorVersion;
Lingfeng Yangb0176982016-03-01 21:27:49 -0800453 int m_maxVertexAttribs;
454 bool m_maxVertexAttribsDirty;
keunyoungb85b2752013-03-08 12:28:03 -0800455 int m_nLocations;
keunyoungb85b2752013-03-08 12:28:03 -0800456 int m_activeTexture;
457 GLint m_currentProgram;
Lingfeng Yangb3dc29f2017-01-09 13:25:31 -0800458 ProgramPipelineMap m_programPipelines;
keunyoungb85b2752013-03-08 12:28:03 -0800459
keunyoungb85b2752013-03-08 12:28:03 -0800460 enum TextureTarget {
461 TEXTURE_2D = 0,
462 TEXTURE_EXTERNAL = 1,
Lingfeng Yang74e29292017-01-10 14:54:38 -0800463 TEXTURE_CUBE_MAP = 2,
464 TEXTURE_2D_ARRAY = 3,
465 TEXTURE_3D = 4,
466 TEXTURE_2D_MULTISAMPLE = 5,
keunyoungb85b2752013-03-08 12:28:03 -0800467 TEXTURE_TARGET_COUNT
468 };
469 struct TextureUnit {
470 unsigned int enables;
471 GLuint texture[TEXTURE_TARGET_COUNT];
472 };
keunyoungb85b2752013-03-08 12:28:03 -0800473 struct TextureState {
474 TextureUnit unit[MAX_TEXTURE_UNITS];
475 TextureUnit* activeUnit;
Lingfeng Yang74e29292017-01-10 14:54:38 -0800476 // Initialized from shared group.
477 SharedTextureDataMap* textureRecs;
keunyoungb85b2752013-03-08 12:28:03 -0800478 };
479 TextureState m_tex;
480
Lingfeng Yange00ec9d2016-09-16 08:54:03 -0700481 // State tracking of cube map definitions.
482 // Currently used only for driver workarounds
483 // when using GL_LUMINANCE and defining cube maps with
484 // glCopyTexImage2D.
485 struct CubeMapDef {
486 GLuint id;
487 GLenum target;
488 GLint level;
489 GLenum internalformat;
490 };
491 struct CubeMapDefCompare {
492 bool operator() (const CubeMapDef& a,
493 const CubeMapDef& b) const {
494 if (a.id != b.id) return a.id < b.id;
495 if (a.target != b.target) return a.target < b.target;
496 if (a.level != b.level) return a.level < b.level;
497 if (a.internalformat != b.internalformat)
498 return a.internalformat < b.internalformat;
499 return false;
500 }
501 };
502 std::set<CubeMapDef, CubeMapDefCompare> m_cubeMapDefs;
503 void writeCopyTexImageState(GLenum target, GLint level,
504 GLenum internalformat);
505 GLenum copyTexImageNeededTarget(GLenum target, GLint level,
506 GLenum internalformat);
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700507
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800508 int m_max_color_attachments;
509 int m_max_draw_buffers;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700510 struct RboState {
511 GLuint boundRenderbuffer;
512 size_t boundRenderbufferIndex;
513 std::vector<RboProps> rboData;
514 };
515 RboState mRboState;
516 void addFreshRenderbuffer(GLuint name);
517 void setBoundRenderbufferIndex();
518 size_t getRboIndex(GLuint name) const;
519 RboProps& boundRboProps();
520 const RboProps& boundRboProps_const() const;
521
522 struct FboState {
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800523 GLuint boundDrawFramebuffer;
524 GLuint boundReadFramebuffer;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700525 size_t boundFramebufferIndex;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800526 std::map<GLuint, FboProps> fboData;
527 GLenum drawFboCheckStatus;
528 GLenum readFboCheckStatus;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700529 };
530 FboState mFboState;
531 void addFreshFramebuffer(GLuint name);
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800532 FboProps& boundFboProps(GLenum target);
533 const FboProps& boundFboProps_const(GLenum target) const;
Lingfeng Yang57cb41b2016-04-08 14:42:34 -0700534
Lingfeng Yang69066602016-04-12 09:29:11 -0700535 // Querying framebuffer format
536 GLenum queryRboFormat(GLuint name) const;
Lingfeng Yang35d5f3b2017-01-09 13:23:25 -0800537 GLsizei queryRboSamples(GLuint name) const;
Lingfeng Yang69066602016-04-12 09:29:11 -0700538 GLenum queryTexType(GLuint name) const;
Lingfeng Yang74e29292017-01-10 14:54:38 -0800539 GLsizei queryTexSamples(GLuint name) const;
Lingfeng Yang69066602016-04-12 09:29:11 -0700540
keunyoungb85b2752013-03-08 12:28:03 -0800541 static int compareTexId(const void* pid, const void* prec);
542 TextureRec* addTextureRec(GLuint id, GLenum target);
Lingfeng Yang74e29292017-01-10 14:54:38 -0800543 TextureRec* getTextureRec(GLuint id) const;
keunyoungb85b2752013-03-08 12:28:03 -0800544
545public:
546 void getClientStatePointer(GLenum pname, GLvoid** params);
547
548 template <class T>
549 int getVertexAttribParameter(GLuint index, GLenum param, T *ptr)
550 {
551 bool handled = true;
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800552 const VertexAttribState& vertexAttrib = getState(index);
553 const BufferBinding& vertexAttribBufferBinding =
554 m_currVaoState.bufferBindings_const()[vertexAttrib.bindingindex];
keunyoungb85b2752013-03-08 12:28:03 -0800555
556 switch(param) {
557 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800558 *ptr = (T)(vertexAttribBufferBinding.buffer);
keunyoungb85b2752013-03-08 12:28:03 -0800559 break;
560 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800561 *ptr = (T)(vertexAttrib.enabled);
562 break;
563#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD
564 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
565 *ptr = (T)(vertexAttrib.isInt);
keunyoungb85b2752013-03-08 12:28:03 -0800566 break;
567 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800568 *ptr = (T)(vertexAttrib.size);
keunyoungb85b2752013-03-08 12:28:03 -0800569 break;
570 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800571 *ptr = (T)(vertexAttribBufferBinding.stride);
keunyoungb85b2752013-03-08 12:28:03 -0800572 break;
573 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800574 *ptr = (T)(vertexAttrib.type);
keunyoungb85b2752013-03-08 12:28:03 -0800575 break;
576 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800577 *ptr = (T)(vertexAttrib.normalized);
keunyoungb85b2752013-03-08 12:28:03 -0800578 break;
579 case GL_CURRENT_VERTEX_ATTRIB:
580 handled = false;
581 break;
582 default:
583 handled = false;
584 ERR("unknown vertex-attrib parameter param %d\n", param);
585 }
586 return handled;
587 }
588
589 template <class T>
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800590 bool getClientStateParameter(GLenum param, T* out)
keunyoungb85b2752013-03-08 12:28:03 -0800591 {
592 bool isClientStateParam = false;
593 switch (param) {
594 case GL_CLIENT_ACTIVE_TEXTURE: {
595 GLint tex = getActiveTexture() + GL_TEXTURE0;
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800596 *out = tex;
keunyoungb85b2752013-03-08 12:28:03 -0800597 isClientStateParam = true;
598 break;
599 }
600 case GL_VERTEX_ARRAY_SIZE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800601 const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION);
602 *out = state.size;
keunyoungb85b2752013-03-08 12:28:03 -0800603 isClientStateParam = true;
604 break;
605 }
606 case GL_VERTEX_ARRAY_TYPE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800607 const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION);
608 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800609 isClientStateParam = true;
610 break;
611 }
612 case GL_VERTEX_ARRAY_STRIDE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800613 const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION);
614 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800615 isClientStateParam = true;
616 break;
617 }
618 case GL_COLOR_ARRAY_SIZE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800619 const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION);
620 *out = state.size;
keunyoungb85b2752013-03-08 12:28:03 -0800621 isClientStateParam = true;
622 break;
623 }
624 case GL_COLOR_ARRAY_TYPE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800625 const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION);
626 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800627 isClientStateParam = true;
628 break;
629 }
630 case GL_COLOR_ARRAY_STRIDE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800631 const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION);
632 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800633 isClientStateParam = true;
634 break;
635 }
636 case GL_NORMAL_ARRAY_TYPE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800637 const GLClientState::VertexAttribState& state = getState(GLClientState::NORMAL_LOCATION);
638 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800639 isClientStateParam = true;
640 break;
641 }
642 case GL_NORMAL_ARRAY_STRIDE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800643 const GLClientState::VertexAttribState& state = getState(GLClientState::NORMAL_LOCATION);
644 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800645 isClientStateParam = true;
646 break;
647 }
648 case GL_TEXTURE_COORD_ARRAY_SIZE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800649 const GLClientState::VertexAttribState& state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION);
650 *out = state.size;
keunyoungb85b2752013-03-08 12:28:03 -0800651 isClientStateParam = true;
652 break;
653 }
654 case GL_TEXTURE_COORD_ARRAY_TYPE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800655 const GLClientState::VertexAttribState& state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION);
656 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800657 isClientStateParam = true;
658 break;
659 }
660 case GL_TEXTURE_COORD_ARRAY_STRIDE: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800661 const GLClientState::VertexAttribState& state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION);
662 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800663 isClientStateParam = true;
664 break;
665 }
666 case GL_POINT_SIZE_ARRAY_TYPE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800667 const GLClientState::VertexAttribState& state = getState(GLClientState::POINTSIZE_LOCATION);
668 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800669 isClientStateParam = true;
670 break;
671 }
672 case GL_POINT_SIZE_ARRAY_STRIDE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800673 const GLClientState::VertexAttribState& state = getState(GLClientState::POINTSIZE_LOCATION);
674 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800675 isClientStateParam = true;
676 break;
677 }
678 case GL_MATRIX_INDEX_ARRAY_SIZE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800679 const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION);
680 *out = state.size;
keunyoungb85b2752013-03-08 12:28:03 -0800681 isClientStateParam = true;
682 break;
683 }
684 case GL_MATRIX_INDEX_ARRAY_TYPE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800685 const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION);
686 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800687 isClientStateParam = true;
688 break;
689 }
690 case GL_MATRIX_INDEX_ARRAY_STRIDE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800691 const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION);
692 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800693 isClientStateParam = true;
694 break;
695 }
696 case GL_WEIGHT_ARRAY_SIZE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800697 const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION);
698 *out = state.size;
keunyoungb85b2752013-03-08 12:28:03 -0800699 isClientStateParam = true;
700 break;
701 }
702 case GL_WEIGHT_ARRAY_TYPE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800703 const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION);
704 *out = state.type;
keunyoungb85b2752013-03-08 12:28:03 -0800705 isClientStateParam = true;
706 break;
707 }
708 case GL_WEIGHT_ARRAY_STRIDE_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800709 const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION);
710 *out = state.stride;
keunyoungb85b2752013-03-08 12:28:03 -0800711 isClientStateParam = true;
712 break;
713 }
714 case GL_VERTEX_ARRAY_BUFFER_BINDING: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800715 const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION);
716 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800717 isClientStateParam = true;
718 break;
719 }
720 case GL_NORMAL_ARRAY_BUFFER_BINDING: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800721 const GLClientState::VertexAttribState& state = getState(GLClientState::NORMAL_LOCATION);
722 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800723 isClientStateParam = true;
724 break;
725 }
726 case GL_COLOR_ARRAY_BUFFER_BINDING: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800727 const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION);
728 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800729 isClientStateParam = true;
730 break;
731 }
732 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800733 const GLClientState::VertexAttribState& state = getState(getActiveTexture()+GLClientState::TEXCOORD0_LOCATION);
734 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800735 isClientStateParam = true;
736 break;
737 }
738 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800739 const GLClientState::VertexAttribState& state = getState(GLClientState::POINTSIZE_LOCATION);
740 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800741 isClientStateParam = true;
742 break;
743 }
744 case GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800745 const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION);
746 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800747 isClientStateParam = true;
748 break;
749 }
750 case GL_WEIGHT_ARRAY_BUFFER_BINDING_OES: {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800751 const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION);
752 *out = state.bufferObject;
keunyoungb85b2752013-03-08 12:28:03 -0800753 isClientStateParam = true;
754 break;
755 }
756 case GL_ARRAY_BUFFER_BINDING: {
757 int buffer = getBuffer(GL_ARRAY_BUFFER);
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800758 *out = buffer;
keunyoungb85b2752013-03-08 12:28:03 -0800759 isClientStateParam = true;
760 break;
761 }
762 case GL_ELEMENT_ARRAY_BUFFER_BINDING: {
763 int buffer = getBuffer(GL_ELEMENT_ARRAY_BUFFER);
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800764 *out = buffer;
keunyoungb85b2752013-03-08 12:28:03 -0800765 isClientStateParam = true;
766 break;
767 }
Lingfeng Yangb0176982016-03-01 21:27:49 -0800768 case GL_MAX_VERTEX_ATTRIBS: {
769 if (m_maxVertexAttribsDirty) {
770 isClientStateParam = false;
771 } else {
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800772 *out = m_maxVertexAttribs;
Lingfeng Yangb0176982016-03-01 21:27:49 -0800773 isClientStateParam = true;
774 }
775 break;
Lingfeng Yangf654f3f2017-01-09 13:12:33 -0800776 }
keunyoungb85b2752013-03-08 12:28:03 -0800777 }
778 return isClientStateParam;
779 }
780
781};
782#endif