visualtest/src/rwhelper.c
author Sam Lantinga
Tue, 10 Jan 2017 08:54:33 -0800
changeset 10806 36f40b8cc979
parent 7924 fcb86d323770
permissions -rw-r--r--
Fixed bugs 2570, 3145, improved OpenGL ES context support on Windows and X11

Mark Callow

The attached patch does the following for the X11 and Windows platforms, the only ones where SDL attempts to use context_create_es_profile:

- Adds SDL_HINT_OPENGL_ES_DRIVER by which the application can
say to use the OpenGL ES driver & EGL rather than the Open GL
driver. (For bug #2570)
- Adds code to {WIN,X11}_GL_InitExtensions to determine the maximum
OpenGL ES version supported by the OpenGL driver (for bug #3145)
- Modifies the test that determines whether to use the OpenGL
driver or the real OpenGL ES driver to take into account the
hint, the requested and supported ES version and whether ES 1.X
is being requested. (For bug #2570 & bug #3145)
- Enables the testgles2 test for __WINDOWS__ and __LINUX__ and adds
the test to the VisualC projects.

With the fix in place I have run testdraw2, testgl and testgles2 without any issues and have run my own apps that use OpenGL, OpenGL ES 3 and OpenGL ES 1.1.
     1 /* See COPYING.txt for the full license governing this code. */
     2 /**
     3  * \file rwhelper.c
     4  *
     5  * Source file with some helper functions for working with SDL_RWops.
     6  */
     7 
     8 #include <SDL_test.h>
     9 #include "SDL_visualtest_sut_configparser.h"
    10 #include "SDL_visualtest_rwhelper.h"
    11 
    12 void
    13 SDLVisualTest_RWHelperResetBuffer(SDLVisualTest_RWHelperBuffer* buffer)
    14 {
    15     if(!buffer)
    16     {
    17         SDLTest_LogError("buffer argument cannot be NULL");
    18         return;
    19     }
    20     buffer->buffer_pos = 0;
    21     buffer->buffer_width = 0;
    22 }
    23 
    24 char
    25 SDLVisualTest_RWHelperReadChar(SDL_RWops* rw, SDLVisualTest_RWHelperBuffer* buffer)
    26 {
    27     if(!rw || !buffer)
    28         return 0;
    29     /* if the buffer has been consumed, we fill it up again */
    30     if(buffer->buffer_pos == buffer->buffer_width)
    31     {
    32         buffer->buffer_width = SDL_RWread(rw, buffer->buffer, 1, RWOPS_BUFFER_LEN);
    33         buffer->buffer_pos = 0;
    34         if(buffer->buffer_width == 0)
    35             return 0;
    36     }
    37     buffer->buffer_pos++;
    38     return buffer->buffer[buffer->buffer_pos - 1];
    39 }
    40 
    41 /* does not include new lines in the buffer and adds a trailing null character */
    42 char*
    43 SDLVisualTest_RWHelperReadLine(SDL_RWops* rw, char* str, int size,
    44                                SDLVisualTest_RWHelperBuffer* buffer,
    45                                char comment_char)
    46 {
    47     char ch;
    48     int current_pos, done;
    49     if(!rw)
    50     {
    51         SDLTest_LogError("rw argument cannot be NULL");
    52         return NULL;
    53     }
    54     if(!str)
    55     {
    56         SDLTest_LogError("str argument cannot be NULL");
    57         return NULL;
    58     }
    59     if(!buffer)
    60     {
    61         SDLTest_LogError("buffer argument cannot be NULL");
    62         return NULL;
    63     }
    64     if(size <= 0)
    65     {
    66         SDLTest_LogError("size argument should be positive");
    67         return NULL;
    68     }
    69 
    70     done = 0;
    71     while(!done)
    72     {
    73         /* ignore leading whitespace */
    74         for(ch = SDLVisualTest_RWHelperReadChar(rw, buffer); ch && SDL_isspace(ch);
    75             ch = SDLVisualTest_RWHelperReadChar(rw, buffer));
    76 
    77         for(current_pos = 0;
    78             ch && ch != '\n' && ch != '\r' && ch != comment_char;
    79             current_pos++)
    80         {
    81             str[current_pos] = ch;
    82             if(current_pos >= size - 2)
    83             {
    84                 current_pos++;
    85                 break;
    86             }
    87             ch = SDLVisualTest_RWHelperReadChar(rw, buffer);
    88         }
    89 
    90         done = 1;
    91         if(ch == comment_char) /* discard all characters until the next line */
    92         {
    93             do
    94             {
    95                 ch = SDLVisualTest_RWHelperReadChar(rw, buffer);
    96             }while(ch && ch != '\n' && ch != '\r');
    97 
    98             if(current_pos == 0)
    99                 done = 0;
   100         }
   101     }
   102     if(current_pos == 0)
   103         return NULL;
   104 
   105     str[current_pos] = '\0';
   106     return str;
   107 }
   108 
   109 /* Lines with all whitespace are ignored */
   110 int
   111 SDLVisualTest_RWHelperCountNonEmptyLines(SDL_RWops* rw,
   112                                          SDLVisualTest_RWHelperBuffer* buffer,
   113                                          char comment_char)
   114 {
   115     int num_lines = 0;
   116     char str[MAX_SUTOPTION_LINE_LENGTH];
   117     if(!rw)
   118     {
   119         SDLTest_LogError("rw argument cannot be NULL");
   120         return -1;
   121     }
   122     if(!buffer)
   123     {
   124         SDLTest_LogError("buffer argument cannot be NULL");
   125         return -1;
   126     }
   127     while(SDLVisualTest_RWHelperReadLine(rw, str, MAX_SUTOPTION_LINE_LENGTH,
   128                                          buffer, comment_char))
   129         num_lines++;
   130     return num_lines;
   131 }