keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 1 | /* |
| 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 Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 25 | #include "TextureSharedData.h" |
| 26 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 27 | #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 Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 37 | #include <vector> |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 38 | #include <map> |
Lingfeng Yang | e00ec9d | 2016-09-16 08:54:03 -0700 | [diff] [blame] | 39 | #include <set> |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 40 | |
| 41 | // Tracking framebuffer objects: |
| 42 | // which framebuffer is bound, |
| 43 | // and which texture names |
| 44 | // are currently bound to which attachment points. |
| 45 | struct FboProps { |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 46 | GLuint name; |
| 47 | bool previouslyBound; |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 48 | std::vector<GLuint> colorAttachmenti_textures; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 49 | GLuint depthAttachment_texture; |
| 50 | GLuint stencilAttachment_texture; |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 51 | GLuint depthstencilAttachment_texture; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 52 | |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 53 | std::vector<bool> colorAttachmenti_hasTex; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 54 | bool depthAttachment_hasTexObj; |
| 55 | bool stencilAttachment_hasTexObj; |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 56 | bool depthstencilAttachment_hasTexObj; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 57 | |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 58 | std::vector<GLuint> colorAttachmenti_rbos; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 59 | GLuint depthAttachment_rbo; |
| 60 | GLuint stencilAttachment_rbo; |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 61 | GLuint depthstencilAttachment_rbo; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 62 | |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 63 | std::vector<bool> colorAttachmenti_hasRbo; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 64 | bool depthAttachment_hasRbo; |
| 65 | bool stencilAttachment_hasRbo; |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 66 | bool depthstencilAttachment_hasRbo; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | // Same for Rbo's |
| 70 | struct RboProps { |
| 71 | GLenum target; |
| 72 | GLuint name; |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 73 | GLenum format; |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 74 | GLsizei multisamples; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 75 | bool previouslyBound; |
| 76 | }; |
| 77 | |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 78 | // Enum for describing whether a framebuffer attachment |
| 79 | // is a texture or renderbuffer. |
| 80 | enum FboAttachmentType { |
| 81 | FBO_ATTACHMENT_RENDERBUFFER = 0, |
| 82 | FBO_ATTACHMENT_TEXTURE = 1, |
| 83 | FBO_ATTACHMENT_NONE = 2 |
| 84 | }; |
| 85 | |
| 86 | // Tracking FBO format |
| 87 | struct FboFormatInfo { |
| 88 | FboAttachmentType type; |
| 89 | GLenum rb_format; |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 90 | GLsizei rb_multisamples; |
| 91 | |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 92 | GLint tex_internalformat; |
| 93 | GLenum tex_format; |
| 94 | GLenum tex_type; |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 95 | GLsizei tex_multisamples; |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 98 | class GLClientState { |
| 99 | public: |
| 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 Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 124 | GLuint reloffset; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 125 | 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 Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 130 | GLuint divisor; |
| 131 | bool isInt; |
| 132 | int bindingindex; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 133 | } VertexAttribState; |
| 134 | |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 135 | struct BufferBinding { |
| 136 | GLintptr offset; |
| 137 | GLintptr stride; |
| 138 | GLintptr effectiveStride; |
| 139 | GLsizeiptr size; |
| 140 | GLuint buffer; |
| 141 | GLuint divisor; |
Lingfeng Yang | 9a2fa6f | 2019-11-08 09:41:17 -0800 | [diff] [blame] | 142 | GLint vertexAttribLoc; |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | typedef std::vector<VertexAttribState> VertexAttribStateVector; |
| 146 | typedef std::vector<BufferBinding> VertexAttribBindingVector; |
| 147 | |
| 148 | struct VAOState { |
| 149 | VAOState(GLuint ibo, int nLoc, int nBindings) : |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 150 | attribState(nLoc), |
Matt Wachowski | dfbc1b3 | 2018-08-10 12:50:40 -0700 | [diff] [blame] | 151 | bindingState(nBindings), |
Lingfeng Yang | 554a515 | 2019-02-21 20:20:48 -0800 | [diff] [blame] | 152 | element_array_buffer_binding(ibo), |
| 153 | element_array_buffer_binding_lastEncode(ibo) { } |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 154 | VertexAttribStateVector attribState; |
| 155 | VertexAttribBindingVector bindingState; |
| 156 | GLuint element_array_buffer_binding; |
Lingfeng Yang | 554a515 | 2019-02-21 20:20:48 -0800 | [diff] [blame] | 157 | GLuint element_array_buffer_binding_lastEncode; |
| 158 | int attributesNeedingUpdateForDraw[CODEC_MAX_VERTEX_ATTRIBUTES]; |
| 159 | int numAttributesNeedingUpdateForDraw; |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | typedef std::map<GLuint, VAOState> VAOStateMap; |
| 163 | struct VAOStateRef { |
| 164 | VAOStateRef() { } |
| 165 | VAOStateRef( |
| 166 | VAOStateMap::iterator iter) : it(iter) { } |
Lingfeng Yang | 554a515 | 2019-02-21 20:20:48 -0800 | [diff] [blame] | 167 | VAOState& vaoState() { return it->second; } |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 168 | VertexAttribState& operator[](size_t k) { return it->second.attribState[k]; } |
| 169 | BufferBinding& bufferBinding(size_t k) { return it->second.bindingState[k]; } |
| 170 | VertexAttribBindingVector& bufferBindings() { return it->second.bindingState; } |
| 171 | const VertexAttribBindingVector& bufferBindings_const() const { return it->second.bindingState; } |
| 172 | GLuint vaoId() const { return it->first; } |
| 173 | GLuint& iboId() { return it->second.element_array_buffer_binding; } |
Lingfeng Yang | 554a515 | 2019-02-21 20:20:48 -0800 | [diff] [blame] | 174 | GLuint& iboIdLastEncode() { return it->second.element_array_buffer_binding_lastEncode; } |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 175 | VAOStateMap::iterator it; |
| 176 | }; |
| 177 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 178 | typedef struct { |
| 179 | int unpack_alignment; |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 180 | |
| 181 | int unpack_row_length; |
| 182 | int unpack_image_height; |
| 183 | int unpack_skip_pixels; |
| 184 | int unpack_skip_rows; |
| 185 | int unpack_skip_images; |
| 186 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 187 | int pack_alignment; |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 188 | |
| 189 | int pack_row_length; |
| 190 | int pack_skip_pixels; |
| 191 | int pack_skip_rows; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 192 | } PixelStoreState; |
| 193 | |
| 194 | enum { |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 195 | MAX_TEXTURE_UNITS = 256, |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | public: |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 199 | GLClientState(); |
| 200 | GLClientState(int majorVersion, int minorVersion); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 201 | ~GLClientState(); |
| 202 | int nLocations() { return m_nLocations; } |
| 203 | const PixelStoreState *pixelStoreState() { return &m_pixelStore; } |
| 204 | int setPixelStore(GLenum param, GLint value); |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 205 | GLuint currentVertexArrayObject() const { return m_currVaoState.vaoId(); } |
Lingfeng Yang | d3ae106 | 2017-01-18 11:42:04 -0800 | [diff] [blame] | 206 | const VertexAttribBindingVector& currentVertexBufferBindings() const { |
| 207 | return m_currVaoState.bufferBindings_const(); |
| 208 | } |
| 209 | |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 210 | GLuint currentArrayVbo() { return m_arrayBuffer; } |
| 211 | GLuint currentIndexVbo() { return m_currVaoState.iboId(); } |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 212 | void enable(int location, int state); |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 213 | // Vertex array objects and vertex attributes |
| 214 | void addVertexArrayObjects(GLsizei n, GLuint* arrays); |
| 215 | void removeVertexArrayObjects(GLsizei n, const GLuint* arrays); |
| 216 | void addVertexArrayObject(GLuint name); |
| 217 | void removeVertexArrayObject(GLuint name); |
| 218 | void setVertexArrayObject(GLuint vao); |
| 219 | bool isVertexArrayObject(GLuint vao) const; |
| 220 | void setVertexAttribState(int location, int size, GLenum type, GLboolean normalized, GLsizei stride, const void *data, bool isInt = false); |
| 221 | void setVertexBindingDivisor(int bindingindex, GLuint divisor); |
| 222 | const BufferBinding& getCurrAttributeBindingInfo(int attribindex); |
| 223 | void setVertexAttribBinding(int attribindex, int bindingindex); |
| 224 | void setVertexAttribFormat(int location, int size, GLenum type, GLboolean normalized, GLuint reloffset, bool isInt = false); |
Lingfeng Yang | 9a2fa6f | 2019-11-08 09:41:17 -0800 | [diff] [blame] | 225 | void getVBOUsage(bool* hasClientArrays, bool* hasVBOs); |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 226 | const VertexAttribState& getState(int location); |
| 227 | const VertexAttribState& getStateAndEnableDirty(int location, bool *enableChanged); |
Lingfeng Yang | 554a515 | 2019-02-21 20:20:48 -0800 | [diff] [blame] | 228 | void updateEnableDirtyArrayForDraw(); |
| 229 | VAOState& currentVaoState(); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 230 | int getLocation(GLenum loc); |
| 231 | void setActiveTexture(int texUnit) {m_activeTexture = texUnit; }; |
| 232 | int getActiveTexture() const { return m_activeTexture; } |
Lingfeng Yang | b017698 | 2016-03-01 21:27:49 -0800 | [diff] [blame] | 233 | void setMaxVertexAttribs(int val) { |
| 234 | m_maxVertexAttribs = val; |
| 235 | m_maxVertexAttribsDirty = false; |
| 236 | } |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 237 | |
Lingfeng Yang | d3ae106 | 2017-01-18 11:42:04 -0800 | [diff] [blame] | 238 | void addBuffer(GLuint id); |
| 239 | void removeBuffer(GLuint id); |
| 240 | bool bufferIdExists(GLuint id) const; |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 241 | void unBindBuffer(GLuint id); |
bohu | b0f0cdf | 2014-11-06 18:08:07 -0800 | [diff] [blame] | 242 | |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 243 | int bindBuffer(GLenum target, GLuint id); |
| 244 | void bindIndexedBuffer(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size, GLintptr stride, GLintptr effectiveStride); |
| 245 | int getMaxIndexedBufferBindings(GLenum target) const; |
Lingfeng Yang | 2c3a0da | 2019-03-07 20:43:53 -0800 | [diff] [blame] | 246 | bool isNonIndexedBindNoOp(GLenum target, GLuint buffer); |
Lingfeng Yang | 554a515 | 2019-02-21 20:20:48 -0800 | [diff] [blame] | 247 | bool isIndexedBindNoOp(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size, GLintptr stride, GLintptr effectiveStride); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 248 | |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 249 | int getBuffer(GLenum target); |
Lingfeng Yang | 554a515 | 2019-02-21 20:20:48 -0800 | [diff] [blame] | 250 | GLuint getLastEncodedBufferBind(GLenum target); |
| 251 | void setLastEncodedBufferBind(GLenum target, GLuint id); |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 252 | |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 253 | size_t pixelDataSize(GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, int pack) const; |
| 254 | size_t pboNeededDataSize(GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, int pack) const; |
| 255 | size_t clearBufferNumElts(GLenum buffer) const; |
Lingfeng Yang | 22dc42d | 2018-05-29 10:11:38 -0700 | [diff] [blame] | 256 | void getPackingOffsets2D(GLsizei width, GLsizei height, GLenum format, GLenum type, int* startOffset, int* pixelRowSize, int* totalRowSize, int* skipRows) const; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 257 | |
| 258 | void setCurrentProgram(GLint program) { m_currentProgram = program; } |
Lingfeng Yang | d3ae106 | 2017-01-18 11:42:04 -0800 | [diff] [blame] | 259 | void setCurrentShaderProgram(GLint program) { m_currentShaderProgram = program; } |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 260 | GLint currentProgram() const { return m_currentProgram; } |
Lingfeng Yang | d3ae106 | 2017-01-18 11:42:04 -0800 | [diff] [blame] | 261 | GLint currentShaderProgram() const { return m_currentShaderProgram; } |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 262 | |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 263 | struct UniformBlockInfoKey { |
| 264 | GLuint program; |
| 265 | GLuint uniformBlockIndex; |
| 266 | }; |
| 267 | struct UniformBlockInfoKeyCompare { |
| 268 | bool operator() (const UniformBlockInfoKey& a, |
| 269 | const UniformBlockInfoKey& b) const { |
| 270 | if (a.program != b.program) return a.program < b.program; |
| 271 | if (a.uniformBlockIndex != b.uniformBlockIndex) return a.uniformBlockIndex < b.uniformBlockIndex; |
| 272 | return false; |
| 273 | } |
| 274 | }; |
| 275 | struct UniformBlockUniformInfo { |
| 276 | size_t numActiveUniforms; |
| 277 | }; |
| 278 | |
| 279 | typedef std::map<UniformBlockInfoKey, UniformBlockUniformInfo, UniformBlockInfoKeyCompare> UniformBlockInfoMap; |
| 280 | UniformBlockInfoMap m_uniformBlockInfoMap; |
| 281 | |
Lingfeng Yang | e6556dc | 2017-01-09 12:04:12 -0800 | [diff] [blame] | 282 | void setNumActiveUniformsInUniformBlock(GLuint program, GLuint uniformBlockIndex, GLint numActiveUniforms); |
| 283 | size_t numActiveUniformsInUniformBlock(GLuint program, GLuint uniformBlockIndex) const; |
Lingfeng Yang | b3dc29f | 2017-01-09 13:25:31 -0800 | [diff] [blame] | 284 | |
| 285 | typedef std::map<GLuint, GLuint> ProgramPipelineMap; |
| 286 | typedef ProgramPipelineMap::iterator ProgramPipelineIterator; |
| 287 | void associateProgramWithPipeline(GLuint program, GLuint pipeline); |
| 288 | ProgramPipelineIterator programPipelineBegin(); |
| 289 | ProgramPipelineIterator programPipelineEnd(); |
| 290 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 291 | /* OES_EGL_image_external |
| 292 | * |
| 293 | * These functions manipulate GL state which interacts with the |
| 294 | * OES_EGL_image_external extension, to support client-side emulation on |
| 295 | * top of host implementations that don't have it. |
| 296 | * |
| 297 | * Most of these calls should only be used with TEXTURE_2D or |
| 298 | * TEXTURE_EXTERNAL_OES texture targets; TEXTURE_CUBE_MAP or other extension |
| 299 | * targets should bypass this. An exception is bindTexture(), which should |
| 300 | * see all glBindTexture() calls for any target. |
| 301 | */ |
| 302 | |
| 303 | // glActiveTexture(GL_TEXTURE0 + i) |
| 304 | // Sets the active texture unit. Up to MAX_TEXTURE_UNITS are supported. |
| 305 | GLenum setActiveTextureUnit(GLenum texture); |
| 306 | GLenum getActiveTextureUnit() const; |
| 307 | |
| 308 | // glEnable(GL_TEXTURE_(2D|EXTERNAL_OES)) |
| 309 | void enableTextureTarget(GLenum target); |
| 310 | |
| 311 | // glDisable(GL_TEXTURE_(2D|EXTERNAL_OES)) |
| 312 | void disableTextureTarget(GLenum target); |
| 313 | |
Lingfeng Yang | 554a515 | 2019-02-21 20:20:48 -0800 | [diff] [blame] | 314 | void bindSampler(GLuint unit, GLuint sampler); |
| 315 | bool isSamplerBindNoOp(GLuint unit, GLuint sampler); |
| 316 | void onDeleteSamplers(GLsizei n, const GLuint* samplers); |
| 317 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 318 | // Implements the target priority logic: |
| 319 | // * Return GL_TEXTURE_EXTERNAL_OES if enabled, else |
| 320 | // * Return GL_TEXTURE_2D if enabled, else |
| 321 | // * Return the allDisabled value. |
| 322 | // For some cases passing GL_TEXTURE_2D for allDisabled makes callee code |
| 323 | // simpler; for other cases passing a recognizable enum like GL_ZERO or |
| 324 | // GL_INVALID_ENUM is appropriate. |
| 325 | GLenum getPriorityEnabledTarget(GLenum allDisabled) const; |
| 326 | |
| 327 | // glBindTexture(GL_TEXTURE_*, ...) |
| 328 | // Set the target binding of the active texture unit to texture. Returns |
| 329 | // GL_NO_ERROR on success or GL_INVALID_OPERATION if the texture has |
| 330 | // previously been bound to a different target. If firstUse is not NULL, |
| 331 | // it is set to indicate whether this is the first use of the texture. |
| 332 | // For accurate error detection, bindTexture should be called for *all* |
| 333 | // targets, not just 2D and EXTERNAL_OES. |
| 334 | GLenum bindTexture(GLenum target, GLuint texture, GLboolean* firstUse); |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 335 | void setBoundEGLImage(GLenum target, GLeglImageOES image); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 336 | |
| 337 | // Return the texture currently bound to GL_TEXTURE_(2D|EXTERNAL_OES). |
| 338 | GLuint getBoundTexture(GLenum target) const; |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 339 | // Other publicly-visible texture queries |
| 340 | GLenum queryTexLastBoundTarget(GLuint name) const; |
| 341 | GLenum queryTexFormat(GLuint name) const; |
| 342 | GLint queryTexInternalFormat(GLuint name) const; |
| 343 | GLsizei queryTexWidth(GLsizei level, GLuint name) const; |
| 344 | GLsizei queryTexHeight(GLsizei level, GLuint name) const; |
| 345 | GLsizei queryTexDepth(GLsizei level, GLuint name) const; |
| 346 | bool queryTexEGLImageBacked(GLuint name) const; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 347 | |
Lingfeng Yang | e00ec9d | 2016-09-16 08:54:03 -0700 | [diff] [blame] | 348 | // For AMD GPUs, it is easy for the emulator to segfault |
| 349 | // (esp. in dEQP) when a cube map is defined using glCopyTexImage2D |
| 350 | // and uses GL_LUMINANCE as internal format. |
| 351 | // In particular, the segfault happens when negative components of |
| 352 | // cube maps are defined before positive ones, |
| 353 | // This procedure checks internal state to see if we have defined |
| 354 | // the positive component of a cube map already. If not, it returns |
| 355 | // which positive component needs to be defined first. |
| 356 | // If there is no need for the extra definition, 0 is returned. |
| 357 | GLenum copyTexImageLuminanceCubeMapAMDWorkaround(GLenum target, GLint level, |
| 358 | GLenum internalformat); |
| 359 | |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 360 | // Tracks the format of the currently bound texture. |
| 361 | // This is to pass dEQP tests for fbo completeness. |
| 362 | void setBoundTextureInternalFormat(GLenum target, GLint format); |
| 363 | void setBoundTextureFormat(GLenum target, GLenum format); |
| 364 | void setBoundTextureType(GLenum target, GLenum type); |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 365 | void setBoundTextureDims(GLenum target, GLsizei level, GLsizei width, GLsizei height, GLsizei depth); |
| 366 | void setBoundTextureSamples(GLenum target, GLsizei samples); |
| 367 | |
| 368 | // glTexStorage2D disallows any change in texture format after it is set for a particular texture. |
| 369 | void setBoundTextureImmutableFormat(GLenum target); |
| 370 | bool isBoundTextureImmutableFormat(GLenum target) const; |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 371 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 372 | // glDeleteTextures(...) |
| 373 | // Remove references to the to-be-deleted textures. |
| 374 | void deleteTextures(GLsizei n, const GLuint* textures); |
| 375 | |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 376 | // Render buffer objects |
| 377 | void addRenderbuffers(GLsizei n, GLuint* renderbuffers); |
| 378 | void removeRenderbuffers(GLsizei n, const GLuint* renderbuffers); |
| 379 | bool usedRenderbufferName(GLuint name) const; |
| 380 | void bindRenderbuffer(GLenum target, GLuint name); |
| 381 | GLuint boundRenderbuffer() const; |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 382 | void setBoundRenderbufferFormat(GLenum format); |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 383 | void setBoundRenderbufferSamples(GLsizei samples); |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 384 | |
| 385 | // Frame buffer objects |
| 386 | void addFramebuffers(GLsizei n, GLuint* framebuffers); |
| 387 | void removeFramebuffers(GLsizei n, const GLuint* framebuffers); |
| 388 | bool usedFramebufferName(GLuint name) const; |
| 389 | void bindFramebuffer(GLenum target, GLuint name); |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 390 | void setCheckFramebufferStatus(GLenum target, GLenum status); |
| 391 | GLenum getCheckFramebufferStatus(GLenum target) const; |
| 392 | GLuint boundFramebuffer(GLenum target) const; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 393 | |
| 394 | // Texture object -> FBO |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 395 | void attachTextureObject(GLenum target, GLenum attachment, GLuint texture); |
| 396 | GLuint getFboAttachmentTextureId(GLenum target, GLenum attachment) const; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 397 | |
| 398 | // RBO -> FBO |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 399 | void detachRbo(GLuint renderbuffer); |
| 400 | void detachRboFromFbo(GLenum target, GLenum attachment, GLuint renderbuffer); |
| 401 | void attachRbo(GLenum target, GLenum attachment, GLuint renderbuffer); |
| 402 | GLuint getFboAttachmentRboId(GLenum target, GLenum attachment) const; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 403 | |
| 404 | // FBO attachments in general |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 405 | bool attachmentHasObject(GLenum target, GLenum attachment) const; |
| 406 | GLuint objectOfAttachment(GLenum target, GLenum attachment) const; |
| 407 | |
Lingfeng Yang | 4a66b31 | 2017-01-09 13:27:49 -0800 | [diff] [blame] | 408 | // Transform feedback state |
| 409 | void setTransformFeedbackActiveUnpaused(bool activeUnpaused); |
| 410 | bool getTransformFeedbackActiveUnpaused() const; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 411 | |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 412 | void setTextureData(SharedTextureDataMap* sharedTexData); |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 413 | // set eglsurface property on default framebuffer |
| 414 | // if coming from eglMakeCurrent |
| 415 | void fromMakeCurrent(); |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 416 | // set indexed buffer state. |
| 417 | // We need to query the underlying OpenGL to get |
| 418 | // accurate values for indexed buffers |
| 419 | // and # render targets. |
| 420 | void initFromCaps( |
| 421 | int max_transform_feedback_separate_attribs, |
| 422 | int max_uniform_buffer_bindings, |
| 423 | int max_atomic_counter_buffer_bindings, |
| 424 | int max_shader_storage_buffer_bindings, |
| 425 | int max_vertex_attrib_bindings, |
| 426 | int max_color_attachments, |
| 427 | int max_draw_buffers); |
| 428 | bool needsInitFromCaps() const; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 429 | |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 430 | // Queries the format backing the current framebuffer. |
| 431 | // Type differs depending on whether the attachment |
| 432 | // is a texture or renderbuffer. |
| 433 | void getBoundFramebufferFormat( |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 434 | GLenum target, |
| 435 | GLenum attachment, |
| 436 | FboFormatInfo* res_info) const; |
| 437 | FboAttachmentType getBoundFramebufferAttachmentType( |
| 438 | GLenum target, |
| 439 | GLenum attachment) const; |
| 440 | int getMaxColorAttachments() const; |
| 441 | int getMaxDrawBuffers() const; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 442 | private: |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 443 | void init(); |
| 444 | bool m_initialized; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 445 | PixelStoreState m_pixelStore; |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 446 | |
Lingfeng Yang | d3ae106 | 2017-01-18 11:42:04 -0800 | [diff] [blame] | 447 | std::set<GLuint> mBufferIds; |
| 448 | |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 449 | // GL_ARRAY_BUFFER_BINDING is separate from VAO state |
| 450 | GLuint m_arrayBuffer; |
Lingfeng Yang | 554a515 | 2019-02-21 20:20:48 -0800 | [diff] [blame] | 451 | GLuint m_arrayBuffer_lastEncode; |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 452 | VAOStateMap m_vaoMap; |
| 453 | VAOStateRef m_currVaoState; |
| 454 | |
Lingfeng Yang | 28a757c | 2019-11-08 21:37:59 -0800 | [diff] [blame] | 455 | uint16_t m_attribEnableCache; |
| 456 | uint16_t m_vaoAttribBindingCacheInvalid; |
| 457 | uint16_t m_vaoAttribBindingHasClientArrayCache; |
| 458 | uint16_t m_vaoAttribBindingHasVboCache; |
Lingfeng Yang | f8519c1 | 2019-11-09 09:35:23 -0800 | [diff] [blame] | 459 | uint8_t m_noClientArraysCache; |
Lingfeng Yang | 9a2fa6f | 2019-11-08 09:41:17 -0800 | [diff] [blame] | 460 | |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 461 | // Other buffer id's, other targets |
| 462 | GLuint m_copyReadBuffer; |
| 463 | GLuint m_copyWriteBuffer; |
| 464 | |
| 465 | GLuint m_pixelPackBuffer; |
| 466 | GLuint m_pixelUnpackBuffer; |
| 467 | |
| 468 | GLuint m_transformFeedbackBuffer; |
| 469 | GLuint m_uniformBuffer; |
| 470 | |
| 471 | GLuint m_atomicCounterBuffer; |
| 472 | GLuint m_dispatchIndirectBuffer; |
| 473 | GLuint m_drawIndirectBuffer; |
| 474 | GLuint m_shaderStorageBuffer; |
| 475 | |
| 476 | bool m_transformFeedbackActiveUnpaused; |
| 477 | |
| 478 | int m_max_transform_feedback_separate_attribs; |
| 479 | int m_max_uniform_buffer_bindings; |
| 480 | int m_max_atomic_counter_buffer_bindings; |
| 481 | int m_max_shader_storage_buffer_bindings; |
| 482 | int m_max_vertex_attrib_bindings; |
| 483 | std::vector<BufferBinding> m_indexedTransformFeedbackBuffers; |
| 484 | std::vector<BufferBinding> m_indexedUniformBuffers; |
| 485 | std::vector<BufferBinding> m_indexedAtomicCounterBuffers; |
| 486 | std::vector<BufferBinding> m_indexedShaderStorageBuffers; |
| 487 | |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 488 | int m_glesMajorVersion; |
| 489 | int m_glesMinorVersion; |
Lingfeng Yang | b017698 | 2016-03-01 21:27:49 -0800 | [diff] [blame] | 490 | int m_maxVertexAttribs; |
| 491 | bool m_maxVertexAttribsDirty; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 492 | int m_nLocations; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 493 | int m_activeTexture; |
| 494 | GLint m_currentProgram; |
Lingfeng Yang | d3ae106 | 2017-01-18 11:42:04 -0800 | [diff] [blame] | 495 | GLint m_currentShaderProgram; |
Lingfeng Yang | b3dc29f | 2017-01-09 13:25:31 -0800 | [diff] [blame] | 496 | ProgramPipelineMap m_programPipelines; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 497 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 498 | enum TextureTarget { |
| 499 | TEXTURE_2D = 0, |
| 500 | TEXTURE_EXTERNAL = 1, |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 501 | TEXTURE_CUBE_MAP = 2, |
| 502 | TEXTURE_2D_ARRAY = 3, |
| 503 | TEXTURE_3D = 4, |
| 504 | TEXTURE_2D_MULTISAMPLE = 5, |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 505 | TEXTURE_TARGET_COUNT |
| 506 | }; |
| 507 | struct TextureUnit { |
| 508 | unsigned int enables; |
| 509 | GLuint texture[TEXTURE_TARGET_COUNT]; |
Lingfeng Yang | 554a515 | 2019-02-21 20:20:48 -0800 | [diff] [blame] | 510 | GLuint boundSampler; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 511 | }; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 512 | struct TextureState { |
| 513 | TextureUnit unit[MAX_TEXTURE_UNITS]; |
| 514 | TextureUnit* activeUnit; |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 515 | // Initialized from shared group. |
| 516 | SharedTextureDataMap* textureRecs; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 517 | }; |
| 518 | TextureState m_tex; |
| 519 | |
Lingfeng Yang | e00ec9d | 2016-09-16 08:54:03 -0700 | [diff] [blame] | 520 | // State tracking of cube map definitions. |
| 521 | // Currently used only for driver workarounds |
| 522 | // when using GL_LUMINANCE and defining cube maps with |
| 523 | // glCopyTexImage2D. |
| 524 | struct CubeMapDef { |
| 525 | GLuint id; |
| 526 | GLenum target; |
| 527 | GLint level; |
| 528 | GLenum internalformat; |
| 529 | }; |
| 530 | struct CubeMapDefCompare { |
| 531 | bool operator() (const CubeMapDef& a, |
| 532 | const CubeMapDef& b) const { |
| 533 | if (a.id != b.id) return a.id < b.id; |
| 534 | if (a.target != b.target) return a.target < b.target; |
| 535 | if (a.level != b.level) return a.level < b.level; |
| 536 | if (a.internalformat != b.internalformat) |
| 537 | return a.internalformat < b.internalformat; |
| 538 | return false; |
| 539 | } |
| 540 | }; |
| 541 | std::set<CubeMapDef, CubeMapDefCompare> m_cubeMapDefs; |
| 542 | void writeCopyTexImageState(GLenum target, GLint level, |
| 543 | GLenum internalformat); |
| 544 | GLenum copyTexImageNeededTarget(GLenum target, GLint level, |
| 545 | GLenum internalformat); |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 546 | |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 547 | int m_max_color_attachments; |
| 548 | int m_max_draw_buffers; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 549 | struct RboState { |
| 550 | GLuint boundRenderbuffer; |
| 551 | size_t boundRenderbufferIndex; |
| 552 | std::vector<RboProps> rboData; |
| 553 | }; |
| 554 | RboState mRboState; |
| 555 | void addFreshRenderbuffer(GLuint name); |
| 556 | void setBoundRenderbufferIndex(); |
| 557 | size_t getRboIndex(GLuint name) const; |
| 558 | RboProps& boundRboProps(); |
| 559 | const RboProps& boundRboProps_const() const; |
| 560 | |
| 561 | struct FboState { |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 562 | GLuint boundDrawFramebuffer; |
| 563 | GLuint boundReadFramebuffer; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 564 | size_t boundFramebufferIndex; |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 565 | std::map<GLuint, FboProps> fboData; |
| 566 | GLenum drawFboCheckStatus; |
| 567 | GLenum readFboCheckStatus; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 568 | }; |
| 569 | FboState mFboState; |
| 570 | void addFreshFramebuffer(GLuint name); |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 571 | FboProps& boundFboProps(GLenum target); |
| 572 | const FboProps& boundFboProps_const(GLenum target) const; |
Lingfeng Yang | 57cb41b | 2016-04-08 14:42:34 -0700 | [diff] [blame] | 573 | |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 574 | // Querying framebuffer format |
| 575 | GLenum queryRboFormat(GLuint name) const; |
Lingfeng Yang | 35d5f3b | 2017-01-09 13:23:25 -0800 | [diff] [blame] | 576 | GLsizei queryRboSamples(GLuint name) const; |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 577 | GLenum queryTexType(GLuint name) const; |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 578 | GLsizei queryTexSamples(GLuint name) const; |
Lingfeng Yang | 6906660 | 2016-04-12 09:29:11 -0700 | [diff] [blame] | 579 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 580 | static int compareTexId(const void* pid, const void* prec); |
| 581 | TextureRec* addTextureRec(GLuint id, GLenum target); |
Lingfeng Yang | 74e2929 | 2017-01-10 14:54:38 -0800 | [diff] [blame] | 582 | TextureRec* getTextureRec(GLuint id) const; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 583 | |
| 584 | public: |
| 585 | void getClientStatePointer(GLenum pname, GLvoid** params); |
| 586 | |
| 587 | template <class T> |
| 588 | int getVertexAttribParameter(GLuint index, GLenum param, T *ptr) |
| 589 | { |
| 590 | bool handled = true; |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 591 | const VertexAttribState& vertexAttrib = getState(index); |
| 592 | const BufferBinding& vertexAttribBufferBinding = |
| 593 | m_currVaoState.bufferBindings_const()[vertexAttrib.bindingindex]; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 594 | |
| 595 | switch(param) { |
Lingfeng Yang | d3ae106 | 2017-01-18 11:42:04 -0800 | [diff] [blame] | 596 | #define GL_VERTEX_ATTRIB_BINDING 0x82D4 |
| 597 | case GL_VERTEX_ATTRIB_BINDING: |
| 598 | *ptr = (T)vertexAttrib.bindingindex; |
| 599 | break; |
| 600 | #define GL_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D5 |
| 601 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 602 | *ptr = (T)vertexAttrib.reloffset; |
| 603 | break; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 604 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 605 | *ptr = (T)(vertexAttribBufferBinding.buffer); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 606 | break; |
| 607 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 608 | *ptr = (T)(vertexAttrib.enabled); |
| 609 | break; |
| 610 | #define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD |
| 611 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 612 | *ptr = (T)(vertexAttrib.isInt); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 613 | break; |
| 614 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 615 | *ptr = (T)(vertexAttrib.size); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 616 | break; |
| 617 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 618 | *ptr = (T)(vertexAttribBufferBinding.stride); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 619 | break; |
| 620 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 621 | *ptr = (T)(vertexAttrib.type); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 622 | break; |
| 623 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 624 | *ptr = (T)(vertexAttrib.normalized); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 625 | break; |
| 626 | case GL_CURRENT_VERTEX_ATTRIB: |
| 627 | handled = false; |
| 628 | break; |
| 629 | default: |
| 630 | handled = false; |
| 631 | ERR("unknown vertex-attrib parameter param %d\n", param); |
| 632 | } |
| 633 | return handled; |
| 634 | } |
| 635 | |
| 636 | template <class T> |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 637 | bool getClientStateParameter(GLenum param, T* out) |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 638 | { |
| 639 | bool isClientStateParam = false; |
| 640 | switch (param) { |
| 641 | case GL_CLIENT_ACTIVE_TEXTURE: { |
| 642 | GLint tex = getActiveTexture() + GL_TEXTURE0; |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 643 | *out = tex; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 644 | isClientStateParam = true; |
| 645 | break; |
| 646 | } |
| 647 | case GL_VERTEX_ARRAY_SIZE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 648 | const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION); |
| 649 | *out = state.size; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 650 | isClientStateParam = true; |
| 651 | break; |
| 652 | } |
| 653 | case GL_VERTEX_ARRAY_TYPE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 654 | const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION); |
| 655 | *out = state.type; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 656 | isClientStateParam = true; |
| 657 | break; |
| 658 | } |
| 659 | case GL_VERTEX_ARRAY_STRIDE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 660 | const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION); |
| 661 | *out = state.stride; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 662 | isClientStateParam = true; |
| 663 | break; |
| 664 | } |
| 665 | case GL_COLOR_ARRAY_SIZE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 666 | const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION); |
| 667 | *out = state.size; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 668 | isClientStateParam = true; |
| 669 | break; |
| 670 | } |
| 671 | case GL_COLOR_ARRAY_TYPE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 672 | const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION); |
| 673 | *out = state.type; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 674 | isClientStateParam = true; |
| 675 | break; |
| 676 | } |
| 677 | case GL_COLOR_ARRAY_STRIDE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 678 | const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION); |
| 679 | *out = state.stride; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 680 | isClientStateParam = true; |
| 681 | break; |
| 682 | } |
| 683 | case GL_NORMAL_ARRAY_TYPE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 684 | const GLClientState::VertexAttribState& state = getState(GLClientState::NORMAL_LOCATION); |
| 685 | *out = state.type; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 686 | isClientStateParam = true; |
| 687 | break; |
| 688 | } |
| 689 | case GL_NORMAL_ARRAY_STRIDE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 690 | const GLClientState::VertexAttribState& state = getState(GLClientState::NORMAL_LOCATION); |
| 691 | *out = state.stride; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 692 | isClientStateParam = true; |
| 693 | break; |
| 694 | } |
| 695 | case GL_TEXTURE_COORD_ARRAY_SIZE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 696 | const GLClientState::VertexAttribState& state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION); |
| 697 | *out = state.size; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 698 | isClientStateParam = true; |
| 699 | break; |
| 700 | } |
| 701 | case GL_TEXTURE_COORD_ARRAY_TYPE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 702 | const GLClientState::VertexAttribState& state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION); |
| 703 | *out = state.type; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 704 | isClientStateParam = true; |
| 705 | break; |
| 706 | } |
| 707 | case GL_TEXTURE_COORD_ARRAY_STRIDE: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 708 | const GLClientState::VertexAttribState& state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION); |
| 709 | *out = state.stride; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 710 | isClientStateParam = true; |
| 711 | break; |
| 712 | } |
| 713 | case GL_POINT_SIZE_ARRAY_TYPE_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 714 | const GLClientState::VertexAttribState& state = getState(GLClientState::POINTSIZE_LOCATION); |
| 715 | *out = state.type; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 716 | isClientStateParam = true; |
| 717 | break; |
| 718 | } |
| 719 | case GL_POINT_SIZE_ARRAY_STRIDE_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 720 | const GLClientState::VertexAttribState& state = getState(GLClientState::POINTSIZE_LOCATION); |
| 721 | *out = state.stride; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 722 | isClientStateParam = true; |
| 723 | break; |
| 724 | } |
| 725 | case GL_MATRIX_INDEX_ARRAY_SIZE_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 726 | const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION); |
| 727 | *out = state.size; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 728 | isClientStateParam = true; |
| 729 | break; |
| 730 | } |
| 731 | case GL_MATRIX_INDEX_ARRAY_TYPE_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 732 | const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION); |
| 733 | *out = state.type; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 734 | isClientStateParam = true; |
| 735 | break; |
| 736 | } |
| 737 | case GL_MATRIX_INDEX_ARRAY_STRIDE_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 738 | const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION); |
| 739 | *out = state.stride; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 740 | isClientStateParam = true; |
| 741 | break; |
| 742 | } |
| 743 | case GL_WEIGHT_ARRAY_SIZE_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 744 | const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION); |
| 745 | *out = state.size; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 746 | isClientStateParam = true; |
| 747 | break; |
| 748 | } |
| 749 | case GL_WEIGHT_ARRAY_TYPE_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 750 | const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION); |
| 751 | *out = state.type; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 752 | isClientStateParam = true; |
| 753 | break; |
| 754 | } |
| 755 | case GL_WEIGHT_ARRAY_STRIDE_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 756 | const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION); |
| 757 | *out = state.stride; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 758 | isClientStateParam = true; |
| 759 | break; |
| 760 | } |
| 761 | case GL_VERTEX_ARRAY_BUFFER_BINDING: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 762 | const GLClientState::VertexAttribState& state = getState(GLClientState::VERTEX_LOCATION); |
| 763 | *out = state.bufferObject; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 764 | isClientStateParam = true; |
| 765 | break; |
| 766 | } |
| 767 | case GL_NORMAL_ARRAY_BUFFER_BINDING: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 768 | const GLClientState::VertexAttribState& state = getState(GLClientState::NORMAL_LOCATION); |
| 769 | *out = state.bufferObject; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 770 | isClientStateParam = true; |
| 771 | break; |
| 772 | } |
| 773 | case GL_COLOR_ARRAY_BUFFER_BINDING: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 774 | const GLClientState::VertexAttribState& state = getState(GLClientState::COLOR_LOCATION); |
| 775 | *out = state.bufferObject; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 776 | isClientStateParam = true; |
| 777 | break; |
| 778 | } |
| 779 | case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 780 | const GLClientState::VertexAttribState& state = getState(getActiveTexture()+GLClientState::TEXCOORD0_LOCATION); |
| 781 | *out = state.bufferObject; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 782 | isClientStateParam = true; |
| 783 | break; |
| 784 | } |
| 785 | case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 786 | const GLClientState::VertexAttribState& state = getState(GLClientState::POINTSIZE_LOCATION); |
| 787 | *out = state.bufferObject; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 788 | isClientStateParam = true; |
| 789 | break; |
| 790 | } |
| 791 | case GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 792 | const GLClientState::VertexAttribState& state = getState(GLClientState::MATRIXINDEX_LOCATION); |
| 793 | *out = state.bufferObject; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 794 | isClientStateParam = true; |
| 795 | break; |
| 796 | } |
| 797 | case GL_WEIGHT_ARRAY_BUFFER_BINDING_OES: { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 798 | const GLClientState::VertexAttribState& state = getState(GLClientState::WEIGHT_LOCATION); |
| 799 | *out = state.bufferObject; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 800 | isClientStateParam = true; |
| 801 | break; |
| 802 | } |
| 803 | case GL_ARRAY_BUFFER_BINDING: { |
| 804 | int buffer = getBuffer(GL_ARRAY_BUFFER); |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 805 | *out = buffer; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 806 | isClientStateParam = true; |
| 807 | break; |
| 808 | } |
| 809 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: { |
| 810 | int buffer = getBuffer(GL_ELEMENT_ARRAY_BUFFER); |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 811 | *out = buffer; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 812 | isClientStateParam = true; |
| 813 | break; |
| 814 | } |
Lingfeng Yang | b017698 | 2016-03-01 21:27:49 -0800 | [diff] [blame] | 815 | case GL_MAX_VERTEX_ATTRIBS: { |
| 816 | if (m_maxVertexAttribsDirty) { |
| 817 | isClientStateParam = false; |
| 818 | } else { |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 819 | *out = m_maxVertexAttribs; |
Lingfeng Yang | b017698 | 2016-03-01 21:27:49 -0800 | [diff] [blame] | 820 | isClientStateParam = true; |
| 821 | } |
| 822 | break; |
Lingfeng Yang | f654f3f | 2017-01-09 13:12:33 -0800 | [diff] [blame] | 823 | } |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 824 | } |
| 825 | return isClientStateParam; |
| 826 | } |
| 827 | |
| 828 | }; |
| 829 | #endif |