Merged default into iOS-improvements

--HG--
branch : iOS-improvements
This commit is contained in:
Alex Szpakowski 2015-01-15 01:15:24 -04:00
commit f2452bba77
110 changed files with 4698 additions and 1105 deletions

View file

@ -28,7 +28,20 @@
#include "../../video/SDL_blit.h"
#include "SDL_shaders_gles2.h"
/* To prevent unnecessary window recreation,
/* !!! FIXME: Emscripten makes these into WebGL calls, and WebGL doesn't offer
!!! FIXME: client-side arrays (without an Emscripten compatibility hack,
!!! FIXME: at least), but the current VBO code here is dramatically
!!! FIXME: slower on actual iOS devices, even though the iOS Simulator
!!! FIXME: is okay. Some time after 2.0.4 ships, we should revisit this,
!!! FIXME: fix the performance bottleneck, and make everything use VBOs.
*/
#ifdef __EMSCRIPTEN__
#define SDL_GLES2_USE_VBOS 1
#else
#define SDL_GLES2_USE_VBOS 0
#endif
/* To prevent unnecessary window recreation,
* these should match the defaults selected in SDL_GL_ResetAttributes
*/
#define RENDERER_CONTEXT_MAJOR 2
@ -180,6 +193,11 @@ typedef struct GLES2_DriverContext
GLES2_ProgramCache program_cache;
GLES2_ProgramCacheEntry *current_program;
Uint8 clear_r, clear_g, clear_b, clear_a;
#if SDL_GLES2_USE_VBOS
GLuint vertex_buffers[4];
GLsizeiptr vertex_buffer_size[4];
#endif
} GLES2_DriverContext;
#define GLES2_MAX_CACHED_PROGRAMS 8
@ -1392,6 +1410,33 @@ GLES2_SetDrawingState(SDL_Renderer * renderer)
return 0;
}
static int
GLES2_UpdateVertexBuffer(SDL_Renderer *renderer, GLES2_Attribute attr,
const void *vertexData, size_t dataSizeInBytes)
{
GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
#if !SDL_GLES2_USE_VBOS
data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, vertexData);
#else
if (!data->vertex_buffers[attr])
data->glGenBuffers(1, &data->vertex_buffers[attr]);
data->glBindBuffer(GL_ARRAY_BUFFER, data->vertex_buffers[attr]);
if (data->vertex_buffer_size[attr] < dataSizeInBytes) {
data->glBufferData(GL_ARRAY_BUFFER, dataSizeInBytes, vertexData, GL_STREAM_DRAW);
data->vertex_buffer_size[attr] = dataSizeInBytes;
} else {
data->glBufferSubData(GL_ARRAY_BUFFER, 0, dataSizeInBytes, vertexData);
}
data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, 0);
#endif
return 0;
}
static int
GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
{
@ -1412,7 +1457,8 @@ GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int cou
vertices[idx * 2] = x;
vertices[(idx * 2) + 1] = y;
}
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, count * 2 * sizeof(GLfloat));
data->glDrawArrays(GL_POINTS, 0, count);
SDL_stack_free(vertices);
return 0;
@ -1438,7 +1484,8 @@ GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int coun
vertices[idx * 2] = x;
vertices[(idx * 2) + 1] = y;
}
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, count * 2 * sizeof(GLfloat));
data->glDrawArrays(GL_LINE_STRIP, 0, count);
/* We need to close the endpoint of the line */
@ -1479,7 +1526,8 @@ GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
vertices[5] = yMax;
vertices[6] = xMax;
vertices[7] = yMax;
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
return GL_CheckError("", renderer);
@ -1675,7 +1723,8 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
vertices[5] = (dstrect->y + dstrect->h);
vertices[6] = (dstrect->x + dstrect->w);
vertices[7] = (dstrect->y + dstrect->h);
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
texCoords[0] = srcrect->x / (GLfloat)texture->w;
texCoords[1] = srcrect->y / (GLfloat)texture->h;
texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
@ -1684,7 +1733,8 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);*/
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_TEXCOORD, texCoords, 8 * sizeof(GLfloat));
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
return GL_CheckError("", renderer);
@ -1734,9 +1784,13 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
vertices[5] = vertices[7] = tmp;
}
data->glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 1, GL_FLOAT, GL_FALSE, 0, &fAngle);
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 1, GL_FLOAT, GL_FALSE, 0, &fAngle);
data->glVertexAttribPointer(GLES2_ATTRIBUTE_CENTER, 2, GL_FLOAT, GL_FALSE, 0, translate);
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 4 * sizeof(GLfloat));
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_CENTER, translate, 8 * sizeof(GLfloat));
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
texCoords[0] = srcrect->x / (GLfloat)texture->w;
texCoords[1] = srcrect->y / (GLfloat)texture->h;
@ -1746,7 +1800,8 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);*/
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_TEXCOORD, texCoords, 8 * sizeof(GLfloat));
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_CENTER);
data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE);