mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-26 12:27:44 +00:00
Use floating point values for viewport, clip rectangle, and texture sizes
These are integer values internally, but the API has been changed to make it easier to mix other render code with querying those values. Fixes https://github.com/libsdl-org/SDL/issues/7519
This commit is contained in:
@@ -252,7 +252,7 @@ static SDL_Texture *CreateTexture(SDL_Renderer *r, unsigned char *data, unsigned
|
||||
|
||||
static void MoveSprite(void)
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_FRect *position, *velocity;
|
||||
int i;
|
||||
|
||||
@@ -578,7 +578,10 @@ static SDL_bool GetTextureForMemoryFrame(AVFrame *frame, SDL_Texture **texture)
|
||||
SDL_PixelFormatEnum frame_format = GetTextureFormat(frame->format);
|
||||
|
||||
if (*texture) {
|
||||
SDL_QueryTexture(*texture, &texture_format, NULL, &texture_width, &texture_height);
|
||||
SDL_PropertiesID props = SDL_GetTextureProperties(*texture);
|
||||
texture_format = (SDL_PixelFormatEnum)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN);
|
||||
texture_width = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
|
||||
texture_height = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
|
||||
}
|
||||
if (!*texture || texture_width != frame->width || texture_height != frame->height ||
|
||||
(frame_format != SDL_PIXELFORMAT_UNKNOWN && texture_format != frame_format) ||
|
||||
@@ -976,7 +979,9 @@ static SDL_bool GetTextureForD3D11Frame(AVFrame *frame, SDL_Texture **texture)
|
||||
UINT iSliceIndex = (UINT)(uintptr_t)frame->data[1];
|
||||
|
||||
if (*texture) {
|
||||
SDL_QueryTexture(*texture, NULL, NULL, &texture_width, &texture_height);
|
||||
SDL_PropertiesID props = SDL_GetTextureProperties(*texture);
|
||||
texture_width = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
|
||||
texture_height = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
|
||||
}
|
||||
if (!*texture || texture_width != frames->width || texture_height != frames->height) {
|
||||
if (*texture) {
|
||||
@@ -1479,12 +1484,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Position sprites and set their velocities */
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
srand((unsigned int)time(NULL));
|
||||
for (i = 0; i < num_sprites; ++i) {
|
||||
positions[i].x = (float)(rand() % (viewport.w - sprite_w));
|
||||
positions[i].y = (float)(rand() % (viewport.h - sprite_h));
|
||||
positions[i].x = (float)(rand() % (int)(viewport.w - sprite_w));
|
||||
positions[i].y = (float)(rand() % (int)(viewport.h - sprite_h));
|
||||
positions[i].w = (float)sprite_w;
|
||||
positions[i].h = (float)sprite_h;
|
||||
velocities[i].x = 0.0f;
|
||||
|
||||
Reference in New Issue
Block a user