Implemented SDL_GL_[GS]etAttribute().
authorRyan C. Gordon <icculus@icculus.org>
Sat, 13 Apr 2013 00:15:23 -0400
changeset 30f0da34bc3c45
parent 29 5cebb18c6f81
child 31 066b1f18cc89
Implemented SDL_GL_[GS]etAttribute().
src/SDL12_compat.c
src/SDL20_syms.h
     1.1 --- a/src/SDL12_compat.c	Fri Apr 12 23:58:58 2013 -0400
     1.2 +++ b/src/SDL12_compat.c	Sat Apr 13 00:15:23 2013 -0400
     1.3 @@ -36,8 +36,6 @@
     1.4  //#include "render/SDL_yuv_sw_c.h"
     1.5  
     1.6  // !!! IMPLEMENT_ME SDL_ConvertSurface
     1.7 -// !!! IMPLEMENT_ME SDL_GL_GetAttribute
     1.8 -// !!! IMPLEMENT_ME SDL_GL_SetAttribute
     1.9  // !!! IMPLEMENT_ME SDL_GetKeyName
    1.10  // !!! IMPLEMENT_ME SDL_GetKeyState
    1.11  // !!! IMPLEMENT_ME SDL_GetModState
    1.12 @@ -312,6 +310,27 @@
    1.13      SDL_Cursor *wm_cursor;  /* the real SDL 1.2 has an opaque pointer to a platform-specific cursor here. */
    1.14  } SDL12_Cursor;
    1.15  
    1.16 +typedef enum
    1.17 +{
    1.18 +    SDL12_GL_RED_SIZE,
    1.19 +    SDL12_GL_GREEN_SIZE,
    1.20 +    SDL12_GL_BLUE_SIZE,
    1.21 +    SDL12_GL_ALPHA_SIZE,
    1.22 +    SDL12_GL_BUFFER_SIZE,
    1.23 +    SDL12_GL_DOUBLEBUFFER,
    1.24 +    SDL12_GL_DEPTH_SIZE,
    1.25 +    SDL12_GL_STENCIL_SIZE,
    1.26 +    SDL12_GL_ACCUM_RED_SIZE,
    1.27 +    SDL12_GL_ACCUM_GREEN_SIZE,
    1.28 +    SDL12_GL_ACCUM_BLUE_SIZE,
    1.29 +    SDL12_GL_ACCUM_ALPHA_SIZE,
    1.30 +    SDL12_GL_STEREO,
    1.31 +    SDL12_GL_MULTISAMPLEBUFFERS,
    1.32 +    SDL12_GL_MULTISAMPLESAMPLES,
    1.33 +    SDL12_GL_ACCELERATED_VISUAL,
    1.34 +    SDL12_GL_SWAP_CONTROL,
    1.35 +    SDL12_GL_MAX_ATTRIBUTE
    1.36 +} SDL12_GLattr;
    1.37  
    1.38  static SDL12_VideoInfo VideoInfo;
    1.39  static SDL_Window *VideoWindow20 = NULL;
    1.40 @@ -331,7 +350,7 @@
    1.41  static SDL12_EventFilter EventFilter12 = NULL;
    1.42  static SDL12_Cursor *CurrentCursor = NULL;
    1.43  static Uint8 EventStates[SDL12_NUMEVENTS];
    1.44 -
    1.45 +static int SwapInterval = 0;
    1.46  
    1.47  // !!! FIXME: need a mutex for the event queue.
    1.48  #define SDL12_MAXEVENTS 128
    1.49 @@ -466,6 +485,7 @@
    1.50          EventStates[SDL12_SYSWMEVENT] = SDL_IGNORE;  /* off by default. */
    1.51          SDL20_SetEventFilter(EventFilter20to12, NULL);
    1.52          VideoDisplayIndex = GetVideoDisplay();
    1.53 +        SwapInterval = 0;
    1.54      }
    1.55  
    1.56      return rc;
    1.57 @@ -1548,6 +1568,9 @@
    1.58          if (SDL_GL_MakeCurrent(VideoWindow20, VideoContext) < 0) {
    1.59              return NULL;
    1.60          }
    1.61 +
    1.62 +        SDL_GL_SetSwapInterval(SwapInterval);  /* don't care if this fails. */
    1.63 +
    1.64          VideoSurface =
    1.65              SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
    1.66          if (!VideoSurface) {
    1.67 @@ -2687,6 +2710,45 @@
    1.68      SDL_free(overlay);
    1.69  }
    1.70  
    1.71 +int
    1.72 +SDL_GL_SetAttribute(SDL12_GLattr attr, int value)
    1.73 +{
    1.74 +    if (attr >= SDL12_GL_MAX_ATTRIBUTE)
    1.75 +    {
    1.76 +        SDL_SetError("Unknown GL attribute");
    1.77 +        return -1;
    1.78 +    }
    1.79 +
    1.80 +    /* swap control was moved out of this API, everything else lines up. */
    1.81 +    if (attr == SDL12_GL_SWAP_CONTROL)
    1.82 +    {
    1.83 +        SwapInterval = value;
    1.84 +        return 0;
    1.85 +    }
    1.86 +
    1.87 +    return SDL20_GL_SetAttribute((SDL_GLattr) attr, value);
    1.88 +}
    1.89 +
    1.90 +int
    1.91 +SDL_GL_GetAttribute(SDL12_GLattr attr, int* value)
    1.92 +{
    1.93 +    if (attr >= SDL12_GL_MAX_ATTRIBUTE)
    1.94 +    {
    1.95 +        SDL_SetError("Unknown GL attribute");
    1.96 +        return -1;
    1.97 +    }
    1.98 +
    1.99 +    /* swap control was moved out of this API, everything else lines up. */
   1.100 +    if (attr == SDL12_GL_SWAP_CONTROL)
   1.101 +    {
   1.102 +        *value = SDL20_GL_GetSwapInterval();
   1.103 +        return 0;
   1.104 +    }
   1.105 +
   1.106 +    return SDL20_GL_GetAttribute((SDL_GLattr) attr, value);
   1.107 +}
   1.108 +
   1.109 +
   1.110  void
   1.111  SDL_GL_SwapBuffers(void)
   1.112  {
     2.1 --- a/src/SDL20_syms.h	Fri Apr 12 23:58:58 2013 -0400
     2.2 +++ b/src/SDL20_syms.h	Sat Apr 13 00:15:23 2013 -0400
     2.3 @@ -45,6 +45,8 @@
     2.4  SDL20_SYM(int,SaveBMP_RW,(SDL_Surface *a, SDL_RWops *b, int c),(a,b,c),return)
     2.5  SDL20_SYM_PASSTHROUGH(int,GL_LoadLibrary,(const char *a),(a),return)
     2.6  SDL20_SYM_PASSTHROUGH(void *,GL_GetProcAddress,(const char *a),(a),return)
     2.7 +SDL20_SYM(int,GL_SetAttribute,(SDL_GLattr a, int b),(a,b),return)
     2.8 +SDL20_SYM(int,GL_GetAttribute,(SDL_GLattr a, int *b),(a,b),return)
     2.9  SDL20_SYM(void,GetClipRect,(SDL_Surface *a, SDL_Rect *b),(a,b),)
    2.10  SDL20_SYM(SDL_bool,SetClipRect,(SDL_Surface *a, const SDL_Rect *b),(a,b),return)
    2.11  SDL20_SYM(int,FillRect,(SDL_Surface *a,const SDL_Rect *b,Uint32 c),(a,b,c),return)