Graphic-Context

Abstracts the os specific way to create an OpenGL graphic context.

Uses lower level of abstractions like eglcontext_t in case of EGL adapting OpenGL to the local windowing system.

Summary
Graphic-ContextAbstracts the os specific way to create an OpenGL graphic context.
CopyrightThis program is free software.
Files
C-kern/api/graphic/gcontext.hHeader file Graphic-Context.
C-kern/graphic/gcontext.cImplementation file Graphic-Context impl.
Types
struct gcontext_tExport gcontext_t into global namespace.
Enumerations
gcontext_api_eDetermines the rendering API the graphic context supports and the client is using for drawing calls.
Functions
test
unittest_graphic_gcontextTest gcontext_t functionality.
gcontext_tWraps the native implementation of an OpenGL context.
lifetime
gcontext_FREEStatic initializer.
init_gcontextCreates a new native OpenGL graphic context.
free_gcontextFrees graphic context cont and associated resources (frame buffers).
query
gl_gcontextReturns the native OpenGL context.
api_gcontextReturns in api the client rendering API cont supports.
configid_gcontextReturns id of the configuration cont in configid used during context creation.
current_gcontextReturns the current native OpenGL context and associated native resources.
update
setcurrent_gcontextSetzt den aktuellen OpenGL Kontext für diesen Thread auf cont.
releasecurrent_gcontextDer Verbindung des Threads mit dem aktuellen Kontextes wird aufgehoben.
inline implementation
gcontext_t
gl_gcontextImplements gcontext_t.gl_gcontext.
api_gcontextImplements gcontext_t.api_gcontext.
configid_gcontextImplements gcontext_t.configid_gcontext.
current_gcontextImplements gcontext_t.current_gcontext.
releasecurrent_gcontextImplements gcontext_t.releasecurrent_gcontext.
setcurrent_gcontextImplements gcontext_t.setcurrent_gcontext.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2014 Jörg Seebohn

Files

C-kern/api/graphic/gcontext.h

Header file Graphic-Context.

C-kern/graphic/gcontext.c

Implementation file Graphic-Context impl.

Types

struct gcontext_t

typedef struct gcontext_t gcontext_t

Export gcontext_t into global namespace.

Enumerations

gcontext_api_e

Determines the rendering API the graphic context supports and the client is using for drawing calls.

gcontext_api_OPENGLESThe client uses api OpenGL ES for drawing.  The default version is 2.  The version can be configured during creation of eglcontext_t.
gcontext_api_OPENVGThe client uses api OpenVG for drawing.
gcontext_api_OPENGLThe client uses api OpenGL for drawing.

Functions

Summary

test

unittest_graphic_gcontext

int unittest_graphic_gcontext(void)

Test gcontext_t functionality.

gcontext_t

struct gcontext_t

Wraps the native implementation of an OpenGL context.

Summary
lifetime
gcontext_FREEStatic initializer.
init_gcontextCreates a new native OpenGL graphic context.
free_gcontextFrees graphic context cont and associated resources (frame buffers).
query
gl_gcontextReturns the native OpenGL context.
api_gcontextReturns in api the client rendering API cont supports.
configid_gcontextReturns id of the configuration cont in configid used during context creation.
current_gcontextReturns the current native OpenGL context and associated native resources.
update
setcurrent_gcontextSetzt den aktuellen OpenGL Kontext für diesen Thread auf cont.
releasecurrent_gcontextDer Verbindung des Threads mit dem aktuellen Kontextes wird aufgehoben.

lifetime

gcontext_FREE

#define gcontext_FREE { 0 }

Static initializer.

init_gcontext

int init_gcontext(/*out*/gcontext_t *cont,
struct display_t *disp,
struct gconfig_t *gconf,
uint8_t api)

Creates a new native OpenGL graphic context.  The context supports rendering with a render API determined by api.  Parameter api must be a value from gcontext_api_e.  If eglconf does not support the rendering API EINVAL is returned.  A copy of the pointer disp is stored internally so do not free display_t disp until win has been freed.

free_gcontext

int free_gcontext(gcontext_t *cont,
struct display_t *disp)

Frees graphic context cont and associated resources (frame buffers).  Before freeing you should make sure that this context is not current to any thread.

query

gl_gcontext

struct opengl_context_t * gl_gcontext(const gcontext_t *cont)

Returns the native OpenGL context.

api_gcontext

int api_gcontext(const gcontext_t *cont,
struct display_t *disp,
/*out*/uint8_t *api)

Returns in api the client rendering API cont supports.  See gcontext_api_e for a list of possible values.

configid_gcontext

int configid_gcontext(const gcontext_t *cont,
struct display_t *disp,
/*out*/uint32_t *configid)

Returns id of the configuration cont in configid used during context creation.

current_gcontext

void current_gcontext(/*out*/struct opengl_context_t **cont,
/*out*/struct opengl_display_t **disp,
/*out*/struct opengl_surface_t **drawsurf,
/*out*/struct opengl_surface_t **readsurf)

Returns the current native OpenGL context and associated native resources.  A an out pointer is set to 0 no value is returned.

Bug: This function returns 0 for any out parameter in case the current context uses not API gcontext_api_OPENGLES.

update

setcurrent_gcontext

int setcurrent_gcontext(const gcontext_t cont,
struct display_t *disp,
struct surface_t *drawsurf,
struct surface_t *readsurf)

Setzt den aktuellen OpenGL Kontext für diesen Thread auf cont.  Das aktuelle render API wird auf das von cont unterstützte API umgeschalten.  Gibt EACCES zurück falls cont gerade von einem anderen Thread verwendet wird oder drawsurf bzw. readsurf an einen anderen Kontext gebunden sind.

Argumente drawsurf / readsurf akzeptieren (da als Makro implementiert)

  • Pointer zu window_t
  • Pointer zu <pixelbuffer_t

releasecurrent_gcontext

int releasecurrent_gcontext(struct display_t *disp)

Der Verbindung des Threads mit dem aktuellen Kontextes wird aufgehoben.  Nach erfolgreicher Rückkehr ist der Thread an keinen Graphik-Kontext mehr gebunden.

gcontext_t

gl_gcontext

#define gl_gcontext(cont) ((cont)->glcontext)

Implements gcontext_t.gl_gcontext.

api_gcontext

#define api_gcontext(
   cont,
   disp,
   api
) api_eglcontext(gl_gcontext(cont), gl_display(disp), api)

Implements gcontext_t.api_gcontext.

configid_gcontext

#define configid_gcontext(
   cont,
   disp,
   configid
) configid_eglcontext(gl_gcontext(cont), gl_display(disp), configid)

Implements gcontext_t.configid_gcontext.

current_gcontext

#define current_gcontext(
   cont,
   disp,
   drawsurf,
   readsurf
) current_eglcontext(cont, disp, drawsurf, readsurf)

Implements gcontext_t.current_gcontext.

releasecurrent_gcontext

#define releasecurrent_gcontext(
   disp
) releasecurrent_eglcontext(gl_display(disp))

Implements gcontext_t.releasecurrent_gcontext.

setcurrent_gcontext

#define setcurrent_gcontext(
   cont,
   disp,
   drawsurf,
   readsurf
) setcurrent_eglcontext(gl_gcontext(cont), gl_display(disp), gl_surface(drawsurf), gl_surface(readsurf))

Implements gcontext_t.setcurrent_gcontext.

Abstracts the os specific way to create an OpenGL graphic context.
Implements Graphic-Context.
typedef struct gcontext_t gcontext_t
Export gcontext_t into global namespace.
struct gcontext_t
Wraps the native implementation of an OpenGL context.
int unittest_graphic_gcontext(void)
Test gcontext_t functionality.
#define gcontext_FREE { 0 }
Static initializer.
int init_gcontext(/*out*/gcontext_t *cont,
struct display_t *disp,
struct gconfig_t *gconf,
uint8_t api)
Creates a new native OpenGL graphic context.
int free_gcontext(gcontext_t *cont,
struct display_t *disp)
Frees graphic context cont and associated resources (frame buffers).
struct opengl_context_t * gl_gcontext(const gcontext_t *cont)
Returns the native OpenGL context.
int api_gcontext(const gcontext_t *cont,
struct display_t *disp,
/*out*/uint8_t *api)
Returns in api the client rendering API cont supports.
int configid_gcontext(const gcontext_t *cont,
struct display_t *disp,
/*out*/uint32_t *configid)
Returns id of the configuration cont in configid used during context creation.
void current_gcontext(/*out*/struct opengl_context_t **cont,
/*out*/struct opengl_display_t **disp,
/*out*/struct opengl_surface_t **drawsurf,
/*out*/struct opengl_surface_t **readsurf)
Returns the current native OpenGL context and associated native resources.
int setcurrent_gcontext(const gcontext_t cont,
struct display_t *disp,
struct surface_t *drawsurf,
struct surface_t *readsurf)
Setzt den aktuellen OpenGL Kontext für diesen Thread auf cont.
int releasecurrent_gcontext(struct display_t *disp)
Der Verbindung des Threads mit dem aktuellen Kontextes wird aufgehoben.
#define gl_gcontext(cont) ((cont)->glcontext)
Implements gcontext_t.gl_gcontext.
#define api_gcontext(
   cont,
   disp,
   api
) api_eglcontext(gl_gcontext(cont), gl_display(disp), api)
Implements gcontext_t.api_gcontext.
#define configid_gcontext(
   cont,
   disp,
   configid
) configid_eglcontext(gl_gcontext(cont), gl_display(disp), configid)
Implements gcontext_t.configid_gcontext.
#define current_gcontext(
   cont,
   disp,
   drawsurf,
   readsurf
) current_eglcontext(cont, disp, drawsurf, readsurf)
Implements gcontext_t.current_gcontext.
#define releasecurrent_gcontext(
   disp
) releasecurrent_eglcontext(gl_display(disp))
Implements gcontext_t.releasecurrent_gcontext.
#define setcurrent_gcontext(
   cont,
   disp,
   drawsurf,
   readsurf
) setcurrent_eglcontext(gl_gcontext(cont), gl_display(disp), gl_surface(drawsurf), gl_surface(readsurf))
Implements gcontext_t.setcurrent_gcontext.
typedef opengl_context_t * eglcontext_t
Points to an OpenGL graphics context.
Determines the rendering API the graphic context supports and the client is using for drawing calls.
struct display_t
Wraps the OS specific graphics display.
The client uses api OpenGL ES for drawing.
Close