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

document surface vs texture vs buffer vs pixelview #34

Open
marcusva opened this issue Jan 4, 2014 · 3 comments
Open

document surface vs texture vs buffer vs pixelview #34

marcusva opened this issue Jan 4, 2014 · 3 comments

Comments

@marcusva
Copy link
Collaborator

marcusva commented Jan 4, 2014

Originally reported by: anatoly techtonik (Bitbucket: techtonik, GitHub: techtonik)


It is pretty confusing to read documentation that speaks about abstract pixels, with some vague connection to bytes in video memory, system memory and the ways Python protects people from messing with those.

I am trying to start with representation of pixel data in Python list and documentation doesn't give me a glue how can I convert it to picture. For that, I need to know:

  1. what input buffer formats of raw pixel data are used by SDL2
  2. how do these look in PySDL2 and why
  3. what is the transformation chain from Python variable to pixel on the screen
  4. how does Python hides direct access to memory (why it is slow)

Actually, the (1,3) are the two most important.


@marcusva
Copy link
Collaborator Author

marcusva commented Jan 4, 2014

Original comment by Marcus von Appen (Bitbucket: marcusva, GitHub: marcusva):


I am not sure to what documentation you refer to, but PySDL2 does not protect you from messing with the bytes in system or video memory. You can gain read-write access to the pixel buffers of a texture or software surface via PySDL2 without any problems (and also without any safety net).

  1. SDL2 supports a variety of formats. An overview about the different supported formats can be found at http://wiki.libsdl.org/SDL_PixelFormatEnum
  2. PySDL2 provides a wrapper around the SDL2 internals. Hence there are no differences, since PySDL2 uses the C structures of SDL2 and just refers to the memory locations.
  3. I do not understand the question
  4. Are we talking about Python (the language) or PySDL2 here? The latter does not hide direct access to memory. Direct access is provided via ctypes.

@marcusva
Copy link
Collaborator Author

marcusva commented Jan 4, 2014

Original comment by anatoly techtonik (Bitbucket: techtonik, GitHub: techtonik):


PySDL2 doesn't protect me from the complexity of SDL2 layer. =) I am looking to some intro / guideline about pixel manipulations with regard to helpers that PySDL2 provides.

  1. Thanks. This page helps. I'd still be interested to see some guidelines about how to use them. What are the most efficient pixel formats? How are they represented in SDL2? How they can be represented in Python? Where to set these pixel format? And how to convert my list of integers to pixel buffer? How to get that pixel buffer shown in window?

  2. There are PixelView and friends - http://pysdl2.readthedocs.org/en/latest/modules/sdl2ext_pixelaccess.html How are they different from continuous C memory buffer packed with raw pixel data? What is ctypes equivalent for these structures? Where memory buffer is locate - in CPU memory or in GPU memory? Can I edit CPU and GPU memory directly? Is it more efficient in Python than converting lists of ints?

  3. I want to have a pixel at 50,50. White. I figure out that white == (255,255,255), so what should I do to pixel = (50,50,(255,255,255) to make white dot appear on the screen? How processing will be different if I have a line of pixels?

  4. So, the ctypes is the only way to edit the memory directly? What about memoryview? How memory editing in Python is different from the same operation in C - is it optimized?

So basically I am looking for some guidelines how a pixel pipeline works in SDL2. Something like https://en.wikibooks.org/wiki/GLSL_Programming/OpenGL_ES_2.0_Pipeline or http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLES30PipelineMap.pdf with regard to SDL2 terms.

@BigBMP
Copy link

BigBMP commented Sep 1, 2021

When using Software rendering "factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)" to creates a SpriteRenderSystem window "spriterenderer = factory.create_sprite_render_system(window)", how to you fill this window with a specific color?

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

No branches or pull requests

2 participants