'OpenGL shaders on sprites using pygame

I recently started learning about the use of OpenGL and shaders since I would like to add some shader effects to certain elements of a game I am developing using pygame (which is a python library for displaying images and playing sounds. Essentially, it contains the tools needed to create a game in python).

My end goal is to use OpenGL shaders to draw images with effects (i.e, add a shine effect to an item, or an enemy). Here is my current process of thinking on how to implement this:

  1. Create a central control object ShaderControlObj that loads and assembles all the shaders I create into an object that is accessible to anything in the game than can be rendered.
  2. Create a renderer object ShaderRenderer that passes in an image (or pygame.Surface()), creates a framebuffer for that image and scales the framebuffer to the actual ingame size of the image after applying any shaders.
  3. Render the framebuffer to the position on screen that the game element would be on

One uncertainty that I have with this approach is that it might not be good performance-wise. This is because I plan to make a separate framebuffer for every surface. As a result, I would be allocating a lot of memory if I want to draw several different game elements with different shader elements.

This brings me to my main question: is my approach to implementing shaders into pygame inefficient? Is there a more efficient way to implement shaders? Or is there no problem with this approach and I may use a framebuffer for as many elements as I need? (keep in mind that I may have over 100+ elements that each need a framebuffer). Thank you in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source