Fixed orientation and color when rendering to texture
This commit is contained in:
parent
e064340717
commit
6cd1ae105e
1 changed files with 74 additions and 62 deletions
|
@ -906,15 +906,23 @@ GLES2_SetOrthographicProjection(SDL_Renderer *renderer)
|
||||||
projection[0][2] = 0.0f;
|
projection[0][2] = 0.0f;
|
||||||
projection[0][3] = 0.0f;
|
projection[0][3] = 0.0f;
|
||||||
projection[1][0] = 0.0f;
|
projection[1][0] = 0.0f;
|
||||||
|
if (renderer->target) {
|
||||||
|
projection[1][1] = 2.0f / renderer->viewport.h;
|
||||||
|
} else {
|
||||||
projection[1][1] = -2.0f / renderer->viewport.h;
|
projection[1][1] = -2.0f / renderer->viewport.h;
|
||||||
|
}
|
||||||
projection[1][2] = 0.0f;
|
projection[1][2] = 0.0f;
|
||||||
projection[1][3] = 0.0f;
|
projection[1][3] = 0.0f;
|
||||||
projection[2][0] = 0.0f;
|
projection[2][0] = 0.0f;
|
||||||
projection[2][1] = 0.0f;
|
projection[2][1] = 0.0f;
|
||||||
projection[2][2] = 1.0f;
|
projection[2][2] = 0.0f;
|
||||||
projection[2][3] = 0.0f;
|
projection[2][3] = 0.0f;
|
||||||
projection[3][0] = -1.0f;
|
projection[3][0] = -1.0f;
|
||||||
|
if (renderer->target) {
|
||||||
|
projection[3][1] = -1.0f;
|
||||||
|
} else {
|
||||||
projection[3][1] = 1.0f;
|
projection[3][1] = 1.0f;
|
||||||
|
}
|
||||||
projection[3][2] = 0.0f;
|
projection[3][2] = 0.0f;
|
||||||
projection[3][3] = 1.0f;
|
projection[3][3] = 1.0f;
|
||||||
|
|
||||||
|
@ -1027,11 +1035,21 @@ GLES2_SetDrawingState(SDL_Renderer * renderer)
|
||||||
|
|
||||||
/* Select the color to draw with */
|
/* Select the color to draw with */
|
||||||
locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
|
locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
|
||||||
|
if (renderer->target &&
|
||||||
|
(renderer->target->format == SDL_PIXELFORMAT_ARGB8888 ||
|
||||||
|
renderer->target->format == SDL_PIXELFORMAT_RGB888)) {
|
||||||
|
rdata->glUniform4f(locColor,
|
||||||
|
renderer->b * inv255f,
|
||||||
|
renderer->g * inv255f,
|
||||||
|
renderer->r * inv255f,
|
||||||
|
renderer->a * inv255f);
|
||||||
|
} else {
|
||||||
rdata->glUniform4f(locColor,
|
rdata->glUniform4f(locColor,
|
||||||
renderer->r * inv255f,
|
renderer->r * inv255f,
|
||||||
renderer->g * inv255f,
|
renderer->g * inv255f,
|
||||||
renderer->b * inv255f,
|
renderer->b * inv255f,
|
||||||
renderer->a * inv255f);
|
renderer->a * inv255f);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1254,11 +1272,21 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
|
||||||
|
|
||||||
/* Configure color modulation */
|
/* Configure color modulation */
|
||||||
locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION];
|
locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION];
|
||||||
|
if (renderer->target &&
|
||||||
|
(renderer->target->format == SDL_PIXELFORMAT_ARGB8888 ||
|
||||||
|
renderer->target->format == SDL_PIXELFORMAT_RGB888)) {
|
||||||
|
rdata->glUniform4f(locModulation,
|
||||||
|
texture->b * inv255f,
|
||||||
|
texture->g * inv255f,
|
||||||
|
texture->r * inv255f,
|
||||||
|
texture->a * inv255f);
|
||||||
|
} else {
|
||||||
rdata->glUniform4f(locModulation,
|
rdata->glUniform4f(locModulation,
|
||||||
texture->r * inv255f,
|
texture->r * inv255f,
|
||||||
texture->g * inv255f,
|
texture->g * inv255f,
|
||||||
texture->b * inv255f,
|
texture->b * inv255f,
|
||||||
texture->a * inv255f);
|
texture->a * inv255f);
|
||||||
|
}
|
||||||
|
|
||||||
/* Configure texture blending */
|
/* Configure texture blending */
|
||||||
GLES2_SetBlendMode(rdata, blendMode);
|
GLES2_SetBlendMode(rdata, blendMode);
|
||||||
|
@ -1266,18 +1294,6 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
|
||||||
GLES2_SetTexCoords(rdata, SDL_TRUE);
|
GLES2_SetTexCoords(rdata, SDL_TRUE);
|
||||||
|
|
||||||
/* Emit the textured quad */
|
/* Emit the textured quad */
|
||||||
if (renderer->target) {
|
|
||||||
// Flip the texture vertically to compensate for the inversion it'll be subjected to later when it's rendered to the screen
|
|
||||||
vertices[0] = (GLfloat)dstrect->x;
|
|
||||||
vertices[1] = (GLfloat)renderer->viewport.h-dstrect->y;
|
|
||||||
vertices[2] = (GLfloat)(dstrect->x + dstrect->w);
|
|
||||||
vertices[3] = (GLfloat)renderer->viewport.h-dstrect->y;
|
|
||||||
vertices[4] = (GLfloat)dstrect->x;
|
|
||||||
vertices[5] = (GLfloat)renderer->viewport.h-(dstrect->y + dstrect->h);
|
|
||||||
vertices[6] = (GLfloat)(dstrect->x + dstrect->w);
|
|
||||||
vertices[7] = (GLfloat)renderer->viewport.h-(dstrect->y + dstrect->h);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
vertices[0] = (GLfloat)dstrect->x;
|
vertices[0] = (GLfloat)dstrect->x;
|
||||||
vertices[1] = (GLfloat)dstrect->y;
|
vertices[1] = (GLfloat)dstrect->y;
|
||||||
vertices[2] = (GLfloat)(dstrect->x + dstrect->w);
|
vertices[2] = (GLfloat)(dstrect->x + dstrect->w);
|
||||||
|
@ -1286,7 +1302,6 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
|
||||||
vertices[5] = (GLfloat)(dstrect->y + dstrect->h);
|
vertices[5] = (GLfloat)(dstrect->y + dstrect->h);
|
||||||
vertices[6] = (GLfloat)(dstrect->x + dstrect->w);
|
vertices[6] = (GLfloat)(dstrect->x + dstrect->w);
|
||||||
vertices[7] = (GLfloat)(dstrect->y + dstrect->h);
|
vertices[7] = (GLfloat)(dstrect->y + dstrect->h);
|
||||||
}
|
|
||||||
rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
|
rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
|
||||||
texCoords[0] = srcrect->x / (GLfloat)texture->w;
|
texCoords[0] = srcrect->x / (GLfloat)texture->w;
|
||||||
texCoords[1] = srcrect->y / (GLfloat)texture->h;
|
texCoords[1] = srcrect->y / (GLfloat)texture->h;
|
||||||
|
@ -1423,11 +1438,21 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
|
||||||
|
|
||||||
/* Configure color modulation */
|
/* Configure color modulation */
|
||||||
locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION];
|
locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION];
|
||||||
|
if (renderer->target &&
|
||||||
|
(renderer->target->format == SDL_PIXELFORMAT_ARGB8888 ||
|
||||||
|
renderer->target->format == SDL_PIXELFORMAT_RGB888)) {
|
||||||
|
rdata->glUniform4f(locModulation,
|
||||||
|
texture->b * inv255f,
|
||||||
|
texture->g * inv255f,
|
||||||
|
texture->r * inv255f,
|
||||||
|
texture->a * inv255f);
|
||||||
|
} else {
|
||||||
rdata->glUniform4f(locModulation,
|
rdata->glUniform4f(locModulation,
|
||||||
texture->r * inv255f,
|
texture->r * inv255f,
|
||||||
texture->g * inv255f,
|
texture->g * inv255f,
|
||||||
texture->b * inv255f,
|
texture->b * inv255f,
|
||||||
texture->a * inv255f);
|
texture->a * inv255f);
|
||||||
|
}
|
||||||
|
|
||||||
/* Configure texture blending */
|
/* Configure texture blending */
|
||||||
GLES2_SetBlendMode(rdata, blendMode);
|
GLES2_SetBlendMode(rdata, blendMode);
|
||||||
|
@ -1435,18 +1460,6 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
|
||||||
GLES2_SetTexCoords(rdata, SDL_TRUE);
|
GLES2_SetTexCoords(rdata, SDL_TRUE);
|
||||||
|
|
||||||
/* Emit the textured quad */
|
/* Emit the textured quad */
|
||||||
if (renderer->target) {
|
|
||||||
// Flip the texture vertically to compensate for the inversion it'll be subjected to later when it's rendered to the screen
|
|
||||||
vertices[0] = (GLfloat)dstrect->x;
|
|
||||||
vertices[1] = (GLfloat)renderer->viewport.h-dstrect->y;
|
|
||||||
vertices[2] = (GLfloat)(dstrect->x + dstrect->w);
|
|
||||||
vertices[3] = (GLfloat)renderer->viewport.h-dstrect->y;
|
|
||||||
vertices[4] = (GLfloat)dstrect->x;
|
|
||||||
vertices[5] = (GLfloat)renderer->viewport.h-(dstrect->y + dstrect->h);
|
|
||||||
vertices[6] = (GLfloat)(dstrect->x + dstrect->w);
|
|
||||||
vertices[7] = (GLfloat)renderer->viewport.h-(dstrect->y + dstrect->h);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
vertices[0] = (GLfloat)dstrect->x;
|
vertices[0] = (GLfloat)dstrect->x;
|
||||||
vertices[1] = (GLfloat)dstrect->y;
|
vertices[1] = (GLfloat)dstrect->y;
|
||||||
vertices[2] = (GLfloat)(dstrect->x + dstrect->w);
|
vertices[2] = (GLfloat)(dstrect->x + dstrect->w);
|
||||||
|
@ -1455,7 +1468,6 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
|
||||||
vertices[5] = (GLfloat)(dstrect->y + dstrect->h);
|
vertices[5] = (GLfloat)(dstrect->y + dstrect->h);
|
||||||
vertices[6] = (GLfloat)(dstrect->x + dstrect->w);
|
vertices[6] = (GLfloat)(dstrect->x + dstrect->w);
|
||||||
vertices[7] = (GLfloat)(dstrect->y + dstrect->h);
|
vertices[7] = (GLfloat)(dstrect->y + dstrect->h);
|
||||||
}
|
|
||||||
if (flip & SDL_FLIP_HORIZONTAL) {
|
if (flip & SDL_FLIP_HORIZONTAL) {
|
||||||
tmp = vertices[0];
|
tmp = vertices[0];
|
||||||
vertices[0] = vertices[4] = vertices[2];
|
vertices[0] = vertices[4] = vertices[2];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue