src/render/opengl/SDL_render_gl.c
changeset 6414 df50b0d6c1c3
parent 6320 6077a1310907
child 6449 fa00544b1374
equal deleted inserted replaced
6413:701a0c0d70d0 6414:df50b0d6c1c3
    71 static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    71 static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    72                                Uint32 pixel_format, void * pixels, int pitch);
    72                                Uint32 pixel_format, void * pixels, int pitch);
    73 static void GL_RenderPresent(SDL_Renderer * renderer);
    73 static void GL_RenderPresent(SDL_Renderer * renderer);
    74 static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    74 static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    75 static void GL_DestroyRenderer(SDL_Renderer * renderer);
    75 static void GL_DestroyRenderer(SDL_Renderer * renderer);
    76 
    76 static int GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
       
    77 static int GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture);
    77 
    78 
    78 SDL_RenderDriver GL_RenderDriver = {
    79 SDL_RenderDriver GL_RenderDriver = {
    79     GL_CreateRenderer,
    80     GL_CreateRenderer,
    80     {
    81     {
    81      "opengl",
    82      "opengl",
   320     renderer->RenderCopyEx = GL_RenderCopyEx;
   321     renderer->RenderCopyEx = GL_RenderCopyEx;
   321     renderer->RenderReadPixels = GL_RenderReadPixels;
   322     renderer->RenderReadPixels = GL_RenderReadPixels;
   322     renderer->RenderPresent = GL_RenderPresent;
   323     renderer->RenderPresent = GL_RenderPresent;
   323     renderer->DestroyTexture = GL_DestroyTexture;
   324     renderer->DestroyTexture = GL_DestroyTexture;
   324     renderer->DestroyRenderer = GL_DestroyRenderer;
   325     renderer->DestroyRenderer = GL_DestroyRenderer;
       
   326     renderer->GL_BindTexture = GL_BindTexture;
       
   327     renderer->GL_UnbindTexture = GL_UnbindTexture;
   325     renderer->info = GL_RenderDriver.info;
   328     renderer->info = GL_RenderDriver.info;
   326     renderer->info.flags = SDL_RENDERER_ACCELERATED;
   329     renderer->info.flags = SDL_RENDERER_ACCELERATED;
   327     renderer->driverdata = data;
   330     renderer->driverdata = data;
   328     renderer->window = window;
   331     renderer->window = window;
   329 
   332 
  1226         SDL_free(data);
  1229         SDL_free(data);
  1227     }
  1230     }
  1228     SDL_free(renderer);
  1231     SDL_free(renderer);
  1229 }
  1232 }
  1230 
  1233 
       
  1234 static int GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) {
       
  1235     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
       
  1236     GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
       
  1237     GL_ActivateRenderer(renderer);
       
  1238 
       
  1239     data->glEnable(texturedata->type);
       
  1240     if (texturedata->yuv) {
       
  1241         data->glActiveTextureARB(GL_TEXTURE2_ARB);
       
  1242         data->glBindTexture(texturedata->type, texturedata->vtexture);
       
  1243 
       
  1244         data->glActiveTextureARB(GL_TEXTURE1_ARB);
       
  1245         data->glBindTexture(texturedata->type, texturedata->utexture);
       
  1246 
       
  1247         data->glActiveTextureARB(GL_TEXTURE0_ARB);
       
  1248     }
       
  1249     data->glBindTexture(texturedata->type, texturedata->texture);
       
  1250 
       
  1251     if(texw) *texw = (float)texturedata->texw;
       
  1252     if(texh) *texh = (float)texturedata->texh;
       
  1253 
       
  1254     return 0;
       
  1255 }
       
  1256 
       
  1257 static int GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) {
       
  1258     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
       
  1259     GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
       
  1260     GL_ActivateRenderer(renderer);
       
  1261 
       
  1262     if (texturedata->yuv) {
       
  1263         data->glActiveTextureARB(GL_TEXTURE2_ARB);
       
  1264         data->glDisable(texturedata->type);
       
  1265 
       
  1266         data->glActiveTextureARB(GL_TEXTURE1_ARB);
       
  1267         data->glDisable(texturedata->type);
       
  1268 
       
  1269         data->glActiveTextureARB(GL_TEXTURE0_ARB);
       
  1270     }
       
  1271     
       
  1272     data->glDisable(texturedata->type);
       
  1273 
       
  1274     return 0;
       
  1275 }
       
  1276 
  1231 #endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */
  1277 #endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */
  1232 
  1278 
  1233 /* vi: set ts=4 sw=4 expandtab: */
  1279 /* vi: set ts=4 sw=4 expandtab: */