1 /* Copyright (C) 2010-2018 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this libretro SDK code part (glsm).
5 * ---------------------------------------------------------------------------------------
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include <glsym/glsym.h>
26 #include <glsm/glsm.h>
28 #ifndef GL_DEPTH_CLAMP
29 #define GL_DEPTH_CLAMP 0x864F
30 #define GL_RASTERIZER_DISCARD 0x8C89
31 #define GL_SAMPLE_MASK 0x8E51
35 extern retro_log_printf_t log_cb;
39 struct gl_cached_state
48 bool used[MAX_ATTRIB];
49 GLint size[MAX_ATTRIB];
50 GLenum type[MAX_ATTRIB];
51 GLboolean normalized[MAX_ATTRIB];
52 GLsizei stride[MAX_ATTRIB];
53 const GLvoid *pointer[MAX_ATTRIB];
54 GLuint buffer[MAX_ATTRIB];
63 bool enabled[MAX_ATTRIB];
64 } vertex_attrib_pointer;
111 } blendfunc_separate;
197 GLenum active_texture;
198 int cap_state[SGL_CAP_MAX];
199 int cap_translate[SGL_CAP_MAX];
202 static GLuint default_framebuffer;
203 static GLint glsm_max_textures;
204 struct retro_hw_render_callback hw_render;
205 static struct gl_cached_state gl_state;
207 /* GL wrapper-side */
214 GLenum rglGetError(void)
226 void rglProvokingVertex( GLenum provokeMode)
228 #if defined(HAVE_OPENGL)
229 glProvokingVertex(provokeMode);
239 void rglGetInteger64v( GLenum pname, int64_t *data)
241 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
242 glGetInteger64v(pname, (GLint64*)data);
252 void rglSamplerParameteri( GLuint sampler,
256 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
257 glSamplerParameteri(sampler, pname, param);
261 void rglGenSamplers( GLsizei n,
264 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
265 glGenSamplers(n, samplers);
269 void rglBindSampler( GLuint unit,
272 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
273 glBindSampler(unit, sampler);
282 void rglClear(GLbitfield mask)
285 log_cb(RETRO_LOG_INFO, "glClear.\n");
295 void rglValidateProgram(GLuint program)
298 log_cb(RETRO_LOG_INFO, "glValidateProgram.\n");
300 glValidateProgram(program);
309 void rglPolygonMode(GLenum face, GLenum mode)
312 log_cb(RETRO_LOG_INFO, "glPolygonMode.\n");
314 #ifndef HAVE_OPENGLES
315 glPolygonMode(face, mode);
319 void rglTexSubImage2D(
328 const GLvoid * pixels)
331 log_cb(RETRO_LOG_INFO, "glTexSubImage2D.\n");
333 glTexSubImage2D(target, level, xoffset, yoffset,
334 width, height, format, type, pixels);
337 void rglGetBufferSubData( GLenum target,
343 log_cb(RETRO_LOG_INFO, "glGetBufferSubData.\n");
345 #if defined(HAVE_OPENGL)
346 glGetBufferSubData(target, offset, size, data);
355 void rglLineWidth(GLfloat width)
358 log_cb(RETRO_LOG_INFO, "glLineWidth.\n");
370 void rglBlitFramebuffer(
371 GLint srcX0, GLint srcY0,
372 GLint srcX1, GLint srcY1,
373 GLint dstX0, GLint dstY0,
374 GLint dstX1, GLint dstY1,
375 GLbitfield mask, GLenum filter)
378 log_cb(RETRO_LOG_INFO, "glBlitFramebuffer.\n");
380 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
381 glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
382 dstX0, dstY0, dstX1, dstY1,
392 void rglReadBuffer(GLenum mode)
395 log_cb(RETRO_LOG_INFO, "glReadBuffer.\n");
397 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
399 gl_state.readbuffer.mode = mode;
408 void rglClearDepth(GLdouble depth)
411 log_cb(RETRO_LOG_INFO, "glClearDepth.\n");
413 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
415 glClearDepthf(depth);
419 gl_state.cleardepth.used = true;
420 gl_state.cleardepth.depth = depth;
428 void rglPixelStorei(GLenum pname, GLint param)
431 log_cb(RETRO_LOG_INFO, "glPixelStorei.\n");
433 glPixelStorei(pname, param);
434 gl_state.pixelstore_i.pname = pname;
435 gl_state.pixelstore_i.param = param;
443 void rglDepthRange(GLclampd zNear, GLclampd zFar)
446 log_cb(RETRO_LOG_INFO, "glDepthRange.\n");
449 glDepthRangef(zNear, zFar);
451 glDepthRange(zNear, zFar);
453 gl_state.depthrange.used = true;
454 gl_state.depthrange.zNear = zNear;
455 gl_state.depthrange.zFar = zFar;
463 void rglFrontFace(GLenum mode)
466 log_cb(RETRO_LOG_INFO, "glFrontFace.\n");
468 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
470 gl_state.frontface.used = true;
471 gl_state.frontface.mode = mode;
479 void rglDepthFunc(GLenum func)
482 log_cb(RETRO_LOG_INFO, "glDepthFunc.\n");
484 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
485 gl_state.depthfunc.used = true;
486 gl_state.depthfunc.func = func;
495 void rglColorMask(GLboolean red, GLboolean green,
496 GLboolean blue, GLboolean alpha)
499 log_cb(RETRO_LOG_INFO, "glColorMask.\n");
501 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
502 glColorMask(red, green, blue, alpha);
503 gl_state.colormask.red = red;
504 gl_state.colormask.green = green;
505 gl_state.colormask.blue = blue;
506 gl_state.colormask.alpha = alpha;
507 gl_state.colormask.used = true;
515 void rglCullFace(GLenum mode)
518 log_cb(RETRO_LOG_INFO, "glCullFace.\n");
520 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
522 gl_state.cullface.used = true;
523 gl_state.cullface.mode = mode;
531 void rglStencilOp(GLenum sfail, GLenum dpfail, GLenum dppass)
534 log_cb(RETRO_LOG_INFO, "glStencilOp.\n");
536 glStencilOp(sfail, dpfail, dppass);
537 gl_state.stencilop.used = true;
538 gl_state.stencilop.sfail = sfail;
539 gl_state.stencilop.dpfail = dpfail;
540 gl_state.stencilop.dppass = dppass;
548 void rglStencilFunc(GLenum func, GLint ref, GLuint mask)
551 log_cb(RETRO_LOG_INFO, "glStencilFunc.\n");
553 glStencilFunc(func, ref, mask);
554 gl_state.stencilfunc.used = true;
555 gl_state.stencilfunc.func = func;
556 gl_state.stencilfunc.ref = ref;
557 gl_state.stencilfunc.mask = mask;
565 GLboolean rglIsEnabled(GLenum cap)
568 log_cb(RETRO_LOG_INFO, "glIsEnabled.\n");
570 return gl_state.cap_state[cap] ? GL_TRUE : GL_FALSE;
578 void rglClearColor(GLclampf red, GLclampf green,
579 GLclampf blue, GLclampf alpha)
582 log_cb(RETRO_LOG_INFO, "glClearColor.\n");
584 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
585 glClearColor(red, green, blue, alpha);
586 gl_state.clear_color.r = red;
587 gl_state.clear_color.g = green;
588 gl_state.clear_color.b = blue;
589 gl_state.clear_color.a = alpha;
595 * OpenGLES : 2.0 (maybe earlier?)
597 void rglScissor(GLint x, GLint y, GLsizei width, GLsizei height)
600 log_cb(RETRO_LOG_INFO, "glScissor.\n");
602 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
603 glScissor(x, y, width, height);
604 gl_state.scissor.used = true;
605 gl_state.scissor.x = x;
606 gl_state.scissor.y = y;
607 gl_state.scissor.w = width;
608 gl_state.scissor.h = height;
616 void rglViewport(GLint x, GLint y, GLsizei width, GLsizei height)
619 log_cb(RETRO_LOG_INFO, "glViewport.\n");
621 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
622 glViewport(x, y, width, height);
623 gl_state.viewport.x = x;
624 gl_state.viewport.y = y;
625 gl_state.viewport.w = width;
626 gl_state.viewport.h = height;
629 void rglBlendFunc(GLenum sfactor, GLenum dfactor)
632 log_cb(RETRO_LOG_INFO, "glBlendFunc.\n");
634 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
635 gl_state.blendfunc.used = true;
636 gl_state.blendfunc.sfactor = sfactor;
637 gl_state.blendfunc.dfactor = dfactor;
638 glBlendFunc(sfactor, dfactor);
647 void rglBlendFuncSeparate(GLenum sfactor, GLenum dfactor)
650 log_cb(RETRO_LOG_INFO, "glBlendFuncSeparate.\n");
652 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
653 gl_state.blendfunc_separate.used = true;
654 gl_state.blendfunc_separate.srcRGB = sfactor;
655 gl_state.blendfunc_separate.dstRGB = dfactor;
656 gl_state.blendfunc_separate.srcAlpha = sfactor;
657 gl_state.blendfunc_separate.dstAlpha = dfactor;
658 glBlendFunc(sfactor, dfactor);
667 void rglActiveTexture(GLenum texture)
670 log_cb(RETRO_LOG_INFO, "glActiveTexture.\n");
672 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
673 glActiveTexture(texture);
674 gl_state.active_texture = texture - GL_TEXTURE0;
682 void rglBindTexture(GLenum target, GLuint texture)
685 log_cb(RETRO_LOG_INFO, "glBindTexture.\n");
687 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
688 glBindTexture(target, texture);
689 gl_state.bind_textures.ids[gl_state.active_texture] = texture;
697 void rglDisable(GLenum cap)
700 log_cb(RETRO_LOG_INFO, "glDisable.\n");
702 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
703 glDisable(gl_state.cap_translate[cap]);
704 gl_state.cap_state[cap] = 0;
712 void rglEnable(GLenum cap)
715 log_cb(RETRO_LOG_INFO, "glEnable.\n");
717 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
718 glEnable(gl_state.cap_translate[cap]);
719 gl_state.cap_state[cap] = 1;
728 void rglUseProgram(GLuint program)
731 log_cb(RETRO_LOG_INFO, "glUseProgram.\n");
733 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
734 gl_state.program = program;
735 glUseProgram(program);
743 void rglDepthMask(GLboolean flag)
746 log_cb(RETRO_LOG_INFO, "glDepthMask.\n");
748 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
750 gl_state.depthmask.used = true;
751 gl_state.depthmask.mask = flag;
759 void rglStencilMask(GLenum mask)
762 log_cb(RETRO_LOG_INFO, "glStencilMask.\n");
765 gl_state.stencilmask.used = true;
766 gl_state.stencilmask.mask = mask;
774 void rglBufferData(GLenum target, GLsizeiptr size,
775 const GLvoid *data, GLenum usage)
778 log_cb(RETRO_LOG_INFO, "glBufferData.\n");
780 glBufferData(target, size, data, usage);
788 void rglBufferSubData(GLenum target, GLintptr offset,
789 GLsizeiptr size, const GLvoid *data)
792 log_cb(RETRO_LOG_INFO, "glBufferSubData.\n");
794 glBufferSubData(target, offset, size, data);
802 void rglBindBuffer(GLenum target, GLuint buffer)
805 log_cb(RETRO_LOG_INFO, "glBindBuffer.\n");
807 if (target == GL_ARRAY_BUFFER)
808 gl_state.array_buffer = buffer;
809 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
810 glBindBuffer(target, buffer);
819 void rglLinkProgram(GLuint program)
822 log_cb(RETRO_LOG_INFO, "glLinkProgram.\n");
824 glLinkProgram(program);
834 void rglFramebufferTexture2D(GLenum target, GLenum attachment,
835 GLenum textarget, GLuint texture, GLint level)
838 log_cb(RETRO_LOG_INFO, "glFramebufferTexture2D.\n");
840 glFramebufferTexture2D(target, attachment, textarget, texture, level);
850 void rglFramebufferTexture(GLenum target, GLenum attachment,
851 GLuint texture, GLint level)
854 log_cb(RETRO_LOG_INFO, "glFramebufferTexture.\n");
856 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3_2)
857 glFramebufferTexture(target, attachment, texture, level);
866 void rglDrawArrays(GLenum mode, GLint first, GLsizei count)
869 log_cb(RETRO_LOG_INFO, "glDrawArrays.\n");
871 glDrawArrays(mode, first, count);
879 void rglDrawElements(GLenum mode, GLsizei count, GLenum type,
880 const GLvoid * indices)
883 log_cb(RETRO_LOG_INFO, "glDrawElements.\n");
885 glDrawElements(mode, count, type, indices);
888 void rglCompressedTexImage2D(GLenum target, GLint level,
889 GLenum internalformat, GLsizei width, GLsizei height,
890 GLint border, GLsizei imageSize, const GLvoid *data)
893 log_cb(RETRO_LOG_INFO, "glCompressedTexImage2D.\n");
895 glCompressedTexImage2D(target, level, internalformat,
896 width, height, border, imageSize, data);
899 void rglDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
902 log_cb(RETRO_LOG_INFO, "glDeleteFramebuffers.\n");
904 glDeleteFramebuffers(n, framebuffers);
907 void rglDeleteTextures(GLsizei n, const GLuint *textures)
910 log_cb(RETRO_LOG_INFO, "glDeleteTextures.\n");
912 glDeleteTextures(n, textures);
920 void rglRenderbufferStorage(GLenum target, GLenum internalFormat,
921 GLsizei width, GLsizei height)
924 log_cb(RETRO_LOG_INFO, "glRenderbufferStorage.\n");
926 glRenderbufferStorage(target, internalFormat, width, height);
936 void rglBindRenderbuffer(GLenum target, GLuint renderbuffer)
939 log_cb(RETRO_LOG_INFO, "glBindRenderbuffer.\n");
941 glBindRenderbuffer(target, renderbuffer);
950 void rglDeleteRenderbuffers(GLsizei n, GLuint *renderbuffers)
953 log_cb(RETRO_LOG_INFO, "glDeleteRenderbuffers.\n");
955 glDeleteRenderbuffers(n, renderbuffers);
965 void rglGenRenderbuffers(GLsizei n, GLuint *renderbuffers)
968 log_cb(RETRO_LOG_INFO, "glGenRenderbuffers.\n");
970 glGenRenderbuffers(n, renderbuffers);
980 void rglGenerateMipmap(GLenum target)
983 log_cb(RETRO_LOG_INFO, "glGenerateMipmap.\n");
985 glGenerateMipmap(target);
994 GLenum rglCheckFramebufferStatus(GLenum target)
997 log_cb(RETRO_LOG_INFO, "glCheckFramebufferStatus.\n");
999 return glCheckFramebufferStatus(target);
1009 void rglFramebufferRenderbuffer(GLenum target, GLenum attachment,
1010 GLenum renderbuffertarget, GLuint renderbuffer)
1013 log_cb(RETRO_LOG_INFO, "glFramebufferRenderbuffer.\n");
1015 glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
1024 void rglBindFragDataLocation(GLuint program, GLuint colorNumber,
1028 log_cb(RETRO_LOG_INFO, "glBindFragDataLocation.\n");
1030 #if !defined(HAVE_OPENGLES2)
1031 glBindFragDataLocation(program, colorNumber, name);
1041 void rglGetProgramiv(GLuint shader, GLenum pname, GLint *params)
1044 log_cb(RETRO_LOG_INFO, "glGetProgramiv.\n");
1046 glGetProgramiv(shader, pname, params);
1056 void rglProgramParameteri( GLuint program,
1061 log_cb(RETRO_LOG_INFO, "glProgramParameteri.\n");
1063 #if !defined(HAVE_OPENGLES) || defined(HAVE_OPENGLES) && (defined(HAVE_OPENGLES3) || defined(HAVE_OPENGLES_3_1))
1064 glProgramParameteri(program, pname, value);
1066 printf("WARNING! Not implemented.\n");
1075 void rglGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize,
1076 GLsizei *length, GLint *size, GLenum *type, GLchar *name)
1079 log_cb(RETRO_LOG_INFO, "glGetActiveUniform.\n");
1081 glGetActiveUniform(program, index, bufsize, length, size, type, name);
1084 void rglGenQueries( GLsizei n,
1088 log_cb(RETRO_LOG_INFO, "glGenQueries.\n");
1090 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1091 glGenQueries(n, ids);
1095 void rglGetQueryObjectuiv( GLuint id,
1100 log_cb(RETRO_LOG_INFO, "glGetQueryObjectuiv.\n");
1102 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1103 glGetQueryObjectuiv(id, pname, params);
1107 void rglDeleteQueries( GLsizei n,
1111 log_cb(RETRO_LOG_INFO, "glDeleteQueries.\n");
1113 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1114 glDeleteQueries(n, ids);
1118 void rglBeginQuery( GLenum target,
1122 log_cb(RETRO_LOG_INFO, "glBeginQuery.\n");
1124 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1125 glBeginQuery(target, id);
1129 void rglEndQuery( GLenum target)
1132 log_cb(RETRO_LOG_INFO, "glEndQuery.\n");
1134 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1147 void rglGetActiveUniformBlockiv(GLuint program,
1148 GLuint uniformBlockIndex,
1153 log_cb(RETRO_LOG_INFO, "glGetActiveUniformBlockiv.\n");
1155 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1156 glGetActiveUniformBlockiv(program, uniformBlockIndex,
1159 printf("WARNING! Not implemented.\n");
1169 void rglGetActiveUniformsiv( GLuint program,
1170 GLsizei uniformCount,
1171 const GLuint *uniformIndices,
1176 log_cb(RETRO_LOG_INFO, "glGetActiveUniformsiv.\n");
1178 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1179 glGetActiveUniformsiv(program, uniformCount,
1180 uniformIndices, pname, params);
1182 printf("WARNING! Not implemented.\n");
1192 void rglGetUniformIndices(GLuint program,
1193 GLsizei uniformCount,
1194 const GLchar **uniformNames,
1195 GLuint *uniformIndices)
1198 log_cb(RETRO_LOG_INFO, "glGetUniformIndices.\n");
1200 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1201 glGetUniformIndices(program, uniformCount,
1202 uniformNames, uniformIndices);
1204 printf("WARNING! Not implemented.\n");
1215 void rglBindBufferBase( GLenum target,
1220 log_cb(RETRO_LOG_INFO, "glBindBufferBase.\n");
1222 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1223 glBindBufferBase(target, index, buffer);
1225 printf("WARNING! Not implemented.\n");
1237 GLuint rglGetUniformBlockIndex( GLuint program,
1238 const GLchar *uniformBlockName)
1241 log_cb(RETRO_LOG_INFO, "glGetUniformBlockIndex.\n");
1243 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1244 return glGetUniformBlockIndex(program, uniformBlockName);
1246 printf("WARNING! Not implemented.\n");
1258 void rglUniformBlockBinding( GLuint program,
1259 GLuint uniformBlockIndex,
1260 GLuint uniformBlockBinding)
1263 log_cb(RETRO_LOG_INFO, "glUniformBlockBinding.\n");
1265 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1266 glUniformBlockBinding(program, uniformBlockIndex,
1267 uniformBlockBinding);
1269 printf("WARNING! Not implemented.\n");
1279 void rglUniform1ui(GLint location, GLuint v)
1282 log_cb(RETRO_LOG_INFO, "glUniform1ui.\n");
1284 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1285 glUniform1ui(location ,v);
1295 void rglUniform2ui(GLint location, GLuint v0, GLuint v1)
1298 log_cb(RETRO_LOG_INFO, "glUniform2ui.\n");
1300 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1301 glUniform2ui(location, v0, v1);
1311 void rglUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
1314 log_cb(RETRO_LOG_INFO, "glUniform3ui.\n");
1316 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1317 glUniform3ui(location, v0, v1, v2);
1327 void rglUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
1330 log_cb(RETRO_LOG_INFO, "glUniform4ui.\n");
1332 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1333 glUniform4ui(location, v0, v1, v2, v3);
1342 void rglUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose,
1343 const GLfloat *value)
1346 log_cb(RETRO_LOG_INFO, "glUniformMatrix4fv.\n");
1348 glUniformMatrix4fv(location, count, transpose, value);
1357 void rglDetachShader(GLuint program, GLuint shader)
1360 log_cb(RETRO_LOG_INFO, "glDetachShader.\n");
1362 glDetachShader(program, shader);
1371 void rglGetShaderiv(GLuint shader, GLenum pname, GLint *params)
1374 log_cb(RETRO_LOG_INFO, "glGetShaderiv.\n");
1376 glGetShaderiv(shader, pname, params);
1385 void rglAttachShader(GLuint program, GLuint shader)
1388 log_cb(RETRO_LOG_INFO, "glAttachShader.\n");
1390 glAttachShader(program, shader);
1398 GLint rglGetAttribLocation(GLuint program, const GLchar *name)
1401 log_cb(RETRO_LOG_INFO, "glGetAttribLocation.\n");
1403 return glGetAttribLocation(program, name);
1412 void rglShaderSource(GLuint shader, GLsizei count,
1413 const GLchar **string, const GLint *length)
1416 log_cb(RETRO_LOG_INFO, "glShaderSource.\n");
1418 return glShaderSource(shader, count, string, length);
1427 void rglCompileShader(GLuint shader)
1430 log_cb(RETRO_LOG_INFO, "glCompileShader.\n");
1432 glCompileShader(shader);
1441 GLuint rglCreateProgram(void)
1444 log_cb(RETRO_LOG_INFO, "glCreateProgram.\n");
1446 return glCreateProgram();
1454 void rglGenTextures(GLsizei n, GLuint *textures)
1457 log_cb(RETRO_LOG_INFO, "glGenTextures.\n");
1459 glGenTextures(n, textures);
1467 void rglGetShaderInfoLog(GLuint shader, GLsizei maxLength,
1468 GLsizei *length, GLchar *infoLog)
1471 log_cb(RETRO_LOG_INFO, "glGetShaderInfoLog.\n");
1473 glGetShaderInfoLog(shader, maxLength, length, infoLog);
1481 void rglGetProgramInfoLog(GLuint shader, GLsizei maxLength,
1482 GLsizei *length, GLchar *infoLog)
1485 log_cb(RETRO_LOG_INFO, "glGetProgramInfoLog.\n");
1487 glGetProgramInfoLog(shader, maxLength, length, infoLog);
1495 GLboolean rglIsProgram(GLuint program)
1498 log_cb(RETRO_LOG_INFO, "glIsProgram.\n");
1500 return glIsProgram(program);
1503 void rglTexCoord2f(GLfloat s, GLfloat t)
1505 #ifdef HAVE_LEGACY_GL
1507 log_cb(RETRO_LOG_INFO, "glTexCoord2f.\n");
1514 * Category: Generic vertex attributes
1520 void rglDisableVertexAttribArray(GLuint index)
1523 log_cb(RETRO_LOG_INFO, "glDisableVertexAttribArray.\n");
1525 gl_state.vertex_attrib_pointer.enabled[index] = 0;
1526 glDisableVertexAttribArray(index);
1530 * Category: Generic vertex attributes
1535 void rglEnableVertexAttribArray(GLuint index)
1538 log_cb(RETRO_LOG_INFO, "glEnableVertexAttribArray.\n");
1540 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
1541 gl_state.vertex_attrib_pointer.enabled[index] = 1;
1542 glEnableVertexAttribArray(index);
1551 void rglVertexAttribIPointer(
1556 const GLvoid * pointer)
1559 log_cb(RETRO_LOG_INFO, "glVertexAttribIPointer.\n");
1561 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
1562 glVertexAttribIPointer(index, size, type, stride, pointer);
1566 void rglVertexAttribLPointer(
1571 const GLvoid * pointer)
1574 log_cb(RETRO_LOG_INFO, "glVertexAttribLPointer.\n");
1576 #if defined(HAVE_OPENGL)
1577 glVertexAttribLPointer(index, size, type, stride, pointer);
1582 * Category: Generic vertex attributes
1587 void rglVertexAttribPointer(GLuint name, GLint size,
1588 GLenum type, GLboolean normalized, GLsizei stride,
1589 const GLvoid* pointer)
1592 log_cb(RETRO_LOG_INFO, "glVertexAttribPointer.\n");
1594 gl_state.attrib_pointer.used[name] = 1;
1595 gl_state.attrib_pointer.size[name] = size;
1596 gl_state.attrib_pointer.type[name] = type;
1597 gl_state.attrib_pointer.normalized[name] = normalized;
1598 gl_state.attrib_pointer.stride[name] = stride;
1599 gl_state.attrib_pointer.pointer[name] = pointer;
1600 gl_state.attrib_pointer.buffer[name] = gl_state.array_buffer;
1601 glVertexAttribPointer(name, size, type, normalized, stride, pointer);
1605 * Category: Generic vertex attributes
1610 void rglBindAttribLocation(GLuint program, GLuint index, const GLchar *name)
1613 log_cb(RETRO_LOG_INFO, "glBindAttribLocation.\n");
1615 glBindAttribLocation(program, index, name);
1623 void rglVertexAttrib4f(GLuint name, GLfloat x, GLfloat y,
1624 GLfloat z, GLfloat w)
1627 log_cb(RETRO_LOG_INFO, "glVertexAttrib4f.\n");
1629 glVertexAttrib4f(name, x, y, z, w);
1637 void rglVertexAttrib4fv(GLuint name, GLfloat* v)
1640 log_cb(RETRO_LOG_INFO, "glVertexAttrib4fv.\n");
1642 glVertexAttrib4fv(name, v);
1651 GLuint rglCreateShader(GLenum shaderType)
1654 log_cb(RETRO_LOG_INFO, "glCreateShader.\n");
1656 return glCreateShader(shaderType);
1665 void rglDeleteProgram(GLuint program)
1668 log_cb(RETRO_LOG_INFO, "glDeleteProgram.\n");
1670 glDeleteProgram(program);
1679 void rglDeleteShader(GLuint shader)
1682 log_cb(RETRO_LOG_INFO, "glDeleteShader.\n");
1684 glDeleteShader(shader);
1693 GLint rglGetUniformLocation(GLuint program, const GLchar *name)
1696 log_cb(RETRO_LOG_INFO, "glGetUniformLocation.\n");
1698 return glGetUniformLocation(program, name);
1702 * Category: VBO and PBO
1707 void rglDeleteBuffers(GLsizei n, const GLuint *buffers)
1710 log_cb(RETRO_LOG_INFO, "glDeleteBuffers.\n");
1712 glDeleteBuffers(n, buffers);
1716 * Category: VBO and PBO
1721 void rglGenBuffers(GLsizei n, GLuint *buffers)
1724 log_cb(RETRO_LOG_INFO, "glGenBuffers.\n");
1726 glGenBuffers(n, buffers);
1735 void rglUniform1f(GLint location, GLfloat v0)
1738 log_cb(RETRO_LOG_INFO, "glUniform1f.\n");
1740 glUniform1f(location, v0);
1749 void rglUniform1fv(GLint location, GLsizei count, const GLfloat *value)
1752 log_cb(RETRO_LOG_INFO, "glUniform1fv.\n");
1754 glUniform1fv(location, count, value);
1763 void rglUniform1iv(GLint location, GLsizei count, const GLint *value)
1766 log_cb(RETRO_LOG_INFO, "glUniform1iv.\n");
1768 glUniform1iv(location, count, value);
1771 void rglClearBufferfv( GLenum buffer,
1773 const GLfloat * value)
1776 log_cb(RETRO_LOG_INFO, "glClearBufferfv.\n");
1778 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3)
1779 glClearBufferfv(buffer, drawBuffer, value);
1783 void rglTexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
1786 log_cb(RETRO_LOG_INFO, "glTexBuffer.\n");
1788 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3_2)
1789 glTexBuffer(target, internalFormat, buffer);
1799 const GLubyte* rglGetStringi(GLenum name, GLuint index)
1802 log_cb(RETRO_LOG_INFO, "glGetString.\n");
1804 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3)
1805 return glGetStringi(name, index);
1811 void rglClearBufferfi( GLenum buffer,
1817 log_cb(RETRO_LOG_INFO, "glClearBufferfi.\n");
1819 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3)
1820 glClearBufferfi(buffer, drawBuffer, depth, stencil);
1830 void rglRenderbufferStorageMultisample( GLenum target,
1832 GLenum internalformat,
1837 log_cb(RETRO_LOG_INFO, "glRenderbufferStorageMultisample.\n");
1839 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3)
1840 glRenderbufferStorageMultisample(target, samples, internalformat, width, height);
1850 void rglUniform1i(GLint location, GLint v0)
1853 log_cb(RETRO_LOG_INFO, "glUniform1i.\n");
1855 glUniform1i(location, v0);
1864 void rglUniform2f(GLint location, GLfloat v0, GLfloat v1)
1867 log_cb(RETRO_LOG_INFO, "glUniform2f.\n");
1869 glUniform2f(location, v0, v1);
1878 void rglUniform2i(GLint location, GLint v0, GLint v1)
1881 log_cb(RETRO_LOG_INFO, "glUniform2i.\n");
1883 glUniform2i(location, v0, v1);
1892 void rglUniform2fv(GLint location, GLsizei count, const GLfloat *value)
1895 log_cb(RETRO_LOG_INFO, "glUniform2fv.\n");
1897 glUniform2fv(location, count, value);
1906 void rglUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
1909 log_cb(RETRO_LOG_INFO, "glUniform3f.\n");
1911 glUniform3f(location, v0, v1, v2);
1920 void rglUniform3fv(GLint location, GLsizei count, const GLfloat *value)
1923 log_cb(RETRO_LOG_INFO, "glUniform3fv.\n");
1925 glUniform3fv(location, count, value);
1934 void rglUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3)
1937 log_cb(RETRO_LOG_INFO, "glUniform4i.\n");
1939 glUniform4i(location, v0, v1, v2, v3);
1948 void rglUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
1951 log_cb(RETRO_LOG_INFO, "glUniform4f.\n");
1953 glUniform4f(location, v0, v1, v2, v3);
1962 void rglUniform4fv(GLint location, GLsizei count, const GLfloat *value)
1965 log_cb(RETRO_LOG_INFO, "glUniform4fv.\n");
1967 glUniform4fv(location, count, value);
1975 void rglPolygonOffset(GLfloat factor, GLfloat units)
1978 log_cb(RETRO_LOG_INFO, "glPolygonOffset.\n");
1980 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
1981 glPolygonOffset(factor, units);
1982 gl_state.polygonoffset.used = true;
1983 gl_state.polygonoffset.factor = factor;
1984 gl_state.polygonoffset.units = units;
1993 void rglGenFramebuffers(GLsizei n, GLuint *ids)
1996 log_cb(RETRO_LOG_INFO, "glGenFramebuffers.\n");
1998 glGenFramebuffers(n, ids);
2007 void rglBindFramebuffer(GLenum target, GLuint framebuffer)
2010 log_cb(RETRO_LOG_INFO, "glBindFramebuffer.\n");
2012 glsm_ctl(GLSM_CTL_IMM_VBO_DRAW, NULL);
2013 glBindFramebuffer(target, framebuffer);
2014 gl_state.framebuf = framebuffer;
2024 void rglDrawBuffers(GLsizei n, const GLenum *bufs)
2027 log_cb(RETRO_LOG_INFO, "glDrawBuffers.\n");
2029 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2030 glDrawBuffers(n, bufs);
2041 void *rglMapBufferRange( GLenum target,
2047 log_cb(RETRO_LOG_INFO, "glMapBufferRange.\n");
2049 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2050 return glMapBufferRange(target, offset, length, access);
2052 printf("WARNING! Not implemented.\n");
2063 void rglTexStorage2DMultisample(GLenum target, GLsizei samples,
2064 GLenum internalformat, GLsizei width, GLsizei height,
2065 GLboolean fixedsamplelocations)
2068 log_cb(RETRO_LOG_INFO, "glTexStorage2DMultisample.\n");
2070 #if defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3_1)
2071 glTexStorage2DMultisample(target, samples, internalformat,
2072 width, height, fixedsamplelocations);
2081 void rglTexStorage2D(GLenum target, GLsizei levels, GLenum internalFormat,
2082 GLsizei width, GLsizei height)
2085 log_cb(RETRO_LOG_INFO, "glTexStorage2D.\n");
2087 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2088 glTexStorage2D(target, levels, internalFormat, width, height);
2097 void rglDrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, GLvoid *indices, GLint basevertex)
2099 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3_2)
2100 glDrawRangeElementsBaseVertex(mode, start, end, count, type, indices, basevertex);
2110 void rglMemoryBarrier( GLbitfield barriers)
2113 log_cb(RETRO_LOG_INFO, "glMemoryBarrier.\n");
2115 #if !defined(HAVE_OPENGLES) || defined(HAVE_OPENGLES3) && defined(HAVE_OPENGLES_3_1)
2116 glMemoryBarrier(barriers);
2118 printf("WARNING! Not implemented.\n");
2128 void rglBindImageTexture( GLuint unit,
2137 log_cb(RETRO_LOG_INFO, "glBindImageTexture.\n");
2139 #if !defined(HAVE_OPENGLES) || defined(HAVE_OPENGLES3) && defined(HAVE_OPENGLES_3_1)
2140 glBindImageTexture(unit, texture, level, layered, layer, access, format);
2142 printf("WARNING! Not implemented.\n");
2152 void rglGetProgramBinary( GLuint program,
2155 GLenum *binaryFormat,
2159 log_cb(RETRO_LOG_INFO, "glGetProgramBinary.\n");
2161 #if !defined(HAVE_OPENGLES) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2162 glGetProgramBinary(program, bufsize, length, binaryFormat, binary);
2164 printf("WARNING! Not implemented.\n");
2174 void rglProgramBinary(GLuint program,
2175 GLenum binaryFormat,
2180 log_cb(RETRO_LOG_INFO, "glProgramBinary.\n");
2182 #if !defined(HAVE_OPENGLES) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3_1)
2183 glProgramBinary(program, binaryFormat, binary, length);
2185 printf("WARNING! Not implemented.\n");
2189 void rglTexImage2DMultisample( GLenum target,
2191 GLenum internalformat,
2194 GLboolean fixedsamplelocations)
2197 log_cb(RETRO_LOG_INFO, "glTexImage2DMultisample.\n");
2199 #ifndef HAVE_OPENGLES
2200 glTexImage2DMultisample(target, samples, internalformat, width, height, fixedsamplelocations);
2204 void rglTexImage3D( GLenum target,
2206 GLint internalFormat,
2213 const GLvoid * data)
2216 log_cb(RETRO_LOG_INFO, "glTexImage3D.\n");
2218 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2219 glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, data);
2228 void * rglMapBuffer( GLenum target, GLenum access)
2231 log_cb(RETRO_LOG_INFO, "glMapBuffer.\n");
2233 #if defined(HAVE_OPENGLES)
2234 return glMapBufferOES(target, access);
2236 return glMapBuffer(target, access);
2245 GLboolean rglUnmapBuffer( GLenum target)
2248 log_cb(RETRO_LOG_INFO, "glUnmapBuffer.\n");
2250 #if defined(HAVE_OPENGLES)
2251 return glUnmapBufferOES(target);
2253 return glUnmapBuffer(target);
2257 void rglBlendEquation(GLenum mode)
2260 log_cb(RETRO_LOG_INFO, "glBlendEquation.\n");
2262 glBlendEquation(mode);
2265 void rglBlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2268 log_cb(RETRO_LOG_INFO, "glBlendColor.\n");
2270 glBlendColor(red, green, blue, alpha);
2274 * Category: Blending
2279 void rglBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2282 log_cb(RETRO_LOG_INFO, "glBlendEquationSeparate.\n");
2284 glBlendEquationSeparate(modeRGB, modeAlpha);
2293 void rglCopyImageSubData( GLuint srcName,
2310 log_cb(RETRO_LOG_INFO, "glCopyImageSubData.\n");
2312 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3_2)
2313 glCopyImageSubData(srcName,
2338 void rglBindVertexArray(GLuint array)
2341 log_cb(RETRO_LOG_INFO, "glBindVertexArray.\n");
2343 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2344 glBindVertexArray(array);
2355 void rglGenVertexArrays(GLsizei n, GLuint *arrays)
2358 log_cb(RETRO_LOG_INFO, "glGenVertexArrays.\n");
2360 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2361 glGenVertexArrays(n, arrays);
2372 void rglDeleteVertexArrays(GLsizei n, const GLuint *arrays)
2375 log_cb(RETRO_LOG_INFO, "glDeleteVertexArrays.\n");
2377 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2378 glDeleteVertexArrays(n, arrays);
2388 void *rglFenceSync(GLenum condition, GLbitfield flags)
2391 log_cb(RETRO_LOG_INFO, "glFenceSync.\n");
2393 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2394 return (GLsync)glFenceSync(condition, flags);
2406 void rglDeleteSync(void * sync)
2409 log_cb(RETRO_LOG_INFO, "glDeleteSync.\n");
2411 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2412 glDeleteSync((GLsync)sync);
2422 void rglWaitSync(void *sync, GLbitfield flags, uint64_t timeout)
2425 log_cb(RETRO_LOG_INFO, "glWaitSync.\n");
2427 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2428 glWaitSync((GLsync)sync, flags, (GLuint64)timeout);
2436 * OpenGLES : Not available
2438 void rglBufferStorage(GLenum target, GLsizeiptr size, const GLvoid *data, GLbitfield flags)
2441 log_cb(RETRO_LOG_INFO, "glBufferStorage.\n");
2443 #if defined(HAVE_OPENGL)
2444 glBufferStorage(target, size, data, flags);
2455 void rglUniform2iv( GLint location,
2460 log_cb(RETRO_LOG_INFO, "glUniform2iv.\n");
2462 glUniform2iv(location, count, value);
2472 void rglUniform2uiv( GLint location,
2474 const GLuint *value)
2477 log_cb(RETRO_LOG_INFO, "glUniform2uiv.\n");
2479 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2480 glUniform2uiv(location, count, value);
2490 void rglTextureView( GLuint texture,
2493 GLenum internalformat,
2500 log_cb(RETRO_LOG_INFO, "glTextureView.\n");
2502 #if defined(HAVE_OPENGL)
2503 glTextureView(texture, target, origtexture, internalformat, minlevel, numlevels, minlayer, numlayers);
2513 void rglFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
2516 log_cb(RETRO_LOG_INFO, "glFlushMappedBufferRange.\n");
2518 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2519 glFlushMappedBufferRange(target, offset, length);
2523 #ifndef GL_WAIT_FAILED
2524 #define GL_WAIT_FAILED 0x911D
2533 GLenum rglClientWaitSync(void *sync, GLbitfield flags, uint64_t timeout)
2536 log_cb(RETRO_LOG_INFO, "glClientWaitSync.\n");
2538 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
2539 return glClientWaitSync((GLsync)sync, flags, (GLuint64)timeout);
2541 return GL_WAIT_FAILED;
2549 * OpenGLES : Not available
2551 void rglDrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
2552 GLvoid *indices, GLint basevertex)
2555 log_cb(RETRO_LOG_INFO, "glDrawElementsBaseVertex.\n");
2557 #if defined(HAVE_OPENGL)
2558 glDrawElementsBaseVertex(mode, count, type, indices, basevertex);
2564 static void glsm_state_setup(void)
2568 gl_state.cap_translate[SGL_DEPTH_TEST] = GL_DEPTH_TEST;
2569 gl_state.cap_translate[SGL_BLEND] = GL_BLEND;
2570 gl_state.cap_translate[SGL_POLYGON_OFFSET_FILL] = GL_POLYGON_OFFSET_FILL;
2571 gl_state.cap_translate[SGL_FOG] = GL_FOG;
2572 gl_state.cap_translate[SGL_CULL_FACE] = GL_CULL_FACE;
2573 gl_state.cap_translate[SGL_ALPHA_TEST] = GL_ALPHA_TEST;
2574 gl_state.cap_translate[SGL_SCISSOR_TEST] = GL_SCISSOR_TEST;
2575 gl_state.cap_translate[SGL_STENCIL_TEST] = GL_STENCIL_TEST;
2577 #ifndef HAVE_OPENGLES
2578 gl_state.cap_translate[SGL_COLOR_LOGIC_OP] = GL_COLOR_LOGIC_OP;
2579 gl_state.cap_translate[SGL_CLIP_DISTANCE0] = GL_CLIP_DISTANCE0;
2580 gl_state.cap_translate[SGL_DEPTH_CLAMP] = GL_DEPTH_CLAMP;
2583 for (i = 0; i < MAX_ATTRIB; i++)
2585 gl_state.vertex_attrib_pointer.enabled[i] = 0;
2586 gl_state.attrib_pointer.used[i] = 0;
2589 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &glsm_max_textures);
2591 gl_state.bind_textures.ids = (GLuint*)calloc(glsm_max_textures, sizeof(GLuint));
2593 default_framebuffer = glsm_get_current_framebuffer();
2594 gl_state.framebuf = default_framebuffer;
2595 gl_state.cullface.mode = GL_BACK;
2596 gl_state.frontface.mode = GL_CCW;
2598 gl_state.blendfunc_separate.used = false;
2599 gl_state.blendfunc_separate.srcRGB = GL_ONE;
2600 gl_state.blendfunc_separate.dstRGB = GL_ZERO;
2601 gl_state.blendfunc_separate.srcAlpha = GL_ONE;
2602 gl_state.blendfunc_separate.dstAlpha = GL_ZERO;
2604 gl_state.depthfunc.used = false;
2606 gl_state.colormask.used = false;
2607 gl_state.colormask.red = GL_TRUE;
2608 gl_state.colormask.green = GL_TRUE;
2609 gl_state.colormask.blue = GL_TRUE;
2610 gl_state.colormask.alpha = GL_TRUE;
2612 gl_state.polygonoffset.used = false;
2614 gl_state.depthfunc.func = GL_LESS;
2616 #ifndef HAVE_OPENGLES
2617 gl_state.colorlogicop = GL_COPY;
2621 glGenVertexArrays(1, &gl_state.vao);
2625 static void glsm_state_bind(void)
2629 glBindVertexArray(gl_state.vao);
2631 glBindBuffer(GL_ARRAY_BUFFER, gl_state.array_buffer);
2633 for (i = 0; i < MAX_ATTRIB; i++)
2635 if (gl_state.vertex_attrib_pointer.enabled[i])
2636 glEnableVertexAttribArray(i);
2638 glDisableVertexAttribArray(i);
2640 if (gl_state.attrib_pointer.used[i] && gl_state.attrib_pointer.buffer[i] == gl_state.array_buffer)
2642 glVertexAttribPointer(
2644 gl_state.attrib_pointer.size[i],
2645 gl_state.attrib_pointer.type[i],
2646 gl_state.attrib_pointer.normalized[i],
2647 gl_state.attrib_pointer.stride[i],
2648 gl_state.attrib_pointer.pointer[i]);
2652 glBindFramebuffer(RARCH_GL_FRAMEBUFFER, default_framebuffer);
2654 if (gl_state.blendfunc.used)
2656 gl_state.blendfunc.sfactor,
2657 gl_state.blendfunc.dfactor);
2659 if (gl_state.blendfunc_separate.used)
2660 glBlendFuncSeparate(
2661 gl_state.blendfunc_separate.srcRGB,
2662 gl_state.blendfunc_separate.dstRGB,
2663 gl_state.blendfunc_separate.srcAlpha,
2664 gl_state.blendfunc_separate.dstAlpha
2668 gl_state.clear_color.r,
2669 gl_state.clear_color.g,
2670 gl_state.clear_color.b,
2671 gl_state.clear_color.a);
2673 if (gl_state.depthfunc.used)
2674 glDepthFunc(gl_state.depthfunc.func);
2676 if (gl_state.colormask.used)
2678 gl_state.colormask.red,
2679 gl_state.colormask.green,
2680 gl_state.colormask.blue,
2681 gl_state.colormask.alpha);
2683 if (gl_state.cullface.used)
2684 glCullFace(gl_state.cullface.mode);
2686 if (gl_state.depthmask.used)
2687 glDepthMask(gl_state.depthmask.mask);
2689 if (gl_state.polygonoffset.used)
2691 gl_state.polygonoffset.factor,
2692 gl_state.polygonoffset.units);
2694 if (gl_state.scissor.used)
2699 gl_state.scissor.h);
2701 glUseProgram(gl_state.program);
2704 gl_state.viewport.x,
2705 gl_state.viewport.y,
2706 gl_state.viewport.w,
2707 gl_state.viewport.h);
2709 for(i = 0; i < SGL_CAP_MAX; i ++)
2711 if (gl_state.cap_state[i])
2712 glEnable(gl_state.cap_translate[i]);
2715 if (gl_state.frontface.used)
2716 glFrontFace(gl_state.frontface.mode);
2718 if (gl_state.stencilmask.used)
2719 glStencilMask(gl_state.stencilmask.mask);
2721 if (gl_state.stencilop.used)
2722 glStencilOp(gl_state.stencilop.sfail,
2723 gl_state.stencilop.dpfail,
2724 gl_state.stencilop.dppass);
2726 if (gl_state.stencilfunc.used)
2728 gl_state.stencilfunc.func,
2729 gl_state.stencilfunc.ref,
2730 gl_state.stencilfunc.mask);
2732 for (i = 0; i < glsm_max_textures; i ++)
2734 glActiveTexture(GL_TEXTURE0 + i);
2735 glBindTexture(GL_TEXTURE_2D, gl_state.bind_textures.ids[i]);
2738 glActiveTexture(GL_TEXTURE0 + gl_state.active_texture);
2741 static void glsm_state_unbind(void)
2745 glBindVertexArray(0);
2747 for (i = 0; i < SGL_CAP_MAX; i ++)
2749 if (gl_state.cap_state[i])
2750 glDisable(gl_state.cap_translate[i]);
2753 glBlendFunc(GL_ONE, GL_ZERO);
2755 if (gl_state.colormask.used)
2756 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
2757 if (gl_state.blendfunc_separate.used)
2758 glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
2760 if (gl_state.cullface.used)
2761 glCullFace(GL_BACK);
2763 if (gl_state.depthmask.used)
2764 glDepthMask(GL_TRUE);
2766 if (gl_state.polygonoffset.used)
2767 glPolygonOffset(0, 0);
2770 glClearColor(0,0,0,0.0f);
2772 if (gl_state.depthrange.used)
2773 rglDepthRange(0, 1);
2776 glFrontFace(GL_CCW);
2777 if (gl_state.depthfunc.used)
2778 glDepthFunc(GL_LESS);
2780 if (gl_state.stencilop.used)
2781 glStencilOp(GL_KEEP,GL_KEEP, GL_KEEP);
2783 if (gl_state.stencilfunc.used)
2784 glStencilFunc(GL_ALWAYS,0,1);
2786 /* Clear textures */
2787 for (i = 0; i < glsm_max_textures; i ++)
2789 glActiveTexture(GL_TEXTURE0 + i);
2790 glBindTexture(GL_TEXTURE_2D, 0);
2792 glActiveTexture(GL_TEXTURE0);
2794 for (i = 0; i < MAX_ATTRIB; i ++)
2795 glDisableVertexAttribArray(i);
2797 glBindFramebuffer(RARCH_GL_FRAMEBUFFER, 0);
2800 static bool glsm_state_ctx_destroy(void *data)
2802 if (gl_state.bind_textures.ids)
2803 free(gl_state.bind_textures.ids);
2804 gl_state.bind_textures.ids = NULL;
2809 static bool glsm_state_ctx_init(glsm_ctx_params_t *params)
2811 if (!params || !params->environ_cb)
2814 #ifdef HAVE_OPENGLES
2815 #if defined(HAVE_OPENGLES_3_1)
2816 hw_render.context_type = RETRO_HW_CONTEXT_OPENGLES_VERSION;
2817 hw_render.version_major = 3;
2818 hw_render.version_minor = 1;
2819 #elif defined(HAVE_OPENGLES3)
2820 hw_render.context_type = RETRO_HW_CONTEXT_OPENGLES3;
2822 hw_render.context_type = RETRO_HW_CONTEXT_OPENGLES2;
2825 hw_render.context_type = RETRO_HW_CONTEXT_OPENGL;
2826 if (params->context_type != RETRO_HW_CONTEXT_NONE)
2827 hw_render.context_type = params->context_type;
2828 if (params->major != 0)
2829 hw_render.version_major = params->major;
2830 if (params->minor != 0)
2831 hw_render.version_minor = params->minor;
2834 hw_render.context_reset = params->context_reset;
2835 hw_render.context_destroy = params->context_destroy;
2836 hw_render.stencil = params->stencil;
2837 hw_render.depth = true;
2838 hw_render.bottom_left_origin = true;
2839 hw_render.cache_context = false;
2841 if (!params->environ_cb(RETRO_ENVIRONMENT_SET_HW_RENDER, &hw_render))
2847 GLuint glsm_get_current_framebuffer(void)
2849 return hw_render.get_current_framebuffer();
2852 bool glsm_ctl(enum glsm_state_ctl state, void *data)
2856 case GLSM_CTL_IMM_VBO_DRAW:
2858 case GLSM_CTL_IMM_VBO_DISABLE:
2860 case GLSM_CTL_IS_IMM_VBO:
2862 case GLSM_CTL_SET_IMM_VBO:
2864 case GLSM_CTL_UNSET_IMM_VBO:
2866 case GLSM_CTL_PROC_ADDRESS_GET:
2868 glsm_ctx_proc_address_t *proc = (glsm_ctx_proc_address_t*)data;
2869 if (!hw_render.get_proc_address)
2871 proc->addr = hw_render.get_proc_address;
2874 case GLSM_CTL_STATE_CONTEXT_RESET:
2875 rglgen_resolve_symbols(hw_render.get_proc_address);
2877 case GLSM_CTL_STATE_CONTEXT_DESTROY:
2878 glsm_state_ctx_destroy(data);
2880 case GLSM_CTL_STATE_CONTEXT_INIT:
2881 return glsm_state_ctx_init((glsm_ctx_params_t*)data);
2882 case GLSM_CTL_STATE_SETUP:
2885 case GLSM_CTL_STATE_UNBIND:
2886 glsm_state_unbind();
2888 case GLSM_CTL_STATE_BIND: