visualtest/src/variator_random.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 variator_random.c
     4  *
     5  * Source file for the variator that tests the SUT with random variations to the
     6  * input parameters.
     7  */
     8 
     9 #include <time.h>
    10 #include <SDL_test.h>
    11 #include "SDL_visualtest_random_variator.h"
    12 
    13 int
    14 SDLVisualTest_InitRandomVariator(SDLVisualTest_RandomVariator* variator,
    15                                  SDLVisualTest_SUTConfig* config, Uint64 seed)
    16 {
    17     if(!variator)
    18     {
    19         SDLTest_LogError("variator argument cannot be NULL");
    20         return 0;
    21     }
    22     if(!config)
    23     {
    24         SDLTest_LogError("config argument cannot be NULL");
    25         return 0;
    26     }
    27 
    28     if(seed)
    29         SDLTest_FuzzerInit(seed);
    30     else
    31         SDLTest_FuzzerInit(time(NULL));
    32 
    33     variator->config = *config;
    34 
    35     if(!SDLVisualTest_InitVariation(&variator->variation, &variator->config))
    36     {
    37         SDLTest_LogError("SDLVisualTest_InitVariation() failed");
    38         return 0;
    39     }
    40 
    41     return 1;
    42 }
    43 
    44 char*
    45 SDLVisualTest_GetNextRandomVariation(SDLVisualTest_RandomVariator* variator)
    46 {
    47     SDLVisualTest_SUTOptionValue* vars;
    48     SDLVisualTest_SUTOption* options;
    49     int i;
    50     if(!variator)
    51     {
    52         SDLTest_LogError("variator argument cannot be NULL");
    53         return NULL;
    54     }
    55  
    56     /* to save typing */
    57     vars = variator->variation.vars;
    58     options = variator->config.options;
    59 
    60     /* generate a random variation */
    61     for(i = 0; i < variator->variation.num_vars; i++)
    62     {
    63         switch(options[i].type)
    64         {
    65             case SDL_SUT_OPTIONTYPE_BOOL:
    66                 vars[i].bool_value = SDLTest_RandomIntegerInRange(0, 1) ? SDL_FALSE :
    67                                                                           SDL_TRUE;
    68             break;
    69 
    70             case SDL_SUT_OPTIONTYPE_ENUM:
    71             {
    72                 int emx = 0;
    73                 while(options[i].data.enum_values[emx])
    74                     emx++;
    75                 vars[i].enumerated.index = SDLTest_RandomIntegerInRange(0, emx - 1);
    76             }
    77             break;
    78             
    79             case SDL_SUT_OPTIONTYPE_INT:
    80                 vars[i].integer.value = SDLTest_RandomIntegerInRange(
    81                                         options[i].data.range.min,
    82                                         options[i].data.range.max);
    83             break;
    84 
    85             case SDL_SUT_OPTIONTYPE_STRING:
    86                 // String values are left unchanged
    87             break;
    88         }
    89     }
    90 
    91     /* convert variation to an arguments string */
    92     if(!SDLVisualTest_MakeStrFromVariation(&variator->variation, &variator->config,
    93                                            variator->buffer, MAX_SUT_ARGS_LEN))
    94     {
    95         SDLTest_LogError("SDLVisualTest_MakeStrFromVariation() failed");
    96         return NULL;
    97     }
    98 
    99     return variator->buffer;
   100 }
   101 
   102 void SDLVisualTest_FreeRandomVariator(SDLVisualTest_RandomVariator* variator)
   103 {
   104     if(!variator)
   105     {
   106         SDLTest_LogError("variator argument cannot be NULL");
   107         return;
   108     }
   109     SDL_free(variator->variation.vars);
   110     variator->variation.vars = NULL;
   111 }