WinRT: merged with latest SDL 2.x/HG code
SDL 2.x recently accepted patches to enable OpenGL ES 2 support via Google's ANGLE library. The thought is to try to eventually merge SDL/WinRT's OpenGL code with SDL-official's.
This commit is contained in:
commit
ebfac58560
999 changed files with 140431 additions and 5035 deletions
|
@ -21,6 +21,7 @@ TARGETS = \
|
|||
testgesture$(EXE) \
|
||||
testgl2$(EXE) \
|
||||
testgles$(EXE) \
|
||||
testgles2$(EXE) \
|
||||
testhaptic$(EXE) \
|
||||
testrumble$(EXE) \
|
||||
testthread$(EXE) \
|
||||
|
@ -49,6 +50,7 @@ TARGETS = \
|
|||
teststreaming$(EXE) \
|
||||
testtimer$(EXE) \
|
||||
testver$(EXE) \
|
||||
testviewport$(EXE) \
|
||||
testwm2$(EXE) \
|
||||
torturethread$(EXE) \
|
||||
testrendercopyex$(EXE) \
|
||||
|
@ -130,6 +132,9 @@ testgl2$(EXE): $(srcdir)/testgl2.c
|
|||
testgles$(EXE): $(srcdir)/testgles.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLESLIB@ @MATHLIB@
|
||||
|
||||
testgles2$(EXE): $(srcdir)/testgles2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLES2LIB@ @MATHLIB@
|
||||
|
||||
testhaptic$(EXE): $(srcdir)/testhaptic.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
|
@ -218,6 +223,9 @@ testtimer$(EXE): $(srcdir)/testtimer.c
|
|||
testver$(EXE): $(srcdir)/testver.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testviewport$(EXE): $(srcdir)/testviewport.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testwm2$(EXE): $(srcdir)/testwm2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
|
|
40
test/configure
vendored
40
test/configure
vendored
|
@ -587,6 +587,7 @@ LIBOBJS
|
|||
SDL_TTF_LIB
|
||||
XLIB
|
||||
GLESLIB
|
||||
GLES2LIB
|
||||
GLLIB
|
||||
CPP
|
||||
XMKMF
|
||||
|
@ -2902,7 +2903,7 @@ case "$host" in
|
|||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lopengl32"
|
||||
;;
|
||||
*-*-beos* | *-*-haiku*)
|
||||
*-*-haiku*)
|
||||
EXE=""
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGL"
|
||||
|
@ -3860,12 +3861,49 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
|||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_opengles" >&5
|
||||
$as_echo "$have_opengles" >&6; }
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for OpenGL ES2 support" >&5
|
||||
$as_echo_n "checking for OpenGL ES2 support... " >&6; }
|
||||
have_opengles2=no
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
#if defined (__IPHONEOS__)
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#include <OpenGLES/ES2/glext.h>
|
||||
#else
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#endif
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
|
||||
have_opengles2=yes
|
||||
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_opengles2" >&5
|
||||
$as_echo "$have_opengles2" >&6; }
|
||||
|
||||
GLLIB=""
|
||||
GLESLIB=""
|
||||
GLES2LIB=""
|
||||
if test x$have_opengles = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_OPENGLES"
|
||||
GLESLIB="$XPATH -lGLESv1_CM"
|
||||
fi
|
||||
if test x$have_opengles2 = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_OPENGLES2"
|
||||
#GLES2LIB="$XPATH -lGLESv2"
|
||||
fi
|
||||
if test x$have_opengl = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_OPENGL"
|
||||
GLLIB="$XPATH $SYS_GL_LIBS"
|
||||
|
|
|
@ -15,7 +15,7 @@ AC_C_CONST
|
|||
|
||||
dnl We only care about this for building testnative at the moment, so these
|
||||
dnl values shouldn't be considered absolute truth.
|
||||
dnl (BeOS, for example, sets none of these.)
|
||||
dnl (Haiku, for example, sets none of these.)
|
||||
ISUNIX="false"
|
||||
ISWINDOWS="false"
|
||||
ISMACOSX="false"
|
||||
|
@ -28,7 +28,7 @@ case "$host" in
|
|||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lopengl32"
|
||||
;;
|
||||
*-*-beos* | *-*-haiku*)
|
||||
*-*-haiku*)
|
||||
EXE=""
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGL"
|
||||
|
@ -135,12 +135,34 @@ have_opengles=yes
|
|||
])
|
||||
AC_MSG_RESULT($have_opengles)
|
||||
|
||||
dnl Check for OpenGL ES2
|
||||
AC_MSG_CHECKING(for OpenGL ES2 support)
|
||||
have_opengles2=no
|
||||
AC_TRY_COMPILE([
|
||||
#if defined (__IPHONEOS__)
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#include <OpenGLES/ES2/glext.h>
|
||||
#else
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#endif
|
||||
],[
|
||||
],[
|
||||
have_opengles2=yes
|
||||
])
|
||||
AC_MSG_RESULT($have_opengles2)
|
||||
|
||||
GLLIB=""
|
||||
GLESLIB=""
|
||||
GLES2LIB=""
|
||||
if test x$have_opengles = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_OPENGLES"
|
||||
GLESLIB="$XPATH -lGLESv1_CM"
|
||||
fi
|
||||
if test x$have_opengles2 = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_OPENGLES2"
|
||||
#GLES2LIB="$XPATH -lGLESv2"
|
||||
fi
|
||||
if test x$have_opengl = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_OPENGL"
|
||||
GLLIB="$XPATH $SYS_GL_LIBS"
|
||||
|
@ -148,6 +170,7 @@ fi
|
|||
|
||||
AC_SUBST(GLLIB)
|
||||
AC_SUBST(GLESLIB)
|
||||
AC_SUBST(GLES2LIB)
|
||||
AC_SUBST(XLIB)
|
||||
|
||||
dnl Check for SDL_ttf
|
||||
|
|
|
@ -1,110 +1,110 @@
|
|||
/*
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
|
||||
This file is created by : Nitin Jain (nitin.j4@samsung.com)
|
||||
*/
|
||||
|
||||
/* Sample program: Draw a Chess Board by using SDL_CreateSoftwareRenderer API */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
void
|
||||
DrawChessBoard(SDL_Renderer * renderer)
|
||||
{
|
||||
int row = 0,coloum = 0,x = 0;
|
||||
SDL_Rect rect, darea;
|
||||
|
||||
/* Get the Size of drawing surface */
|
||||
SDL_RenderGetViewport(renderer, &darea);
|
||||
|
||||
for(row; row < 8; row++)
|
||||
{
|
||||
coloum = row%2;
|
||||
x = x + coloum;
|
||||
for(coloum; coloum < 4+(row%2); coloum++)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
|
||||
rect.w = darea.w/8;
|
||||
rect.h = darea.h/8;
|
||||
rect.x = x * rect.w;
|
||||
rect.y = row * rect.h;
|
||||
x = x + 2;
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
x=0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Surface *surface;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
/*
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
|
||||
This file is created by : Nitin Jain (nitin.j4@samsung.com)
|
||||
*/
|
||||
|
||||
/* Sample program: Draw a Chess Board by using SDL_CreateSoftwareRenderer API */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
void
|
||||
DrawChessBoard(SDL_Renderer * renderer)
|
||||
{
|
||||
int row = 0,coloum = 0,x = 0;
|
||||
SDL_Rect rect, darea;
|
||||
|
||||
/* Get the Size of drawing surface */
|
||||
SDL_RenderGetViewport(renderer, &darea);
|
||||
|
||||
for(row; row < 8; row++)
|
||||
{
|
||||
coloum = row%2;
|
||||
x = x + coloum;
|
||||
for(coloum; coloum < 4+(row%2); coloum++)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
|
||||
rect.w = darea.w/8;
|
||||
rect.h = darea.h/8;
|
||||
rect.x = x * rect.w;
|
||||
rect.y = row * rect.h;
|
||||
x = x + 2;
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
x=0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Surface *surface;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL */
|
||||
if(SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Create window and renderer for given surface */
|
||||
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
|
||||
if(!window)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
surface = SDL_GetWindowSurface(window);
|
||||
renderer = SDL_CreateSoftwareRenderer(surface);
|
||||
if(!renderer)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Clear the rendering surface with the specified color */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
|
||||
/* Draw the Image on rendering surface */
|
||||
while(1)
|
||||
{
|
||||
SDL_Event e;
|
||||
if (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_QUIT)
|
||||
break;
|
||||
|
||||
if(e.key.keysym.sym == SDLK_ESCAPE)
|
||||
break;
|
||||
}
|
||||
|
||||
DrawChessBoard(renderer);
|
||||
|
||||
/* Got everything on rendering surface,
|
||||
now Update the drawing image on window screen */
|
||||
SDL_UpdateWindowSurface(window);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL */
|
||||
if(SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Create window and renderer for given surface */
|
||||
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
|
||||
if(!window)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
surface = SDL_GetWindowSurface(window);
|
||||
renderer = SDL_CreateSoftwareRenderer(surface);
|
||||
if(!renderer)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Clear the rendering surface with the specified color */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
|
||||
/* Draw the Image on rendering surface */
|
||||
while(1)
|
||||
{
|
||||
SDL_Event e;
|
||||
if (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_QUIT)
|
||||
break;
|
||||
|
||||
if(e.key.keysym.sym == SDLK_ESCAPE)
|
||||
break;
|
||||
}
|
||||
|
||||
DrawChessBoard(renderer);
|
||||
|
||||
/* Got everything on rendering surface,
|
||||
now Update the drawing image on window screen */
|
||||
SDL_UpdateWindowSurface(window);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ int main(int argc, char* argv[])
|
|||
SDL_Surface *screen;
|
||||
SDL_Event event;
|
||||
SDL_bool quitting = SDL_FALSE;
|
||||
SDL_RWops *src;
|
||||
SDL_RWops *stream;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -241,14 +241,14 @@ int main(int argc, char* argv[])
|
|||
SDL_RecordGesture(-1);
|
||||
break;
|
||||
case SDLK_s:
|
||||
src = SDL_RWFromFile("gestureSave","w");
|
||||
SDL_Log("Wrote %i templates",SDL_SaveAllDollarTemplates(src));
|
||||
SDL_RWclose(src);
|
||||
stream = SDL_RWFromFile("gestureSave", "w");
|
||||
SDL_Log("Wrote %i templates", SDL_SaveAllDollarTemplates(stream));
|
||||
SDL_RWclose(stream);
|
||||
break;
|
||||
case SDLK_l:
|
||||
src = SDL_RWFromFile("gestureSave","r");
|
||||
SDL_Log("Loaded: %i",SDL_LoadDollarTemplates(-1,src));
|
||||
SDL_RWclose(src);
|
||||
stream = SDL_RWFromFile("gestureSave", "r");
|
||||
SDL_Log("Loaded: %i", SDL_LoadDollarTemplates(-1, stream));
|
||||
SDL_RWclose(stream);
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
quitting = SDL_TRUE;
|
||||
|
|
|
@ -335,7 +335,9 @@ main(int argc, char *argv[])
|
|||
SDL_Log("%2.2f frames per second\n",
|
||||
((double) frames * 1000) / (now - then));
|
||||
}
|
||||
#if !defined(__ANDROID__)
|
||||
quit(0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
693
test/testgles2.c
Normal file
693
test/testgles2.c
Normal file
|
@ -0,0 +1,693 @@
|
|||
/*
|
||||
Copyright (r) 1997-2011 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#if defined(__IPHONEOS__) || defined(__ANDROID__)
|
||||
#define HAVE_OPENGLES2
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENGLES2
|
||||
|
||||
#include "SDL_opengles2.h"
|
||||
|
||||
typedef struct GLES2_Context
|
||||
{
|
||||
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
|
||||
#include "../src/render/opengles2/SDL_gles2funcs.h"
|
||||
#undef SDL_PROC
|
||||
} GLES2_Context;
|
||||
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_GLContext *context = NULL;
|
||||
static int depth = 16;
|
||||
static GLES2_Context ctx;
|
||||
|
||||
static int LoadContext(GLES2_Context * data)
|
||||
{
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_ANDROID
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_PANDORA
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#endif
|
||||
|
||||
#if defined __SDL_NOGETPROCADDR__
|
||||
#define SDL_PROC(ret,func,params) data->func=func;
|
||||
#else
|
||||
#define SDL_PROC(ret,func,params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if ( ! data->func ) { \
|
||||
return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \
|
||||
} \
|
||||
} while ( 0 );
|
||||
#endif /* _SDL_NOGETPROCADDR_ */
|
||||
|
||||
#include "../src/render/opengles2/SDL_gles2funcs.h"
|
||||
#undef SDL_PROC
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (context != NULL) {
|
||||
for (i = 0; i < state->num_windows; i++) {
|
||||
if (context[i]) {
|
||||
SDL_GL_DeleteContext(context[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_free(context);
|
||||
}
|
||||
|
||||
SDLTest_CommonQuit(state);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
#define GL_CHECK(x) \
|
||||
x; \
|
||||
{ \
|
||||
GLenum glError = ctx.glGetError(); \
|
||||
if(glError != GL_NO_ERROR) { \
|
||||
SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \
|
||||
quit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Simulates desktop's glRotatef. The matrix is returned in column-major
|
||||
* order.
|
||||
*/
|
||||
static void
|
||||
rotate_matrix(double angle, double x, double y, double z, float *r)
|
||||
{
|
||||
double radians, c, s, c1, u[3], length;
|
||||
int i, j;
|
||||
|
||||
radians = (angle * M_PI) / 180.0;
|
||||
|
||||
c = cos(radians);
|
||||
s = sin(radians);
|
||||
|
||||
c1 = 1.0 - cos(radians);
|
||||
|
||||
length = sqrt(x * x + y * y + z * z);
|
||||
|
||||
u[0] = x / length;
|
||||
u[1] = y / length;
|
||||
u[2] = z / length;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
r[i] = 0.0;
|
||||
}
|
||||
|
||||
r[15] = 1.0;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
r[i * 4 + (i + 1) % 3] = u[(i + 2) % 3] * s;
|
||||
r[i * 4 + (i + 2) % 3] = -u[(i + 1) % 3] * s;
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
r[i * 4 + j] += c1 * u[i] * u[j] + (i == j ? c : 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Simulates gluPerspectiveMatrix
|
||||
*/
|
||||
static void
|
||||
perspective_matrix(double fovy, double aspect, double znear, double zfar, float *r)
|
||||
{
|
||||
int i;
|
||||
double f;
|
||||
|
||||
f = 1.0/tan(fovy * 0.5);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
r[i] = 0.0;
|
||||
}
|
||||
|
||||
r[0] = f / aspect;
|
||||
r[5] = f;
|
||||
r[10] = (znear + zfar) / (znear - zfar);
|
||||
r[11] = -1.0;
|
||||
r[14] = (2.0 * znear * zfar) / (znear - zfar);
|
||||
r[15] = 0.0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Multiplies lhs by rhs and writes out to r. All matrices are 4x4 and column
|
||||
* major. In-place multiplication is supported.
|
||||
*/
|
||||
static void
|
||||
multiply_matrix(float *lhs, float *rhs, float *r)
|
||||
{
|
||||
int i, j, k;
|
||||
float tmp[16];
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
tmp[j * 4 + i] = 0.0;
|
||||
|
||||
for (k = 0; k < 4; k++) {
|
||||
tmp[j * 4 + i] += lhs[k * 4 + i] * rhs[j * 4 + k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
r[i] = tmp[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create shader, load in source, compile, dump debug as necessary.
|
||||
*
|
||||
* shader: Pointer to return created shader ID.
|
||||
* source: Passed-in shader source code.
|
||||
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
|
||||
*/
|
||||
void
|
||||
process_shader(GLuint *shader, const char * source, GLint shader_type)
|
||||
{
|
||||
GLint status = GL_FALSE;
|
||||
const char *shaders[1] = { NULL };
|
||||
|
||||
/* Create shader and load into GL. */
|
||||
*shader = GL_CHECK(ctx.glCreateShader(shader_type));
|
||||
|
||||
shaders[0] = source;
|
||||
|
||||
GL_CHECK(ctx.glShaderSource(*shader, 1, shaders, NULL));
|
||||
|
||||
/* Clean up shader source. */
|
||||
shaders[0] = NULL;
|
||||
|
||||
/* Try compiling the shader. */
|
||||
GL_CHECK(ctx.glCompileShader(*shader));
|
||||
GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status));
|
||||
|
||||
// Dump debug info (source and log) if compilation failed.
|
||||
if(status != GL_TRUE) {
|
||||
SDL_Log("Shader compilation failed");
|
||||
quit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* 3D data. Vertex range -0.5..0.5 in all axes.
|
||||
* Z -0.5 is near, 0.5 is far. */
|
||||
const float _vertices[] =
|
||||
{
|
||||
/* Front face. */
|
||||
/* Bottom left */
|
||||
-0.5, 0.5, -0.5,
|
||||
0.5, -0.5, -0.5,
|
||||
-0.5, -0.5, -0.5,
|
||||
/* Top right */
|
||||
-0.5, 0.5, -0.5,
|
||||
0.5, 0.5, -0.5,
|
||||
0.5, -0.5, -0.5,
|
||||
/* Left face */
|
||||
/* Bottom left */
|
||||
-0.5, 0.5, 0.5,
|
||||
-0.5, -0.5, -0.5,
|
||||
-0.5, -0.5, 0.5,
|
||||
/* Top right */
|
||||
-0.5, 0.5, 0.5,
|
||||
-0.5, 0.5, -0.5,
|
||||
-0.5, -0.5, -0.5,
|
||||
/* Top face */
|
||||
/* Bottom left */
|
||||
-0.5, 0.5, 0.5,
|
||||
0.5, 0.5, -0.5,
|
||||
-0.5, 0.5, -0.5,
|
||||
/* Top right */
|
||||
-0.5, 0.5, 0.5,
|
||||
0.5, 0.5, 0.5,
|
||||
0.5, 0.5, -0.5,
|
||||
/* Right face */
|
||||
/* Bottom left */
|
||||
0.5, 0.5, -0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
0.5, -0.5, -0.5,
|
||||
/* Top right */
|
||||
0.5, 0.5, -0.5,
|
||||
0.5, 0.5, 0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
/* Back face */
|
||||
/* Bottom left */
|
||||
0.5, 0.5, 0.5,
|
||||
-0.5, -0.5, 0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
/* Top right */
|
||||
0.5, 0.5, 0.5,
|
||||
-0.5, 0.5, 0.5,
|
||||
-0.5, -0.5, 0.5,
|
||||
/* Bottom face */
|
||||
/* Bottom left */
|
||||
-0.5, -0.5, -0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
-0.5, -0.5, 0.5,
|
||||
/* Top right */
|
||||
-0.5, -0.5, -0.5,
|
||||
0.5, -0.5, -0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
};
|
||||
|
||||
const float _colors[] =
|
||||
{
|
||||
/* Front face */
|
||||
/* Bottom left */
|
||||
1.0, 0.0, 0.0, /* red */
|
||||
0.0, 0.0, 1.0, /* blue */
|
||||
0.0, 1.0, 0.0, /* green */
|
||||
/* Top right */
|
||||
1.0, 0.0, 0.0, /* red */
|
||||
1.0, 1.0, 0.0, /* yellow */
|
||||
0.0, 0.0, 1.0, /* blue */
|
||||
/* Left face */
|
||||
/* Bottom left */
|
||||
1.0, 1.0, 1.0, /* white */
|
||||
0.0, 1.0, 0.0, /* green */
|
||||
0.0, 1.0, 1.0, /* cyan */
|
||||
/* Top right */
|
||||
1.0, 1.0, 1.0, /* white */
|
||||
1.0, 0.0, 0.0, /* red */
|
||||
0.0, 1.0, 0.0, /* green */
|
||||
/* Top face */
|
||||
/* Bottom left */
|
||||
1.0, 1.0, 1.0, /* white */
|
||||
1.0, 1.0, 0.0, /* yellow */
|
||||
1.0, 0.0, 0.0, /* red */
|
||||
/* Top right */
|
||||
1.0, 1.0, 1.0, /* white */
|
||||
0.0, 0.0, 0.0, /* black */
|
||||
1.0, 1.0, 0.0, /* yellow */
|
||||
/* Right face */
|
||||
/* Bottom left */
|
||||
1.0, 1.0, 0.0, /* yellow */
|
||||
1.0, 0.0, 1.0, /* magenta */
|
||||
0.0, 0.0, 1.0, /* blue */
|
||||
/* Top right */
|
||||
1.0, 1.0, 0.0, /* yellow */
|
||||
0.0, 0.0, 0.0, /* black */
|
||||
1.0, 0.0, 1.0, /* magenta */
|
||||
/* Back face */
|
||||
/* Bottom left */
|
||||
0.0, 0.0, 0.0, /* black */
|
||||
0.0, 1.0, 1.0, /* cyan */
|
||||
1.0, 0.0, 1.0, /* magenta */
|
||||
/* Top right */
|
||||
0.0, 0.0, 0.0, /* black */
|
||||
1.0, 1.0, 1.0, /* white */
|
||||
0.0, 1.0, 1.0, /* cyan */
|
||||
/* Bottom face */
|
||||
/* Bottom left */
|
||||
0.0, 1.0, 0.0, /* green */
|
||||
1.0, 0.0, 1.0, /* magenta */
|
||||
0.0, 1.0, 1.0, /* cyan */
|
||||
/* Top right */
|
||||
0.0, 1.0, 0.0, /* green */
|
||||
0.0, 0.0, 1.0, /* blue */
|
||||
1.0, 0.0, 1.0, /* magenta */
|
||||
};
|
||||
|
||||
const char* _shader_vert_src =
|
||||
" attribute vec4 av4position; "
|
||||
" attribute vec3 av3color; "
|
||||
" uniform mat4 mvp; "
|
||||
" varying vec3 vv3color; "
|
||||
" void main() { "
|
||||
" vv3color = av3color; "
|
||||
" gl_Position = mvp * av4position; "
|
||||
" } ";
|
||||
|
||||
const char* _shader_frag_src =
|
||||
" precision lowp float; "
|
||||
" varying vec3 vv3color; "
|
||||
" void main() { "
|
||||
" gl_FragColor = vec4(vv3color, 1.0); "
|
||||
" } ";
|
||||
|
||||
typedef struct shader_data
|
||||
{
|
||||
GLuint shader_program, shader_frag, shader_vert;
|
||||
|
||||
GLint attr_position;
|
||||
GLint attr_color, attr_mvp;
|
||||
|
||||
int angle_x, angle_y, angle_z;
|
||||
|
||||
} shader_data;
|
||||
|
||||
static void
|
||||
Render(unsigned int width, unsigned int height, shader_data* data)
|
||||
{
|
||||
float matrix_rotate[16], matrix_modelview[16], matrix_perspective[16], matrix_mvp[16];
|
||||
|
||||
/*
|
||||
* Do some rotation with Euler angles. It is not a fixed axis as
|
||||
* quaterions would be, but the effect is cool.
|
||||
*/
|
||||
rotate_matrix(data->angle_x, 1.0, 0.0, 0.0, matrix_modelview);
|
||||
rotate_matrix(data->angle_y, 0.0, 1.0, 0.0, matrix_rotate);
|
||||
|
||||
multiply_matrix(matrix_rotate, matrix_modelview, matrix_modelview);
|
||||
|
||||
rotate_matrix(data->angle_z, 0.0, 1.0, 0.0, matrix_rotate);
|
||||
|
||||
multiply_matrix(matrix_rotate, matrix_modelview, matrix_modelview);
|
||||
|
||||
/* Pull the camera back from the cube */
|
||||
matrix_modelview[14] -= 2.5;
|
||||
|
||||
perspective_matrix(45.0, (double)width/(double)height, 0.01, 100.0, matrix_perspective);
|
||||
multiply_matrix(matrix_perspective, matrix_modelview, matrix_mvp);
|
||||
|
||||
GL_CHECK(ctx.glUniformMatrix4fv(data->attr_mvp, 1, GL_FALSE, matrix_mvp));
|
||||
|
||||
data->angle_x += 3;
|
||||
data->angle_y += 2;
|
||||
data->angle_z += 1;
|
||||
|
||||
if(data->angle_x >= 360) data->angle_x -= 360;
|
||||
if(data->angle_x < 0) data->angle_x += 360;
|
||||
if(data->angle_y >= 360) data->angle_y -= 360;
|
||||
if(data->angle_y < 0) data->angle_y += 360;
|
||||
if(data->angle_z >= 360) data->angle_z -= 360;
|
||||
if(data->angle_z < 0) data->angle_z += 360;
|
||||
|
||||
GL_CHECK(ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
|
||||
GL_CHECK(ctx.glDrawArrays(GL_TRIANGLES, 0, 36));
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
int i, done;
|
||||
SDL_DisplayMode mode;
|
||||
SDL_Event event;
|
||||
Uint32 then, now, frames;
|
||||
int status;
|
||||
shader_data *datas, *data;
|
||||
|
||||
/* Initialize parameters */
|
||||
fsaa = 0;
|
||||
accel = 0;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
|
||||
++fsaa;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
|
||||
++accel;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
|
||||
i++;
|
||||
if (!argv[i]) {
|
||||
consumed = -1;
|
||||
} else {
|
||||
depth = SDL_atoi(argv[i]);
|
||||
consumed = 1;
|
||||
}
|
||||
} else {
|
||||
consumed = -1;
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
SDL_Log ("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
|
||||
SDLTest_CommonUsage(state));
|
||||
quit(1);
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
|
||||
/* Set OpenGL parameters */
|
||||
state->window_flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS;
|
||||
state->gl_red_size = 5;
|
||||
state->gl_green_size = 5;
|
||||
state->gl_blue_size = 5;
|
||||
state->gl_depth_size = depth;
|
||||
state->gl_major_version = 2;
|
||||
state->gl_minor_version = 0;
|
||||
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
|
||||
|
||||
if (fsaa) {
|
||||
state->gl_multisamplebuffers=1;
|
||||
state->gl_multisamplesamples=fsaa;
|
||||
}
|
||||
if (accel) {
|
||||
state->gl_accelerated=1;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
context = SDL_calloc(state->num_windows, sizeof(context));
|
||||
if (context == NULL) {
|
||||
SDL_Log("Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* Create OpenGL ES contexts */
|
||||
for (i = 0; i < state->num_windows; i++) {
|
||||
context[i] = SDL_GL_CreateContext(state->windows[i]);
|
||||
if (!context[i]) {
|
||||
SDL_Log("SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Important: call this *after* creating the context */
|
||||
if (LoadContext(&ctx) < 0) {
|
||||
SDL_Log("Could not load GLES2 functions\n");
|
||||
quit(2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
} else {
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(0, &mode);
|
||||
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
|
||||
SDL_Log("\n");
|
||||
SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));
|
||||
SDL_Log("Renderer : %s\n", ctx.glGetString(GL_RENDERER));
|
||||
SDL_Log("Version : %s\n", ctx.glGetString(GL_VERSION));
|
||||
SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS));
|
||||
SDL_Log("\n");
|
||||
|
||||
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_RED_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_GREEN_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_BLUE_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
if (fsaa) {
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
|
||||
value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
if (accel) {
|
||||
status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
datas = SDL_calloc(state->num_windows, sizeof(shader_data));
|
||||
|
||||
/* Set rendering settings for each context */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
ctx.glViewport(0, 0, state->window_w, state->window_h);
|
||||
|
||||
data = &datas[i];
|
||||
data->angle_x = 0; data->angle_y = 0; data->angle_z = 0;
|
||||
|
||||
/* Shader Initialization */
|
||||
process_shader(&data->shader_vert, _shader_vert_src, GL_VERTEX_SHADER);
|
||||
process_shader(&data->shader_frag, _shader_frag_src, GL_FRAGMENT_SHADER);
|
||||
|
||||
/* Create shader_program (ready to attach shaders) */
|
||||
data->shader_program = GL_CHECK(ctx.glCreateProgram());
|
||||
|
||||
/* Attach shaders and link shader_program */
|
||||
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
|
||||
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
|
||||
GL_CHECK(ctx.glLinkProgram(data->shader_program));
|
||||
|
||||
/* Get attribute locations of non-fixed attributes like color and texture coordinates. */
|
||||
data->attr_position = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av4position"));
|
||||
data->attr_color = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av3color"));
|
||||
|
||||
/* Get uniform locations */
|
||||
data->attr_mvp = GL_CHECK(ctx.glGetUniformLocation(data->shader_program, "mvp"));
|
||||
|
||||
GL_CHECK(ctx.glUseProgram(data->shader_program));
|
||||
|
||||
/* Enable attributes for position, color and texture coordinates etc. */
|
||||
GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_position));
|
||||
GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_color));
|
||||
|
||||
/* Populate attributes for position, color and texture coordinates etc. */
|
||||
GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, _vertices));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, _colors));
|
||||
|
||||
GL_CHECK(ctx.glEnable(GL_CULL_FACE));
|
||||
GL_CHECK(ctx.glEnable(GL_DEPTH_TEST));
|
||||
}
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
break;
|
||||
}
|
||||
/* Change view port to the new window dimensions */
|
||||
ctx.glViewport(0, 0, event.window.data1, event.window.data2);
|
||||
/* Update window content */
|
||||
Render(event.window.data1, event.window.data2, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
Render(state->window_w, state->window_h, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
SDL_Log("%2.2f frames per second\n",
|
||||
((double) frames * 1000) / (now - then));
|
||||
}
|
||||
#if !defined(__ANDROID__)
|
||||
quit(0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* HAVE_OPENGLES2 */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Log("No OpenGL ES support on this system\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* HAVE_OPENGLES2 */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -187,7 +187,7 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
|
|||
}
|
||||
glUseProgramObjectARB(0);
|
||||
|
||||
return (glGetError() == GL_NO_ERROR);
|
||||
return (glGetError() == GL_NO_ERROR) ? SDL_TRUE : SDL_FALSE;
|
||||
}
|
||||
|
||||
static void DestroyShaderProgram(ShaderData *data)
|
||||
|
|
|
@ -248,8 +248,6 @@ main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
state->window_flags |= SDL_WINDOW_RESIZABLE;
|
||||
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
|
|
184
test/testviewport.c
Normal file
184
test/testviewport.c
Normal file
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
/* Simple program: Check viewports */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "SDL_test.h"
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDLTest_CommonQuit(state);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
void
|
||||
DrawOnViewport(SDL_Renderer * renderer, SDL_Rect viewport)
|
||||
{
|
||||
SDL_Rect rect;
|
||||
|
||||
/* Set the viewport */
|
||||
SDL_RenderSetViewport(renderer, &viewport);
|
||||
|
||||
/* Draw a gray background */
|
||||
SDL_SetRenderDrawColor(renderer, 0x80, 0x80, 0x80, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
/* Test inside points */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xF, 0xFF);
|
||||
SDL_RenderDrawPoint(renderer, viewport.h/2 + 10, viewport.w/2);
|
||||
SDL_RenderDrawPoint(renderer, viewport.h/2 - 10, viewport.w/2);
|
||||
SDL_RenderDrawPoint(renderer, viewport.h/2 , viewport.w/2 - 10);
|
||||
SDL_RenderDrawPoint(renderer, viewport.h/2 , viewport.w/2 + 10);
|
||||
|
||||
/* Test horizontal and vertical lines */
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
|
||||
SDL_RenderDrawLine(renderer, 1, 0, viewport.w-2, 0);
|
||||
SDL_RenderDrawLine(renderer, 1, viewport.h-1, viewport.w-2, viewport.h-1);
|
||||
SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h-2);
|
||||
SDL_RenderDrawLine(renderer, viewport.w-1, 1, viewport.w-1, viewport.h-2);
|
||||
|
||||
/* Test diagonal lines */
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xFF, 0xFF);
|
||||
SDL_RenderDrawLine(renderer, 0, 0,
|
||||
viewport.w-1, viewport.h-1);
|
||||
SDL_RenderDrawLine(renderer, viewport.w-1, 0,
|
||||
0, viewport.h-1);
|
||||
|
||||
/* Test outside points */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xF, 0xFF);
|
||||
SDL_RenderDrawPoint(renderer, viewport.h/2 + viewport.h, viewport.w/2);
|
||||
SDL_RenderDrawPoint(renderer, viewport.h/2 - viewport.h, viewport.w/2);
|
||||
SDL_RenderDrawPoint(renderer, viewport.h/2 , viewport.w/2 - viewport.w);
|
||||
SDL_RenderDrawPoint(renderer, viewport.h/2 , viewport.w/2 + viewport.w);
|
||||
|
||||
/* Add a box at the top */
|
||||
rect.w = 8;
|
||||
rect.h = 8;
|
||||
rect.x = (viewport.w - rect.w) / 2;
|
||||
rect.y = 0;
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, j, done;
|
||||
SDL_Event event;
|
||||
Uint32 then, now, frames;
|
||||
SDL_Rect viewport;
|
||||
SDL_bool use_target = SDL_FALSE;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
consumed = -1;
|
||||
if (SDL_strcasecmp(argv[i], "--target") == 0) {
|
||||
use_target = SDL_TRUE;
|
||||
consumed = 1;
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
SDL_Log("Usage: %s %s [--target]\n",
|
||||
argv[0], SDLTest_CommonUsage(state));
|
||||
quit(1);
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
}
|
||||
|
||||
if (use_target) {
|
||||
int w, h;
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_GetWindowSize(state->windows[i], &w, &h);
|
||||
state->targets[i] = SDL_CreateTexture(state->renderers[i], SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, w, h);
|
||||
SDL_SetRenderTarget(state->renderers[i], state->targets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
j = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
|
||||
/* Move a viewport box in steps around the screen */
|
||||
viewport.x = j * 100;
|
||||
viewport.y = viewport.x;
|
||||
viewport.w = 100 + j * 50;
|
||||
viewport.h = 100 + j * 50;
|
||||
j = (j + 1) % 4;
|
||||
SDL_Log("Current Viewport x=%i y=%i w=%i h=%i", viewport.x, viewport.y, viewport.w, viewport.h);
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
|
||||
/* Draw using viewport */
|
||||
DrawOnViewport(state->renderers[i], viewport);
|
||||
|
||||
/* Update the screen! */
|
||||
if (use_target) {
|
||||
SDL_SetRenderTarget(state->renderers[i], NULL);
|
||||
SDL_RenderCopy(state->renderers[i], state->targets[i], NULL, NULL);
|
||||
SDL_RenderPresent(state->renderers[i]);
|
||||
SDL_SetRenderTarget(state->renderers[i], state->targets[i]);
|
||||
} else {
|
||||
SDL_RenderPresent(state->renderers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Delay(1000);
|
||||
}
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
}
|
||||
quit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
Loading…
Add table
Add a link
Reference in a new issue