SDL 2.0
sdl_qnx.h File Reference
#include "../SDL_sysvideo.h"
#include <screen/screen.h>
#include <EGL/egl.h>
+ Include dependency graph for sdl_qnx.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  window_impl_t
 

Functions

void handleKeyboardEvent (screen_event_t event)
 
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)
 

Function Documentation

◆ 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
khronos_int32_t EGLint
Definition: eglplatform.h:122
static EGLDisplay egl_disp
Definition: gl.c:25
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
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
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().

◆ handleKeyboardEvent()

void handleKeyboardEvent ( screen_event_t  event)

Called from the event dispatcher when a keyboard event is encountered. Translates the event such that it can be handled by SDL.

Parameters
eventScreen keyboard event

Definition at line 99 of file keyboard.c.

100{
101 int val;
102 SDL_Scancode scancode;
103
104 // Get the key value.
105 if (screen_get_event_property_iv(event, SCREEN_PROPERTY_SYM, &val) < 0) {
106 return;
107 }
108
109 // Skip unrecognized keys.
110 if ((val < 0) || (val >= SDL_TABLESIZE(key_to_sdl))) {
111 return;
112 }
113
114 // Translate to an SDL scan code.
115 scancode = key_to_sdl[val];
116 if (scancode == 0) {
117 return;
118 }
119
120 // Get event flags (key state).
121 if (screen_get_event_property_iv(event, SCREEN_PROPERTY_FLAGS, &val) < 0) {
122 return;
123 }
124
125 // Propagate the event to SDL.
126 // FIXME:
127 // Need to handle more key states (such as key combinations).
128 if (val & KEY_DOWN) {
130 } else {
132 }
133}
#define SDL_RELEASED
Definition: SDL_events.h:49
#define SDL_PRESSED
Definition: SDL_events.h:50
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
struct _cl_event * event
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:44
#define SDL_TABLESIZE(table)
Definition: SDL_stdinc.h:116
static int key_to_sdl[]
Definition: keyboard.c:33

References key_to_sdl, SDL_PRESSED, SDL_RELEASED, SDL_SendKeyboardKey(), and SDL_TABLESIZE.

Referenced by pumpEvents().