SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Remove int/float duplication in SDL_Render #6656

Open 1bsyl opened this issue 3 years ago • 10 comments

Remove int/float duplication in SDL_Render #6656

maybe we could should add: SDL_Render{Set,Get}ViewportF SDL_Render{Set,Get}ClipRectF SDL_SetWindowHitTestF

1bsyl avatar Nov 28 '22 11:11 1bsyl

maybe we could remove the "warning C4244: 'function': conversion from 'int' to 'float'," from being treated as an error ?

1bsyl avatar Nov 28 '22 11:11 1bsyl

Should the F suffixes be removed from the Render functions/structs? They feel a bit redundant to me now.

maybe we could should add: SDL_Render{Set,Get}ViewportF SDL_Render{Set,Get}ClipRectF SDL_SetWindowHitTestF

Normally the viewport and clip rect etc. cannot use fractional pixels (unlike rendered geometry). But I suppose if scaling is applied to their coordinate system then they'd be able to use fractional units?

slime73 avatar Nov 28 '22 11:11 slime73

it was more to have a convenient API . eg: you to {get,set} the {viewport,cliprect} using the same variable used with a FRect function. but maybe not usefull

(indeed internally, if one use SDL_RenderSetScale the clip/viewport becomes fractionnal)

1bsyl avatar Nov 28 '22 12:11 1bsyl

I don't know if we should do this. @icculus, what's your thought on making the entire API float instead of int?

slouken avatar Nov 28 '22 16:11 slouken

If we do end up doing this, we should remove the *F functions and just change the types of the normal functions to reduce the amount of redundant typing involved.

slouken avatar Nov 28 '22 16:11 slouken

My thinking is the int versions can go away (and the 'F' suffix can go away).

The reason these were ints in the first place, I assume, was to make everything snap to pixel alignment, but there was clearly a desire for subpixel precision, and there's no reason an app can't use the float versions to snap to pixel alignment anyhow by truncating (or just working in ints and casting to float for the function calls).

SDL_Rect itself is useful outside the renderer, though, so we'd probably need to keep the separate SDL_FRect struct.

icculus avatar Nov 29 '22 01:11 icculus

@icculus, do we really want to cause this for everyone using the render API?

D:\a\SDL\SDL\test\testautomation_render.c(408,13): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(409,13): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(418,19): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(419,19): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(478,13): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(479,13): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(495,19): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(496,19): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(559,13): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(560,13): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(576,19): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(577,19): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(628,13): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(629,13): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(645,19): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(646,19): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(697,13): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(698,13): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(790,19): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]
D:\a\SDL\SDL\test\testautomation_render.c(791,19): warning C4244: '=': conversion from 'int' to 'float', possible loss of data [D:\a\SDL\SDL\build\SDL\test\testautomation.vcxproj]

slouken avatar Nov 29 '22 17:11 slouken

do we really want to cause this for everyone using the render API?

Mmmm...that's not ideal. To be fair, it's a one-time migration cost, but that is messy.

icculus avatar Nov 29 '22 18:11 icculus

... and adding (float) casts to every parameter for existing code seems like painful unnecessary work.

slouken avatar Nov 29 '22 18:11 slouken

I'm leaning toward not changing the API here. Are there other internal benefits we would get by doing this?

@icculus, what do you think?

slouken avatar Dec 02 '22 20:12 slouken

I went ahead and created a new pull request based on the current API changes.

slouken avatar Dec 31 '22 19:12 slouken