SDL_render_gles.c
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 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, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED
#include "SDL_hints.h"
#include "SDL_opengles.h"
#include "../SDL_sysrender.h"
/* To prevent unnecessary window recreation,
* these should match the defaults selected in SDL_GL_ResetAttributes
*/
#define RENDERER_CONTEXT_MAJOR 1
#define RENDERER_CONTEXT_MINOR 1
#if defined(SDL_VIDEO_DRIVER_PANDORA)
/* Empty function stub to get OpenGL ES 1.x support without */
/* OpenGL ES extension GL_OES_draw_texture supported */
GL_API void GL_APIENTRY
glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
{
return;
}
#endif /* SDL_VIDEO_DRIVER_PANDORA */
/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
/* Used to re-create the window with OpenGL ES capability */
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
static const float inv255f = 1.0f / 255.0f;
static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags);
static void GLES_WindowEvent(SDL_Renderer * renderer,
const SDL_WindowEvent *event);
static int GLES_GetOutputSize(SDL_Renderer * renderer, int *w, int *h);
static SDL_bool GLES_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode);
static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch);
static void GLES_UnlockTexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static int GLES_SetRenderTarget(SDL_Renderer * renderer,
SDL_Texture * texture);
static int GLES_UpdateViewport(SDL_Renderer * renderer);
static int GLES_UpdateClipRect(SDL_Renderer * renderer);
static int GLES_RenderClear(SDL_Renderer * renderer);
static int GLES_RenderDrawPoints(SDL_Renderer * renderer,
const SDL_FPoint * points, int count);
static int GLES_RenderDrawLines(SDL_Renderer * renderer,
const SDL_FPoint * points, int count);
static int GLES_RenderFillRects(SDL_Renderer * renderer,
const SDL_FRect * rects, int count);
static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect,
const SDL_FRect * dstrect);
static int GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
static int GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, void * pixels, int pitch);
static void GLES_RenderPresent(SDL_Renderer * renderer);
static void GLES_DestroyTexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static void GLES_DestroyRenderer(SDL_Renderer * renderer);
static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture);
typedef struct GLES_FBOList GLES_FBOList;
struct GLES_FBOList
{
Uint32 w, h;
GLuint FBO;
GLES_FBOList *next;
};
SDL_RenderDriver GLES_RenderDriver = {
GLES_CreateRenderer,
{
"opengles",
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
1,
{SDL_PIXELFORMAT_ABGR8888},
0,
0}
};
typedef struct
{
SDL_GLContext context;
struct {
Uint32 color;
SDL_BlendMode blendMode;
SDL_bool tex_coords;
} current;
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
#define SDL_PROC_OES SDL_PROC
#include "SDL_glesfuncs.h"
#undef SDL_PROC
#undef SDL_PROC_OES
SDL_bool GL_OES_framebuffer_object_supported;
GLES_FBOList *framebuffers;
GLuint window_framebuffer;
SDL_bool GL_OES_blend_func_separate_supported;
SDL_bool GL_OES_blend_equation_separate_supported;
SDL_bool GL_OES_blend_subtract_supported;
} GLES_RenderData;
typedef struct
{
GLuint texture;
GLenum type;
GLfloat texw;
GLfloat texh;
GLenum format;
GLenum formattype;
void *pixels;
int pitch;
GLES_FBOList *fbo;
} GLES_TextureData;
static int
GLES_SetError(const char *prefix, GLenum result)
{
const char *error;
switch (result) {
case GL_NO_ERROR:
error = "GL_NO_ERROR";
break;
case GL_INVALID_ENUM:
error = "GL_INVALID_ENUM";
break;
case GL_INVALID_VALUE:
error = "GL_INVALID_VALUE";
break;
case GL_INVALID_OPERATION:
error = "GL_INVALID_OPERATION";
break;
case GL_STACK_OVERFLOW:
error = "GL_STACK_OVERFLOW";
break;
case GL_STACK_UNDERFLOW:
error = "GL_STACK_UNDERFLOW";
break;
case GL_OUT_OF_MEMORY:
error = "GL_OUT_OF_MEMORY";
break;
default:
error = "UNKNOWN";
break;
}
return SDL_SetError("%s: %s", prefix, error);
}
static int GLES_LoadFunctions(GLES_RenderData * 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
#ifdef __SDL_NOGETPROCADDR__
#define SDL_PROC(ret,func,params) data->func=func;
#define SDL_PROC_OES(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 GLES function %s: %s", #func, SDL_GetError()); \
} \
} while ( 0 );
#define SDL_PROC_OES(ret,func,params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
} while ( 0 );
#endif /* __SDL_NOGETPROCADDR__ */
#include "SDL_glesfuncs.h"
#undef SDL_PROC
#undef SDL_PROC_OES
return 0;
}
static SDL_GLContext SDL_CurrentContext = NULL;
static GLES_FBOList *
GLES_GetFBO(GLES_RenderData *data, Uint32 w, Uint32 h)
{
GLES_FBOList *result = data->framebuffers;
while ((result) && ((result->w != w) || (result->h != h)) ) {
result = result->next;
}
if (result == NULL) {
result = SDL_malloc(sizeof(GLES_FBOList));
result->w = w;
result->h = h;
data->glGenFramebuffersOES(1, &result->FBO);
result->next = data->framebuffers;
data->framebuffers = result;
}
return result;
}
static int
GLES_ActivateRenderer(SDL_Renderer * renderer)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
if (SDL_CurrentContext != data->context) {
if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
return -1;
}
SDL_CurrentContext = data->context;
GLES_UpdateViewport(renderer);
}
return 0;
}
/* This is called if we need to invalidate all of the SDL OpenGL state */
static void
GLES_ResetState(SDL_Renderer *renderer)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
if (SDL_CurrentContext == data->context) {
GLES_UpdateViewport(renderer);
} else {
GLES_ActivateRenderer(renderer);
}
data->current.color = 0xffffffff;
data->current.blendMode = SDL_BLENDMODE_INVALID;
data->current.tex_coords = SDL_FALSE;
data->glDisable(GL_DEPTH_TEST);
data->glDisable(GL_CULL_FACE);
data->glMatrixMode(GL_MODELVIEW);
data->glLoadIdentity();
data->glEnableClientState(GL_VERTEX_ARRAY);
data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
SDL_Renderer *
GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
{
SDL_Renderer *renderer;
GLES_RenderData *data;
GLint value;
Uint32 window_flags;
int profile_mask = 0, major = 0, minor = 0;
SDL_bool changed_window = SDL_FALSE;
SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL) ||
profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
changed_window = SDL_TRUE;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
goto error;
}
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
goto error;
}
data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data));
if (!data) {
GLES_DestroyRenderer(renderer);
SDL_OutOfMemory();
goto error;
}
renderer->WindowEvent = GLES_WindowEvent;
renderer->GetOutputSize = GLES_GetOutputSize;
renderer->SupportsBlendMode = GLES_SupportsBlendMode;
renderer->CreateTexture = GLES_CreateTexture;
renderer->UpdateTexture = GLES_UpdateTexture;
renderer->LockTexture = GLES_LockTexture;
renderer->UnlockTexture = GLES_UnlockTexture;
renderer->SetRenderTarget = GLES_SetRenderTarget;
renderer->UpdateViewport = GLES_UpdateViewport;
renderer->UpdateClipRect = GLES_UpdateClipRect;
renderer->RenderClear = GLES_RenderClear;
renderer->RenderDrawPoints = GLES_RenderDrawPoints;
renderer->RenderDrawLines = GLES_RenderDrawLines;
renderer->RenderFillRects = GLES_RenderFillRects;
renderer->RenderCopy = GLES_RenderCopy;
renderer->RenderCopyEx = GLES_RenderCopyEx;
renderer->RenderReadPixels = GLES_RenderReadPixels;
renderer->RenderPresent = GLES_RenderPresent;
renderer->DestroyTexture = GLES_DestroyTexture;
renderer->DestroyRenderer = GLES_DestroyRenderer;
renderer->GL_BindTexture = GLES_BindTexture;
renderer->GL_UnbindTexture = GLES_UnbindTexture;
renderer->info = GLES_RenderDriver.info;
renderer->info.flags = SDL_RENDERER_ACCELERATED;
renderer->driverdata = data;
renderer->window = window;
data->context = SDL_GL_CreateContext(window);
if (!data->context) {
GLES_DestroyRenderer(renderer);
goto error;
}
if (SDL_GL_MakeCurrent(window, data->context) < 0) {
GLES_DestroyRenderer(renderer);
goto error;
}
if (GLES_LoadFunctions(data) < 0) {
GLES_DestroyRenderer(renderer);
goto error;
}
if (flags & SDL_RENDERER_PRESENTVSYNC) {
SDL_GL_SetSwapInterval(1);
} else {
SDL_GL_SetSwapInterval(0);
}
if (SDL_GL_GetSwapInterval() > 0) {
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
}
value = 0;
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
renderer->info.max_texture_width = value;
value = 0;
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
renderer->info.max_texture_height = value;
/* Android does not report GL_OES_framebuffer_object but the functionality seems to be there anyway */
if (SDL_GL_ExtensionSupported("GL_OES_framebuffer_object") || data->glGenFramebuffersOES) {
data->GL_OES_framebuffer_object_supported = SDL_TRUE;
renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
value = 0;
data->glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &value);
data->window_framebuffer = (GLuint)value;
}
data->framebuffers = NULL;
if (SDL_GL_ExtensionSupported("GL_OES_blend_func_separate")) {
data->GL_OES_blend_func_separate_supported = SDL_TRUE;
}
if (SDL_GL_ExtensionSupported("GL_OES_blend_equation_separate")) {
data->GL_OES_blend_equation_separate_supported = SDL_TRUE;
}
if (SDL_GL_ExtensionSupported("GL_OES_blend_subtract")) {
data->GL_OES_blend_subtract_supported = SDL_TRUE;
}
/* Set up parameters for rendering */
GLES_ResetState(renderer);
return renderer;
error:
if (changed_window) {
/* Uh oh, better try to put it back... */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
SDL_RecreateWindow(window, window_flags);
}
return NULL;
}
static void
GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
event->event == SDL_WINDOWEVENT_SHOWN ||
event->event == SDL_WINDOWEVENT_HIDDEN) {
/* Rebind the context to the window area and update matrices */
SDL_CurrentContext = NULL;
}
if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
/* According to Apple documentation, we need to finish drawing NOW! */
data->glFinish();
}
}
static int
GLES_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
{
SDL_GL_GetDrawableSize(renderer->window, w, h);
return 0;
}
static GLenum GetBlendFunc(SDL_BlendFactor factor)
{
switch (factor) {
case SDL_BLENDFACTOR_ZERO:
return GL_ZERO;
case SDL_BLENDFACTOR_ONE:
return GL_ONE;
case SDL_BLENDFACTOR_SRC_COLOR:
return GL_SRC_COLOR;
case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR:
return GL_ONE_MINUS_SRC_COLOR;
case SDL_BLENDFACTOR_SRC_ALPHA:
return GL_SRC_ALPHA;
case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
return GL_ONE_MINUS_SRC_ALPHA;
case SDL_BLENDFACTOR_DST_COLOR:
return GL_DST_COLOR;
case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR:
return GL_ONE_MINUS_DST_COLOR;
case SDL_BLENDFACTOR_DST_ALPHA:
return GL_DST_ALPHA;
case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
return GL_ONE_MINUS_DST_ALPHA;
default:
return GL_INVALID_ENUM;
}
}
static GLenum GetBlendEquation(SDL_BlendOperation operation)
{
switch (operation) {
case SDL_BLENDOPERATION_ADD:
return GL_FUNC_ADD_OES;
case SDL_BLENDOPERATION_SUBTRACT:
return GL_FUNC_SUBTRACT_OES;
case SDL_BLENDOPERATION_REV_SUBTRACT:
return GL_FUNC_REVERSE_SUBTRACT_OES;
default:
return GL_INVALID_ENUM;
}
}
static SDL_bool
GLES_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode);
SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode);
SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
if (GetBlendFunc(srcColorFactor) == GL_INVALID_ENUM ||
GetBlendFunc(srcAlphaFactor) == GL_INVALID_ENUM ||
GetBlendEquation(colorOperation) == GL_INVALID_ENUM ||
GetBlendFunc(dstColorFactor) == GL_INVALID_ENUM ||
GetBlendFunc(dstAlphaFactor) == GL_INVALID_ENUM ||
GetBlendEquation(alphaOperation) == GL_INVALID_ENUM) {
return SDL_FALSE;
}
if ((srcColorFactor != srcAlphaFactor || dstColorFactor != dstAlphaFactor) && !data->GL_OES_blend_func_separate_supported) {
return SDL_FALSE;
}
if (colorOperation != alphaOperation && !data->GL_OES_blend_equation_separate_supported) {
return SDL_FALSE;
}
if (colorOperation != SDL_BLENDOPERATION_ADD && !data->GL_OES_blend_subtract_supported) {
return SDL_FALSE;
}
return SDL_TRUE;
}
static SDL_INLINE int
power_of_2(int input)
{
int value = 1;
while (value < input) {
value <<= 1;
}
return value;
}
static GLenum
GetScaleQuality(void)
{
const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
return GL_NEAREST;
} else {
return GL_LINEAR;
}
}
static int
GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *data;
GLint internalFormat;
GLenum format, type;
int texture_w, texture_h;
GLenum scaleMode;
GLenum result;
GLES_ActivateRenderer(renderer);
switch (texture->format) {
case SDL_PIXELFORMAT_ABGR8888:
internalFormat = GL_RGBA;
format = GL_RGBA;
type = GL_UNSIGNED_BYTE;
break;
default:
return SDL_SetError("Texture format not supported");
}
data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data));
if (!data) {
return SDL_OutOfMemory();
}
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
data->pixels = SDL_calloc(1, texture->h * data->pitch);
if (!data->pixels) {
SDL_free(data);
return SDL_OutOfMemory();
}
}
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
if (!renderdata->GL_OES_framebuffer_object_supported) {
SDL_free(data);
return SDL_SetError("GL_OES_framebuffer_object not supported");
}
data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
} else {
data->fbo = NULL;
}
renderdata->glGetError();
renderdata->glEnable(GL_TEXTURE_2D);
renderdata->glGenTextures(1, &data->texture);
result = renderdata->glGetError();
if (result != GL_NO_ERROR) {
SDL_free(data);
return GLES_SetError("glGenTextures()", result);
}
data->type = GL_TEXTURE_2D;
/* no NPOV textures allowed in OpenGL ES (yet) */
texture_w = power_of_2(texture->w);
texture_h = power_of_2(texture->h);
data->texw = (GLfloat) texture->w / texture_w;
data->texh = (GLfloat) texture->h / texture_h;
data->format = format;
data->formattype = type;
scaleMode = GetScaleQuality();
renderdata->glBindTexture(data->type, data->texture);
renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode);
renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode);
renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
texture_h, 0, format, type, NULL);
renderdata->glDisable(GL_TEXTURE_2D);
result = renderdata->glGetError();
if (result != GL_NO_ERROR) {
SDL_free(data);
return GLES_SetError("glTexImage2D()", result);
}
texture->driverdata = data;
return 0;
}
static int
GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
Uint8 *blob = NULL;
Uint8 *src;
int srcPitch;
int y;
GLES_ActivateRenderer(renderer);
/* Bail out if we're supposed to update an empty rectangle */
if (rect->w <= 0 || rect->h <= 0) {
return 0;
}
/* Reformat the texture data into a tightly packed array */
srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format);
src = (Uint8 *)pixels;
if (pitch != srcPitch) {
blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
if (!blob) {
return SDL_OutOfMemory();
}
src = blob;
for (y = 0; y < rect->h; ++y) {
SDL_memcpy(src, pixels, srcPitch);
src += srcPitch;
pixels = (Uint8 *)pixels + pitch;
}
src = blob;
}
/* Create a texture subimage with the supplied data */
renderdata->glGetError();
renderdata->glEnable(data->type);
renderdata->glBindTexture(data->type, data->texture);
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
renderdata->glTexSubImage2D(data->type,
0,
rect->x,
rect->y,
rect->w,
rect->h,
data->format,
data->formattype,
src);
renderdata->glDisable(data->type);
SDL_free(blob);
if (renderdata->glGetError() != GL_NO_ERROR) {
return SDL_SetError("Failed to update texture");
}
return 0;
}
static int
GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch)
{
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
*pixels =
(void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = data->pitch;
return 0;
}
static void
GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
SDL_Rect rect;
/* We do whole texture updates, at least for now */
rect.x = 0;
rect.y = 0;
rect.w = texture->w;
rect.h = texture->h;
GLES_UpdateTexture(renderer, texture, &rect, data->pixels, data->pitch);
}
static int
GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *texturedata = NULL;
GLenum status;
if (!data->GL_OES_framebuffer_object_supported) {
return SDL_SetError("Can't enable render target support in this renderer");
}
if (texture == NULL) {
data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, data->window_framebuffer);
return 0;
}
texturedata = (GLES_TextureData *) texture->driverdata;
data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, texturedata->fbo->FBO);
/* TODO: check if texture pixel format allows this operation */
data->glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, texturedata->type, texturedata->texture, 0);
/* Check FBO status */
status = data->glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
if (status != GL_FRAMEBUFFER_COMPLETE_OES) {
return SDL_SetError("glFramebufferTexture2DOES() failed");
}
return 0;
}
static int
GLES_UpdateViewport(SDL_Renderer * renderer)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
if (SDL_CurrentContext != data->context) {
/* We'll update the viewport after we rebind the context */
return 0;
}
if (renderer->target) {
data->glViewport(renderer->viewport.x, renderer->viewport.y,
renderer->viewport.w, renderer->viewport.h);
} else {
int w, h;
SDL_GL_GetDrawableSize(renderer->window, &w, &h);
data->glViewport(renderer->viewport.x, (h - renderer->viewport.y - renderer->viewport.h),
renderer->viewport.w, renderer->viewport.h);
}
data->glMatrixMode(GL_PROJECTION);
data->glLoadIdentity();
if (renderer->viewport.w && renderer->viewport.h) {
if (renderer->target) {
data->glOrthof((GLfloat) 0,
(GLfloat) renderer->viewport.w,
(GLfloat) 0,
(GLfloat) renderer->viewport.h,
0.0, 1.0);
} else {
data->glOrthof((GLfloat) 0,
(GLfloat) renderer->viewport.w,
(GLfloat) renderer->viewport.h,
(GLfloat) 0,
0.0, 1.0);
}
}
data->glMatrixMode(GL_MODELVIEW);
return 0;
}
static int
GLES_UpdateClipRect(SDL_Renderer * renderer)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
if (SDL_CurrentContext != data->context) {
/* We'll update the clip rect after we rebind the context */
return 0;
}
if (renderer->clipping_enabled) {
const SDL_Rect *rect = &renderer->clip_rect;
data->glEnable(GL_SCISSOR_TEST);
if (renderer->target) {
data->glScissor(renderer->viewport.x + rect->x, renderer->viewport.y + rect->y, rect->w, rect->h);
} else {
int w, h;
SDL_GL_GetDrawableSize(renderer->window, &w, &h);
data->glScissor(renderer->viewport.x + rect->x, h - renderer->viewport.y - rect->y - rect->h, rect->w, rect->h);
}
} else {
data->glDisable(GL_SCISSOR_TEST);
}
return 0;
}
static void
GLES_SetColor(GLES_RenderData * data, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
if (color != data->current.color) {
data->glColor4f((GLfloat) r * inv255f,
(GLfloat) g * inv255f,
(GLfloat) b * inv255f,
(GLfloat) a * inv255f);
data->current.color = color;
}
}
static void
GLES_SetBlendMode(GLES_RenderData * data, SDL_BlendMode blendMode)
{
if (blendMode != data->current.blendMode) {
if (blendMode == SDL_BLENDMODE_NONE) {
data->glDisable(GL_BLEND);
} else {
data->glEnable(GL_BLEND);
if (data->GL_OES_blend_func_separate_supported) {
data->glBlendFuncSeparateOES(GetBlendFunc(SDL_GetBlendModeSrcColorFactor(blendMode)),
GetBlendFunc(SDL_GetBlendModeDstColorFactor(blendMode)),
GetBlendFunc(SDL_GetBlendModeSrcAlphaFactor(blendMode)),
GetBlendFunc(SDL_GetBlendModeDstAlphaFactor(blendMode)));
} else {
data->glBlendFunc(GetBlendFunc(SDL_GetBlendModeSrcColorFactor(blendMode)),
GetBlendFunc(SDL_GetBlendModeDstColorFactor(blendMode)));
}
if (data->GL_OES_blend_equation_separate_supported) {
data->glBlendEquationSeparateOES(GetBlendEquation(SDL_GetBlendModeColorOperation(blendMode)),
GetBlendEquation(SDL_GetBlendModeAlphaOperation(blendMode)));
} else if (data->GL_OES_blend_subtract_supported) {
data->glBlendEquationOES(GetBlendEquation(SDL_GetBlendModeColorOperation(blendMode)));
}
}
data->current.blendMode = blendMode;
}
}
static void
GLES_SetTexCoords(GLES_RenderData * data, SDL_bool enabled)
{
if (enabled != data->current.tex_coords) {
if (enabled) {
data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
} else {
data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
data->current.tex_coords = enabled;
}
}
static void
GLES_SetDrawingState(SDL_Renderer * renderer)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_ActivateRenderer(renderer);
GLES_SetColor(data, (GLfloat) renderer->r,
(GLfloat) renderer->g,
(GLfloat) renderer->b,
(GLfloat) renderer->a);
GLES_SetBlendMode(data, renderer->blendMode);
GLES_SetTexCoords(data, SDL_FALSE);
}
static int
GLES_RenderClear(SDL_Renderer * renderer)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_ActivateRenderer(renderer);
data->glClearColor((GLfloat) renderer->r * inv255f,
(GLfloat) renderer->g * inv255f,
(GLfloat) renderer->b * inv255f,
(GLfloat) renderer->a * inv255f);
if (renderer->clipping_enabled) {
data->glDisable(GL_SCISSOR_TEST);
}
data->glClear(GL_COLOR_BUFFER_BIT);
if (renderer->clipping_enabled) {
data->glEnable(GL_SCISSOR_TEST);
}
return 0;
}
static int
GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
int count)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLfloat *vertices;
int idx;
GLES_SetDrawingState(renderer);
/* Emit the specified vertices as points */
vertices = SDL_stack_alloc(GLfloat, count * 2);
for (idx = 0; idx < count; ++idx) {
GLfloat x = points[idx].x + 0.5f;
GLfloat y = points[idx].y + 0.5f;
vertices[idx * 2] = x;
vertices[(idx * 2) + 1] = y;
}
data->glVertexPointer(2, GL_FLOAT, 0, vertices);
data->glDrawArrays(GL_POINTS, 0, count);
SDL_stack_free(vertices);
return 0;
}
static int
GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
int count)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLfloat *vertices;
int idx;
GLES_SetDrawingState(renderer);
/* Emit a line strip including the specified vertices */
vertices = SDL_stack_alloc(GLfloat, count * 2);
for (idx = 0; idx < count; ++idx) {
GLfloat x = points[idx].x + 0.5f;
GLfloat y = points[idx].y + 0.5f;
vertices[idx * 2] = x;
vertices[(idx * 2) + 1] = y;
}
data->glVertexPointer(2, GL_FLOAT, 0, vertices);
if (count > 2 &&
points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
/* GL_LINE_LOOP takes care of the final segment */
--count;
data->glDrawArrays(GL_LINE_LOOP, 0, count);
} else {
data->glDrawArrays(GL_LINE_STRIP, 0, count);
/* We need to close the endpoint of the line */
data->glDrawArrays(GL_POINTS, count-1, 1);
}
SDL_stack_free(vertices);
return 0;
}
static int
GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
int count)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
int i;
GLES_SetDrawingState(renderer);
for (i = 0; i < count; ++i) {
const SDL_FRect *rect = &rects[i];
GLfloat minx = rect->x;
GLfloat maxx = rect->x + rect->w;
GLfloat miny = rect->y;
GLfloat maxy = rect->y + rect->h;
GLfloat vertices[8];
vertices[0] = minx;
vertices[1] = miny;
vertices[2] = maxx;
vertices[3] = miny;
vertices[4] = minx;
vertices[5] = maxy;
vertices[6] = maxx;
vertices[7] = maxy;
data->glVertexPointer(2, GL_FLOAT, 0, vertices);
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
return 0;
}
static int
GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
GLfloat minx, miny, maxx, maxy;
GLfloat minu, maxu, minv, maxv;
GLfloat vertices[8];
GLfloat texCoords[8];
GLES_ActivateRenderer(renderer);
data->glEnable(GL_TEXTURE_2D);
data->glBindTexture(texturedata->type, texturedata->texture);
if (texture->modMode) {
GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a);
} else {
GLES_SetColor(data, 255, 255, 255, 255);
}
GLES_SetBlendMode(data, texture->blendMode);
GLES_SetTexCoords(data, SDL_TRUE);
minx = dstrect->x;
miny = dstrect->y;
maxx = dstrect->x + dstrect->w;
maxy = dstrect->y + dstrect->h;
minu = (GLfloat) srcrect->x / texture->w;
minu *= texturedata->texw;
maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
maxu *= texturedata->texw;
minv = (GLfloat) srcrect->y / texture->h;
minv *= texturedata->texh;
maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
maxv *= texturedata->texh;
vertices[0] = minx;
vertices[1] = miny;
vertices[2] = maxx;
vertices[3] = miny;
vertices[4] = minx;
vertices[5] = maxy;
vertices[6] = maxx;
vertices[7] = maxy;
texCoords[0] = minu;
texCoords[1] = minv;
texCoords[2] = maxu;
texCoords[3] = minv;
texCoords[4] = minu;
texCoords[5] = maxv;
texCoords[6] = maxu;
texCoords[7] = maxv;
data->glVertexPointer(2, GL_FLOAT, 0, vertices);
data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
data->glDisable(GL_TEXTURE_2D);
return 0;
}
static int
GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
GLfloat minx, miny, maxx, maxy;
GLfloat minu, maxu, minv, maxv;
GLfloat centerx, centery;
GLfloat vertices[8];
GLfloat texCoords[8];
GLES_ActivateRenderer(renderer);
data->glEnable(GL_TEXTURE_2D);
data->glBindTexture(texturedata->type, texturedata->texture);
if (texture->modMode) {
GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a);
} else {
GLES_SetColor(data, 255, 255, 255, 255);
}
GLES_SetBlendMode(data, texture->blendMode);
GLES_SetTexCoords(data, SDL_TRUE);
centerx = center->x;
centery = center->y;
/* Rotate and translate */
data->glPushMatrix();
data->glTranslatef(dstrect->x + centerx, dstrect->y + centery, 0.0f);
data->glRotatef((GLfloat)angle, 0.0f, 0.0f, 1.0f);
if (flip & SDL_FLIP_HORIZONTAL) {
minx = dstrect->w - centerx;
maxx = -centerx;
} else {
minx = -centerx;
maxx = dstrect->w - centerx;
}
if (flip & SDL_FLIP_VERTICAL) {
miny = dstrect->h - centery;
maxy = -centery;
} else {
miny = -centery;
maxy = dstrect->h - centery;
}
minu = (GLfloat) srcrect->x / texture->w;
minu *= texturedata->texw;
maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
maxu *= texturedata->texw;
minv = (GLfloat) srcrect->y / texture->h;
minv *= texturedata->texh;
maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
maxv *= texturedata->texh;
vertices[0] = minx;
vertices[1] = miny;
vertices[2] = maxx;
vertices[3] = miny;
vertices[4] = minx;
vertices[5] = maxy;
vertices[6] = maxx;
vertices[7] = maxy;
texCoords[0] = minu;
texCoords[1] = minv;
texCoords[2] = maxu;
texCoords[3] = minv;
texCoords[4] = minu;
texCoords[5] = maxv;
texCoords[6] = maxu;
texCoords[7] = maxv;
data->glVertexPointer(2, GL_FLOAT, 0, vertices);
data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
data->glPopMatrix();
data->glDisable(GL_TEXTURE_2D);
return 0;
}
static int
GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, void * pixels, int pitch)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
void *temp_pixels;
int temp_pitch;
Uint8 *src, *dst, *tmp;
int w, h, length, rows;
int status;
GLES_ActivateRenderer(renderer);
temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
temp_pixels = SDL_malloc(rect->h * temp_pitch);
if (!temp_pixels) {
return SDL_OutOfMemory();
}
SDL_GetRendererOutputSize(renderer, &w, &h);
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h,
rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
/* Flip the rows to be top-down if necessary */
if (!renderer->target) {
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
dst = (Uint8*)temp_pixels;
tmp = SDL_stack_alloc(Uint8, length);
rows = rect->h / 2;
while (rows--) {
SDL_memcpy(tmp, dst, length);
SDL_memcpy(dst, src, length);
SDL_memcpy(src, tmp, length);
dst += temp_pitch;
src -= temp_pitch;
}
SDL_stack_free(tmp);
}
status = SDL_ConvertPixels(rect->w, rect->h,
temp_format, temp_pixels, temp_pitch,
pixel_format, pixels, pitch);
SDL_free(temp_pixels);
return status;
}
static void
GLES_RenderPresent(SDL_Renderer * renderer)
{
GLES_ActivateRenderer(renderer);
SDL_GL_SwapWindow(renderer->window);
}
static void
GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
GLES_ActivateRenderer(renderer);
if (!data) {
return;
}
if (data->texture) {
renderdata->glDeleteTextures(1, &data->texture);
}
SDL_free(data->pixels);
SDL_free(data);
texture->driverdata = NULL;
}
static void
GLES_DestroyRenderer(SDL_Renderer * renderer)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
if (data) {
if (data->context) {
while (data->framebuffers) {
GLES_FBOList *nextnode = data->framebuffers->next;
data->glDeleteFramebuffersOES(1, &data->framebuffers->FBO);
SDL_free(data->framebuffers);
data->framebuffers = nextnode;
}
SDL_GL_DeleteContext(data->context);
}
SDL_free(data);
}
SDL_free(renderer);
}
static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
GLES_ActivateRenderer(renderer);
data->glEnable(GL_TEXTURE_2D);
data->glBindTexture(texturedata->type, texturedata->texture);
if (texw) {
*texw = (float)texturedata->texw;
}
if (texh) {
*texh = (float)texturedata->texh;
}
return 0;
}
static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
GLES_ActivateRenderer(renderer);
data->glDisable(texturedata->type);
return 0;
}
#endif /* SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */
SDL_GetBlendModeSrcColorFactor
SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode)
Definition: SDL_render.c:2193
SDL_BlendFactor
SDL_BlendFactor
The normalized factor used to multiply pixel components.
Definition: SDL_blendmode.h:75
SDL_Renderer::RenderDrawLines
int(* RenderDrawLines)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
Definition: SDL_sysrender.h:107
GL_ONE
#define GL_ONE
Definition: SDL_opengl.h:401
GL_STACK_UNDERFLOW
#define GL_STACK_UNDERFLOW
Definition: SDL_opengl.h:724
SDL_Texture::blendMode
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:57
SDL_FRect::w
float w
Definition: SDL_sysrender.h:44
SDL_GL_ExtensionSupported
#define SDL_GL_ExtensionSupported
Definition: SDL_dynapi_overrides.h:556
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GL_INVALID_ENUM
#define GL_INVALID_ENUM
Definition: SDL_opengl.h:720
SDL_Renderer::RenderDrawPoints
int(* RenderDrawPoints)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
Definition: SDL_sysrender.h:105
SDL_Renderer::LockTexture
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_sysrender.h:98
SDL_FLIP_HORIZONTAL
Definition: SDL_render.h:114
GL_INVALID_OPERATION
#define GL_INVALID_OPERATION
Definition: SDL_opengl.h:722
SDL_RendererInfo::max_texture_width
int max_texture_width
Definition: SDL_render.h:84
z
GLdouble GLdouble z
Definition: SDL_opengl_glext.h:404
SDL_TRUE
Definition: SDL_stdinc.h:142
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
GL_SCISSOR_TEST
#define GL_SCISSOR_TEST
Definition: SDL_opengl.h:615
SDL_RENDERER_ACCELERATED
Definition: SDL_render.h:67
SDL_GL_CreateContext
#define SDL_GL_CreateContext
Definition: SDL_dynapi_overrides.h:559
SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR
Definition: SDL_blendmode.h:84
SDL_Renderer::RenderReadPixels
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
Definition: SDL_sysrender.h:116
framebuffers
const GLuint * framebuffers
Definition: SDL_opengl_glext.h:1175
SDL_WINDOWEVENT_MINIMIZED
Definition: SDL_video.h:159
SDL_Renderer::info
SDL_RendererInfo info
Definition: SDL_sysrender.h:130
SDL_RENDERER_TARGETTEXTURE
Definition: SDL_render.h:71
SDL_RendererInfo::flags
Uint32 flags
Definition: SDL_render.h:81
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1737
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_BLENDMODE_NONE
Definition: SDL_blendmode.h:42
GL_PROJECTION
#define GL_PROJECTION
Definition: SDL_opengl.h:272
GLES_RenderDriver
SDL_RenderDriver GLES_RenderDriver
SDL_BlendMode
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:40
SDL_Texture::g
Uint8 g
Definition: SDL_sysrender.h:58
SDL_Renderer::SupportsBlendMode
SDL_bool(* SupportsBlendMode)(SDL_Renderer *renderer, SDL_BlendMode blendMode)
Definition: SDL_sysrender.h:82
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
rect
SDL_Rect rect
Definition: testrelative.c:27
GL_LINEAR
#define GL_LINEAR
Definition: SDL_opengl.h:447
SDL_HINT_RENDER_SCALE_QUALITY
#define SDL_HINT_RENDER_SCALE_QUALITY
A variable controlling the scaling quality.
Definition: SDL_hints.h:143
GL_CLAMP_TO_EDGE
#define GL_CLAMP_TO_EDGE
Definition: SDL_opengl.h:1507
SDL_FALSE
Definition: SDL_stdinc.h:141
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
SDL_RENDERER_PRESENTVSYNC
Definition: SDL_render.h:69
SDL_Renderer::driverdata
void * driverdata
Definition: SDL_sysrender.h:171
GLint
int GLint
Definition: SDL_opengl.h:182
GL_RGBA
#define GL_RGBA
Definition: SDL_opengl.h:529
context
static screen_context_t context
Definition: video.c:25
SDL_GetBlendModeDstAlphaFactor
SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode)
Definition: SDL_render.c:2221
SDL_GetHint
#define SDL_GetHint
Definition: SDL_dynapi_overrides.h:191
SDL_GetWindowFlags
#define SDL_GetWindowFlags
Definition: SDL_dynapi_overrides.h:518
SDL_Renderer
Definition: SDL_sysrender.h:76
SDL_FLIP_VERTICAL
Definition: SDL_render.h:115
SDL_GetBlendModeColorOperation
SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode)
Definition: SDL_render.c:2207
f
GLfloat f
Definition: SDL_opengl_glext.h:1870
SDL_BYTESPERPIXEL
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GL_TEXTURE_MAG_FILTER
#define GL_TEXTURE_MAG_FILTER
Definition: SDL_opengl.h:674
SDL_Renderer::RenderFillRects
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
Definition: SDL_sysrender.h:109
SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA
Definition: SDL_blendmode.h:86
SDL_Renderer::clip_rect
SDL_Rect clip_rect
Definition: SDL_sysrender.h:150
GL_TRIANGLE_STRIP
#define GL_TRIANGLE_STRIP
Definition: SDL_opengl.h:221
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:181
GLfloat
float GLfloat
Definition: SDL_opengl.h:187
SDL_strcasecmp
#define SDL_strcasecmp
Definition: SDL_dynapi_overrides.h:419
src
GLenum src
Definition: SDL_opengl_glext.h:1737
SDL_WINDOWEVENT_SIZE_CHANGED
Definition: SDL_video.h:156
SDL_RendererInfo::max_texture_height
int max_texture_height
Definition: SDL_render.h:85
GL_ONE_MINUS_SRC_ALPHA
#define GL_ONE_MINUS_SRC_ALPHA
Definition: SDL_opengl.h:405
SDL_BlendOperation
SDL_BlendOperation
The blend operation used when combining source and destination pixel components.
Definition: SDL_blendmode.h:62
SDL_FRect::y
float y
Definition: SDL_sysrender.h:43
SDL_Renderer::window
SDL_Window * window
Definition: SDL_sysrender.h:133
SDL_RenderDriver::info
SDL_RendererInfo info
Definition: SDL_sysrender.h:180
GL_ONE_MINUS_SRC_COLOR
#define GL_ONE_MINUS_SRC_COLOR
Definition: SDL_opengl.h:403
SDL_Renderer::RenderClear
int(* RenderClear)(SDL_Renderer *renderer)
Definition: SDL_sysrender.h:104
SDL_Texture::a
Uint8 a
Definition: SDL_sysrender.h:58
SDL_WINDOWEVENT_HIDDEN
Definition: SDL_video.h:150
SDL_Renderer::DestroyRenderer
void(* DestroyRenderer)(SDL_Renderer *renderer)
Definition: SDL_sysrender.h:121
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
points
GLfixed GLfixed GLint GLint GLfixed points
Definition: SDL_opengl_glext.h:4558
SDL_Texture
Definition: SDL_sysrender.h:49
SDL_Renderer::GetOutputSize
int(* GetOutputSize)(SDL_Renderer *renderer, int *w, int *h)
Definition: SDL_sysrender.h:81
SDL_GL_CONTEXT_MINOR_VERSION
Definition: SDL_video.h:200
SDL_opengles.h
GL_PACK_ALIGNMENT
#define GL_PACK_ALIGNMENT
Definition: SDL_opengl.h:652
GL_MAX_TEXTURE_SIZE
#define GL_MAX_TEXTURE_SIZE
Definition: SDL_opengl.h:536
GL_NO_ERROR
#define GL_NO_ERROR
Definition: SDL_opengl.h:719
blendMode
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
GL_BLEND
#define GL_BLEND
Definition: SDL_opengl.h:397
GL_SRC_COLOR
#define GL_SRC_COLOR
Definition: SDL_opengl.h:402
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
SDL_Renderer::UpdateTexture
int(* UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_sysrender.h:90
SDL_GL_SetAttribute
#define SDL_GL_SetAttribute
Definition: SDL_dynapi_overrides.h:557
SDL_GL_GetDrawableSize
#define SDL_GL_GetDrawableSize
Definition: SDL_dynapi_overrides.h:563
GL_ONE_MINUS_DST_ALPHA
#define GL_ONE_MINUS_DST_ALPHA
Definition: SDL_opengl.h:407
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
texture
GLenum GLenum GLuint texture
Definition: SDL_opengl_glext.h:1178
SDL_BLENDFACTOR_SRC_COLOR
Definition: SDL_blendmode.h:79
SDL_GetBlendModeAlphaOperation
SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode)
Definition: SDL_render.c:2228
SDL_GLContext
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:175
SDL_GL_GetSwapInterval
#define SDL_GL_GetSwapInterval
Definition: SDL_dynapi_overrides.h:565
input
GLenum GLenum GLenum input
Definition: SDL_opengl_glext.h:9374
SDL_GL_CONTEXT_MAJOR_VERSION
Definition: SDL_video.h:199
SDL_BLENDFACTOR_DST_COLOR
Definition: SDL_blendmode.h:83
SDL_Renderer::target
SDL_Texture * target
Definition: SDL_sysrender.h:166
SDL_Renderer::g
Uint8 g
Definition: SDL_sysrender.h:168
SDL_PIXELFORMAT_ABGR8888
Definition: SDL_pixels.h:254
SDL_RecreateWindow
int SDL_RecreateWindow(SDL_Window *window, Uint32 flags)
Definition: SDL_video.c:1542
GL_STACK_OVERFLOW
#define GL_STACK_OVERFLOW
Definition: SDL_opengl.h:723
GetScaleQuality
static int GetScaleQuality(void)
Definition: SDL_render_sw.c:591
renderer
static SDL_Renderer * renderer
Definition: testaudiocapture.c:21
SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR
Definition: SDL_blendmode.h:80
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:157
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_stack_alloc
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:354
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_Renderer::blendMode
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:169
SDL_GL_SetSwapInterval
#define SDL_GL_SetSwapInterval
Definition: SDL_dynapi_overrides.h:564
GL_LINE_STRIP
#define GL_LINE_STRIP
Definition: SDL_opengl.h:219
GL_TEXTURE_WRAP_T
#define GL_TEXTURE_WRAP_T
Definition: SDL_opengl.h:673
GL_LINE_LOOP
#define GL_LINE_LOOP
Definition: SDL_opengl.h:218
SDL_Renderer::b
Uint8 b
Definition: SDL_sysrender.h:168
GL_FLOAT
#define GL_FLOAT
Definition: SDL_opengl.h:209
SDL_TEXTUREACCESS_STREAMING
Definition: SDL_render.h:94
SDL_Renderer::GL_BindTexture
int(* GL_BindTexture)(SDL_Renderer *renderer, SDL_Texture *texture, float *texw, float *texh)
Definition: SDL_sysrender.h:123
GL_TEXTURE_2D
#define GL_TEXTURE_2D
Definition: SDL_opengl.h:671
SDL_hints.h
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
GL_UNSIGNED_BYTE
#define GL_UNSIGNED_BYTE
Definition: SDL_opengl.h:204
GL_APIENTRY
#define GL_APIENTRY
Definition: SDL_opengles2_gl2platform.h:27
SDL_Texture::w
int w
Definition: SDL_sysrender.h:54
SDL_Renderer::UnlockTexture
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:100
SDL_BLENDFACTOR_SRC_ALPHA
Definition: SDL_blendmode.h:81
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GL_DST_COLOR
#define GL_DST_COLOR
Definition: SDL_opengl.h:408
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_WindowEvent::event
Uint8 event
Definition: SDL_events.h:179
SDL_Renderer::SetRenderTarget
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:101
SDL_Renderer::UpdateViewport
int(* UpdateViewport)(SDL_Renderer *renderer)
Definition: SDL_sysrender.h:102
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
GL_COLOR_BUFFER_BIT
#define GL_COLOR_BUFFER_BIT
Definition: SDL_opengl.h:742
GL_INVALID_VALUE
#define GL_INVALID_VALUE
Definition: SDL_opengl.h:721
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_Renderer::GL_UnbindTexture
int(* GL_UnbindTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:124
SDL_BLENDOPERATION_ADD
Definition: SDL_blendmode.h:64
SDL_FRect::h
float h
Definition: SDL_sysrender.h:45
SDL_RendererFlip
SDL_RendererFlip
Flip constants for SDL_RenderCopyEx.
Definition: SDL_render.h:111
enabled
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: SDL_opengl_glext.h:2479
SDL_GL_CONTEXT_PROFILE_MASK
Definition: SDL_video.h:203
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
SDL_Renderer::RenderCopy
int(* RenderCopy)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
Definition: SDL_sysrender.h:111
SDL_WindowEvent
Window state change event data (event.window.*)
Definition: SDL_events.h:174
SDL_BLENDFACTOR_DST_ALPHA
Definition: SDL_blendmode.h:85
SDL_glesfuncs.h
GLenum
unsigned int GLenum
Definition: SDL_opengl.h:176
internalFormat
GLenum internalFormat
Definition: SDL_opengl_glext.h:5063
GL_POINTS
#define GL_POINTS
Definition: SDL_opengl.h:216
SDL_BLENDFACTOR_ONE
Definition: SDL_blendmode.h:78
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139
GL_CULL_FACE
#define GL_CULL_FACE
Definition: SDL_opengl.h:302
GL_MODELVIEW
#define GL_MODELVIEW
Definition: SDL_opengl.h:271
SDL_Texture::b
Uint8 b
Definition: SDL_sysrender.h:58
SDL_GetBlendModeSrcAlphaFactor
SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode)
Definition: SDL_render.c:2214
SDL_BLENDOPERATION_SUBTRACT
Definition: SDL_blendmode.h:65
GLuint
unsigned int GLuint
Definition: SDL_opengl.h:185
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
GL_OUT_OF_MEMORY
#define GL_OUT_OF_MEMORY
Definition: SDL_opengl.h:725
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_RenderDriver
Definition: SDL_sysrender.h:175
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
SDL_Renderer::RenderCopyEx
int(* RenderCopyEx)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
Definition: SDL_sysrender.h:113
SDL_calloc
#define SDL_calloc
Definition: SDL_dynapi_overrides.h:375
SDL_GL_MakeCurrent
#define SDL_GL_MakeCurrent
Definition: SDL_dynapi_overrides.h:560
SDL_WINDOWEVENT_SHOWN
Definition: SDL_video.h:149
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_GetRendererOutputSize
#define SDL_GetRendererOutputSize
Definition: SDL_dynapi_overrides.h:305
SDL_BLENDFACTOR_ZERO
Definition: SDL_blendmode.h:77
GL_VERTEX_ARRAY
#define GL_VERTEX_ARRAY
Definition: SDL_opengl.h:228
SDL_Renderer::viewport
SDL_Rect viewport
Definition: SDL_sysrender.h:146
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:73
GL_ZERO
#define GL_ZERO
Definition: SDL_opengl.h:400
GL_ONE_MINUS_DST_COLOR
#define GL_ONE_MINUS_DST_COLOR
Definition: SDL_opengl.h:409
SDL_GetBlendModeDstColorFactor
SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode)
Definition: SDL_render.c:2200
color
GLuint color
Definition: SDL_opengl_glext.h:1148
GL_SRC_ALPHA
#define GL_SRC_ALPHA
Definition: SDL_opengl.h:404
GL_NEAREST
#define GL_NEAREST
Definition: SDL_opengl.h:704
SDL_Renderer::WindowEvent
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
Definition: SDL_sysrender.h:80
SDL_TEXTUREACCESS_TARGET
Definition: SDL_render.h:95
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA
Definition: SDL_blendmode.h:82
angle
GLfloat angle
Definition: SDL_opengl_glext.h:6097
type
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
SDL_Texture::format
Uint32 format
Definition: SDL_sysrender.h:52
SDL_Texture::modMode
int modMode
Definition: SDL_sysrender.h:56
GL_TEXTURE_COORD_ARRAY
#define GL_TEXTURE_COORD_ARRAY
Definition: SDL_opengl.h:232
GL_DST_ALPHA
#define GL_DST_ALPHA
Definition: SDL_opengl.h:406
SDL_Texture::driverdata
void * driverdata
Definition: SDL_sysrender.h:69
SDL_INLINE
#define SDL_INLINE
Definition: begin_code.h:131
GL_DEPTH_TEST
#define GL_DEPTH_TEST
Definition: SDL_opengl.h:327
SDL_WINDOW_OPENGL
Definition: SDL_video.h:101
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_GL_GetAttribute
#define SDL_GL_GetAttribute
Definition: SDL_dynapi_overrides.h:558
SDL_ConvertPixels
#define SDL_ConvertPixels
Definition: SDL_dynapi_overrides.h:465
SDL_Renderer::DestroyTexture
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:119
SDL_Renderer::CreateTexture
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:83
SDL_Renderer::RenderPresent
void(* RenderPresent)(SDL_Renderer *renderer)
Definition: SDL_sysrender.h:118
SDL_BLENDOPERATION_REV_SUBTRACT
Definition: SDL_blendmode.h:66
SDL_GL_DeleteContext
#define SDL_GL_DeleteContext
Definition: SDL_dynapi_overrides.h:567
SDL_Renderer::r
Uint8 r
Definition: SDL_sysrender.h:168
rects
EGLSurface EGLint * rects
Definition: eglext.h:282
SDL_stack_free
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:355
SDL_FRect::x
float x
Definition: SDL_sysrender.h:42
GL_TEXTURE_WRAP_S
#define GL_TEXTURE_WRAP_S
Definition: SDL_opengl.h:672
length
GLuint GLsizei GLsizei * length
Definition: SDL_opengl_glext.h:669
GL_TEXTURE_MIN_FILTER
#define GL_TEXTURE_MIN_FILTER
Definition: SDL_opengl.h:675
SDL_Renderer::a
Uint8 a
Definition: SDL_sysrender.h:168
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1109
SDL_GL_CONTEXT_PROFILE_ES
Definition: SDL_video.h:215
GL_UNPACK_ALIGNMENT
#define GL_UNPACK_ALIGNMENT
Definition: SDL_opengl.h:658
SDL_Renderer::UpdateClipRect
int(* UpdateClipRect)(SDL_Renderer *renderer)
Definition: SDL_sysrender.h:103
g
GLboolean GLboolean g
Definition: SDL_opengl_glext.h:1109
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1109
SDL_BLENDMODE_INVALID
Definition: SDL_blendmode.h:53
SDL_Texture::access
int access
Definition: SDL_sysrender.h:53
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_GL_SwapWindow
#define SDL_GL_SwapWindow
Definition: SDL_dynapi_overrides.h:566
SDL_FPoint::x
float x
Definition: SDL_sysrender.h:36
SDL_Renderer::clipping_enabled
SDL_bool clipping_enabled
Definition: SDL_sysrender.h:154
SDL_FRect
Definition: SDL_sysrender.h:40
SDL_FPoint
Definition: SDL_sysrender.h:34
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
SDL_Texture::h
int h
Definition: SDL_sysrender.h:55
SDL_FPoint::y
float y
Definition: SDL_sysrender.h:37
SDL_Texture::r
Uint8 r
Definition: SDL_sysrender.h:58