-
-
Notifications
You must be signed in to change notification settings - Fork 191
Port Texture to C code #3330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Port Texture to C code #3330
Conversation
commit 813f384 Author: Josip Komljenović <[email protected]> Date: Wed Jan 29 15:43:45 2025 +0100 Add interface for _sdl2.video classes commit 702958c Author: Josip Komljenović <[email protected]> Date: Wed Jan 29 15:38:01 2025 +0100 Add interface for _sdl2.video classes commit 081b032 Author: Josip Komljenović <[email protected]> Date: Wed Jan 29 15:33:20 2025 +0100 Add interface for _sdl2.video classes commit c9ffd1c Author: Josip Komljenović <[email protected]> Date: Wed Jan 29 15:25:10 2025 +0100 Add interface for _sdl2.video classes
commit 813f384 Author: Josip Komljenović <[email protected]> Date: Wed Jan 29 15:43:45 2025 +0100 Add interface for _sdl2.video classes commit 702958c Author: Josip Komljenović <[email protected]> Date: Wed Jan 29 15:38:01 2025 +0100 Add interface for _sdl2.video classes commit 081b032 Author: Josip Komljenović <[email protected]> Date: Wed Jan 29 15:33:20 2025 +0100 Add interface for _sdl2.video classes commit c9ffd1c Author: Josip Komljenović <[email protected]> Date: Wed Jan 29 15:25:10 2025 +0100 Add interface for _sdl2.video classes
@@ -629,12 +1234,14 @@ static PyTypeObject pgRenderer_Type = { | |||
.tp_getset = renderer_getset}; | |||
|
|||
static PyTypeObject pgTexture_Type = { | |||
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "pygame._render.Texture", | |||
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "pygame._renderer.Texture", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the render module, not the renderer module
else { | ||
access = SDL_TEXTUREACCESS_STATIC; | ||
} | ||
self->renderer = renderer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this need to be incref-ed?
if (!new_texture->texture) { | ||
return RAISE(pgExc_SDLError, SDL_GetError()); | ||
} | ||
new_texture->renderer = renderer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concern here about refcounting.
texture_set_blend_mode(pgTextureObject *self, PyObject *arg, void *closure) | ||
{ | ||
if (PyLong_Check(arg)) { | ||
long longval = PyLong_AsLong(arg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this function could fail and return -1 with an error set, which you're not checking.
Rather than doing PyLong_Check + PyLong_AsLong you could just do PyLong_AsLong and check it succeeds?
if (!pg_TwoFloatsFromObj(originobj, &origin.x, &origin.y)) { | ||
return RAISE(PyExc_ValueError, "origin must be a point or None"); | ||
} | ||
originptr = &origin; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could pass &origin into SDL_RenderCopyExF
directly rather than needing this extra variable. (I see the Cython has it, maybe it's a weird Cython thing or the person who wrote it wasn't as experienced with pointers).
This PR converts pygame._sdl2.video.Texture to C code. It has the implementation of all the Texture methods and attributes.
TODO: fix Renderer.target reference counting in set_target