src/render/opengl/SDL_render_gl.c
changeset 6414 df50b0d6c1c3
parent 6320 6077a1310907
child 6449 fa00544b1374
     1.1 --- a/src/render/opengl/SDL_render_gl.c	Sun Sep 02 19:37:36 2012 -0400
     1.2 +++ b/src/render/opengl/SDL_render_gl.c	Mon Sep 03 11:16:12 2012 -0300
     1.3 @@ -73,7 +73,8 @@
     1.4  static void GL_RenderPresent(SDL_Renderer * renderer);
     1.5  static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
     1.6  static void GL_DestroyRenderer(SDL_Renderer * renderer);
     1.7 -
     1.8 +static int GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
     1.9 +static int GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture);
    1.10  
    1.11  SDL_RenderDriver GL_RenderDriver = {
    1.12      GL_CreateRenderer,
    1.13 @@ -322,6 +323,8 @@
    1.14      renderer->RenderPresent = GL_RenderPresent;
    1.15      renderer->DestroyTexture = GL_DestroyTexture;
    1.16      renderer->DestroyRenderer = GL_DestroyRenderer;
    1.17 +    renderer->GL_BindTexture = GL_BindTexture;
    1.18 +    renderer->GL_UnbindTexture = GL_UnbindTexture;
    1.19      renderer->info = GL_RenderDriver.info;
    1.20      renderer->info.flags = SDL_RENDERER_ACCELERATED;
    1.21      renderer->driverdata = data;
    1.22 @@ -1228,6 +1231,49 @@
    1.23      SDL_free(renderer);
    1.24  }
    1.25  
    1.26 +static int GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) {
    1.27 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
    1.28 +    GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
    1.29 +    GL_ActivateRenderer(renderer);
    1.30 +
    1.31 +    data->glEnable(texturedata->type);
    1.32 +    if (texturedata->yuv) {
    1.33 +        data->glActiveTextureARB(GL_TEXTURE2_ARB);
    1.34 +        data->glBindTexture(texturedata->type, texturedata->vtexture);
    1.35 +
    1.36 +        data->glActiveTextureARB(GL_TEXTURE1_ARB);
    1.37 +        data->glBindTexture(texturedata->type, texturedata->utexture);
    1.38 +
    1.39 +        data->glActiveTextureARB(GL_TEXTURE0_ARB);
    1.40 +    }
    1.41 +    data->glBindTexture(texturedata->type, texturedata->texture);
    1.42 +
    1.43 +    if(texw) *texw = (float)texturedata->texw;
    1.44 +    if(texh) *texh = (float)texturedata->texh;
    1.45 +
    1.46 +    return 0;
    1.47 +}
    1.48 +
    1.49 +static int GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) {
    1.50 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
    1.51 +    GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
    1.52 +    GL_ActivateRenderer(renderer);
    1.53 +
    1.54 +    if (texturedata->yuv) {
    1.55 +        data->glActiveTextureARB(GL_TEXTURE2_ARB);
    1.56 +        data->glDisable(texturedata->type);
    1.57 +
    1.58 +        data->glActiveTextureARB(GL_TEXTURE1_ARB);
    1.59 +        data->glDisable(texturedata->type);
    1.60 +
    1.61 +        data->glActiveTextureARB(GL_TEXTURE0_ARB);
    1.62 +    }
    1.63 +    
    1.64 +    data->glDisable(texturedata->type);
    1.65 +
    1.66 +    return 0;
    1.67 +}
    1.68 +
    1.69  #endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */
    1.70  
    1.71  /* vi: set ts=4 sw=4 expandtab: */