diff --git a/src/video/morphos/SDL_mosmodes.c b/src/video/morphos/SDL_mosmodes.c index 4a0b99abd2b9b0..3cc2ade10ff9eb 100644 --- a/src/video/morphos/SDL_mosmodes.c +++ b/src/video/morphos/SDL_mosmodes.c @@ -295,7 +295,7 @@ MOS_GetScreen(_THIS, BYTE fullscreen, SDL_bool support3d) int use_wb_screen = 0; ULONG openError = 0; - D("[%s] Use monitor '%s' - Screen %d\n", __FUNCTION__, data->ScrMonName ? data->ScrMonName : (STRPTR)"Workbench", data->CustomScreen); + D("[%s] support3d=%d - Use monitor '%s' - Screen %d\n", __FUNCTION__, support3d, data->ScrMonName ? data->ScrMonName : (STRPTR)"Workbench", data->CustomScreen); if (!fullscreen && data->ScrMonName == NULL) { data->CustomScreen = NULL; diff --git a/src/video/morphos/SDL_mosopengl.c b/src/video/morphos/SDL_mosopengl.c index 2247710db93cb0..02e9ef74a73171 100644 --- a/src/video/morphos/SDL_mosopengl.c +++ b/src/video/morphos/SDL_mosopengl.c @@ -93,65 +93,112 @@ MOS_GL_UnloadLibrary(_THIS) } } -SDL_GLContext -MOS_GL_CreateContext(_THIS, SDL_Window * window) +SDL_bool MOS_GL_AllocBitmap(_THIS, SDL_Window * window) +{ + D("[%s]\n", __FUNCTION__); + SDL_WindowData *data = (SDL_WindowData *) window->driverdata; + + if (data->bitmap == NULL) { + FreeBitMap(data->bitmap); + data->bitmap = NULL; + } + + int sizex = window->w; //data->win->Width - data->win->BorderLeft - data->win->BorderRight; + int sizey = window->h; //data->win->Height - data->win->BorderTop - data->win->BorderBottom; + data->bitmap = AllocBitMap(sizex, sizey, data->win->RPort->BitMap->Depth, BMF_MINPLANES|BMF_DISPLAYABLE|BMF_3DTARGET, data->win->RPort->BitMap); + + if (data->bitmap == NULL) { + D("[%s] Failed to create Bitmap\n", __FUNCTION__); + return SDL_FALSE; + } + + return SDL_TRUE; +} + +SDL_bool MOS_GL_InitContext(_THIS, SDL_Window * window, GLContext *glcont) { + SDL_WindowData *data = (SDL_WindowData *) window->driverdata; + + if (data->__tglContext != NULL) { + GLADestroyContext(data->__tglContext); + if (data->bitmap != NULL) { + FreeBitMap(data->bitmap); + data->bitmap = NULL; + } + } + + struct TagItem tgltags[] = + { + {TAG_IGNORE, 0}, + {TGL_CONTEXT_STENCIL, TRUE}, + {TAG_DONE} + }; + SDL_VideoData *vd = data->videodata; BYTE fullscreen = data->winflags & SDL_MOS_WINDOW_FULLSCREEN; + if (fullscreen) { + + tgltags[0].ti_Tag = TGL_CONTEXT_SCREEN; + tgltags[0].ti_Data = (IPTR)vd->CustomScreen; + + } else { + + if (MOS_GL_AllocBitmap(_this, window)) { + tgltags[0].ti_Tag = TGL_CONTEXT_BITMAP; + tgltags[0].ti_Data = (IPTR)data->bitmap; + } else { + tgltags[0].ti_Tag = TGL_CONTEXT_WINDOW; + tgltags[0].ti_Data = (IPTR)data->win; + } + } + + // Initialize new context + int success = GLAInitializeContext(glcont, tgltags); + if (success) { + __tglContext = glcont; + + 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 (withnewextension) + tglEnableNewExtensions(0); // Active TinyGL New extensions + } + + return success ? SDL_TRUE : SDL_FALSE; +} + +void MOS_GL_DestroyContext(_THIS) +{ + +} + +SDL_GLContext +MOS_GL_CreateContext(_THIS, SDL_Window * window) +{ + SDL_WindowData *data = (SDL_WindowData *) window->driverdata; GLContext *glcont = GLInit(); - D("[%s] new context 0x%08lx\n", __FUNCTION__, glcont); if (glcont) { - int success; - struct TagItem tgltags[] = - { - {TAG_IGNORE, 0}, - {TGL_CONTEXT_STENCIL, TRUE}, // TODO check if stencil and depth are needed - {TAG_DONE} - }; - - if (fullscreen) { - tgltags[0].ti_Tag = TGL_CONTEXT_SCREEN; - tgltags[0].ti_Data = (IPTR)vd->CustomScreen; - } if (data->win) { - tgltags[0].ti_Tag = TGL_CONTEXT_WINDOW; - tgltags[0].ti_Data = (IPTR)data->win; - } else { - // window not exist but you want createContext (example: SDL_WINDOW_HIDDEN) - // so use Ambient screen and Context Bitmap ?! - if (vd->WScreen == NULL) - MOS_GetScreen(vd->VideoDevice, 0, (window->flags & SDL_WINDOW_OPENGL) != 0); - - D("[%s] new context unless window 0x%08lx - 0x%08lx\n", __FUNCTION__, glcont, vd->WScreen); - tgltags[0].ti_Tag = TGL_CONTEXT_BITMAP; - tgltags[0].ti_Data = (IPTR)vd->WScreen->RastPort.BitMap; - } - - success = GLAInitializeContext(glcont, tgltags); + int success = MOS_GL_InitContext(_this, window, glcont); if (success) { - *SDL2Base->MyGLContext = __tglContext = glcont; - data->__tglContext = glcont; - D("[%s] new context SUCCES 0x%08lx\n", __FUNCTION__, glcont); - - // Disabled tglNewExtensions if SDL_RENDER_OPENGL_SHADERS is disabled (per defaut) - char *val = val = MOS_getenv("SDL_RENDER_OPENGL_SHADERS"); - if (val && strlen(val)>0) { - if (strcmp(val, "0")!=0) { - D("[%s] Using tglEnableNewExtensions(0);\n", __FUNCTION__); - tglEnableNewExtensions(0); - } - } else { - D("[%s] Using tglEnableNewExtensions(0);\n", __FUNCTION__); - tglEnableNewExtensions(0); - } + *SDL2Base->MyGLContext = data->__tglContext = glcont; + D("[%s] SUCCES 0x%08lx\n", __FUNCTION__, glcont); return glcont; } - D("[%s] new context FAILED 0x%08lx\n", __FUNCTION__, glcont); + D("[%s] FAILED 0x%08lx\n", __FUNCTION__, glcont); + if (data->bitmap) { + FreeBitMap(data->bitmap); + data->bitmap = NULL; + } GLClose(glcont); - data->__tglContext = NULL; + *SDL2Base->MyGLContext = data->__tglContext = __tglContext = NULL; SDL_SetError("Couldn't initialize context TinyGL"); } else { @@ -180,13 +227,14 @@ MOS_GL_GetDrawableSize(_THIS, SDL_Window * window, int *w, int *h) *w = data->win->Width - data->win->BorderLeft - data->win->BorderRight; if (h) *h = data->win->Height - data->win->BorderTop - data->win->BorderBottom; + } + } int MOS_GL_SetSwapInterval(_THIS, int interval) { - //D("[%s] interval=%d\n", __FUNCTION__, interval); SDL_VideoData *data = _this->driverdata; switch (interval) { @@ -216,7 +264,7 @@ int MOS_GL_SwapWindow(_THIS, SDL_Window * window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; - //D("[%s] context 0x%08lx\n", __FUNCTION__, data->__tglContext, data->win); + if (!data->win || !data->__tglContext || !__tglContext) return -1; @@ -229,6 +277,15 @@ MOS_GL_SwapWindow(_THIS, SDL_Window * window) } GLASwapBuffers(data->__tglContext); + + if (data->bitmap != NULL) { + + BltBitMapRastPort(data->bitmap, 0, 0, data->win->RPort, data->win->BorderLeft, data->win->BorderTop, + window->w/*(data->win->Width - data->win->BorderRight - data->win->BorderLeft)*//*GetBitMapAttr(data->bitmap, BMA_WIDTH)*/, + window->h/*(data->win->Height - data->win->BorderTop - data->win->BorderBottom)*//*GetBitMapAttr(data->bitmap, BMA_HEIGHT)*/, 0xc0); + } + + return 0; } @@ -237,10 +294,9 @@ MOS_GL_DeleteContext(_THIS, SDL_GLContext context) { D("[%s] context 0x%08lx\n", __FUNCTION__, context); - if (TinyGLBase == NULL) { - D("[%s] the library is already closed\n", __FUNCTION__); + if (TinyGLBase == NULL) return; - } + if (context) { SDL_Window *sdlwin; @@ -251,10 +307,15 @@ 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); + + if (data->bitmap != NULL) + FreeBitMap(data->bitmap); + GLClose(context); data->__tglContext = NULL; } } + *SDL2Base->MyGLContext = __tglContext = NULL; } } @@ -262,12 +323,9 @@ int MOS_GL_ResizeContext(_THIS, SDL_Window *window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; - SDL_VideoData *vd = data->videodata; - int success; + SDL_bool success; if (data->__tglContext == NULL || __tglContext == NULL) { - // only if __tglContext exists - D("[%s] no OpenGL context\n", __FUNCTION__); return -1; } if (data->win == NULL) { @@ -275,18 +333,8 @@ MOS_GL_ResizeContext(_THIS, SDL_Window *window) return -1; } - if (vd->CustomScreen) { - struct TagItem tgltags[] = - { - {TGL_CONTEXT_SCREEN, (IPTR)vd->CustomScreen}, - {TGL_CONTEXT_STENCIL, TRUE}, // TODO check if stencil and depth are needed - {TAG_DONE} - }; - GLADestroyContext(data->__tglContext); - success = GLAInitializeContext(data->__tglContext, tgltags); - } else { - success = GLAReinitializeContextWindowed(data->__tglContext, data->win); - } + success = MOS_GL_InitContext(_this, window, data->__tglContext); + D("[%s] success %d\n", __FUNCTION__, success); return success ? 0 : -1; diff --git a/src/video/morphos/SDL_mosopengl.h b/src/video/morphos/SDL_mosopengl.h index 631b2396ba7601..a1bac32e2a58f1 100644 --- a/src/video/morphos/SDL_mosopengl.h +++ b/src/video/morphos/SDL_mosopengl.h @@ -40,5 +40,7 @@ extern void MOS_GL_DeleteContext(_THIS, SDL_GLContext context); /* Non-SDL functions */ extern int MOS_GL_ResizeContext(_THIS, SDL_Window *window); +extern SDL_bool MOS_GL_AllocBitmap(_THIS, SDL_Window * window); +extern SDL_bool MOS_GL_InitContext(_THIS, SDL_Window * window, GLContext *glcont); #endif /* _SDL_mosopengl_h */ diff --git a/src/video/morphos/SDL_moswindow.h b/src/video/morphos/SDL_moswindow.h index 376591ea1f7aab..60969c0073992a 100644 --- a/src/video/morphos/SDL_moswindow.h +++ b/src/video/morphos/SDL_moswindow.h @@ -87,6 +87,9 @@ typedef struct APTR visualinfo; struct Menu *menu; + + struct BitMap *bitmap; + } SDL_WindowData; /* Is this window shown (not iconified) */