Skip to content
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

Add interface for _sdl2.video classes #3317

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

MightyJosip
Copy link
Contributor

@MightyJosip MightyJosip commented Jan 28, 2025

I imagined this as the first PR towards the goal of rewriting _sdl2.video stuff in C code. Since those classes are used in combination with each other, I wanted to add them all, so then for example when I will write the implementation for Renderer, I can do it without any compilation errors where I am missing the declaration for Texture. At this moment, this code itself doesn't do anything, you can write

import pygame
import pygame._renderer

window = pygame.Window()
renderer = pygame._renderer.Renderer(window)
texture = pygame._renderer.Texture(renderer)
image = pygame._renderer.Image(texture)

print(renderer)
print(texture)
print(image)

for example, and you get

<pygame._renderer.Renderer object at 0x000001CBE813E8E0>
<pygame._renderer.Texture object at 0x000001CBE662C6C0>
<pygame._renderer.Image object at 0x000001CBE8E13230>

as the output. But that is everything that has been implemented. Also, I didn't include _render in pygame.init, so you need to manually import it, otherwise it won't work, so at the moment, this module is basically hidden, just so it doesn't break anything

@MightyJosip MightyJosip requested a review from a team as a code owner January 28, 2025 11:51
@MightyJosip MightyJosip mentioned this pull request Jan 28, 2025
1 task
@Starbuck5
Copy link
Member

Starbuck5 commented Jan 29, 2025

Hey, good to see you moving this forward, this is important for us to do!

Some organizational things:
I'm surprised to see the 3 classes all getting their own module. I would think they would all be part of one module, as they are currently. (You could still have separate files for implementation and have them in one module).

Also, I would think these new files would live in the _sdl2 folder. I believe when Window was ported it went there first.

@damusss
Copy link
Member

damusss commented Jan 29, 2025

I agree that they should live in one module. a good name would be pygame.renderer (privatized at the moment) in my opinion. Just like pygame.gpu should hold all gpu features in the future. it makes so things that are directly related to each other and that depend on each other under the same name (you can't use a texture without a renderer, but you can use a window with regular surfaces, you get the idea)

@MightyJosip
Copy link
Contributor Author

MightyJosip commented Jan 29, 2025

Yea you are correct about the multiple modules, I will add it in a single module. Is there an example of that in the repo at this moment, I can probably do that with the multiple header files, but if we already have more elegant solution I would like to use it, probably call it pygame._renderer like damusss said. (EDIT: I guess I can do the same as it is done for geometry module)

About _sdl2, I am pretty sure Window was added outside of it in the first commit https://github.com/pygame-community/pygame-ce/pull/2114/files#diff-3279c6977adb71e8d262e5974889267e57e33c5ef0d5c76a0146999fba0b40c6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants