src/render/opengl/SDL_render_gl.c
changeset 5228 811beeb698f9
parent 5227 9c0c4d767ef6
child 5229 c015d3e63631
equal deleted inserted replaced
5227:9c0c4d767ef6 5228:811beeb698f9
    23 
    23 
    24 #if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED
    24 #if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED
    25 
    25 
    26 #include "SDL_opengl.h"
    26 #include "SDL_opengl.h"
    27 #include "../SDL_sysrender.h"
    27 #include "../SDL_sysrender.h"
       
    28 #include "SDL_shaders_gl.h"
    28 
    29 
    29 #ifdef __MACOSX__
    30 #ifdef __MACOSX__
    30 #include <OpenGL/OpenGL.h>
    31 #include <OpenGL/OpenGL.h>
    31 #endif
    32 #endif
    32 
    33 
    92 #include "SDL_glfuncs.h"
    93 #include "SDL_glfuncs.h"
    93 #undef SDL_PROC
    94 #undef SDL_PROC
    94 
    95 
    95     void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
    96     void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
    96                                  const GLvoid * pointer);
    97                                  const GLvoid * pointer);
       
    98 
       
    99     /* Multitexture support */
       
   100     SDL_bool GL_ARB_multitexture_supported;
       
   101     PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
       
   102     int num_texture_units;
       
   103 
       
   104     /* Shader support */
       
   105     GL_ShaderContext *shaders;
       
   106 
    97 } GL_RenderData;
   107 } GL_RenderData;
    98 
   108 
    99 typedef struct
   109 typedef struct
   100 {
   110 {
   101     GLuint texture;
   111     GLuint texture;
   259     if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
   269     if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
   260         data->glTextureRangeAPPLE =
   270         data->glTextureRangeAPPLE =
   261             (void (*)(GLenum, GLsizei, const GLvoid *))
   271             (void (*)(GLenum, GLsizei, const GLvoid *))
   262             SDL_GL_GetProcAddress("glTextureRangeAPPLE");
   272             SDL_GL_GetProcAddress("glTextureRangeAPPLE");
   263     }
   273     }
       
   274 
       
   275     /* Check for multitexture support */
       
   276     if (SDL_GL_ExtensionSupported("GL_ARB_multitexture")) {
       
   277         data->glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB");
       
   278         if (data->glActiveTextureARB) {
       
   279             data->GL_ARB_multitexture_supported = SDL_TRUE;
       
   280             data->glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &data->num_texture_units);
       
   281         }
       
   282     }
       
   283 
       
   284     /* Check for shader support */
       
   285     //data->shaders = GL_CreateShaderContext();
       
   286 
       
   287 #if 0
       
   288     /* We support YV12 textures using 3 textures and a shader */
       
   289     if (data->shaders && data->num_texture_units >= 3) {
       
   290         renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_YV12;
       
   291     }
       
   292 #endif
   264 
   293 
   265     /* Set up parameters for rendering */
   294     /* Set up parameters for rendering */
   266     data->blendMode = -1;
   295     data->blendMode = -1;
   267     data->glDisable(GL_DEPTH_TEST);
   296     data->glDisable(GL_DEPTH_TEST);
   268     data->glDisable(GL_CULL_FACE);
   297     data->glDisable(GL_CULL_FACE);
   577     int i;
   606     int i;
   578 
   607 
   579     GL_ActivateRenderer(renderer);
   608     GL_ActivateRenderer(renderer);
   580 
   609 
   581     GL_SetBlendMode(data, renderer->blendMode);
   610     GL_SetBlendMode(data, renderer->blendMode);
       
   611     GL_SelectShader(data->shaders, SHADER_SOLID);
   582 
   612 
   583     data->glColor4f((GLfloat) renderer->r * inv255f,
   613     data->glColor4f((GLfloat) renderer->r * inv255f,
   584                     (GLfloat) renderer->g * inv255f,
   614                     (GLfloat) renderer->g * inv255f,
   585                     (GLfloat) renderer->b * inv255f,
   615                     (GLfloat) renderer->b * inv255f,
   586                     (GLfloat) renderer->a * inv255f);
   616                     (GLfloat) renderer->a * inv255f);
   602     int i;
   632     int i;
   603 
   633 
   604     GL_ActivateRenderer(renderer);
   634     GL_ActivateRenderer(renderer);
   605 
   635 
   606     GL_SetBlendMode(data, renderer->blendMode);
   636     GL_SetBlendMode(data, renderer->blendMode);
       
   637     GL_SelectShader(data->shaders, SHADER_SOLID);
   607 
   638 
   608     data->glColor4f((GLfloat) renderer->r * inv255f,
   639     data->glColor4f((GLfloat) renderer->r * inv255f,
   609                     (GLfloat) renderer->g * inv255f,
   640                     (GLfloat) renderer->g * inv255f,
   610                     (GLfloat) renderer->b * inv255f,
   641                     (GLfloat) renderer->b * inv255f,
   611                     (GLfloat) renderer->a * inv255f);
   642                     (GLfloat) renderer->a * inv255f);
   672     int i;
   703     int i;
   673 
   704 
   674     GL_ActivateRenderer(renderer);
   705     GL_ActivateRenderer(renderer);
   675 
   706 
   676     GL_SetBlendMode(data, renderer->blendMode);
   707     GL_SetBlendMode(data, renderer->blendMode);
       
   708     GL_SelectShader(data->shaders, SHADER_SOLID);
   677 
   709 
   678     data->glColor4f((GLfloat) renderer->r * inv255f,
   710     data->glColor4f((GLfloat) renderer->r * inv255f,
   679                     (GLfloat) renderer->g * inv255f,
   711                     (GLfloat) renderer->g * inv255f,
   680                     (GLfloat) renderer->b * inv255f,
   712                     (GLfloat) renderer->b * inv255f,
   681                     (GLfloat) renderer->a * inv255f);
   713                     (GLfloat) renderer->a * inv255f);
   725     } else {
   757     } else {
   726         data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
   758         data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
   727     }
   759     }
   728 
   760 
   729     GL_SetBlendMode(data, texture->blendMode);
   761     GL_SetBlendMode(data, texture->blendMode);
       
   762     GL_SelectShader(data->shaders, SHADER_RGB);
   730 
   763 
   731     data->glBegin(GL_TRIANGLE_STRIP);
   764     data->glBegin(GL_TRIANGLE_STRIP);
   732     data->glTexCoord2f(minu, minv);
   765     data->glTexCoord2f(minu, minv);
   733     data->glVertex2f((GLfloat) minx, (GLfloat) miny);
   766     data->glVertex2f((GLfloat) minx, (GLfloat) miny);
   734     data->glTexCoord2f(maxu, minv);
   767     data->glTexCoord2f(maxu, minv);