Skip to content

Commit

Permalink
MorphOS: rework Bitmap
Browse files Browse the repository at this point in the history
Rework some functions

Now use bitmap in windowed mode and fullscreen
  • Loading branch information
BeWorld2018 committed Oct 11, 2023
1 parent 55a0860 commit 9284a5d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/video/morphos/SDL_mosmodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ MOS_GetScreen(_THIS, BYTE fullscreen, SDL_bool support3d)
} else {

screen = OpenScreenTags(NULL,
support3d ? SA_3DSupport : TAG_IGNORE, TRUE,
/*support3d ? SA_3DSupport : TAG_IGNORE, TRUE,*/
SA_GammaControl, TRUE,
SA_Width, data->ScrWidth,
SA_Height, data->ScrHeight,
Expand Down
156 changes: 80 additions & 76 deletions src/video/morphos/SDL_mosopengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ MOS_GL_LoadLibrary(_THIS, const char *path)
*SDL2Base->MyTinyGLBase = TinyGLBase;

return 0;
}
} else
SDL_SetError("Failed to open tinygl.library 53.7");

SDL_SetError("Failed to open tinygl.library 53.7");
return -1;
}

Expand Down Expand Up @@ -104,20 +104,47 @@ SDL_bool MOS_GL_AllocBitmap(_THIS, SDL_Window * window)
FreeBitMap(data->bitmap);
data->bitmap = NULL;
}
ULONG flags = GetBitMapAttr(vd->WScreen->RastPort.BitMap, BMA_FLAGS);
return (!(flags & BMF_3DTARGET) && (data->bitmap = AllocBitMap(window->w, window->h, data->win->RPort->BitMap->Depth, BMF_MINPLANES|BMF_DISPLAYABLE|BMF_3DTARGET, data->win->RPort->BitMap)) != NULL);

int h = 0, w = 0;
struct BitMap * friend_bitmap;
ULONG depth = 0;
if (data->winflags & SDL_MOS_WINDOW_FULLSCREEN_DESKTOP) {
D("[%s] DESKTOP FULLSCREEN\n", __FUNCTION__);
w = vd->WScreen->Width;
h = vd->WScreen->Height;
friend_bitmap = data->win->RPort->BitMap;
depth = data->win->RPort->BitMap->Depth;
} else if (data->winflags & SDL_MOS_WINDOW_FULLSCREEN){
D("[%s] REAL FULLSCREEN\n", __FUNCTION__);
w = vd->CustomScreen->Width;
h = vd->CustomScreen->Height;
friend_bitmap=vd->CustomScreen->RastPort.BitMap;
depth = vd->CustomScreen->RastPort.BitMap->Depth;
} else {
D("[%s] WINDOWED\n", __FUNCTION__);
w = window->w;
h= window->h;
friend_bitmap = data->win->RPort->BitMap;
depth = data->win->RPort->BitMap->Depth;
}

D("[%s] AllocBitMap w=%d h=%d depth=%d\n", __FUNCTION__, w, h, depth);
return (data->bitmap = AllocBitMap(w, h, depth, BMF_MINPLANES|BMF_DISPLAYABLE|BMF_3DTARGET, friend_bitmap)) != NULL;

}

SDL_bool MOS_GL_InitContext(_THIS, SDL_Window * window, GLContext *glcont)
SDL_bool MOS_GL_InitContext(_THIS, SDL_Window * window)
{
D("[%s]\n", __FUNCTION__);
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;

SDL_VideoData *vd = data->videodata;

if (data->__tglContext != NULL) {
//D("[%s] GLADestroyContext\n", __FUNCTION__);
GLADestroyContext(data->__tglContext);
data->__tglContext = NULL;
if (data->bitmap != NULL) {
D("[%s] FreeBitMap\n", __FUNCTION__);
//D("[%s] FreeBitMap\n", __FUNCTION__);
FreeBitMap(data->bitmap);
data->bitmap = NULL;
}
Expand All @@ -128,40 +155,33 @@ SDL_bool MOS_GL_InitContext(_THIS, SDL_Window * window, GLContext *glcont)
{TAG_IGNORE, 0},
{TGL_CONTEXT_STENCIL, TRUE},
{TAG_DONE}
};

SDL_VideoData *vd = data->videodata;
BYTE fullscreen = data->winflags & SDL_MOS_WINDOW_FULLSCREEN;
D("[%s] fullscreen=%d\n", __FUNCTION__, fullscreen);
if (fullscreen) {
};

tgltags[0].ti_Tag = TGL_CONTEXT_SCREEN;
tgltags[0].ti_Data = (IPTR)vd->CustomScreen;

if (MOS_GL_AllocBitmap(_this, window)) {
//D("[%s] TGL_CONTEXT_BITMAP \n", __FUNCTION__);
tgltags[0].ti_Tag = TGL_CONTEXT_BITMAP;
tgltags[0].ti_Data = (IPTR)data->bitmap;
} else {

if (MOS_GL_AllocBitmap(_this, window)) {
D("[%s] TGL_CONTEXT_BITMAP\n", __FUNCTION__);
tgltags[0].ti_Tag = TGL_CONTEXT_BITMAP;
tgltags[0].ti_Data = (IPTR)data->bitmap;
if (vd->CustomScreen != NULL && (data->winflags & SDL_MOS_WINDOW_FULLSCREEN) && (!(data->winflags & SDL_MOS_WINDOW_FULLSCREEN_DESKTOP))) {
tgltags[0].ti_Tag = TGL_CONTEXT_SCREEN;
tgltags[0].ti_Data = (IPTR)vd->CustomScreen;
} else {
D("[%s] TGL_CONTEXT_WINDOW\n", __FUNCTION__);
tgltags[0].ti_Tag = TGL_CONTEXT_WINDOW;
tgltags[0].ti_Data = (IPTR)data->win;
tgltags[0].ti_Data = (IPTR)data->win;
}
}

// Initialize new context
int success = GLAInitializeContext(glcont, tgltags);
int success = GLAInitializeContext(__tglContext, tgltags);
if (success) {
__tglContext = glcont;
data->__tglContext = __tglContext;

SDL_bool withnewextension = SDL_TRUE;

char *val = val = MOS_getenv("SDL_RENDER_OPENGL_SHADERS");
if (val && strlen(val)>0)
if (strcmp(val, "0")==0)
withnewextension = SDL_FALSE;
if (val && strlen(val)>0 && strcmp(val, "0")==0)
withnewextension = SDL_FALSE;

if (withnewextension)
tglEnableNewExtensions(0); // Active TinyGL New extensions
Expand All @@ -174,30 +194,30 @@ SDL_bool MOS_GL_InitContext(_THIS, SDL_Window * window, GLContext *glcont)
SDL_GLContext
MOS_GL_CreateContext(_THIS, SDL_Window * window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;

SDL_WindowData *data = window->driverdata;
GLContext *glcont = GLInit();

if (glcont) {

int success = MOS_GL_InitContext(_this, window, glcont);
__tglContext = glcont;
int success = MOS_GL_InitContext(_this, window);
if (success) {
*SDL2Base->MyGLContext = data->__tglContext = glcont;
D("[%s] SUCCES 0x%08lx\n", __FUNCTION__, glcont);
D("[%s] MOS_GL_InitContext SUCCES 0x%08lx, data->__tglContext=0x%08lx\n", __FUNCTION__, glcont, data->__tglContext);
*SDL2Base->MyGLContext = glcont;
return glcont;
} else {
D("[%s] MOS_GL_InitContext FAILED 0x%08lx, data->__tglContext=0x%08lx\n", __FUNCTION__, glcont, data->__tglContext);
if (data->bitmap != NULL) {
D("[%s] FreeBitMap\n", __FUNCTION__);
FreeBitMap(data->bitmap);
data->bitmap = NULL;
}
GLClose(glcont);
*SDL2Base->MyGLContext = data->__tglContext = __tglContext = NULL;

SDL_SetError("Couldn't initialize TinyGL context");
}
D("[%s] FAILED 0x%08lx\n", __FUNCTION__, glcont);
if (data->bitmap != NULL) {
D("[%s] FreeBitMap\n", __FUNCTION__);
FreeBitMap(data->bitmap);
data->bitmap = NULL;
}
GLClose(glcont);
*SDL2Base->MyGLContext = data->__tglContext = __tglContext = NULL;

SDL_SetError("Couldn't initialize context TinyGL");
} else {
SDL_SetError("Couldn't create TinyGL/OpenGL context");
SDL_SetError("Couldn't create TinyGL context");
}

return NULL;
Expand All @@ -209,14 +229,15 @@ MOS_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
D("[%s] context 0x%08lx\n", __FUNCTION__, context);
if (context)
*SDL2Base->MyGLContext = __tglContext = context;

return 0;
}

void
MOS_GL_GetDrawableSize(_THIS, SDL_Window * window, int *w, int *h)
{
SDL_WindowData * data = window->driverdata;
if (window) {
SDL_WindowData * data = window->driverdata;

if (w)
*w = data->win->Width - data->win->BorderLeft - data->win->BorderRight;
Expand All @@ -234,15 +255,10 @@ MOS_GL_SetSwapInterval(_THIS, int interval)

switch (interval) {
case 0:
// always VSYNC in fullscreen
data->vsyncEnabled = data->CustomScreen != NULL ? TRUE : FALSE;
return 0;
break;
case 1:

data->vsyncEnabled = TRUE;
// always VSYNC in fullscreen
data->vsyncEnabled = /*data->CustomScreen != NULL ? TRUE : */(interval ? TRUE : FALSE);
return 0;
break;
default:
return -1;
}
Expand All @@ -264,7 +280,7 @@ MOS_GL_SwapWindow(_THIS, SDL_Window * window)
return -1;

SDL_VideoData *video = _this->driverdata;
if (video->vsyncEnabled) {
if (video->vsyncEnabled /*&& data->CustomScreen == NULL*/) {
BOOL displayed = getv(data->win->WScreen, SA_Displayed);
if (displayed) {
WaitBOVP(&data->win->WScreen->ViewPort);
Expand All @@ -288,10 +304,7 @@ MOS_GL_DeleteContext(_THIS, SDL_GLContext context)
{
D("[%s] context 0x%08lx\n", __FUNCTION__, context);

if (TinyGLBase == NULL)
return;

if (context) {
if (TinyGLBase != NULL && context) {
SDL_Window *sdlwin;

for (sdlwin = _this->windows; sdlwin; sdlwin = sdlwin->next) {
Expand All @@ -301,40 +314,31 @@ MOS_GL_DeleteContext(_THIS, SDL_GLContext context)
if (data->__tglContext == context) {
D("[%s] Found TinyGL context 0x%08lx, clearing window binding\n", __FUNCTION__, context);
GLADestroyContext(context);

data->__tglContext = NULL;
if (data->bitmap != NULL) {
FreeBitMap(data->bitmap);
D("[%s] FreeBitMap\n", __FUNCTION__);
FreeBitMap(data->bitmap);
data->bitmap = NULL;
}

GLClose(context);
data->__tglContext = NULL;

}
}
GLClose(context);
*SDL2Base->MyGLContext = __tglContext = NULL;
}
}

int
MOS_GL_ResizeContext(_THIS, SDL_Window *window)
{

SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_bool success;

if (data->__tglContext == NULL || __tglContext == NULL) {
return -1;
}
if (data->win == NULL) {
D("[%s] no window\n", __FUNCTION__);
D("[%s] Context=0x%08lx data->__tglContext=0x%08lx\n", __FUNCTION__, __tglContext, data->__tglContext);
if (data->__tglContext == NULL || __tglContext == NULL || data->win == NULL) {
return -1;
}

success = MOS_GL_InitContext(_this, window, data->__tglContext);

D("[%s] success %d\n", __FUNCTION__, success);

return success ? 0 : -1;
return (MOS_GL_InitContext(_this, window) ? 0 : -1);
}

#endif /* SDL_VIDEO_DRIVER_MORPHOS */

0 comments on commit 9284a5d

Please sign in to comment.