projectM-visualizer / projectm

projectM - Cross-platform Music Visualization Library. Open-source and Milkdrop-compatible.
https://discord.gg/mMrxAqaa3W
GNU Lesser General Public License v2.1
3.32k stars 372 forks source link

[FEATURE] Implement a postprocessing middleware library for scaling, filtering etc. #845

Open kblaschke opened 4 days ago

kblaschke commented 4 days ago

Is Your Enhancement Related to a Problem?

Currently, libprojectM always renders to the current viewport at [0,0] with the set resolution. There is no way of performing up- or downscaling to a different canvas size. There are also no ways of applaying additional filters like blur, sharpen, hue shifts etc. without adding another (complex) rendering step in the embedding application.

Your Suggested Enhancement

Add a new repository which willl contain a separate library which can act as a middleware between libprojectM and the application. This library would provide a set of filters and effects to be applied to the projectM rendering output, returning a texture (or drawing onto a native surface, e.g. FBO 0) with the configured filters applied.

Having this as a separate library has many advantages over adding this functionality directly into libprojectM:

  1. The library can be licensed under a more permissive license like MIT to allow static linking or fully embedding into closed-source applications.
  2. The libprojectM API will stay as simple as possible.
  3. The release cycle of this filtering library would be decoupled from libprojectM, making it easier to quickly add new features.
  4. The middleware would be compatible with a range of libprojectM versions, e.g. any version from 4.2 onwards (as this version will introduce FBO rendering support). This would enable backwards compatibility as well, as long as libprojectM supports the required API calls.
  5. Putting the code into a separate library will keep the projectM core codebase cleaner and thus reduces the potential for bugs. Application developers can then opt-in to use the additional dependency if needd.

The new library should provide a similar C API as libprojectM to make it useable in a wider range of programming languages. The implementation itself could be done in different languages like C, C++ or Rust. It should compile on the same platforms as libprojectM.

Some potential effects that could be implemented include:

There are many more possible filters that could be added. Configuring them could be done by building a filter chain, as filter order is important.

Alternative Solutions

No response

Additional Context

Originally suggested in PR #844