Switch OpenGL contexts when switching render contexts.

Query the maximum texture size and show the current render parameters.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401968
This commit is contained in:
Sam Lantinga 2006-07-22 19:51:48 +00:00
parent 5c1901a93d
commit 68df2209ba
4 changed files with 31 additions and 9 deletions

View File

@ -33,6 +33,7 @@
/* OpenGL renderer implementation */
static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
static int GL_ActivateRenderer(SDL_Renderer * renderer);
static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int GL_SetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture,
@ -147,6 +148,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
return NULL;
}
renderer->ActivateRenderer = GL_ActivateRenderer;
renderer->CreateTexture = GL_CreateTexture;
renderer->SetTexturePalette = GL_SetTexturePalette;
renderer->GetTexturePalette = GL_GetTexturePalette;
@ -185,9 +187,8 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->info.flags |= SDL_Renderer_PresentVSync;
}
/* FIXME: Add a function to make the rendering context current when selecting the renderer */
/* FIXME: Query maximum texture size */
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &renderer->info.max_texture_width);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &renderer->info.max_texture_height);
/* FIXME: Check for GL_ARB_texture_rectangle and GL_EXT_texture_rectangle */
@ -209,6 +210,15 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
return renderer;
}
static int
GL_ActivateRenderer(SDL_Renderer * renderer)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
return SDL_GL_MakeCurrent(window->id, data->context);
}
static __inline__ int
power_of_2(int input)
{

View File

@ -55,6 +55,7 @@ struct SDL_Texture
/* Define the SDL renderer structure */
struct SDL_Renderer
{
int (*ActivateRenderer) (SDL_Renderer * renderer);
int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
void **pixels, int *pitch);

View File

@ -1366,10 +1366,7 @@ SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags)
window->renderer =
SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window,
flags);
if (!window->renderer) {
return -1;
}
SDL_CurrentDisplay.current_renderer = window->renderer;
SDL_SelectRenderer(window->id);
return 0;
}
@ -1378,11 +1375,18 @@ int
SDL_SelectRenderer(SDL_WindowID windowID)
{
SDL_Window *window = SDL_GetWindowFromID(windowID);
SDL_Renderer *renderer;
if (!window || !window->renderer) {
return -1;
}
SDL_CurrentDisplay.current_renderer = window->renderer;
renderer = window->renderer;
if (renderer && renderer->ActivateRenderer) {
if (renderer->ActivateRenderer(renderer) < 0) {
return -1;
}
}
SDL_CurrentDisplay.current_renderer = renderer;
return 0;
}

View File

@ -610,7 +610,7 @@ CommonInit(CommonState * state)
if (n == 0) {
fprintf(stderr, "No built-in render drivers\n");
} else {
fprintf(stderr, "Built-in render video drivers:\n");
fprintf(stderr, "Built-in render drivers:\n");
for (i = 0; i < n; ++i) {
SDL_GetRendererInfo(i, &info);
PrintRenderer(&info);
@ -690,6 +690,13 @@ CommonInit(CommonState * state)
SDL_GetError());
return SDL_FALSE;
}
if (state->verbose & VERBOSE_RENDER) {
SDL_RendererInfo info;
fprintf(stderr, "Current renderer:\n");
SDL_GetRendererInfo(-1, &info);
PrintRenderer(&info);
}
}
}
SDL_SelectRenderer(state->windows[0]);