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)
void * | glGetProcAddress (_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 |
  window | The 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.

References context, and SDL_Window::driverdata.

Referenced by createDevice().

{
window_impl_t *impl = (window_impl_t *)window->driverdata;
EGLContext context;
EGLSurface surface;
struct {
EGLint client_version[2];
EGLint none;
} egl_ctx_attr = {
.client_version = { EGL_CONTEXT_CLIENT_VERSION, 2 },
.none = EGL_NONE
};
struct {
EGLint render_buffer[2];
EGLint none;
} egl_surf_attr = {
.render_buffer = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER },
.none = EGL_NONE
};
context = eglCreateContext(egl_disp, impl->conf, EGL_NO_CONTEXT,
(EGLint *)&egl_ctx_attr);
if (context == EGL_NO_CONTEXT) {
return NULL;
}
surface = eglCreateWindowSurface(egl_disp, impl->conf, impl->window,
(EGLint *)&egl_surf_attr);
if (surface == EGL_NO_SURFACE) {
return NULL;
}
eglMakeCurrent(egl_disp, surface, surface, context);
impl->surface = surface;
return context;
}
EGLSurface
void * EGLSurface
Definition: egl.h:59
eglCreateWindowSurface
EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
eglMakeCurrent
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
EGL_NO_SURFACE
#define EGL_NO_SURFACE
Definition: egl.h:100
surface
EGLSurface surface
Definition: eglext.h:248
context
static screen_context_t context
Definition: video.c:25
EGL_NONE
#define EGL_NONE
Definition: egl.h:95
EGL_RENDER_BUFFER
#define EGL_RENDER_BUFFER
Definition: egl.h:196
EGLContext
void * EGLContext
Definition: egl.h:60
EGL_NO_CONTEXT
#define EGL_NO_CONTEXT
Definition: egl.h:98
EGL_CONTEXT_CLIENT_VERSION
#define EGL_CONTEXT_CLIENT_VERSION
Definition: egl.h:212
window_impl_t
Definition: sdl_qnx.h:29
EGLint
khronos_int32_t EGLint
Definition: eglplatform.h:122
NULL
#define NULL
Definition: begin_code.h:164
egl_disp
static EGLDisplay egl_disp
Definition: gl.c:25
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:111
EGL_BACK_BUFFER
#define EGL_BACK_BUFFER
Definition: egl.h:149
eglCreateContext
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)

## glDeleteContext()

void glDeleteContext | ( | _THIS | ,
|  | SDL_GLContext | context
| ) |  |

Destroys a context.

Parameters

  _THIS |
  context | The context to destroy

Definition at line 272 of file gl.c.

References egl_disp, and eglDestroyContext().

Referenced by createDevice().

{
eglDestroyContext(egl_disp, context);
}
context
static screen_context_t context
Definition: video.c:25
eglDestroyContext
EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
egl_disp
static EGLDisplay egl_disp
Definition: gl.c:25

## glGetConfig()

int glGetConfig | ( | EGLConfig * | pconf,
|  | int * | pformat
| ) |  |

Enumerates the supported EGL configurations and chooses a suitable one.

Parameters

  [out] | pconf | The chosen configuration
  [out] | pformat | The chosen pixel format

Returns
  0 if successful, -1 on error

Definition at line 68 of file gl.c.

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().

{
EGLConfig egl_conf = (EGLConfig)0;
EGLConfig *egl_configs;
EGLint egl_num_configs;
EGLint val;
EGLBoolean rc;
EGLint i;
// Determine the numbfer of configurations.
rc = eglGetConfigs(egl_disp, NULL, 0, &egl_num_configs);
if (rc != EGL_TRUE) {
return -1;
}
if (egl_num_configs == 0) {
return -1;
}
// Allocate enough memory for all configurations.
egl_configs = malloc(egl_num_configs * sizeof(*egl_configs));
if (egl_configs == NULL) {
return -1;
}
// Get the list of configurations.
rc = eglGetConfigs(egl_disp, egl_configs, egl_num_configs,
&egl_num_configs);
if (rc != EGL_TRUE) {
free(egl_configs);
return -1;
}
// Find a good configuration.
for (i = 0; i < egl_num_configs; i++) {
eglGetConfigAttrib(egl_disp, egl_configs[i], EGL_SURFACE_TYPE, &val);
if (!(val & EGL_WINDOW_BIT)) {
continue;
}
eglGetConfigAttrib(egl_disp, egl_configs[i], EGL_RENDERABLE_TYPE, &val);
if (!(val & EGL_OPENGL_ES2_BIT)) {
continue;
}
eglGetConfigAttrib(egl_disp, egl_configs[i], EGL_DEPTH_SIZE, &val);
if (val == 0) {
continue;
}
egl_conf = egl_configs[i];
break;
}
free(egl_configs);
*pconf = egl_conf;
*pformat = chooseFormat(egl_conf);
return 0;
}
EGL_WINDOW_BIT
#define EGL_WINDOW_BIT
Definition: egl.h:120
EGLConfig
void * EGLConfig
Definition: egl.h:58
EGL_SURFACE_TYPE
#define EGL_SURFACE_TYPE
Definition: egl.h:110
free
SDL_EventEntry * free
Definition: SDL_events.c:84
chooseFormat
static int chooseFormat(EGLConfig egl_conf)
Definition: gl.c:34
eglGetConfigAttrib
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
EGL_TRUE
#define EGL_TRUE
Definition: egl.h:116
EGLBoolean
unsigned int EGLBoolean
Definition: egl.h:54
val
GLuint GLfloat * val
Definition: SDL_opengl_glext.h:1492
EGLint
khronos_int32_t EGLint
Definition: eglplatform.h:122
eglGetConfigs
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
EGL_DEPTH_SIZE
#define EGL_DEPTH_SIZE
Definition: egl.h:80
i
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
NULL
#define NULL
Definition: begin_code.h:164
egl_disp
static EGLDisplay egl_disp
Definition: gl.c:25
EGL_RENDERABLE_TYPE
#define EGL_RENDERABLE_TYPE
Definition: egl.h:195
malloc
#define malloc
Definition: SDL_qsort.c:47
EGL_OPENGL_ES2_BIT
#define EGL_OPENGL_ES2_BIT
Definition: egl.h:214

## glGetProcAddress()

void* glGetProcAddress | ( | _THIS | ,
|  | const char * | proc
| ) |  |

Finds the address of an EGL extension function.

Parameters

  proc | Function name

Returns
  Function address

Definition at line 158 of file gl.c.

References eglGetProcAddress().

Referenced by createDevice().

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

## glLoadLibrary()

int glLoadLibrary | ( | _THIS | ,
|  | const char * | name
| ) |  |

Initializes the EGL library.

Parameters

  _THIS |
  name | unused

Returns
  0 if successful, -1 on error

Definition at line 136 of file gl.c.

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

Referenced by createDevice().

{
EGLNativeDisplayType disp_id = EGL_DEFAULT_DISPLAY;
egl_disp = eglGetDisplay(disp_id);
if (egl_disp == EGL_NO_DISPLAY) {
return -1;
}
if (eglInitialize(egl_disp, NULL, NULL) == EGL_FALSE) {
return -1;
}
return 0;
}
EGLNativeDisplayType
HDC EGLNativeDisplayType
Definition: eglplatform.h:76
EGL_NO_DISPLAY
#define EGL_NO_DISPLAY
Definition: egl.h:99
EGL_DEFAULT_DISPLAY
#define EGL_DEFAULT_DISPLAY
Definition: egl.h:227
EGL_FALSE
#define EGL_FALSE
Definition: egl.h:84
NULL
#define NULL
Definition: begin_code.h:164
eglGetDisplay
EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
egl_disp
static EGLDisplay egl_disp
Definition: gl.c:25
eglInitialize
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)

## glMakeCurrent()

int glMakeCurrent | ( | _THIS | ,
|  | SDL_Window * | window,
|  | SDL_GLContext | context
| ) |  |

Makes the given context the current one for drawing operations.

Parameters

  _THIS |
  window | SDL window associated with the context (maybe NULL)
  context | The context to activate

Returns
  0 if successful, -1 on error

Definition at line 249 of file gl.c.

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

Referenced by createDevice().

{
window_impl_t *impl;
EGLSurface surface = NULL;
if (window) {
impl = (window_impl_t *)window->driverdata;
surface = impl->surface;
}
if (eglMakeCurrent(egl_disp, surface, surface, context) != EGL_TRUE) {
return -1;
}
return 0;
}
EGLSurface
void * EGLSurface
Definition: egl.h:59
eglMakeCurrent
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
surface
EGLSurface surface
Definition: eglext.h:248
context
static screen_context_t context
Definition: video.c:25
EGL_TRUE
#define EGL_TRUE
Definition: egl.h:116
window_impl_t::surface
EGLSurface surface
Definition: sdl_qnx.h:32
window_impl_t
Definition: sdl_qnx.h:29
NULL
#define NULL
Definition: begin_code.h:164
egl_disp
static EGLDisplay egl_disp
Definition: gl.c:25
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:111

## glSetSwapInterval()

int glSetSwapInterval | ( | _THIS | ,
|  | int | interval
| ) |  |

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

Parameters

  _THIS |
  interval | New interval value

Returns
  0 if successful, -1 on error

Definition at line 218 of file gl.c.

References egl_disp, EGL_TRUE, and eglSwapInterval().

Referenced by createDevice().

{
if (eglSwapInterval(egl_disp, interval) != EGL_TRUE) {
return -1;
}
return 0;
}
EGL_TRUE
#define EGL_TRUE
Definition: egl.h:116
egl_disp
static EGLDisplay egl_disp
Definition: gl.c:25
eglSwapInterval
EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval)

## glSwapWindow()

int glSwapWindow | ( | _THIS | ,
|  | SDL_Window * | window
| ) |  |

Swaps the EGL buffers associated with the given window

Parameters

  _THIS |
  window | Window to swap buffers for

Returns
  0 if successful, -1 on error

Definition at line 234 of file gl.c.

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

Referenced by createDevice().

{
/* !!! FIXME: should we migrate this all over to use SDL_egl.c? */
window_impl_t *impl = (window_impl_t *)window->driverdata;
return eglSwapBuffers(egl_disp, impl->surface) == EGL_TRUE ? 0 : -1;
}
EGL_TRUE
#define EGL_TRUE
Definition: egl.h:116
window_impl_t::surface
EGLSurface surface
Definition: sdl_qnx.h:32
window_impl_t
Definition: sdl_qnx.h:29
eglSwapBuffers
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
egl_disp
static EGLDisplay egl_disp
Definition: gl.c:25
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:111

## glUnloadLibrary()

void glUnloadLibrary | ( | _THIS |  | ) |

Terminates access to the EGL library.

Parameters

  _THIS |

Definition at line 282 of file gl.c.

References egl_disp, and eglTerminate().

Referenced by createDevice().

{
eglTerminate(egl_disp);
}
eglTerminate
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
egl_disp
static EGLDisplay egl_disp
Definition: gl.c:25

## 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

  event | Screen keyboard event

Definition at line 99 of file keyboard.c.

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

Referenced by pumpEvents().

{
int val;
SDL_Scancode scancode;
// Get the key value.
if (screen_get_event_property_iv(event, SCREEN_PROPERTY_SYM, &val) < 0) {
return;
}
// Skip unrecognized keys.
if ((val < 0) || (val >= SDL_TABLESIZE(key_to_sdl))) {
return;
}
// Translate to an SDL scan code.
scancode = key_to_sdl[val];
if (scancode == 0) {
return;
}
// Get event flags (key state).
if (screen_get_event_property_iv(event, SCREEN_PROPERTY_FLAGS, &val) < 0) {
return;
}
// Propagate the event to SDL.
// FIXME:
// Need to handle more key states (such as key combinations).
if (val & KEY_DOWN) {
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
} else {
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
}
}
key_to_sdl
static int key_to_sdl[]
Definition: keyboard.c:33
SDL_SendKeyboardKey
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
val
GLuint GLfloat * val
Definition: SDL_opengl_glext.h:1492
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_TABLESIZE
#define SDL_TABLESIZE(table)
Definition: SDL_stdinc.h:94
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
SDL_Scancode
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:43