• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Graphics library for Mercury, including OpenGL bindings, TGA image reading, and X11, Win32, and SDL2 windowing and input.


コミットメタ情報

リビジョン8f211d9892a54f92bfcbfff5a40d2cd5491e82e7 (tree)
日時2022-04-27 11:04:55
作者AlaskanEmily <emily@alas...>
コミッターAlaskanEmily

ログメッセージ

Fix support for non-GL3+ systems

変更サマリ

差分

--- a/saffron.gl.buffer.inc
+++ b/saffron.gl.buffer.inc
@@ -62,7 +62,7 @@ struct SaffronGL_BufferCtx{
6262 #define SAFFRON_GL_LOAD_BUFFER_CTX(GLCTX, CTX) (*(CTX) = 0)
6363 #else
6464 #define SAFFRON_GL_BUFFER_FUNC(CTX, X) ((CTX)->X)
65-#define SAFFRON_GL_BUFFER_CTX struct SaffronGL_BufferCtx
65+#define SAFFRON_GL_BUFFER_CTX struct SaffronGL_BufferCtx*
6666 int SaffronGL_LoadBufferCtx(MR_Word gl_ctx, struct SaffronGL_BufferCtx **ctx_ptr);
6767 #define SAFFRON_GL_LOAD_BUFFER_CTX SaffronGL_LoadBufferCtx
6868 #endif
@@ -80,11 +80,13 @@ int SaffronGL_LoadBufferCtx(MR_Word gl_ctx, struct SaffronGL_BufferCtx **ctx_ptr
8080 return 0;
8181 }while(0);
8282 #define SAFFRON_GL_LOAD_FUNC_BUFFER_ARB(X) SAFFRON_GL_FUNC_LOAD(X, "ARB")
83- if(SaffronGL_SupportsExtension("GL_ARB_vertex_buffer_object")) do{
84- SAFFRON_GL_BUFFER_FUNCS(SAFFRON_GL_LOAD_FUNC_BUFFER_ARB)
85- *ctx_ptr = ctx;
86- return 0;
87- }while(0);
83+ if(SaffronGL_SupportsExtension(gl_ctx, (MR_String)"GL_ARB_vertex_buffer_object")){
84+ do{
85+ SAFFRON_GL_BUFFER_FUNCS(SAFFRON_GL_LOAD_FUNC_BUFFER_ARB)
86+ *ctx_ptr = ctx;
87+ return 0;
88+ }while(0);
89+ }
8890 return 1;
8991 }
9092 #endif
--- a/saffron.gl.buffer.m
+++ b/saffron.gl.buffer.m
@@ -41,7 +41,8 @@
4141 %-----------------------------------------------------------------------------%
4242
4343 :- pred create_buffer_ctx(Ctx, maybe.maybe_error(buffer_ctx), io.io, io.io)
44- <= saffron.gl.context(Ctx).
44+ <= (saffron.gl.context(Ctx),
45+ saffron.gl.supports_extensions(Ctx)).
4546 :- mode create_buffer_ctx(in, out, di, uo) is det.
4647
4748 %-----------------------------------------------------------------------------%
--- a/saffron.gl.m
+++ b/saffron.gl.m
@@ -155,6 +155,8 @@ typedef char SaffronGLchar;
155155
156156 #endif
157157
158+# undef SAFFRON_GL_EXPECT_BUFFER
159+# undef SAFFRON_GL_EXPECT_SHADER
158160 /* GL_NV_draw_texture */
159161 typedef void(APIENTRY*SaffronGL_DrawTextureNV_PROC)(
160162 GLuint,
@@ -326,7 +328,10 @@ texture_upload_at(_Ctx, Tex, B, X, Y, W, H, !IO) :-
326328 % existentially type functor which we can pass to a Mercury predicate that will
327329 % unpack it and invoke the predicate.
328330 :- type gl_load_func_ctx --->
329- some [Ctx] (gl_load_func_ctx(Ctx) => saffron.context(Ctx)).
331+ some [Ctx] (gl_load_func_ctx(Ctx)
332+ => (saffron.context(Ctx),
333+ saffron.gl.context(Ctx),
334+ saffron.gl.supports_extensions(Ctx))).
330335
331336 %-----------------------------------------------------------------------------%
332337 % A non-higher-typed version of load_function that takes gl_load_func_ctx.
@@ -349,6 +354,47 @@ gl_load_function(gl_load_func_ctx(Ctx), Name, MaybeFunc, !IO) :-
349354 gl_load_function(in, in, out, di, uo),
350355 "SaffronGL_LoadFunction").
351356
357+:- pred gl_version(
358+ gl_load_func_ctx,
359+ int,
360+ int,
361+ io.io, io.io).
362+:- mode gl_version(
363+ in,
364+ out,
365+ out,
366+ di, uo) is det.
367+
368+gl_version(gl_load_func_ctx(Ctx), Major, Minor, !IO) :-
369+ opengl_version(Ctx, MaybeSemVer, !IO),
370+ (
371+ MaybeSemVer = maybe.ok(SemVer),
372+ Major = major(SemVer),
373+ Minor = minor(SemVer)
374+ ;
375+ MaybeSemVer = maybe.error(Error),
376+ trace [io(!XIO)] (
377+ io.write_string("Error getting OpenGL version: ", !XIO),
378+ io.write_string(Error, !XIO),
379+ io.nl(!XIO)
380+ ),
381+ Major = 0,
382+ Minor = 0
383+ ).
384+
385+:- pragma foreign_export("C",
386+ gl_version(in, out, out, di, uo),
387+ "SaffronGL_Version").
388+
389+:- pred gl_supports_extension(gl_load_func_ctx::in, string::in) is semidet.
390+
391+gl_supports_extension(gl_load_func_ctx(Ctx), Ext) :-
392+ saffron.gl.supports_extension(Ctx, Ext).
393+
394+:- pragma foreign_export("C",
395+ gl_supports_extension(in, in),
396+ "SaffronGL_SupportsExtension").
397+
352398 %-----------------------------------------------------------------------------%
353399
354400 :- type version_type ---> gl ; glsl.
--- a/saffron.gl.shader.csv
+++ b/saffron.gl.shader.csv
@@ -1,6 +1,6 @@
11 func,CreateShader,GLenum,=GLuint
22 func,DeleteShader,GLuint
3-func,ShaderSource,GLuint,GLsizei,const SaffronGLchar**,const GLint
3+func,ShaderSource,GLuint,GLsizei,const SaffronGLchar**,const GLint*
44 func,CompileShader,GLuint
55 func,GetShaderiv,GLuint,GLenum,GLint*
66 func,GetShaderInfoLog,GLuint,GLsizei,GLsizei*,SaffronGLchar*
--- a/saffron.gl.shader.inc
+++ b/saffron.gl.shader.inc
@@ -23,7 +23,7 @@ typedef void(APIENTRY*SaffronGL_ShaderSource_PROC)(
2323 GLuint,
2424 GLsizei,
2525 const SaffronGLchar**,
26- const GLint);
26+ const GLint*);
2727 #endif
2828 #ifndef SAFFRON_GL_IMPL
2929 typedef void(APIENTRY*SaffronGL_CompileShader_PROC)(
@@ -96,7 +96,7 @@ struct SaffronGL_ShaderCtx{
9696 #define SAFFRON_GL_LOAD_SHADER_CTX(GLCTX, CTX) (*(CTX) = 0)
9797 #else
9898 #define SAFFRON_GL_SHADER_FUNC(CTX, X) ((CTX)->X)
99-#define SAFFRON_GL_SHADER_CTX struct SaffronGL_ShaderCtx
99+#define SAFFRON_GL_SHADER_CTX struct SaffronGL_ShaderCtx*
100100 int SaffronGL_LoadShaderCtx(MR_Word gl_ctx, struct SaffronGL_ShaderCtx **ctx_ptr);
101101 #define SAFFRON_GL_LOAD_SHADER_CTX SaffronGL_LoadShaderCtx
102102 #endif
--- a/saffron.gl.shader.m
+++ b/saffron.gl.shader.m
@@ -25,7 +25,8 @@
2525 %-----------------------------------------------------------------------------%
2626
2727 :- pred create_shader_ctx(Ctx, maybe.maybe_error(shader_ctx), io.io, io.io)
28- <= saffron.context(Ctx).
28+ <= (saffron.gl.context(Ctx),
29+ saffron.gl.supports_extensions(Ctx)).
2930 :- mode create_shader_ctx(in, out, di, uo) is det.
3031
3132 %-----------------------------------------------------------------------------%
@@ -85,7 +86,7 @@
8586 #include ""saffron.gl.shader.inc""
8687 ").
8788
88-:- pragma foreign_decl("C", "
89+:- pragma foreign_code("C", "
8990 #define SAFFRON_GL_IMPL
9091 #include ""saffron.gl.shader.inc""
9192 #undef SAFFRON_GL_IMPL
--- a/saffron.gl2.m
+++ b/saffron.gl2.m
@@ -859,6 +859,8 @@ init(Ctx,
859859 !IO) :-
860860
861861 saffron.make_current(Ctx, !IO),
862+ % Get the supports_extension implementation for GL 2 contexts.
863+ TempCtx = context(Ctx, maybe.no, maybe.no),
862864 saffron.gl.shader_model_version(Ctx, MaybeGLSLVersion, !IO),
863865 % TODO: Should this live inside create_shader_ctx?
864866 ( if
@@ -866,12 +868,12 @@ init(Ctx,
866868 saffron.sem_ver_compare(GLSLCmp, GLSLVersion, saffron.sem_ver(1, 20)),
867869 GLSLCmp \= (<)
868870 then
869- saffron.gl.shader.create_shader_ctx(Ctx, MaybeErrShaderCtx, !IO),
871+ saffron.gl.shader.create_shader_ctx(TempCtx, MaybeErrShaderCtx, !IO),
870872 MaybeShaderCtx = complete_load_ctx("shader", MaybeErrShaderCtx)
871873 else
872874 MaybeShaderCtx = maybe.no
873875 ),
874- saffron.gl.buffer.create_buffer_ctx(Ctx, MaybeErrBufferCtx, !IO),
876+ saffron.gl.buffer.create_buffer_ctx(TempCtx, MaybeErrBufferCtx, !IO),
875877 MaybeBufferCtx = complete_load_ctx("buffer", MaybeErrBufferCtx),
876878 init(!IO).
877879
--- a/saffron.gl_gen.awk
+++ b/saffron.gl_gen.awk
@@ -87,7 +87,7 @@ $1 == "load" {
8787 sig = "int SaffronGL_Load" $2 "Ctx(MR_Word gl_ctx, " struct " **ctx_ptr)";
8888 print("\
8989 #define SAFFRON_GL_" upper2 "_FUNC(CTX, X) ((CTX)->X)\n\
90-#define SAFFRON_GL_" upper2 "_CTX " struct "\n\
90+#define SAFFRON_GL_" upper2 "_CTX " struct "*\n\
9191 " sig ";\n\
9292 #define SAFFRON_GL_LOAD_" upper2 "_CTX SaffronGL_Load" $2 "Ctx");
9393 if(core != ""){
@@ -128,11 +128,13 @@ $1 == "load" {
128128 macro = "SAFFRON_GL_LOAD_FUNC_" upper2 "_" sfx;
129129 print("\
130130 #define " macro "(X) SAFFRON_GL_FUNC_LOAD(X, \"" sfx "\")\n\
131- if(SaffronGL_SupportsExtension(\"" ext "\")) do{ \n\
132- SAFFRON_GL_" upper2 "_FUNCS(" macro ")\n\
133- *ctx_ptr = ctx;\n\
134- return 0;\n\
135- }while(0);");
131+ if(SaffronGL_SupportsExtension(gl_ctx, (MR_String)\"" ext "\")){\n\
132+ do{\n\
133+ SAFFRON_GL_" upper2 "_FUNCS(" macro ")\n\
134+ *ctx_ptr = ctx;\n\
135+ return 0;\n\
136+ }while(0);\n\
137+ }");
136138 }
137139 }
138140 print(" return 1;\n}");