sdl2: start getting opengl working again

This commit is contained in:
Ronald Kinard 2014-07-22 01:23:08 -05:00
parent 145618785c
commit 0a37bdf76d
3 changed files with 81 additions and 73 deletions

View file

@ -119,9 +119,7 @@ static SDL_bool disable_mouse = SDL_FALSE;
static INT32 firstEntry = 0; static INT32 firstEntry = 0;
// SDL vars // SDL vars
#ifndef HWRENDER //[segabor] !!! I had problem compiling this source with gcc 3.3
static SDL_Surface *vidSurface = NULL; static SDL_Surface *vidSurface = NULL;
#endif
static SDL_Surface *bufSurface = NULL; static SDL_Surface *bufSurface = NULL;
static SDL_Surface *icoSurface = NULL; static SDL_Surface *icoSurface = NULL;
static SDL_Color localPalette[256]; static SDL_Color localPalette[256];
@ -243,32 +241,44 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen)
SDL_RenderSetLogicalSize(renderer, width, height); SDL_RenderSetLogicalSize(renderer, width, height);
// Set up Texture if (rendermode == render_soft)
realwidth = width;
realheight = height;
if (texture != NULL)
{ {
SDL_DestroyTexture(texture); // Set up Texture
} realwidth = width;
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, width, height); realheight = height;
if (texture != NULL)
{
SDL_DestroyTexture(texture);
}
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, width, height);
// Set up SW surface // Set up SW surface
if (vidSurface != NULL) if (vidSurface != NULL)
{ {
SDL_FreeSurface(vidSurface); SDL_FreeSurface(vidSurface);
} }
#ifdef SDL_BIG_ENDIAN #ifdef SDL_BIG_ENDIAN
rmask = 0xFF000000; rmask = 0xFF000000;
gmask = 0x00FF0000; gmask = 0x00FF0000;
bmask = 0x0000FF00; bmask = 0x0000FF00;
amask = 0x000000FF; amask = 0x000000FF;
#else // HEAD HEADS UP THE ASSIGNMENT ORDER IS FLIPPED, I WAS LAZY --Fury #else // HEAD HEADS UP THE ASSIGNMENT ORDER IS FLIPPED, I WAS LAZY --Fury
amask = 0xFF000000; amask = 0xFF000000;
bmask = 0x00FF0000; bmask = 0x00FF0000;
gmask = 0x0000FF00; gmask = 0x0000FF00;
rmask = 0x000000FF; rmask = 0x000000FF;
#endif
vidSurface = SDL_CreateRGBSurface(0, width, height, 32, rmask, gmask, bmask, amask);
}
#ifdef HWRENDER
else if (rendermode == render_opengl)
{
if (sdlglcontext == 0)
{
sdlglcontext = SDL_GL_CreateContext(window);
}
}
#endif #endif
vidSurface = SDL_CreateRGBSurface(0, width, height, 32, rmask, gmask, bmask, amask);
} }
// //
@ -1813,15 +1823,46 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen)
#ifdef HWRENDER #ifdef HWRENDER
if (rendermode == render_opengl) if (rendermode == render_opengl)
{ {
flags |= SDL_WINDOW_OPENGL; /*
* We want at least 1 bit R, G, and B,
* and at least 16 bpp. Why 1 bit? May be more?
*/
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 1);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 1);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 1);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
window = SDL_CreateWindow("SRB2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
realwidth, realheight, flags | SDL_WINDOW_OPENGL);
if (window != NULL)
{
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer != NULL)
{
SDL_RenderSetLogicalSize(renderer, BASEVIDWIDTH, BASEVIDHEIGHT);
sdlglcontext = SDL_GL_CreateContext(window);
}
else return SDL_FALSE;
}
else return SDL_FALSE;
} }
#endif #endif
if (rendermode == render_soft)
{
window = SDL_CreateWindow("SRB2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
realwidth, realheight, flags);
if (window != NULL)
{
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer != NULL)
{
SDL_RenderSetLogicalSize(renderer, BASEVIDWIDTH, BASEVIDHEIGHT);
}
else return SDL_FALSE;
}
else return SDL_FALSE;
}
window = SDL_CreateWindow("SRB2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
realwidth, realheight, flags);
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_RenderSetLogicalSize(renderer, BASEVIDWIDTH, BASEVIDHEIGHT);
return SDL_TRUE; return SDL_TRUE;
} }
@ -2000,17 +2041,14 @@ void I_StartupGraphics(void)
vid.height = BASEVIDHEIGHT; vid.height = BASEVIDHEIGHT;
if (HWD.pfnInit(I_Error)) // let load the OpenGL library if (HWD.pfnInit(I_Error)) // let load the OpenGL library
{ {
/*
* We want at least 1 bit R, G, and B, // Contrary to SDL1 implementation, all we need is a window and a GL context.
* and at least 16 bpp. Why 1 bit? May be more? // No setting up a special surface to draw to.
*/ // If the GL context was already made, we're good to go.
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 1);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 1); /*if (!OglSdlSurface(vid.width, vid.height, (USE_FULLSCREEN)))
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 1);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (!OglSdlSurface(vid.width, vid.height, (USE_FULLSCREEN)))
if (!OglSdlSurface(vid.width, vid.height, !(USE_FULLSCREEN))) if (!OglSdlSurface(vid.width, vid.height, !(USE_FULLSCREEN)))
rendermode = render_soft; rendermode = render_soft;*/
} }
else else
rendermode = render_soft; rendermode = render_soft;

View file

@ -62,19 +62,11 @@ PFNglGetIntegerv pglGetIntegerv;
PFNglGetString pglGetString; PFNglGetString pglGetString;
#endif #endif
#ifdef _PSP
static const Uint32 WOGLFlags = SDL_HWSURFACE|SDL_OPENGL/*|SDL_RESIZABLE*/;
static const Uint32 FOGLFlags = SDL_HWSURFACE|SDL_OPENGL|SDL_FULLSCREEN;
#else
static const Uint32 WOGLFlags = SDL_OPENGL/*|SDL_RESIZABLE*/;
static const Uint32 FOGLFlags = SDL_OPENGL|SDL_FULLSCREEN;
#endif
/** \brief SDL video display surface /** \brief SDL video display surface
*/ */
SDL_Surface *vidSurface = NULL;
INT32 oglflags = 0; INT32 oglflags = 0;
void *GLUhandle = NULL; void *GLUhandle = NULL;
SDL_GLContext sdlglcontext = 0;
#ifndef STATIC_OPENGL #ifndef STATIC_OPENGL
void *GetGLFunc(const char *proc) void *GetGLFunc(const char *proc)
@ -159,33 +151,11 @@ boolean LoadGL(void)
boolean OglSdlSurface(INT32 w, INT32 h, boolean isFullscreen) boolean OglSdlSurface(INT32 w, INT32 h, boolean isFullscreen)
{ {
INT32 cbpp; INT32 cbpp;
Uint32 OGLFlags; //Uint32 OGLFlags;
const GLvoid *glvendor = NULL, *glrenderer = NULL, *glversion = NULL; const GLvoid *glvendor = NULL, *glrenderer = NULL, *glversion = NULL;
cbpp = cv_scr_depth.value < 16 ? 16 : cv_scr_depth.value; cbpp = cv_scr_depth.value < 16 ? 16 : cv_scr_depth.value;
if (vidSurface)
{
//Alam: SDL_Video system free vidSurface for me
#ifdef VOODOOSAFESWITCHING
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
#endif
}
if (isFullscreen)
OGLFlags = FOGLFlags;
else
OGLFlags = WOGLFlags;
cbpp = SDL_VideoModeOK(w, h, cbpp, OGLFlags);
if (cbpp < 16)
return true; //Alam: Let just say we did, ok?
vidSurface = SDL_SetVideoMode(w, h, cbpp, OGLFlags);
if (!vidSurface)
return false;
glvendor = pglGetString(GL_VENDOR); glvendor = pglGetString(GL_VENDOR);
// Get info and extensions. // Get info and extensions.
//BP: why don't we make it earlier ? //BP: why don't we make it earlier ?
@ -274,7 +244,7 @@ void OglSdlFinishUpdate(boolean waitvbl)
} }
oldwaitvbl = waitvbl; oldwaitvbl = waitvbl;
SDL_GL_SwapBuffers(); SDL_GL_SwapWindow(window);
} }
EXPORT void HWRAPI( OglSdlSetPalette) (RGBA_t *palette, RGBA_t *pgamma) EXPORT void HWRAPI( OglSdlSetPalette) (RGBA_t *palette, RGBA_t *pgamma)

View file

@ -18,7 +18,6 @@
#include "../v_video.h" #include "../v_video.h"
extern SDL_Surface *vidSurface;
extern void *GLUhandle; extern void *GLUhandle;
boolean OglSdlSurface(INT32 w, INT32 h, boolean isFullscreen); boolean OglSdlSurface(INT32 w, INT32 h, boolean isFullscreen);
@ -27,6 +26,7 @@ void OglSdlFinishUpdate(boolean vidwait);
extern SDL_Window *window; extern SDL_Window *window;
extern SDL_Renderer *renderer; extern SDL_Renderer *renderer;
extern SDL_GLContext sdlglcontext;
#ifdef _CREATE_DLL_ #ifdef _CREATE_DLL_
EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette, RGBA_t *pgamma); EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette, RGBA_t *pgamma);