src/dynapi/gendynapi.pl
author Sam Lantinga <slouken@libsdl.org>
Wed, 18 Oct 2017 08:52:04 -0700
changeset 11630 ad4b5d85edee
parent 10737 3406a0f8b041
child 11811 5d94cb6b24d3
permissions -rwxr-xr-x
Fixed bug 3821 - Allow SDL_CreateWindow and SDL_CreateRenderer with OpenGL ES 3.0 (GLES3) for Angle (Windows)

Carlos

Angle supports GLES3 but when using these functions (SDL_CreateWindow and SDL_CreateRenderer), defaults again to GLES2.0.

A current workaround (hack) to retrieve a GLES3.0 context with Angle is:

1) set

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

after InitSDL AND after calling SDL_CreateWindow (before SDL_CreateRenderer)

2) Comment lines 2032-2044 in SDL_render_gles2.c, funtion GLES2_CreateRenderer

window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL) ||
profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {

changed_window = SDL_TRUE;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);

if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
goto error;
}
}

This retrives a GLES3 context as confirmed using glGetString(GL_VERSION). This should be fixed by modifying a few if's.
icculus@8094
     1
#!/usr/bin/perl -w
icculus@8094
     2
icculus@8094
     3
#  Simple DirectMedia Layer
slouken@10737
     4
#  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
icculus@8094
     5
#
icculus@8094
     6
#  This software is provided 'as-is', without any express or implied
icculus@8094
     7
#  warranty.  In no event will the authors be held liable for any damages
icculus@8094
     8
#  arising from the use of this software.
icculus@8094
     9
#
icculus@8094
    10
#  Permission is granted to anyone to use this software for any purpose,
icculus@8094
    11
#  including commercial applications, and to alter it and redistribute it
icculus@8094
    12
#  freely, subject to the following restrictions:
icculus@8094
    13
#
icculus@8094
    14
#  1. The origin of this software must not be misrepresented; you must not
icculus@8094
    15
#     claim that you wrote the original software. If you use this software
icculus@8094
    16
#     in a product, an acknowledgment in the product documentation would be
icculus@8094
    17
#     appreciated but is not required.
icculus@8094
    18
#  2. Altered source versions must be plainly marked as such, and must not be
icculus@8094
    19
#     misrepresented as being the original software.
icculus@8094
    20
#  3. This notice may not be removed or altered from any source distribution.
icculus@8094
    21
icculus@8094
    22
# WHAT IS THIS?
icculus@8094
    23
#  When you add a public API to SDL, please run this script, make sure the
icculus@8094
    24
#  output looks sane (hg diff, it adds to existing files), and commit it.
icculus@8094
    25
#  It keeps the dynamic API jump table operating correctly.
icculus@8094
    26
icculus@8094
    27
# If you wanted this to be readable, you shouldn't have used perl.
icculus@8094
    28
icculus@8094
    29
use warnings;
icculus@8094
    30
use strict;
icculus@8094
    31
use File::Basename;
icculus@8094
    32
icculus@8094
    33
chdir(dirname(__FILE__) . '/../..');
icculus@8094
    34
my $sdl_dynapi_procs_h = "src/dynapi/SDL_dynapi_procs.h";
icculus@8094
    35
my $sdl_dynapi_overrides_h = "src/dynapi/SDL_dynapi_overrides.h";
icculus@8094
    36
icculus@8094
    37
my %existing = ();
icculus@8094
    38
if (-f $sdl_dynapi_procs_h) {
icculus@8094
    39
    open(SDL_DYNAPI_PROCS_H, '<', $sdl_dynapi_procs_h) or die("Can't open $sdl_dynapi_procs_h: $!\n");
icculus@8094
    40
    while (<SDL_DYNAPI_PROCS_H>) {
icculus@8094
    41
        if (/\ASDL_DYNAPI_PROC\(.*?,(.*?),/) {
icculus@8094
    42
            $existing{$1} = 1;
icculus@8094
    43
        }
icculus@8094
    44
    }
icculus@8094
    45
    close(SDL_DYNAPI_PROCS_H)
icculus@8094
    46
}
icculus@8094
    47
icculus@8094
    48
open(SDL_DYNAPI_PROCS_H, '>>', $sdl_dynapi_procs_h) or die("Can't open $sdl_dynapi_procs_h: $!\n");
icculus@8094
    49
open(SDL_DYNAPI_OVERRIDES_H, '>>', $sdl_dynapi_overrides_h) or die("Can't open $sdl_dynapi_overrides_h: $!\n");
icculus@8094
    50
icculus@8094
    51
opendir(HEADERS, 'include') or die("Can't open include dir: $!\n");
icculus@8094
    52
while (readdir(HEADERS)) {
icculus@8094
    53
    next if not /\.h\Z/;
icculus@8094
    54
    my $header = "include/$_";
icculus@8094
    55
    open(HEADER, '<', $header) or die("Can't open $header: $!\n");
icculus@8094
    56
    while (<HEADER>) {
icculus@8094
    57
        chomp;
icculus@8094
    58
        next if not /\A\s*extern\s+DECLSPEC/;
icculus@8094
    59
        my $decl = "$_ ";
icculus@8094
    60
        if (not $decl =~ /\)\s*;/) {
icculus@8094
    61
            while (<HEADER>) {
icculus@8094
    62
                chomp;
icculus@8094
    63
                s/\A\s+//;
icculus@8094
    64
                s/\s+\Z//;
icculus@8094
    65
                $decl .= "$_ ";
icculus@8094
    66
                last if /\)\s*;/;
icculus@8094
    67
            }
icculus@8094
    68
        }
icculus@8094
    69
icculus@8094
    70
        $decl =~ s/\s+\Z//;
icculus@8094
    71
        #print("DECL: [$decl]\n");
icculus@8094
    72
icculus@8094
    73
        if ($decl =~ /\A\s*extern\s+DECLSPEC\s+(const\s+|)(unsigned\s+|)(.*?)\s*(\*?)\s*SDLCALL\s+(.*?)\s*\((.*?)\);/) {
icculus@8094
    74
            my $rc = "$1$2$3$4";
icculus@8094
    75
            my $fn = $5;
icculus@8094
    76
icculus@8094
    77
            next if $existing{$fn};   # already slotted into the jump table.
icculus@8094
    78
icculus@8094
    79
            my @params = split(',', $6);
icculus@8094
    80
icculus@8094
    81
            #print("rc == '$rc', fn == '$fn', params == '$params'\n");
icculus@8094
    82
icculus@8094
    83
            my $retstr = ($rc eq 'void') ? '' : 'return';
icculus@8094
    84
            my $paramstr = '(';
icculus@8094
    85
            my $argstr = '(';
icculus@8094
    86
            my $i = 0;
icculus@8094
    87
            foreach (@params) {
icculus@8094
    88
                my $str = $_;
icculus@8094
    89
                $str =~ s/\A\s+//;
icculus@8094
    90
                $str =~ s/\s+\Z//;
icculus@8094
    91
                #print("1PARAM: $str\n");
icculus@8094
    92
                if ($str eq 'void') {
icculus@8094
    93
                    $paramstr .= 'void';
icculus@8094
    94
                } elsif ($str eq '...') {
icculus@8094
    95
                    if ($i > 0) {
icculus@8094
    96
                        $paramstr .= ', ';
icculus@8094
    97
                    }
icculus@8094
    98
                    $paramstr .= $str;
icculus@8094
    99
                } elsif ($str =~ /\A\s*((const\s+|)(unsigned\s+|)([a-zA-Z0-9_]*)\s*([\*\s]*))\s*(.*?)\Z/) {
icculus@8094
   100
                    #print("PARSED: [$1], [$2], [$3], [$4], [$5]\n");
icculus@8094
   101
                    my $type = $1;
icculus@8094
   102
                    my $var = $6;
icculus@8094
   103
                    $type =~ s/\A\s+//;
icculus@8094
   104
                    $type =~ s/\s+\Z//;
icculus@8094
   105
                    $var =~ s/\A\s+//;
icculus@8094
   106
                    $var =~ s/\s+\Z//;
icculus@8094
   107
                    $type =~ s/\s*\*\Z/*/g;
icculus@8094
   108
                    $type =~ s/\s*(\*+)\Z/ $1/;
icculus@8094
   109
                    #print("SPLIT: ($type, $var)\n");
icculus@8094
   110
                    my $name = chr(ord('a') + $i);
icculus@8094
   111
                    if ($i > 0) {
icculus@8094
   112
                        $paramstr .= ', ';
icculus@8094
   113
                        $argstr .= ',';
icculus@8094
   114
                    }
icculus@8094
   115
                    my $spc = ($type =~ /\*\Z/) ? '' : ' ';
icculus@8094
   116
                    $paramstr .= "$type$spc$name";
icculus@8094
   117
                    $argstr .= "$name";
icculus@8094
   118
                }
icculus@8094
   119
                $i++;
icculus@8094
   120
            }
icculus@8094
   121
icculus@8094
   122
            $paramstr = '(void' if ($i == 0);  # Just to make this consistent.
icculus@8094
   123
icculus@8094
   124
            $paramstr .= ')';
icculus@8094
   125
            $argstr .= ')';
icculus@8094
   126
icculus@8094
   127
            print("NEW: $decl\n");
icculus@8094
   128
            print SDL_DYNAPI_PROCS_H "SDL_DYNAPI_PROC($rc,$fn,$paramstr,$argstr,$retstr)\n";
icculus@8094
   129
            print SDL_DYNAPI_OVERRIDES_H "#define $fn ${fn}_REAL\n";
icculus@8094
   130
        } else {
icculus@8094
   131
            print("Failed to parse decl [$decl]!\n");
icculus@8094
   132
        }
icculus@8094
   133
    }
icculus@8094
   134
    close(HEADER);
icculus@8094
   135
}
icculus@8094
   136
closedir(HEADERS);
icculus@8094
   137
icculus@8094
   138
close(SDL_DYNAPI_PROCS_H);
icculus@8094
   139
close(SDL_DYNAPI_OVERRIDES_H);
icculus@8094
   140
icculus@8094
   141
# vi: set ts=4 sw=4 expandtab: