mirror of
https://github.com/Ryujinx/SDL.git
synced 2024-12-23 01:05:28 +00:00
Use normalized texture coordinates
This commit is contained in:
parent
5828cc415a
commit
f73c1eff10
|
@ -144,8 +144,7 @@ typedef struct SDL_Vertex
|
|||
{
|
||||
SDL_FPoint position; /**< Vertex position, in SDL_Renderer coordinates */
|
||||
SDL_Color color; /**< Vertex color */
|
||||
SDL_FPoint tex_coord; /**< Texture coordinates (0..texture width, 0..texture height),
|
||||
if needed */
|
||||
SDL_FPoint tex_coord; /**< Normalized texture coordinates, if needed */
|
||||
} SDL_Vertex;
|
||||
|
||||
|
||||
|
@ -1472,7 +1471,6 @@ extern DECLSPEC int SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
|
|||
SDL_Vertex *vertices, int num_vertices,
|
||||
int *indices, int num_indices);
|
||||
|
||||
|
||||
/**
|
||||
* Read pixels from the current rendering target to an array of pixels.
|
||||
*
|
||||
|
|
|
@ -3369,7 +3369,7 @@ SDL_RenderGeometry(SDL_Renderer *renderer,
|
|||
|
||||
if (texture) {
|
||||
for (i = 0; i < num_vertices; ++i) {
|
||||
if (vertices[i].tex_coord.x < 0 || vertices[i].tex_coord.y < 0 || vertices[i].tex_coord.x >= texture->w || vertices[i].tex_coord.y >= texture->h) {
|
||||
if (vertices[i].tex_coord.x < 0.0f || vertices[i].tex_coord.y < 0.0f || vertices[i].tex_coord.x > 1.0f || vertices[i].tex_coord.y > 1.0f) {
|
||||
return SDL_SetError("Values of 'vertices' out of bounds");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1891,8 +1891,8 @@ D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
|
|||
verts->color.w = v->color.a / 255.0f;
|
||||
|
||||
if (texture) {
|
||||
verts->tex.x = v->tex_coord.x / texture->w;
|
||||
verts->tex.y = v->tex_coord.y / texture->h;
|
||||
verts->tex.x = v->tex_coord.x;
|
||||
verts->tex.y = v->tex_coord.y;
|
||||
} else {
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
|
|
|
@ -1381,12 +1381,8 @@ static int
|
|||
METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
SDL_Vertex *vertices, int num_vertices, int *indices, int num_indices, float scale_x, float scale_y)
|
||||
{
|
||||
const float texw = (float) (texture ? texture->w : 0);
|
||||
const float texh = (float) (texture ? texture->h : 0);
|
||||
int count = indices ? num_indices : num_vertices;
|
||||
int i;
|
||||
int sz = 2 + 4 + (texture ? 2 : 0);
|
||||
|
||||
const size_t vertlen = sizeof (float) * sz * count;
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
|
@ -1395,7 +1391,7 @@ METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
|
|||
|
||||
cmd->data.draw.count = count;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
SDL_Vertex *v = &vertices[indices ? indices[i] : i];
|
||||
|
||||
*(verts++) = v->position.x * scale_x;
|
||||
|
@ -1407,8 +1403,8 @@ METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
|
|||
*(verts++) = v->color.a * inv255f;
|
||||
|
||||
if (texture) {
|
||||
*(verts++) = normtex(v->tex_coord.x, texw);
|
||||
*(verts++) = normtex(v->tex_coord.y, texh);
|
||||
*(verts++) = v->tex_coord.x;
|
||||
*(verts++) = v->tex_coord.y;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1085,8 +1085,8 @@ GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
|
|||
*(verts++) = v->color.a * inv255f;
|
||||
|
||||
if (texture) {
|
||||
*(verts++) = (v->tex_coord.x / texture->w) * texturedata->texw;
|
||||
*(verts++) = (v->tex_coord.y / texture->h) * texturedata->texh;
|
||||
*(verts++) = v->tex_coord.x * texturedata->texw;
|
||||
*(verts++) = v->tex_coord.y * texturedata->texh;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -986,8 +986,8 @@ GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
|
|||
*(verts++) = v->color.a * inv255f;
|
||||
|
||||
if (texture) {
|
||||
*(verts++) = v->tex_coord.x / texture->w;
|
||||
*(verts++) = v->tex_coord.y / texture->h;
|
||||
*(verts++) = v->tex_coord.x;
|
||||
*(verts++) = v->tex_coord.y;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -596,8 +596,8 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
|
|||
for (i = 0; i < count; i++) {
|
||||
SDL_Vertex *v = &vertices[indices ? indices[i] : i];
|
||||
|
||||
ptr->src.x = v->tex_coord.x;
|
||||
ptr->src.y = v->tex_coord.y;
|
||||
ptr->src.x = v->tex_coord.x * texture->w;
|
||||
ptr->src.y = v->tex_coord.y * texture->h;
|
||||
|
||||
ptr->dst.x = v->position.x * scale_x + renderer->viewport.x;
|
||||
ptr->dst.y = v->position.y * scale_y + renderer->viewport.y;
|
||||
|
|
Loading…
Reference in a new issue