1custom_preprocesses = {
2"glBindVertexArray" : """
3    ctx->setVertexArrayObject(array);
4""",
5
6"glDeleteVertexArrays" : """
7    ctx->removeVertexArrayObjects(n, arrays);
8""",
9
10"glBindBufferRange" : """
11    ctx->bindBuffer(target, buffer);
12    ctx->bindIndexedBuffer(target, index, buffer, offset, size);
13""",
14
15"glBindBufferBase" : """
16    ctx->bindBuffer(target, buffer);
17    ctx->bindIndexedBuffer(target, index, buffer);
18""",
19
20"glVertexAttribIPointer" : """
21    SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE);
22    s_glPrepareVertexAttribPointer(ctx, index, size, type, false, stride, pointer, true);
23    if (ctx->isBindedBuffer(GL_ARRAY_BUFFER)) {
24""",
25
26"glVertexAttribDivisor" : """
27    SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE);
28    ctx->setVertexAttribBindingIndex(index, index);
29    ctx->setVertexAttribDivisor(index, divisor);
30""",
31
32"glRenderbufferStorageMultisample" : """
33    GLint err = GL_NO_ERROR;
34    internalformat = sPrepareRenderbufferStorage(internalformat, &err);
35    SET_ERROR_IF(err != GL_NO_ERROR, err);
36""",
37
38"glFramebufferTextureLayer" : """
39    GLenum textarget = GL_TEXTURE_2D_ARRAY;
40    SET_ERROR_IF(!(GLESv2Validate::framebufferTarget(ctx, target) &&
41                   GLESv2Validate::framebufferAttachment(ctx, attachment)), GL_INVALID_ENUM);
42    if (texture) {
43        if (!ctx->shareGroup()->isObject(NamedObjectType::TEXTURE, texture)) {
44            ctx->shareGroup()->genName(NamedObjectType::TEXTURE, texture);
45        }
46        TextureData* texData = getTextureData(texture);
47        textarget = texData->target;
48    }
49""",
50
51"glTexStorage2D" : """
52    GLint err = GL_NO_ERROR;
53    GLenum format, type;
54    GLESv2Validate::getCompatibleFormatTypeForInternalFormat(internalformat, &format, &type);
55    for (GLsizei i = 0; i < levels; i++)
56        sPrepareTexImage2D(target, i, (GLint)internalformat, width, height, 0, format, type, NULL, &type, (GLint*)&internalformat, &err);
57    SET_ERROR_IF(err != GL_NO_ERROR, err);
58""",
59
60"glGenSamplers" : """
61    if(ctx->shareGroup().get()) {
62        for(int i=0; i<n ;i++) {
63            samplers[i] = ctx->shareGroup()->genName(NamedObjectType::SAMPLER,
64                                                     0, true);
65        }
66    }
67""",
68
69"glDeleteSamplers" : """
70    if(ctx->shareGroup().get()) {
71        for(int i=0; i<n ;i++) {
72            ctx->shareGroup()->deleteName(NamedObjectType::SAMPLER, samplers[i]);
73        }
74    }
75""",
76
77"glGenQueries" : """
78    if(ctx->shareGroup().get()) {
79        for(int i=0; i<n ;i++) {
80            queries[i] = ctx->shareGroup()->genName(NamedObjectType::QUERY,
81                                                     0, true);
82        }
83    }
84""",
85
86"glDeleteQueries" : """
87    if(ctx->shareGroup().get()) {
88        for(int i=0; i<n ;i++) {
89            ctx->shareGroup()->deleteName(NamedObjectType::QUERY, queries[i]);
90        }
91    }
92""",
93
94"glTexImage3D" : """
95    SET_ERROR_IF(!GLESv2Validate::isCompressedFormat(internalFormat) &&
96                 !GLESv2Validate::pixelSizedFrmt(ctx, internalFormat, format, type),
97                 GL_INVALID_OPERATION);
98    s_glInitTexImage3D(target, level, internalFormat, width, height, depth, border);
99""",
100
101"glTexStorage3D" : """
102    for (int i = 0; i < levels; i++) {
103        s_glInitTexImage3D(target, i, internalformat, width, height, depth, 0);
104    }
105""",
106
107"glDrawArraysInstanced" : """
108    SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
109    SET_ERROR_IF(!(GLESv2Validate::drawMode(mode)),GL_INVALID_ENUM);
110    s_glDrawPre(ctx, mode);
111    if (ctx->isBindedBuffer(GL_ARRAY_BUFFER)) {
112        ctx->dispatcher().glDrawArraysInstanced(mode, first, count, primcount);
113    } else {
114        GLESConversionArrays tmpArrs;
115        s_glDrawSetupArraysPre(ctx, tmpArrs, first, count, 0, NULL, true);
116        ctx->dispatcher().glDrawArrays(mode,first,count);
117        s_glDrawSetupArraysPost(ctx);
118    }
119    s_glDrawPost(ctx, mode);
120""",
121
122"glDrawElementsInstanced" : """
123    SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
124    SET_ERROR_IF(!(GLESv2Validate::drawMode(mode) && GLESv2Validate::drawType(type)),GL_INVALID_ENUM);
125    s_glDrawPre(ctx, mode);
126    if (ctx->isBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)) {
127        ctx->dispatcher().glDrawElementsInstanced(mode,count,type,indices, primcount);
128    } else {
129        s_glDrawEmulateClientArraysPre(ctx);
130        GLESConversionArrays tmpArrs;
131        s_glDrawSetupArraysPre(ctx,tmpArrs,0,count,type,indices,false);
132        ctx->dispatcher().glDrawElementsInstanced(mode,count,type,indices, primcount);
133        s_glDrawSetupArraysPost(ctx);
134        s_glDrawEmulateClientArraysPost(ctx);
135    }
136    s_glDrawPost(ctx, mode);
137""",
138
139"glDrawRangeElements" : """
140    SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
141    SET_ERROR_IF(!(GLESv2Validate::drawMode(mode) && GLESv2Validate::drawType(type)),GL_INVALID_ENUM);
142    s_glDrawPre(ctx, mode);
143    if (ctx->isBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)) {
144        ctx->dispatcher().glDrawRangeElements(mode,start,end,count,type,indices);
145    } else {
146        s_glDrawEmulateClientArraysPre(ctx);
147        GLESConversionArrays tmpArrs;
148        s_glDrawSetupArraysPre(ctx,tmpArrs,0,count,type,indices,false);
149        ctx->dispatcher().glDrawRangeElements(mode,start,end,count,type,indices);
150        s_glDrawSetupArraysPost(ctx);
151        s_glDrawEmulateClientArraysPost(ctx);
152    }
153    s_glDrawPost(ctx, mode);
154""",
155
156"glGetUniformuiv" : """
157    SET_ERROR_IF(location < 0,GL_INVALID_OPERATION);
158""",
159}
160
161custom_postprocesses = {
162"glGenVertexArrays" : """
163    ctx->addVertexArrayObjects(n, arrays);
164""",
165"glVertexAttribIPointer" : """
166    }
167""",
168"glFramebufferTextureLayer" : """
169    GLuint fbName = ctx->getFramebufferBinding(target);
170    auto fbObj = ctx->shareGroup()->getObjectData(
171            NamedObjectType::FRAMEBUFFER, fbName);
172    if (fbObj) {
173        FramebufferData *fbData = (FramebufferData *)fbObj;
174        fbData->setAttachment(attachment, textarget,
175                              texture, ObjectDataPtr());
176    }
177""",
178"glGetInteger64v" : """
179    s_glStateQueryTv<GLint64>(true, pname, data, s_glGetInteger64v_wrapper);
180""",
181"glGetIntegeri_v" : """
182    s_glStateQueryTi_v<GLint>(target, index, data, s_glGetIntegeri_v_wrapper);
183""",
184"glGetInteger64i_v" : """
185    s_glStateQueryTi_v<GLint64>(target, index, data, s_glGetInteger64i_v_wrapper);
186""",
187}
188
189custom_share_processing = {
190"glBindSampler" : """
191        SET_ERROR_IF(sampler && !globalSampler, GL_INVALID_OPERATION);
192""",
193"glGetUniformuiv" : """
194        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
195        auto objData = ctx->shareGroup()->getObjectData(
196                NamedObjectType::SHADER_OR_PROGRAM, program);
197        SET_ERROR_IF(objData->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
198        ProgramData* pData = (ProgramData *)objData;
199        SET_ERROR_IF(pData->getLinkStatus() != GL_TRUE,GL_INVALID_OPERATION);
200""",
201}
202
203no_passthrough = {
204    "glGenSamplers": True,
205    "glDeleteSamplers": True,
206    "glGenQueries": True,
207    "glDeleteQueries": True,
208    "glGetInteger64_v": True,
209    "glGetIntegeri_v": True,
210    "glGetInteger64i_v": True,
211}