SDL 2.0
gl.c File Reference
#include "../../SDL_internal.h"
#include "sdl_qnx.h"
+ Include dependency graph for gl.c:

Go to the source code of this file.

Functions

static int chooseFormat (EGLConfig egl_conf)
 
int glGetConfig (EGLConfig *pconf, int *pformat)
 
int glLoadLibrary (_THIS, const char *name)
 
voidglGetProcAddress (_THIS, const char *proc)
 
SDL_GLContext glCreateContext (_THIS, SDL_Window *window)
 
int glSetSwapInterval (_THIS, int interval)
 
int glSwapWindow (_THIS, SDL_Window *window)
 
int glMakeCurrent (_THIS, SDL_Window *window, SDL_GLContext context)
 
void glDeleteContext (_THIS, SDL_GLContext context)
 
void glUnloadLibrary (_THIS)
 

Variables

static EGLDisplay egl_disp
 

Function Documentation

◆ chooseFormat()

static int chooseFormat ( EGLConfig  egl_conf)
static

Detertmines the pixel format to use based on the current display and EGL configuration.

Parameters
egl_confEGL configuration to use
Returns
A SCREEN_FORMAT* constant for the pixel format to use

Definition at line 34 of file gl.c.

35{
36 EGLint buffer_bit_depth;
37 EGLint alpha_bit_depth;
38
39 eglGetConfigAttrib(egl_disp, egl_conf, EGL_BUFFER_SIZE, &buffer_bit_depth);
40 eglGetConfigAttrib(egl_disp, egl_conf, EGL_ALPHA_SIZE, &alpha_bit_depth);
41
42 switch (buffer_bit_depth) {
43 case 32:
44 return SCREEN_FORMAT_RGBX8888;
45 case 24:
46 return SCREEN_FORMAT_RGB888;
47 case 16:
48 switch (alpha_bit_depth) {
49 case 4:
50 return SCREEN_FORMAT_RGBX4444;
51 case 1:
52 return SCREEN_FORMAT_RGBA5551;
53 default:
54 return SCREEN_FORMAT_RGB565;
55 }
56 default:
57 return 0;
58 }
59}
#define EGL_ALPHA_SIZE
Definition: egl.h:62
#define EGL_BUFFER_SIZE
Definition: egl.h:76
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
khronos_int32_t EGLint
Definition: eglplatform.h:122
static EGLDisplay egl_disp
Definition: gl.c:25

References EGL_ALPHA_SIZE, EGL_BUFFER_SIZE, egl_disp, and eglGetConfigAttrib().

Referenced by glGetConfig().

◆ glCreateContext()

SDL_GLContext glCreateContext ( _THIS  ,
SDL_Window window 
)

Associates the given window with the necessary EGL structures for drawing and displaying content.

Parameters
_THIS
windowThe SDL window to create the context for
Returns
A pointer to the created context, if successful, NULL on error

Definition at line 171 of file gl.c.

172{
173 window_impl_t *impl = (window_impl_t *)window->driverdata;
176
177 struct {
178 EGLint client_version[2];
179 EGLint none;
180 } egl_ctx_attr = {
181 .client_version = { EGL_CONTEXT_CLIENT_VERSION, 2 },
182 .none = EGL_NONE
183 };
184
185 struct {
186 EGLint render_buffer[2];
187 EGLint none;
188 } egl_surf_attr = {
189 .render_buffer = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER },
190 .none = EGL_NONE
191 };
192
194 (EGLint *)&egl_ctx_attr);
195 if (context == EGL_NO_CONTEXT) {
196 return NULL;
197 }
198
199 surface = eglCreateWindowSurface(egl_disp, impl->conf, impl->window,
200 (EGLint *)&egl_surf_attr);
201 if (surface == EGL_NO_SURFACE) {
202 return NULL;
203 }
204
206
207 impl->surface = surface;
208 return context;
209}
#define NULL
Definition: begin_code.h:167
#define EGL_NO_CONTEXT
Definition: egl.h:98
void * EGLContext
Definition: egl.h:60
EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
#define EGL_NONE
Definition: egl.h:95
#define EGL_CONTEXT_CLIENT_VERSION
Definition: egl.h:212
#define EGL_NO_SURFACE
Definition: egl.h:100
#define EGL_BACK_BUFFER
Definition: egl.h:149
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
#define EGL_RENDER_BUFFER
Definition: egl.h:196
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
void * EGLSurface
Definition: egl.h:59
EGLSurface surface
Definition: eglext.h:248
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
static screen_context_t context
Definition: video.c:25

References context.

Referenced by createDevice().

◆ glDeleteContext()

void glDeleteContext ( _THIS  ,
SDL_GLContext  context 
)

Destroys a context.

Parameters
_THIS
contextThe context to destroy

Definition at line 272 of file gl.c.

273{
275}
EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx)

References context, egl_disp, and eglDestroyContext().

Referenced by createDevice().

◆ glGetConfig()

int glGetConfig ( EGLConfig pconf,
int *  pformat 
)

Enumerates the supported EGL configurations and chooses a suitable one.

Parameters
[out]pconfThe chosen configuration
[out]pformatThe chosen pixel format
Returns
0 if successful, -1 on error

Definition at line 68 of file gl.c.

69{
70 EGLConfig egl_conf = (EGLConfig)0;
71 EGLConfig *egl_configs;
72 EGLint egl_num_configs;
73 EGLint val;
74 EGLBoolean rc;
75 EGLint i;
76
77 // Determine the numbfer of configurations.
78 rc = eglGetConfigs(egl_disp, NULL, 0, &egl_num_configs);
79 if (rc != EGL_TRUE) {
80 return -1;
81 }
82
83 if (egl_num_configs == 0) {
84 return -1;
85 }
86
87 // Allocate enough memory for all configurations.
88 egl_configs = malloc(egl_num_configs * sizeof(*egl_configs));
89 if (egl_configs == NULL) {
90 return -1;
91 }
92
93 // Get the list of configurations.
94 rc = eglGetConfigs(egl_disp, egl_configs, egl_num_configs,
95 &egl_num_configs);
96 if (rc != EGL_TRUE) {
97 free(egl_configs);
98 return -1;
99 }
100
101 // Find a good configuration.
102 for (i = 0; i < egl_num_configs; i++) {
104 if (!(val & EGL_WINDOW_BIT)) {
105 continue;
106 }
107
109 if (!(val & EGL_OPENGL_ES2_BIT)) {
110 continue;
111 }
112
114 if (val == 0) {
115 continue;
116 }
117
118 egl_conf = egl_configs[i];
119 break;
120 }
121
122 free(egl_configs);
123 *pconf = egl_conf;
124 *pformat = chooseFormat(egl_conf);
125
126 return 0;
127}
SDL_EventEntry * free
Definition: SDL_events.c:82
GLuint GLfloat * val
#define malloc
Definition: SDL_qsort.c:47
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define EGL_WINDOW_BIT
Definition: egl.h:120
#define EGL_RENDERABLE_TYPE
Definition: egl.h:195
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
void * EGLConfig
Definition: egl.h:58
#define EGL_OPENGL_ES2_BIT
Definition: egl.h:214
unsigned int EGLBoolean
Definition: egl.h:54
#define EGL_SURFACE_TYPE
Definition: egl.h:110
#define EGL_TRUE
Definition: egl.h:116
#define EGL_DEPTH_SIZE
Definition: egl.h:80
static int chooseFormat(EGLConfig egl_conf)
Definition: gl.c:34

References chooseFormat(), EGL_DEPTH_SIZE, egl_disp, EGL_OPENGL_ES2_BIT, EGL_RENDERABLE_TYPE, EGL_SURFACE_TYPE, EGL_TRUE, EGL_WINDOW_BIT, eglGetConfigAttrib(), eglGetConfigs(), free, i, malloc, and NULL.

Referenced by createWindow().

◆ glGetProcAddress()

void * glGetProcAddress ( _THIS  ,
const char *  proc 
)

Finds the address of an EGL extension function.

Parameters
procFunction name
Returns
Function address

Definition at line 158 of file gl.c.

159{
160 return eglGetProcAddress(proc);
161}
EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname)

References eglGetProcAddress().

Referenced by createDevice().

◆ glLoadLibrary()

int glLoadLibrary ( _THIS  ,
const char *  name 
)

Initializes the EGL library.

Parameters
_THIS
nameunused
Returns
0 if successful, -1 on error

Definition at line 136 of file gl.c.

137{
139
140 egl_disp = eglGetDisplay(disp_id);
141 if (egl_disp == EGL_NO_DISPLAY) {
142 return -1;
143 }
144
146 return -1;
147 }
148
149 return 0;
150}
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
#define EGL_FALSE
Definition: egl.h:84
#define EGL_DEFAULT_DISPLAY
Definition: egl.h:227
#define EGL_NO_DISPLAY
Definition: egl.h:99
EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
HDC EGLNativeDisplayType
Definition: eglplatform.h:76

References EGL_DEFAULT_DISPLAY, egl_disp, EGL_FALSE, EGL_NO_DISPLAY, eglGetDisplay(), eglInitialize(), and NULL.

Referenced by createDevice().

◆ glMakeCurrent()

int glMakeCurrent ( _THIS  ,
SDL_Window window,
SDL_GLContext  context 
)

Makes the given context the current one for drawing operations.

Parameters
_THIS
windowSDL window associated with the context (maybe NULL)
contextThe context to activate
Returns
0 if successful, -1 on error

Definition at line 249 of file gl.c.

250{
251 window_impl_t *impl;
253
254 if (window) {
255 impl = (window_impl_t *)window->driverdata;
256 surface = impl->surface;
257 }
258
260 return -1;
261 }
262
263 return 0;
264}
EGLSurface surface
Definition: sdl_qnx.h:32

References context, egl_disp, EGL_TRUE, eglMakeCurrent(), NULL, and window_impl_t::surface.

Referenced by createDevice().

◆ glSetSwapInterval()

int glSetSwapInterval ( _THIS  ,
int  interval 
)

Sets a new value for the number of frames to display before swapping buffers.

Parameters
_THIS
intervalNew interval value
Returns
0 if successful, -1 on error

Definition at line 218 of file gl.c.

219{
220 if (eglSwapInterval(egl_disp, interval) != EGL_TRUE) {
221 return -1;
222 }
223
224 return 0;
225}
EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval)

References egl_disp, EGL_TRUE, and eglSwapInterval().

Referenced by createDevice().

◆ glSwapWindow()

int glSwapWindow ( _THIS  ,
SDL_Window window 
)

Swaps the EGL buffers associated with the given window

Parameters
_THIS
windowWindow to swap buffers for
Returns
0 if successful, -1 on error

Definition at line 234 of file gl.c.

235{
236 /* !!! FIXME: should we migrate this all over to use SDL_egl.c? */
237 window_impl_t *impl = (window_impl_t *)window->driverdata;
238 return eglSwapBuffers(egl_disp, impl->surface) == EGL_TRUE ? 0 : -1;
239}
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)

References egl_disp, EGL_TRUE, eglSwapBuffers(), and window_impl_t::surface.

Referenced by createDevice().

◆ glUnloadLibrary()

void glUnloadLibrary ( _THIS  )

Terminates access to the EGL library.

Parameters
_THIS

Definition at line 282 of file gl.c.

283{
285}
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)

References egl_disp, and eglTerminate().

Referenced by createDevice().

Variable Documentation

◆ egl_disp