Skip to content

Commit

Permalink
add SDL_GL_MakeCurrent(), SDL_GL_GetCurrentWindow(), SDL_GL_GetCurren…
Browse files Browse the repository at this point in the history
…tContext(), see #1
  • Loading branch information
remicollet committed Dec 21, 2013
1 parent 19d9c97 commit c057b65
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 8 deletions.
46 changes: 44 additions & 2 deletions REFLECTION
Expand Up @@ -277,6 +277,23 @@ Extension [ <persistent> extension #16 SDL version 2.0.0-dev ] {
Parameter #0 [ <required> SDL_GLContext $GLcontext ]
}
}
Function [ <internal:SDL> function SDL_GL_MakeCurrent ] {

- Parameters [2] {
Parameter #0 [ <required> SDL_Window $window ]
Parameter #1 [ <optional> SDL_GLContext $context ]
}
}
Function [ <internal:SDL> function SDL_GL_GetCurrentWindow ] {

- Parameters [0] {
}
}
Function [ <internal:SDL> function SDL_GL_GetCurrentContext ] {

- Parameters [0] {
}
}
Function [ <internal:SDL> function SDL_ShowSimpleMessageBox ] {

- Parameters [4] {
Expand Down Expand Up @@ -1398,7 +1415,7 @@ Extension [ <persistent> extension #16 SDL version 2.0.0-dev ] {
- Properties [0] {
}

- Methods [2] {
- Methods [3] {
Method [ <internal:SDL, ctor> public method __construct ] {

- Parameters [1] {
Expand All @@ -1411,6 +1428,12 @@ Extension [ <persistent> extension #16 SDL version 2.0.0-dev ] {
- Parameters [0] {
}
}

Method [ <internal:SDL> public method GL_GetCurrent ] {

- Parameters [0] {
}
}
}
}

Expand Down Expand Up @@ -2477,7 +2500,7 @@ Extension [ <persistent> extension #16 SDL version 2.0.0-dev ] {
- Properties [0] {
}

- Methods [39] {
- Methods [42] {
Method [ <internal:SDL, ctor> public method __construct ] {

- Parameters [6] {
Expand Down Expand Up @@ -2752,6 +2775,25 @@ Extension [ <persistent> extension #16 SDL version 2.0.0-dev ] {
Parameter #2 [ <required> &$blue ]
}
}

Method [ <internal:SDL> public method GL_CreateContext ] {

- Parameters [0] {
}
}

Method [ <internal:SDL> public method GL_MakeCurrent ] {

- Parameters [1] {
Parameter #0 [ <required> SDL_GLContext $context ]
}
}

Method [ <internal:SDL> public method GL_GetCurrent ] {

- Parameters [0] {
}
}
}
}
}
Expand Down
77 changes: 73 additions & 4 deletions glcontext.c
Expand Up @@ -66,7 +66,7 @@ zend_class_entry *get_php_sdl_glcontext_ce(void)
}

/* {{{ sdl_glcontext_to_zval */
zend_bool sdl_glcontext_to_zval(SDL_GLContext glcontext, zval *z_val, Uint32 flags, char *buf TSRMLS_DC)
zend_bool sdl_glcontext_to_zval(SDL_GLContext glcontext, zval *z_val, Uint32 flags TSRMLS_DC)
{
if (glcontext) {
struct php_sdl_glcontext *intern;
Expand Down Expand Up @@ -259,7 +259,7 @@ static PHP_METHOD(SDL_GLContext, __construct)
extern DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window *
window);
*/
static PHP_FUNCTION(SDL_GL_CreateContext)
PHP_FUNCTION(SDL_GL_CreateContext)
{
SDL_GLContext context;
zval *z_window;
Expand All @@ -271,7 +271,7 @@ static PHP_FUNCTION(SDL_GL_CreateContext)
window = zval_to_sdl_window(z_window TSRMLS_CC);
if (window) {
context = SDL_GL_CreateContext(window);
sdl_glcontext_to_zval(context, return_value, 0, NULL TSRMLS_CC);
sdl_glcontext_to_zval(context, return_value, 0 TSRMLS_CC);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid SDL_Window object");
}
Expand All @@ -281,7 +281,7 @@ static PHP_FUNCTION(SDL_GL_CreateContext)

/* {{{ proto void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context)
* \brief Delete an OpenGL context.
* \brief Delete an OpenGL context.
*
* \sa SDL_GL_CreateContext()
extern DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context);
Expand All @@ -303,6 +303,71 @@ static PHP_FUNCTION(SDL_GL_DeleteContext)
/* }}} */


ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GL_MakeCurrent, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0)
ZEND_ARG_OBJ_INFO(0, context, SDL_GLContext, 0)
ZEND_END_ARG_INFO()

/* {{{ proto int SDLCALL SDL_GL_MakeCurrent(SDL_Window window, SDL_GLContext context)
* \brief Set up an OpenGL context for rendering into an OpenGL window.
*
* \note The context must have been created with a compatible window.
extern DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_Window * window,
SDL_GLContext context);
*/
PHP_FUNCTION(SDL_GL_MakeCurrent)
{
struct php_sdl_glcontext *intern;
zval *z_context, *z_window;
SDL_GLContext context;
SDL_Window *window;

if (FAILURE == zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &z_window, get_php_sdl_window_ce(), &z_context, php_sdl_glcontext_ce)) {
return;
}
FETCH_GLCONTEXT(context, z_context, 1);
window = zval_to_sdl_window(z_window TSRMLS_CC);
if (window) {
RETVAL_LONG(SDL_GL_MakeCurrent(window, context));
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid SDL_Window object");
}
}
/* }}} */


/* {{{ proto SDL_Window SDLCALL SDL_GL_GetCurrentWindow(void)
* \brief Get the currently active OpenGL window.
extern DECLSPEC SDL_Window* SDLCALL SDL_GL_GetCurrentWindow(void);
*/
PHP_FUNCTION(SDL_GL_GetCurrentWindow)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
sdl_window_to_zval(SDL_GL_GetCurrentWindow(), return_value TSRMLS_CC);
}


/* {{{ proto SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void)
* \brief Get the currently active OpenGL context.
extern DECLSPEC SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void);
*/
static PHP_FUNCTION(SDL_GL_GetCurrentContext)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
sdl_glcontext_to_zval(SDL_GL_GetCurrentContext(), return_value, SDL_DONTFREE TSRMLS_CC);
}



/* generic arginfo */

ZEND_BEGIN_ARG_INFO_EX(arginfo_none, 0, 0, 0)
ZEND_END_ARG_INFO()

Expand All @@ -315,6 +380,7 @@ static const zend_function_entry php_sdl_glcontext_methods[] = {
PHP_ME(SDL_GLContext, __construct, arginfo_SDL_GLContext__construct, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)

PHP_FALIAS(Delete, SDL_GL_DeleteContext, arginfo_none)
PHP_FALIAS(GL_GetCurrent, SDL_GL_GetCurrentContext, arginfo_none)
ZEND_FE_END
};
/* }}} */
Expand All @@ -327,6 +393,9 @@ zend_function_entry sdl_glcontext_functions[] = {
ZEND_FE(SDL_GL_GetAttribute, arginfo_SDL_GL_GetAttribute)
ZEND_FE(SDL_GL_CreateContext, arginfo_SDL_GLContext__construct)
ZEND_FE(SDL_GL_DeleteContext, arginfo_SDL_GLContext)
ZEND_FE(SDL_GL_MakeCurrent, arginfo_SDL_GL_MakeCurrent)
ZEND_FE(SDL_GL_GetCurrentWindow, arginfo_none)
ZEND_FE(SDL_GL_GetCurrentContext, arginfo_none)
ZEND_FE_END
};
/* }}} */
Expand Down
6 changes: 5 additions & 1 deletion glcontext.h
Expand Up @@ -27,9 +27,13 @@ extern "C" {
#endif

zend_class_entry *get_php_sdl_glcontext_ce(void);
zend_bool sdl_glcontext_to_zval(SDL_GLContext glcontext, zval *z_val, Uint32 flags, char *buf TSRMLS_DC);
zend_bool sdl_glcontext_to_zval(SDL_GLContext glcontext, zval *z_val, Uint32 flags TSRMLS_DC);
SDL_GLContext zval_to_sdl_glcontext(zval *z_val TSRMLS_DC);

PHP_FUNCTION(SDL_GL_CreateContext);
PHP_FUNCTION(SDL_GL_MakeCurrent);
PHP_FUNCTION(SDL_GL_GetCurrentWindow);

PHP_MINIT_FUNCTION(sdl_glcontext);

#ifdef __cplusplus
Expand Down
9 changes: 9 additions & 0 deletions window.c
Expand Up @@ -33,9 +33,11 @@
*/

#include "php_sdl.h"
#include "glcontext.h"
#include "rect.h"
#include "surface.h"
#include "video.h"
#include "window.h"

/* used to associate PHP object handle to SDL_Window */
#define PHP_SDL_MAGICDATA "__php__handle"
Expand Down Expand Up @@ -1627,6 +1629,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GLContext, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, context, SDL_GLContext, 0)
ZEND_END_ARG_INFO()


/* {{{ sdl_window_functions[] */
zend_function_entry sdl_window_functions[] = {
Expand Down Expand Up @@ -1718,6 +1724,9 @@ static const zend_function_entry php_sdl_window_methods[] = {
PHP_FALIAS(GetBrightness, SDL_GetWindowBrightness, arginfo_window_none)
PHP_FALIAS(SetGammaRamp, SDL_SetWindowGammaRamp, arginfo_SDL_Window_SetGammaRamp)
PHP_FALIAS(GetGammaRamp, SDL_GetWindowGammaRamp, arginfo_SDL_Window_GetGammaRamp)
PHP_FALIAS(GL_CreateContext, SDL_GL_CreateContext, arginfo_window_none)
PHP_FALIAS(GL_MakeCurrent, SDL_GL_MakeCurrent, arginfo_SDL_GLContext)
PHP_FALIAS(GL_GetCurrent, SDL_GL_GetCurrentWindow, arginfo_window_none)

PHP_FE_END
};
Expand Down
2 changes: 1 addition & 1 deletion window.h
Expand Up @@ -27,7 +27,7 @@ extern "C" {
#endif

zend_class_entry *get_php_sdl_window_ce(void);
void sdl_window_to_zval(SDL_Window *window, zval *z_val, Uint32 flags TSRMLS_DC);
zend_bool sdl_window_to_zval(SDL_Window *window, zval *z_val TSRMLS_DC);
SDL_Window *zval_to_sdl_window(zval *z_val TSRMLS_DC);

PHP_MINIT_FUNCTION(sdl_window);
Expand Down

0 comments on commit c057b65

Please sign in to comment.