Permalink
Browse files

Merge pull request #14 from mgerhardy/pr/sdl2-template

SDL template
  • Loading branch information...
2 parents 35592d7 + 1d466de commit caa14aa18b51aa6961c3a1214cb52997f48247c5 @ginkgo committed on GitHub Jan 18, 2017
Showing with 199 additions and 0 deletions.
  1. +106 −0 templates/sdl/flextGL.c.template
  2. +93 −0 templates/sdl/flextGL.h.template
@@ -0,0 +1,106 @@
+@require(passthru, functions, enums, options, version, extensions)
+/* WARNING: This file was automatically generated */
+/* Do not edit. */
+
+#include "flextGL.h"
+#include <SDL.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+void flextLoadOpenGLFunctions(void);
+
+/**
+ * \return -1 on error, 0 on success
+ * \sa SDL_GetError
+ */
+int flextInit(void)
+{
+ @if version.int_value() >= 32 and not version.profile == 'core':
+ GLint profile;
+ @end
+ int major;
+ int minor;
+
+ SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
+ SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
+
+ flextLoadOpenGLFunctions();
+
+ /* --- Check for minimal version and profile --- */
+
+ if (major * 10 + minor < @version.int_value()!s) {
+ return SDL_SetError("OpenGL context hasn't the expected version @version.major!s.@version.minor!s.");
+ }
+
+ @if version.int_value() >= 32 and not version.profile == 'core':
+ glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
+
+ if ((profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) == 0) {
+ return SDL_SetError("This application requires a compatibility profile");
+ }
+ @end
+
+ /* --- Check for extensions --- */
+
+ @for extension,required in extensions:
+ @if required:
+ if (!SDL_GL_ExtensionSupported("GL_@extension")) {
+ return SDL_SetError("OpenGL extension @extension not supported.");
+ }
+ @else:
+ if (SDL_GL_ExtensionSupported("GL_@extension")) {
+ FLEXT_@extension = GL_TRUE;
+ }
+ @end
+
+ @end
+
+ return 0;
+}
+
+
+
+void flextLoadOpenGLFunctions(void)
+{
+ /* --- Function pointer loading --- */
+
+
+ @for category,funcs in functions:
+ @if category not in ['VERSION_1_0', 'VERSION_1_1','VERSION_1_0_DEPRECATED', 'VERSION_1_1_DEPRECATED']:
+ /* GL_@category */
+
+ @for f in funcs:
+ glpf@f.name = (PFNGL@f.name.upper()_PROC*)SDL_GL_GetProcAddress("gl@f.name");
+ @end
+
+
+ @end
+ @end
+}
+
+/* ----------------------- Extension flag definitions ---------------------- */
+@for extension,required in extensions:
+int FLEXT_@extension = GL_FALSE;
+@end
+
+/* ---------------------- Function pointer definitions --------------------- */
+
+@for category,funcs in functions:
+@if len(funcs) > 0 and category not in ['VERSION_1_0', 'VERSION_1_1','VERSION_1_0_DEPRECATED', 'VERSION_1_1_DEPRECATED' ]:
+/* GL_@category */
+
+@for f in funcs:
+PFNGL@f.name.upper()_PROC* glpf@f.name = NULL;
+@end
+
+@end
+@end
+
+
+#ifdef __cplusplus
+}
+#endif
@@ -0,0 +1,93 @@
+@require(passthru, functions, enums, options, version, extensions)
+/* WARNING: This file was automatically generated */
+/* Do not edit. */
+
+#ifndef __gl_h_
+#define __gl_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Function declaration macros - to move into glplatform.h */
+
+#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
+#define WIN32_LEAN_AND_MEAN 1
+#ifndef WINAPI
+#define WINAPI __stdcall
+#endif
+#define APIENTRY WINAPI
+#endif
+
+#ifndef APIENTRY
+#define APIENTRY
+#endif
+#ifndef APIENTRYP
+#define APIENTRYP APIENTRY *
+#endif
+#ifndef GLAPI
+#define GLAPI extern
+#endif
+
+/* -------------------------------- DATA TYPES ------------------------------- */
+
+@passthru
+
+/* ----------------------------------- ENUMS --------------------------------- */
+
+@enums
+
+/* --------------------------- FUNCTION PROTOTYPES --------------------------- */
+
+@for cat,funcs in functions:
+
+/* GL_@cat */
+
+ @if cat in ['VERSION_1_0', 'VERSION_1_1','VERSION_1_0_DEPRECATED', 'VERSION_1_1_DEPRECATED']:
+ @for f in funcs:
+GLAPI @f.returntype APIENTRY gl@f.name (@f.param_list_string());
+ @end
+ @else:
+ @for f in funcs:
+typedef @f.returntype (APIENTRY PFNGL@f.name.upper()_PROC (@f.param_list_string()));
+ @end
+
+ @for f in funcs:
+GLAPI PFNGL@f.name.upper()_PROC* glpf@f.name;
+ @end
+
+ @for f in funcs:
+#define gl@f.name glpf@f.name
+ @end
+ @end
+
+@end
+
+/* --------------------------- CATEGORY DEFINES ------------------------------ */
+
+@for cat,funcs in functions:
+#define GL_@cat
+@end
+
+/* ---------------------- Flags for optional extensions ---------------------- */
+
+
+@for extension,required in extensions:
+extern int FLEXT_@extension;
+@end
+
+int flextInit(void);
+
+#define FLEXT_MAJOR_VERSION @version.major!s
+#define FLEXT_MINOR_VERSION @version.minor!s
+@if version.profile == 'core':
+#define FLEXT_CORE_PROFILE 1
+@else:
+#define FLEXT_CORE_PROFILE 0
+@end
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _gl_h_ */

0 comments on commit caa14aa

Please sign in to comment.