early-access version 2281

This commit is contained in:
pineappleEA
2021-12-07 02:20:09 +01:00
parent c2ae6d480a
commit c4fa174d53
591 changed files with 36978 additions and 18653 deletions

View File

@@ -159,7 +159,7 @@ SDL_PROC_UNUSED(void, glGetBooleanv, (GLenum pname, GLboolean * params))
SDL_PROC_UNUSED(void, glGetClipPlane, (GLenum plane, GLdouble * equation))
SDL_PROC_UNUSED(void, glGetDoublev, (GLenum pname, GLdouble * params))
SDL_PROC(GLenum, glGetError, (void))
SDL_PROC_UNUSED(void, glGetFloatv, (GLenum pname, GLfloat * params))
SDL_PROC(void, glGetFloatv, (GLenum pname, GLfloat * params))
SDL_PROC(void, glGetIntegerv, (GLenum pname, GLint * params))
SDL_PROC_UNUSED(void, glGetLightfv,
(GLenum light, GLenum pname, GLfloat * params))
@@ -302,14 +302,14 @@ SDL_PROC_UNUSED(void, glPolygonOffset, (GLfloat factor, GLfloat units))
SDL_PROC_UNUSED(void, glPolygonStipple, (const GLubyte * mask))
SDL_PROC_UNUSED(void, glPopAttrib, (void))
SDL_PROC_UNUSED(void, glPopClientAttrib, (void))
SDL_PROC(void, glPopMatrix, (void))
SDL_PROC_UNUSED(void, glPopMatrix, (void))
SDL_PROC_UNUSED(void, glPopName, (void))
SDL_PROC_UNUSED(void, glPrioritizeTextures,
(GLsizei n, const GLuint * textures,
const GLclampf * priorities))
SDL_PROC_UNUSED(void, glPushAttrib, (GLbitfield mask))
SDL_PROC_UNUSED(void, glPushClientAttrib, (GLbitfield mask))
SDL_PROC(void, glPushMatrix, (void))
SDL_PROC_UNUSED(void, glPushMatrix, (void))
SDL_PROC_UNUSED(void, glPushName, (GLuint name))
SDL_PROC_UNUSED(void, glRasterPos2d, (GLdouble x, GLdouble y))
SDL_PROC_UNUSED(void, glRasterPos2dv, (const GLdouble * v))
@@ -354,7 +354,7 @@ SDL_PROC_UNUSED(void, glRects,
(GLshort x1, GLshort y1, GLshort x2, GLshort y2))
SDL_PROC_UNUSED(void, glRectsv, (const GLshort * v1, const GLshort * v2))
SDL_PROC_UNUSED(GLint, glRenderMode, (GLenum mode))
SDL_PROC(void, glRotated,
SDL_PROC_UNUSED(void, glRotated,
(GLdouble angle, GLdouble x, GLdouble y, GLdouble z))
SDL_PROC(void, glRotatef,
(GLfloat angle, GLfloat x, GLfloat y, GLfloat z))
@@ -442,7 +442,7 @@ SDL_PROC(void, glTexSubImage2D,
GLsizei width, GLsizei height, GLenum format, GLenum type,
const GLvoid * pixels))
SDL_PROC_UNUSED(void, glTranslated, (GLdouble x, GLdouble y, GLdouble z))
SDL_PROC(void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z))
SDL_PROC_UNUSED(void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z))
SDL_PROC_UNUSED(void, glVertex2d, (GLdouble x, GLdouble y))
SDL_PROC_UNUSED(void, glVertex2dv, (const GLdouble * v))
SDL_PROC(void, glVertex2f, (GLfloat x, GLfloat y))

View File

@@ -21,7 +21,6 @@
#include "../../SDL_internal.h"
#if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED
#include "SDL_hints.h"
#include "SDL_opengl.h"
#include "../SDL_sysrender.h"
@@ -124,6 +123,7 @@ typedef struct
GLfloat texh;
GLenum format;
GLenum formattype;
GL_Shader shader;
void *pixels;
int pitch;
SDL_Rect locked_rect;
@@ -631,6 +631,57 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
}
#endif
if (texture->format == SDL_PIXELFORMAT_ABGR8888 || texture->format == SDL_PIXELFORMAT_ARGB8888) {
data->shader = SHADER_RGBA;
} else {
data->shader = SHADER_RGB;
}
#if SDL_HAVE_YUV
if (data->yuv || data->nv12) {
switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) {
case SDL_YUV_CONVERSION_JPEG:
if (data->yuv) {
data->shader = SHADER_YUV_JPEG;
} else if (texture->format == SDL_PIXELFORMAT_NV12) {
data->shader = SHADER_NV12_JPEG;
} else {
data->shader = SHADER_NV21_JPEG;
}
break;
case SDL_YUV_CONVERSION_BT601:
if (data->yuv) {
data->shader = SHADER_YUV_BT601;
} else if (texture->format == SDL_PIXELFORMAT_NV12) {
if (SDL_GetHintBoolean("SDL_RENDER_OPENGL_NV12_RG_SHADER", SDL_FALSE)) {
data->shader = SHADER_NV12_RG_BT601;
} else {
data->shader = SHADER_NV12_RA_BT601;
}
} else {
data->shader = SHADER_NV21_BT601;
}
break;
case SDL_YUV_CONVERSION_BT709:
if (data->yuv) {
data->shader = SHADER_YUV_BT709;
} else if (texture->format == SDL_PIXELFORMAT_NV12) {
if (SDL_GetHintBoolean("SDL_RENDER_OPENGL_NV12_RG_SHADER", SDL_FALSE)) {
data->shader = SHADER_NV12_RG_BT709;
} else {
data->shader = SHADER_NV12_RA_BT709;
}
} else {
data->shader = SHADER_NV21_BT709;
}
break;
default:
SDL_assert(!"unsupported YUV conversion mode");
break;
}
}
#endif /* SDL_HAVE_YUV */
return GL_CheckError("", renderer);
}
@@ -891,164 +942,98 @@ static int
GL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{
int i;
GLfloat prevx, prevy;
const size_t vertlen = (sizeof (GLfloat) * 2) * count;
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first);
if (!verts) {
return -1;
}
cmd->data.draw.count = count;
/* Offset to hit the center of the pixel. */
for (i = 0; i < count; i++) {
*(verts++) = 0.5f + points[i].x;
*(verts++) = 0.5f + points[i].y;
/* 0.5f offset to hit the center of the pixel. */
prevx = 0.5f + points->x;
prevy = 0.5f + points->y;
*(verts++) = prevx;
*(verts++) = prevy;
/* bump the end of each line segment out a quarter of a pixel, to provoke
the diamond-exit rule. Without this, you won't just drop the last
pixel of the last line segment, but you might also drop pixels at the
edge of any given line segment along the way too. */
for (i = 1; i < count; i++) {
const GLfloat xstart = prevx;
const GLfloat ystart = prevy;
const GLfloat xend = points[i].x + 0.5f; /* 0.5f to hit pixel center. */
const GLfloat yend = points[i].y + 0.5f;
/* bump a little in the direction we are moving in. */
const GLfloat deltax = xend - xstart;
const GLfloat deltay = yend - ystart;
const GLfloat angle = SDL_atan2f(deltay, deltax);
prevx = xend + (SDL_cosf(angle) * 0.25f);
prevy = yend + (SDL_sinf(angle) * 0.25f);
*(verts++) = prevx;
*(verts++) = prevy;
}
/* Make the last line segment one pixel longer, to satisfy the
diamond-exit rule. */
verts -= 4;
{
const GLfloat xstart = verts[0];
const GLfloat ystart = verts[1];
const GLfloat xend = verts[2];
const GLfloat yend = verts[3];
return 0;
}
if (ystart == yend) { /* horizontal line */
verts[(xend > xstart) ? 2 : 0] += 1.0f;
} else if (xstart == xend) { /* vertical line */
verts[(yend > ystart) ? 3 : 1] += 1.0f;
} else { /* bump a pixel in the direction we are moving in. */
const GLfloat deltax = xend - xstart;
const GLfloat deltay = yend - ystart;
const GLfloat angle = SDL_atan2f(deltay, deltax);
verts[2] += SDL_cosf(angle);
verts[3] += SDL_sinf(angle);
static int
GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const int *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y)
{
GL_TextureData *texturedata = NULL;
int i;
int count = indices ? num_indices : num_vertices;
GLfloat *verts;
int sz = 2 + 4 + (texture ? 2 : 0);
verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * sz * sizeof (GLfloat), 0, &cmd->data.draw.first);
if (!verts) {
return -1;
}
if (texture) {
texturedata = (GL_TextureData *) texture->driverdata;
}
cmd->data.draw.count = count;
size_indices = indices ? size_indices : 0;
for (i = 0; i < count; i++) {
int j;
float *xy_;
SDL_Color col_;
if (size_indices == 4) {
j = ((const Uint32 *)indices)[i];
} else if (size_indices == 2) {
j = ((const Uint16 *)indices)[i];
} else if (size_indices == 1) {
j = ((const Uint8 *)indices)[i];
} else {
j = i;
}
xy_ = (float *)((char*)xy + j * xy_stride);
col_ = *(SDL_Color *)((char*)color + j * color_stride);
*(verts++) = xy_[0] * scale_x;
*(verts++) = xy_[1] * scale_y;
*(verts++) = col_.r * inv255f;
*(verts++) = col_.g * inv255f;
*(verts++) = col_.b * inv255f;
*(verts++) = col_.a * inv255f;
if (texture) {
float *uv_ = (float *)((char*)uv + j * uv_stride);
*(verts++) = uv_[0] * texturedata->texw;
*(verts++) = uv_[1] * texturedata->texh;
}
}
return 0;
}
static int
GL_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
{
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 4 * sizeof (GLfloat), 0, &cmd->data.draw.first);
int i;
if (!verts) {
return -1;
}
cmd->data.draw.count = count;
for (i = 0; i < count; i++) {
const SDL_FRect *rect = &rects[i];
*(verts++) = rect->x;
*(verts++) = rect->y;
*(verts++) = rect->x + rect->w;
*(verts++) = rect->y + rect->h;
}
return 0;
}
static int
GL_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
{
GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
GLfloat minx, miny, maxx, maxy;
GLfloat minu, maxu, minv, maxv;
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, 8 * sizeof (GLfloat), 0, &cmd->data.draw.first);
if (!verts) {
return -1;
}
cmd->data.draw.count = 1;
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;
cmd->data.draw.count = 1;
*(verts++) = minx;
*(verts++) = miny;
*(verts++) = maxx;
*(verts++) = maxy;
*(verts++) = minu;
*(verts++) = maxu;
*(verts++) = minv;
*(verts++) = maxv;
return 0;
}
static int
GL_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
{
GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
GLfloat minx, miny, maxx, maxy;
GLfloat centerx, centery;
GLfloat minu, maxu, minv, maxv;
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, 11 * sizeof (GLfloat), 0, &cmd->data.draw.first);
if (!verts) {
return -1;
}
centerx = center->x;
centery = center->y;
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;
cmd->data.draw.count = 1;
*(verts++) = minx;
*(verts++) = miny;
*(verts++) = maxx;
*(verts++) = maxy;
*(verts++) = minu;
*(verts++) = maxu;
*(verts++) = minv;
*(verts++) = maxv;
*(verts++) = (GLfloat) dstrect->x + centerx;
*(verts++) = (GLfloat) dstrect->y + centery;
*(verts++) = (GLfloat) angle;
return 0;
}
@@ -1128,71 +1113,33 @@ SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd)
{
SDL_Texture *texture = cmd->data.draw.texture;
const GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
GL_Shader shader;
if (texture->format == SDL_PIXELFORMAT_ABGR8888 || texture->format == SDL_PIXELFORMAT_ARGB8888) {
shader = SHADER_RGBA;
} else {
shader = SHADER_RGB;
}
#if SDL_HAVE_YUV
if (data->shaders) {
if (texturedata->yuv || texturedata->nv12) {
switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) {
case SDL_YUV_CONVERSION_JPEG:
if (texturedata->yuv) {
shader = SHADER_YUV_JPEG;
} else if (texture->format == SDL_PIXELFORMAT_NV12) {
shader = SHADER_NV12_JPEG;
} else {
shader = SHADER_NV21_JPEG;
}
break;
case SDL_YUV_CONVERSION_BT601:
if (texturedata->yuv) {
shader = SHADER_YUV_BT601;
} else if (texture->format == SDL_PIXELFORMAT_NV12) {
shader = SHADER_NV12_BT601;
} else {
shader = SHADER_NV21_BT601;
}
break;
case SDL_YUV_CONVERSION_BT709:
if (texturedata->yuv) {
shader = SHADER_YUV_BT709;
} else if (texture->format == SDL_PIXELFORMAT_NV12) {
shader = SHADER_NV12_BT709;
} else {
shader = SHADER_NV21_BT709;
}
break;
default:
SDL_assert(!"unsupported YUV conversion mode");
break;
}
}
}
#endif
SetDrawState(data, cmd, shader);
SetDrawState(data, cmd, texturedata->shader);
if (texture != data->drawstate.texture) {
const GLenum textype = data->textype;
#if SDL_HAVE_YUV
if (texturedata->yuv) {
data->glActiveTextureARB(GL_TEXTURE2_ARB);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE2_ARB);
}
data->glBindTexture(textype, texturedata->vtexture);
data->glActiveTextureARB(GL_TEXTURE1_ARB);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE1_ARB);
}
data->glBindTexture(textype, texturedata->utexture);
}
if (texturedata->nv12) {
data->glActiveTextureARB(GL_TEXTURE1_ARB);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE1_ARB);
}
data->glBindTexture(textype, texturedata->utexture);
}
#endif
data->glActiveTextureARB(GL_TEXTURE0_ARB);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE0_ARB);
}
data->glBindTexture(textype, texturedata->texture);
data->drawstate.texture = texture;
@@ -1212,9 +1159,22 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
data->drawstate.target = renderer->target;
if (!data->drawstate.target) {
SDL_GL_GetDrawableSize(renderer->window, &data->drawstate.drawablew, &data->drawstate.drawableh);
int w, h;
SDL_GL_GetDrawableSize(renderer->window, &w, &h);
if ((w != data->drawstate.drawablew) || (h != data->drawstate.drawableh)) {
data->drawstate.viewport_dirty = SDL_TRUE; // if the window dimensions changed, invalidate the current viewport, etc.
data->drawstate.cliprect_dirty = SDL_TRUE;
data->drawstate.drawablew = w;
data->drawstate.drawableh = h;
}
}
#ifdef __MACOSX__
// On macOS, moving the window seems to invalidate the OpenGL viewport state,
// so don't bother trying to persist it across frames; always reset it.
// Workaround for: https://github.com/libsdl-org/SDL/issues/1504
data->drawstate.viewport_dirty = SDL_TRUE;
#endif
while (cmd) {
switch (cmd->command) {
@@ -1223,7 +1183,7 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
const Uint8 g = cmd->data.color.g;
const Uint8 b = cmd->data.color.b;
const Uint8 a = cmd->data.color.a;
const Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
const Uint32 color = (((Uint32)a << 24) | (r << 16) | (g << 8) | b);
if (color != data->drawstate.color) {
data->glColor4f((GLfloat) r * inv255f,
(GLfloat) g * inv255f,
@@ -1261,7 +1221,7 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
const Uint8 g = cmd->data.color.g;
const Uint8 b = cmd->data.color.b;
const Uint8 a = cmd->data.color.a;
const Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
const Uint32 color = (((Uint32)a << 24) | (r << 16) | (g << 8) | b);
if (color != data->drawstate.clear_color) {
const GLfloat fr = ((GLfloat) r) * inv255f;
const GLfloat fg = ((GLfloat) g) * inv255f;
@@ -1306,72 +1266,56 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
break;
}
case SDL_RENDERCMD_FILL_RECTS: {
const size_t count = cmd->data.draw.count;
case SDL_RENDERCMD_FILL_RECTS: /* unused */
break;
case SDL_RENDERCMD_COPY: /* unused */
break;
case SDL_RENDERCMD_COPY_EX: /* unused */
break;
case SDL_RENDERCMD_GEOMETRY: {
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
SetDrawState(data, cmd, SHADER_SOLID);
for (i = 0; i < count; ++i, verts += 4) {
data->glRectf(verts[0], verts[1], verts[2], verts[3]);
SDL_Texture *texture = cmd->data.draw.texture;
const size_t count = cmd->data.draw.count;
if (texture) {
SetCopyState(data, cmd);
} else {
SetDrawState(data, cmd, SHADER_SOLID);
}
{
size_t j;
float currentColor[4];
data->glGetFloatv(GL_CURRENT_COLOR, currentColor);
data->glBegin(GL_TRIANGLES);
for (j = 0; j < count; ++j)
{
const GLfloat x = *(verts++);
const GLfloat y = *(verts++);
const GLfloat r = *(verts++);
const GLfloat g = *(verts++);
const GLfloat b = *(verts++);
const GLfloat a = *(verts++);
data->glColor4f(r, g, b, a);
if (texture) {
GLfloat u = *(verts++);
GLfloat v = *(verts++);
data->glTexCoord2f(u,v);
}
data->glVertex2f(x, y);
}
data->glEnd();
data->glColor4f(currentColor[0], currentColor[1], currentColor[2], currentColor[3]);
}
break;
}
}
case SDL_RENDERCMD_COPY: {
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
const GLfloat minx = verts[0];
const GLfloat miny = verts[1];
const GLfloat maxx = verts[2];
const GLfloat maxy = verts[3];
const GLfloat minu = verts[4];
const GLfloat maxu = verts[5];
const GLfloat minv = verts[6];
const GLfloat maxv = verts[7];
SetCopyState(data, cmd);
data->glBegin(GL_TRIANGLE_STRIP);
data->glTexCoord2f(minu, minv);
data->glVertex2f(minx, miny);
data->glTexCoord2f(maxu, minv);
data->glVertex2f(maxx, miny);
data->glTexCoord2f(minu, maxv);
data->glVertex2f(minx, maxy);
data->glTexCoord2f(maxu, maxv);
data->glVertex2f(maxx, maxy);
data->glEnd();
break;
}
case SDL_RENDERCMD_COPY_EX: {
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
const GLfloat minx = verts[0];
const GLfloat miny = verts[1];
const GLfloat maxx = verts[2];
const GLfloat maxy = verts[3];
const GLfloat minu = verts[4];
const GLfloat maxu = verts[5];
const GLfloat minv = verts[6];
const GLfloat maxv = verts[7];
const GLfloat translatex = verts[8];
const GLfloat translatey = verts[9];
const GLdouble angle = verts[10];
SetCopyState(data, cmd);
/* Translate to flip, rotate, translate to position */
data->glPushMatrix();
data->glTranslatef(translatex, translatey, 0.0f);
data->glRotated(angle, 0.0, 0.0, 1.0);
data->glBegin(GL_TRIANGLE_STRIP);
data->glTexCoord2f(minu, minv);
data->glVertex2f(minx, miny);
data->glTexCoord2f(maxu, minv);
data->glVertex2f(maxx, miny);
data->glTexCoord2f(minu, maxv);
data->glVertex2f(minx, maxy);
data->glTexCoord2f(maxu, maxv);
data->glVertex2f(maxx, maxy);
data->glEnd();
data->glPopMatrix();
break;
}
case SDL_RENDERCMD_NO_OP:
break;
@@ -1544,13 +1488,29 @@ GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, floa
data->glEnable(textype);
#if SDL_HAVE_YUV
if (texturedata->yuv) {
data->glActiveTextureARB(GL_TEXTURE2_ARB);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE2_ARB);
}
data->glBindTexture(textype, texturedata->vtexture);
data->glActiveTextureARB(GL_TEXTURE1_ARB);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE1_ARB);
}
data->glBindTexture(textype, texturedata->utexture);
data->glActiveTextureARB(GL_TEXTURE0_ARB);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE0_ARB);
}
}
if (texturedata->nv12) {
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE1_ARB);
}
data->glBindTexture(textype, texturedata->utexture);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE0_ARB);
}
}
#endif
data->glBindTexture(textype, texturedata->texture);
@@ -1558,9 +1518,12 @@ GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, floa
data->drawstate.texturing = SDL_TRUE;
data->drawstate.texture = texture;
if(texw) *texw = (float)texturedata->texw;
if(texh) *texh = (float)texturedata->texh;
if (texw) {
*texw = (float)texturedata->texw;
}
if (texh) {
*texh = (float)texturedata->texh;
}
return 0;
}
@@ -1575,16 +1538,35 @@ GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
#if SDL_HAVE_YUV
if (texturedata->yuv) {
data->glActiveTextureARB(GL_TEXTURE2_ARB);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE2_ARB);
}
data->glBindTexture(textype, 0);
data->glDisable(textype);
data->glActiveTextureARB(GL_TEXTURE1_ARB);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE1_ARB);
}
data->glBindTexture(textype, 0);
data->glDisable(textype);
data->glActiveTextureARB(GL_TEXTURE0_ARB);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE0_ARB);
}
}
if (texturedata->nv12) {
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE1_ARB);
}
data->glBindTexture(textype, 0);
data->glDisable(textype);
if (data->GL_ARB_multitexture_supported) {
data->glActiveTextureARB(GL_TEXTURE0_ARB);
}
}
#endif
data->glBindTexture(textype, 0);
data->glDisable(textype);
data->drawstate.texturing = SDL_FALSE;
@@ -1593,6 +1575,26 @@ GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
return 0;
}
static int
GL_SetVSync(SDL_Renderer * renderer, const int vsync)
{
int retval;
if (vsync) {
retval = SDL_GL_SetSwapInterval(1);
} else {
retval = SDL_GL_SetSwapInterval(0);
}
if (retval != 0) {
return retval;
}
if (SDL_GL_GetSwapInterval() > 0) {
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
} else {
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
}
return retval;
}
static SDL_Renderer *
GL_CreateRenderer(SDL_Window * window, Uint32 flags)
@@ -1651,14 +1653,13 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->QueueSetDrawColor = GL_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
renderer->QueueDrawPoints = GL_QueueDrawPoints;
renderer->QueueDrawLines = GL_QueueDrawLines;
renderer->QueueFillRects = GL_QueueFillRects;
renderer->QueueCopy = GL_QueueCopy;
renderer->QueueCopyEx = GL_QueueCopyEx;
renderer->QueueGeometry = GL_QueueGeometry;
renderer->RunCommandQueue = GL_RunCommandQueue;
renderer->RenderReadPixels = GL_RenderReadPixels;
renderer->RenderPresent = GL_RenderPresent;
renderer->DestroyTexture = GL_DestroyTexture;
renderer->DestroyRenderer = GL_DestroyRenderer;
renderer->SetVSync = GL_SetVSync;
renderer->GL_BindTexture = GL_BindTexture;
renderer->GL_UnbindTexture = GL_UnbindTexture;
renderer->info = GL_RenderDriver.info;

View File

@@ -149,7 +149,7 @@ struct GL_ShaderContext
"uniform sampler2D tex1; // U/V \n" \
"\n" \
#define NV12_SHADER_BODY \
#define NV12_RA_SHADER_BODY \
"\n" \
"void main()\n" \
"{\n" \
@@ -174,6 +174,31 @@ struct GL_ShaderContext
" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" \
"}" \
#define NV12_RG_SHADER_BODY \
"\n" \
"void main()\n" \
"{\n" \
" vec2 tcoord;\n" \
" vec3 yuv, rgb;\n" \
"\n" \
" // Get the Y value \n" \
" tcoord = v_texCoord;\n" \
" yuv.x = texture2D(tex0, tcoord).r;\n" \
"\n" \
" // Get the U and V values \n" \
" tcoord *= UVCoordScale;\n" \
" yuv.yz = texture2D(tex1, tcoord).rg;\n" \
"\n" \
" // Do the color transform \n" \
" yuv += offset;\n" \
" rgb.r = dot(yuv, Rcoeff);\n" \
" rgb.g = dot(yuv, Gcoeff);\n" \
" rgb.b = dot(yuv, Bcoeff);\n" \
"\n" \
" // That was easy. :) \n" \
" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" \
"}" \
#define NV21_SHADER_PROLOGUE \
"varying vec4 v_color;\n" \
"varying vec2 v_texCoord;\n" \
@@ -294,25 +319,43 @@ static const char *shader_source[NUM_SHADERS][2] =
/* fragment shader */
NV12_SHADER_PROLOGUE
JPEG_SHADER_CONSTANTS
NV12_SHADER_BODY
NV12_RA_SHADER_BODY
},
/* SHADER_NV12_BT601 */
/* SHADER_NV12_RA_BT601 */
{
/* vertex shader */
TEXTURE_VERTEX_SHADER,
/* fragment shader */
NV12_SHADER_PROLOGUE
BT601_SHADER_CONSTANTS
NV12_SHADER_BODY
NV12_RA_SHADER_BODY
},
/* SHADER_NV12_BT709 */
/* SHADER_NV12_RG_BT601 */
{
/* vertex shader */
TEXTURE_VERTEX_SHADER,
/* fragment shader */
NV12_SHADER_PROLOGUE
BT601_SHADER_CONSTANTS
NV12_RG_SHADER_BODY
},
/* SHADER_NV12_RA_BT709 */
{
/* vertex shader */
TEXTURE_VERTEX_SHADER,
/* fragment shader */
NV12_SHADER_PROLOGUE
BT709_SHADER_CONSTANTS
NV12_SHADER_BODY
NV12_RA_SHADER_BODY
},
/* SHADER_NV12_RG_BT709 */
{
/* vertex shader */
TEXTURE_VERTEX_SHADER,
/* fragment shader */
NV12_SHADER_PROLOGUE
BT709_SHADER_CONSTANTS
NV12_RG_SHADER_BODY
},
/* SHADER_NV21_JPEG */
{

View File

@@ -36,8 +36,10 @@ typedef enum {
SHADER_YUV_BT601,
SHADER_YUV_BT709,
SHADER_NV12_JPEG,
SHADER_NV12_BT601,
SHADER_NV12_BT709,
SHADER_NV12_RA_BT601,
SHADER_NV12_RG_BT601,
SHADER_NV12_RA_BT709,
SHADER_NV12_RG_BT709,
SHADER_NV21_JPEG,
SHADER_NV21_BT601,
SHADER_NV21_BT709,