Skip to content

Commit

Permalink
Added support for TinyGL context versions
Browse files Browse the repository at this point in the history
By bigfoot
TinyGL has been updated to support the notion of context versions to
be able to fix cases where TinyGL previously worked contrary to the
OpenGL specifications, but where existing applications might rely on
TinyGL's wrong behaviour.

An application built against the updated TinyGL SDK will have a
defined maximum context version it is expecting built into it, which
TinyGL when then use to set the context version for the application.

With this commit, SDL has been updated to perform a similar function.
An application built against an updated SDL SDK will also have a
defined maximum TinyGL context version, and SDL will in turn inform
TinyGL of this maximum context version.
  • Loading branch information
BeWorld2018 committed Sep 16, 2024
1 parent 4bf5653 commit 96697a4
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/core/morphos/SDL_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ struct Library *LIB_Open(void)
#include "SDL_stubs.h"

extern void LIB_InitTGL();
extern void LIB_InitTGL2();
extern void LIB_SetExitPointer();
extern void LIB_SDL_VSetError();

Expand Down
1 change: 1 addition & 0 deletions src/core/morphos/SDL_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct SDL_Library
APTR tglcontext;
struct Library **MyTinyGLBase;
void **MyGLContext;
unsigned int (*MyGetMaximumContextVersion)(struct Library *TinGLBase);

union
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/morphos/SDL_mosversion.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define str(s) #s
#define xstr(s) str(s)
#define VERSION 53
#define REVISION 16
#define VERSTAG "\0$VER: sdl2.library " xstr(VERSION) "." xstr(REVISION) " (" __AMIGADATE__ ") © Bruno Peloille, Szilárd Biró, Ilkka Lehtoranta"
#define REVISION 17
#define VERSTAG "\0$VER: sdl2.library " xstr(VERSION) "." xstr(REVISION) " (" __AMIGADATE__ ") © Bruno Peloille, Szil¡rd Biro, Ilkka Lehtoranta"
11 changes: 11 additions & 0 deletions src/core/morphos/SDL_startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,15 @@ VOID LIB_InitTGL(struct SDL_Library *base, void **glc, struct Library **tgl)
}
}

VOID LIB_InitTGL2(struct SDL_Library *base, void **glc, struct Library **tgl, unsigned int (*getmaximumcontextversion)(struct Library *TinyGLBase))
{
if (base->MyTinyGLBase == NULL)
{
base->MyTinyGLBase = tgl;
base->MyGLContext = glc;
base->MyGetMaximumContextVersion = getmaximumcontextversion;
}
}


void __chkabort(void) { }
6 changes: 5 additions & 1 deletion src/core/morphos/SDL_stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,4 +895,8 @@
STUB(SDL_DestroyWindowSurface)
//
STUB(SDL_GameControllerGetSteamHandle)


// sdl2.library 53.17++
#if defined(GENERATE_POINTERS)
(APTR)&LIB_InitTGL2,
#endif
14 changes: 11 additions & 3 deletions src/core/morphos/devenv/sdl-startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,17 @@ static CONSTRUCTOR_P(init_SDL2Base, 100)
OldLock = CurrentDir(NewLock);

SDL2Base = base;

SDL_InitTGL((void **) &__tglContext, (struct Library **) &TinyGLBase);


#ifdef TGL_CONTEXT_VERSION_53_9
if (LIB_MINVER(base, 53, 15))
{
SDL_InitTGL2((void **) &__tglContext, (struct Library **) &TinyGLBase, TGLGetMaximumContextVersion);
}
else
#endif
{
SDL_InitTGL((void **) &__tglContext, (struct Library **) &TinyGLBase);
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/core/morphos/sdk/clib/sdl2_protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
struct Library;

void SDL_InitTGL(void **glc, struct Library **tgl);
void SDL_InitTGL2(void **glc, struct Library **tgl, unsigned int (*getmaximumcontextversion)(struct Library *TinyGLBase));
void SDL_SetExitPointer(void (*exitfunc)(int));
SDL_RWops *SDL_RWFromFP_clib(void *fp, int autoclose, Sint64 (*size)(struct SDL_RWops *), Sint64 (*seek)(struct SDL_RWops *, Sint64, int), size_t (*read)(struct SDL_RWops *, void *, size_t, size_t), size_t (*write)(struct SDL_RWops *, const void *, size_t, size_t), int (*close)(struct SDL_RWops *));
int SDL_VSetError(const char *fmt, va_list ap);
Expand Down
1 change: 1 addition & 0 deletions src/core/morphos/sdk/fd/sdl2_lib.fd
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,4 @@ SDL_strcasestr(haystack,needle)(sysv,r12base)
SDL_HasWindowSurface(window)(sysv,r12base)
SDL_DestroyWindowSurface(window)(sysv,r12base)
SDL_GameControllerGetSteamHandle(gamecontroller)(sysv,r12base)
SDL_InitTGL2(glcptr,tglptr,getmaximumcontextversion)(base,sysv)
7 changes: 7 additions & 0 deletions src/core/morphos/sdk/ppcinline/sdl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#define SDL_InitTGL(__p0, __p1) \
(((void (*)(void *, void **, struct Library **))*(void**)((long)(SDL2_BASE_NAME) - 28))((void*)(SDL2_BASE_NAME), __p0, __p1))

#define SDL_InitTGL2(__p0, __p1, __p2) \
LP3NRFP(4818, SDL_InitTGL2, \
void **, __p0, base, \
struct Library **, __p1, sysr, \
__ft, __p2, , \
, SDL2_BASE_NAME, unsigned int (* __ft)(struct Library *TinyGLBase), 0, 0, 0, 0, 0, 0)

#define SDL_SetExitPointer(__p0) \
(((void (*)(void *, void (*)(int)))*(void**)((long)(SDL2_BASE_NAME) - 34))((void*)(SDL2_BASE_NAME), __p0))

Expand Down
20 changes: 19 additions & 1 deletion src/video/morphos/SDL_mosopengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ SDL_bool MOS_GL_InitContext(_THIS, SDL_Window * window)
int success = GLAInitializeContext(__tglContext, tgltags);
if (success) {
data->__tglContext = __tglContext;
tglEnableNewExtensions(0); // Active TinyGL New extensions
//tglEnableNewExtensions(0); // Active TinyGL New extensions
}

return success ? SDL_TRUE : SDL_FALSE;
Expand All @@ -187,6 +187,24 @@ MOS_GL_CreateContext(_THIS, SDL_Window * window)
GLContext *glcont = GLInit();
if (glcont) {
__tglContext = glcont;
#ifdef TGL_CONTEXT_VERSION_53_9
#warning TGL_CONTEXT_VERSION_53_9
if (SDL2Base->MyGetMaximumContextVersion)
{
unsigned int contextversion;

contextversion = SDL2Base->MyGetMaximumContextVersion(TinyGLBase);

if (contextversion == TGL_CONTEXT_VERSION_53_1)
{
TGLEnableNewExtensions(__tglContext, 0);
}
else if (contextversion >= TGL_CONTEXT_VERSION_53_9)
{
TGLSetContextVersion(__tglContext, contextversion);
}
}
#endif
int success = MOS_GL_InitContext(_this, window);
if (success) {
D("[%s] MOS_GL_InitContext SUCCES 0x%08lx, data->__tglContext=0x%08lx\n", __FUNCTION__, glcont, data->__tglContext);
Expand Down

0 comments on commit 96697a4

Please sign in to comment.