• 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.


コミットメタ情報

リビジョンb66b36f2487d0e3a19333992d0be262a9bdfee0e (tree)
日時2022-06-14 08:04:06
作者AlaskanEmily <emily@alas...>
コミッターAlaskanEmily

ログメッセージ

Make supports_extension a generic function on any GL context that has a gl_load_func_ctx.

This prevents the circular dependency on needing a gl_ctx for the context to test, and needing to test for extensions to create the context.

変更サマリ

差分

--- a/saffron.gl.buffer.inc
+++ b/saffron.gl.buffer.inc
@@ -71,6 +71,7 @@ int SaffronGL_LoadBufferCtx(MR_Word gl_ctx, struct SaffronGL_BufferCtx **ctx_ptr
7171 int SaffronGL_LoadBufferCtx(MR_Word gl_ctx, struct SaffronGL_BufferCtx **ctx_ptr){
7272 struct SaffronGL_BufferCtx *ctx = MR_GC_malloc_atomic(sizeof(struct SaffronGL_BufferCtx));
7373 MR_Word maybe_func, func;
74+ MR_Bool have_ext;
7475 MR_String err = NULL;
7576 MR_Integer major, minor;
7677 SaffronGL_Version(gl_ctx, &major, &minor);
@@ -80,7 +81,8 @@ int SaffronGL_LoadBufferCtx(MR_Word gl_ctx, struct SaffronGL_BufferCtx **ctx_ptr
8081 return 0;
8182 }while(0);
8283 #define SAFFRON_GL_LOAD_FUNC_BUFFER_ARB(X) SAFFRON_GL_FUNC_LOAD(X, "ARB")
83- if(SaffronGL_SupportsExtension(gl_ctx, (MR_String)"GL_ARB_vertex_buffer_object")){
84+ SaffronGL_SupportsExtension(gl_ctx, (MR_String)"GL_ARB_vertex_buffer_object", &have_ext);
85+ if(have_ext){
8486 do{
8587 SAFFRON_GL_BUFFER_FUNCS(SAFFRON_GL_LOAD_FUNC_BUFFER_ARB)
8688 *ctx_ptr = ctx;
--- a/saffron.gl.buffer.m
+++ b/saffron.gl.buffer.m
@@ -41,8 +41,7 @@
4141 %-----------------------------------------------------------------------------%
4242
4343 :- pred create_buffer_ctx(Ctx, maybe.maybe_error(buffer_ctx), io.io, io.io)
44- <= (saffron.gl.context(Ctx),
45- saffron.gl.supports_extensions(Ctx)).
44+ <= saffron.gl.context(Ctx).
4645 :- mode create_buffer_ctx(in, out, di, uo) is det.
4746
4847 %-----------------------------------------------------------------------------%
--- a/saffron.gl.m
+++ b/saffron.gl.m
@@ -61,9 +61,9 @@
6161
6262 %-----------------------------------------------------------------------------%
6363
64-:- typeclass supports_extensions(Ctx) where [
65- pred supports_extension(Ctx::in, string::in) is semidet
66-].
64+:- pred supports_extension(Ctx, string, bool.bool, io.io, io.io)
65+ <= saffron.gl.context(Ctx).
66+:- mode supports_extension(in, in, uo, di, uo) is det.
6767
6868 %-----------------------------------------------------------------------------%
6969
@@ -153,6 +153,7 @@ typedef char SaffronGLchar;
153153 #else
154154
155155 # if (defined __linux__) || (defined __OpenBSD__) || (defined __FreeBSD__)
156+# define SAFFRON_GL_EXPECT_GL3
156157 # define SAFFRON_GL_EXPECT_BUFFER
157158 # define SAFFRON_GL_EXPECT_SHADER
158159 # define GL_GLEXT_PROTOTYPES
@@ -208,7 +209,6 @@ typedef void(APIENTRY*SaffronGL_DrawTextureNV_PROC)(
208209 # define SAFFRON_GL_RAW_INTS
209210 #endif
210211
211-
212212 ").
213213
214214 %-----------------------------------------------------------------------------%
@@ -242,6 +242,39 @@ primitive_type(saffron.geometry.triangle_fan, saffron.gl.triangle_fan).
242242
243243 %-----------------------------------------------------------------------------%
244244
245+:- pred supports_extension_inner(string, bool.bool, io.io, io.io).
246+:- mode supports_extension_inner(in, uo, di, uo) is det.
247+
248+supports_extension_inner(_, bool.no, !IO).
249+:- pragma foreign_proc("C",
250+ supports_extension_inner(Ext::in, Supports::uo, IOi::di, IOo::uo),
251+ [will_not_call_mercury, promise_pure, thread_safe, will_not_throw_exception,
252+ may_duplicate, does_not_affect_liveness],
253+ "
254+ const MR_Integer len = strnlen(Ext, 512);
255+ const char *str = (void*)glGetString(GL_EXTENSIONS);
256+ Supports = MR_NO;
257+ IOo = IOi;
258+ if(str != NULL){
259+ do{
260+ if(strncmp(str, Ext, len) != 0 &&
261+ (str[len] == ' ' || str[len] == 0)){
262+
263+ Supports = MR_YES;
264+ break;
265+ }
266+ }while((str = strchr(str, ' ')) != NULL && *(++str) != 0);
267+ }
268+ ").
269+
270+%-----------------------------------------------------------------------------%
271+
272+supports_extension(Ctx, Ext, Supports, !IO) :-
273+ saffron.make_current(Ctx, !IO),
274+ supports_extension_inner(Ext, Supports, !IO).
275+
276+%-----------------------------------------------------------------------------%
277+
245278 float_bytes = 8.
246279
247280 :- pragma foreign_proc("C", float_bytes = (N::out),
@@ -378,8 +411,7 @@ texture_upload_at(_Ctx, Tex, B, X, Y, W, H, !IO) :-
378411 :- type gl_load_func_ctx --->
379412 some [Ctx] (gl_load_func_ctx(Ctx)
380413 => (saffron.context(Ctx),
381- saffron.gl.context(Ctx),
382- saffron.gl.supports_extensions(Ctx))).
414+ saffron.gl.context(Ctx))).
383415
384416 %-----------------------------------------------------------------------------%
385417 % A non-higher-typed version of load_function that takes gl_load_func_ctx.
@@ -434,13 +466,22 @@ gl_version(gl_load_func_ctx(Ctx), Major, Minor, !IO) :-
434466 gl_version(in, out, out, di, uo),
435467 "SaffronGL_Version").
436468
437-:- pred gl_supports_extension(gl_load_func_ctx::in, string::in) is semidet.
469+:- pred gl_supports_extension(
470+ gl_load_func_ctx,
471+ string,
472+ bool.bool,
473+ io.io, io.io).
474+:- mode gl_supports_extension(
475+ in,
476+ in,
477+ uo,
478+ di, uo) is det.
438479
439-gl_supports_extension(gl_load_func_ctx(Ctx), Ext) :-
440- saffron.gl.supports_extension(Ctx, Ext).
480+gl_supports_extension(gl_load_func_ctx(Ctx), Ext, Supports, !IO) :-
481+ supports_extension(Ctx, Ext, Supports, !IO).
441482
442483 :- pragma foreign_export("C",
443- gl_supports_extension(in, in),
484+ gl_supports_extension(in, in, uo, di, uo),
444485 "SaffronGL_SupportsExtension").
445486
446487 %-----------------------------------------------------------------------------%
--- a/saffron.gl.shader.inc
+++ b/saffron.gl.shader.inc
@@ -210,6 +210,7 @@ int SaffronGL_LoadShaderCoreCtx(MR_Word gl_ctx, struct SaffronGL_ShaderCoreCtx *
210210 int SaffronGL_LoadShaderCoreCtx(MR_Word gl_ctx, struct SaffronGL_ShaderCoreCtx **ctx_ptr){
211211 struct SaffronGL_ShaderCoreCtx *ctx = MR_GC_malloc_atomic(sizeof(struct SaffronGL_ShaderCoreCtx));
212212 MR_Word maybe_func, func;
213+ MR_Bool have_ext;
213214 MR_String err = NULL;
214215 MR_Integer major, minor;
215216 SaffronGL_Version(gl_ctx, &major, &minor);
@@ -310,9 +311,11 @@ int SaffronGL_LoadShaderFP64Ctx(MR_Word gl_ctx, struct SaffronGL_ShaderFP64Ctx *
310311 int SaffronGL_LoadShaderFP64Ctx(MR_Word gl_ctx, struct SaffronGL_ShaderFP64Ctx **ctx_ptr){
311312 struct SaffronGL_ShaderFP64Ctx *ctx = MR_GC_malloc_atomic(sizeof(struct SaffronGL_ShaderFP64Ctx));
312313 MR_Word maybe_func, func;
314+ MR_Bool have_ext;
313315 MR_String err = NULL;
314316 #define SAFFRON_GL_LOAD_FUNC_SHADERFP64_ARB(X) SAFFRON_GL_FUNC_LOAD(X, "ARB")
315- if(SaffronGL_SupportsExtension(gl_ctx, (MR_String)"GL_ARB_gpu_shader_fp64")){
317+ SaffronGL_SupportsExtension(gl_ctx, (MR_String)"GL_ARB_gpu_shader_fp64", &have_ext);
318+ if(have_ext){
316319 do{
317320 SAFFRON_GL_SHADERFP64_FUNCS(SAFFRON_GL_LOAD_FUNC_SHADERFP64_ARB)
318321 *ctx_ptr = ctx;
@@ -370,6 +373,7 @@ int SaffronGL_LoadProgramBinaryCtx(MR_Word gl_ctx, struct SaffronGL_ProgramBinar
370373 int SaffronGL_LoadProgramBinaryCtx(MR_Word gl_ctx, struct SaffronGL_ProgramBinaryCtx **ctx_ptr){
371374 struct SaffronGL_ProgramBinaryCtx *ctx = MR_GC_malloc_atomic(sizeof(struct SaffronGL_ProgramBinaryCtx));
372375 MR_Word maybe_func, func;
376+ MR_Bool have_ext;
373377 MR_String err = NULL;
374378 MR_Integer major, minor;
375379 SaffronGL_Version(gl_ctx, &major, &minor);
@@ -379,7 +383,8 @@ int SaffronGL_LoadProgramBinaryCtx(MR_Word gl_ctx, struct SaffronGL_ProgramBinar
379383 return 0;
380384 }while(0);
381385 #define SAFFRON_GL_LOAD_FUNC_PROGRAMBINARY_ARB(X) SAFFRON_GL_FUNC_LOAD(X, "ARB")
382- if(SaffronGL_SupportsExtension(gl_ctx, (MR_String)"GL_ARB_get_program_binary")){
386+ SaffronGL_SupportsExtension(gl_ctx, (MR_String)"GL_ARB_get_program_binary", &have_ext);
387+ if(have_ext){
383388 do{
384389 SAFFRON_GL_PROGRAMBINARY_FUNCS(SAFFRON_GL_LOAD_FUNC_PROGRAMBINARY_ARB)
385390 *ctx_ptr = ctx;
@@ -415,9 +420,11 @@ int SaffronGL_LoadSPIRVCtx(MR_Word gl_ctx, struct SaffronGL_SPIRVCtx **ctx_ptr);
415420 int SaffronGL_LoadSPIRVCtx(MR_Word gl_ctx, struct SaffronGL_SPIRVCtx **ctx_ptr){
416421 struct SaffronGL_SPIRVCtx *ctx = MR_GC_malloc_atomic(sizeof(struct SaffronGL_SPIRVCtx));
417422 MR_Word maybe_func, func;
423+ MR_Bool have_ext;
418424 MR_String err = NULL;
419425 #define SAFFRON_GL_LOAD_FUNC_SPIRV_ARB(X) SAFFRON_GL_FUNC_LOAD(X, "ARB")
420- if(SaffronGL_SupportsExtension(gl_ctx, (MR_String)"GL_ARB_gl_spirv")){
426+ SaffronGL_SupportsExtension(gl_ctx, (MR_String)"GL_ARB_gl_spirv", &have_ext);
427+ if(have_ext){
421428 do{
422429 SAFFRON_GL_SPIRV_FUNCS(SAFFRON_GL_LOAD_FUNC_SPIRV_ARB)
423430 *ctx_ptr = ctx;
--- a/saffron.gl.shader.m
+++ b/saffron.gl.shader.m
@@ -27,8 +27,7 @@
2727 %-----------------------------------------------------------------------------%
2828
2929 :- pred create_shader_ctx(Ctx, maybe.maybe_error(shader_ctx), io.io, io.io)
30- <= (saffron.gl.context(Ctx),
31- saffron.gl.supports_extensions(Ctx)).
30+ <= saffron.gl.context(Ctx).
3231 :- mode create_shader_ctx(in, out, di, uo) is det.
3332
3433 %-----------------------------------------------------------------------------%
--- a/saffron.gl2.m
+++ b/saffron.gl2.m
@@ -35,11 +35,6 @@
3535
3636 %-----------------------------------------------------------------------------%
3737
38-:- instance saffron.gl.supports_extensions(context(Ctx))
39- <= saffron.gl.context(Ctx).
40-
41-%-----------------------------------------------------------------------------%
42-
4338 :- instance saffron.draw.basic_transform(context(Ctx))
4439 <= saffron.gl.context(Ctx).
4540
@@ -253,36 +248,6 @@ const char *Saffron_GL2_DebugError(void){
253248
254249 %-----------------------------------------------------------------------------%
255250
256-:- pred supports_extension(_::in, string::in) is semidet.
257-
258-supports_extension(_, _) :- false.
259-
260-:- pragma foreign_proc("C", supports_extension(Ctx::in, Ext::in),
261- [will_not_call_mercury, promise_pure, thread_safe, will_not_throw_exception,
262- tabled_for_io, may_duplicate, does_not_affect_liveness],
263- "
264- const char *str = (void*)glGetString(GL_EXTENSIONS);
265- const MR_Integer len = strlen(Ext);
266- (void)Ctx;
267- SUCCESS_INDICATOR = 0;
268- while((str = strstr(str, Ext)) != NULL){
269- if(str[len] == ' ' || str[len] == 0){
270- SUCCESS_INDICATOR = 1;
271- break;
272- }
273- }
274- ").
275-
276-%-----------------------------------------------------------------------------%
277-
278-:- instance saffron.gl.supports_extensions(context(Ctx))
279- <= saffron.gl.context(Ctx) where [
280-
281- pred(saffron.gl.supports_extension/2) is saffron.gl2.supports_extension
282-].
283-
284-%-----------------------------------------------------------------------------%
285-
286251 :- pragma foreign_export("C",
287252 saffron.draw.raise_matrix_stack_error,
288253 "Saffron_GL2_RaiseMatrixStackError").
@@ -859,8 +824,6 @@ init(Ctx,
859824 !IO) :-
860825
861826 saffron.make_current(Ctx, !IO),
862- % Get the supports_extension implementation for GL 2 contexts.
863- TempCtx = context(Ctx, maybe.no, maybe.no),
864827 saffron.gl.shader_model_version(Ctx, MaybeGLSLVersion, !IO),
865828 % TODO: Should this live inside create_shader_ctx?
866829 ( if
@@ -868,12 +831,12 @@ init(Ctx,
868831 saffron.sem_ver_compare(GLSLCmp, GLSLVersion, saffron.sem_ver(1, 20)),
869832 GLSLCmp \= (<)
870833 then
871- saffron.gl.shader.create_shader_ctx(TempCtx, MaybeErrShaderCtx, !IO),
834+ saffron.gl.shader.create_shader_ctx(Ctx, MaybeErrShaderCtx, !IO),
872835 MaybeShaderCtx = complete_load_ctx("shader", MaybeErrShaderCtx)
873836 else
874837 MaybeShaderCtx = maybe.no
875838 ),
876- saffron.gl.buffer.create_buffer_ctx(TempCtx, MaybeErrBufferCtx, !IO),
839+ saffron.gl.buffer.create_buffer_ctx(Ctx, MaybeErrBufferCtx, !IO),
877840 MaybeBufferCtx = complete_load_ctx("buffer", MaybeErrBufferCtx),
878841 init(!IO).
879842
--- a/saffron.gl_gen.awk
+++ b/saffron.gl_gen.awk
@@ -104,6 +104,7 @@ $1 == "load" {
104104 print(sig "{\n\
105105 " struct " *ctx = MR_GC_malloc_atomic(sizeof(" struct "));\n\
106106 MR_Word maybe_func, func;\n\
107+ MR_Bool have_ext;\n\
107108 MR_String err = NULL;");
108109 if(core != 0){
109110 print("\
@@ -130,7 +131,8 @@ $1 == "load" {
130131 macro = "SAFFRON_GL_LOAD_FUNC_" upper2 "_" sfx;
131132 print("\
132133 #define " macro "(X) SAFFRON_GL_FUNC_LOAD(X, \"" sfx "\")\n\
133- if(SaffronGL_SupportsExtension(gl_ctx, (MR_String)\"" ext "\")){\n\
134+ SaffronGL_SupportsExtension(gl_ctx, (MR_String)\"" ext "\", &have_ext);\n\
135+ if(have_ext){\n\
134136 do{\n\
135137 SAFFRON_GL_" upper2 "_FUNCS(" macro ")\n\
136138 *ctx_ptr = ctx;\n\