Skip to content

Add texture loading callback for custom texture sources#956

Merged
revmischa merged 2 commits into
masterfrom
feature/texture-callback-870
Feb 2, 2026
Merged

Add texture loading callback for custom texture sources#956
revmischa merged 2 commits into
masterfrom
feature/texture-callback-870

Conversation

@revmischa
Copy link
Copy Markdown
Member

Adds a callback that allows applications to provide textures from non-filesystem sources like archives, network, or procedurally generated content. The callback receives the texture name and can return either raw pixel data or an existing OpenGL texture ID.

Fixes #870

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for loading textures from non-filesystem sources through a callback mechanism. Applications can now provide textures from archives, network sources, or generate them procedurally. The callback can return either raw pixel data or an existing OpenGL texture ID, with automatic fallback to filesystem loading if the callback doesn't provide the requested texture.

Changes:

  • Added TextureLoadCallback type and TextureLoadData structure to define the callback interface
  • Extended TextureManager to try callback-based loading before filesystem loading
  • Exposed the callback through both C++ (ProjectM::SetTextureLoadCallback) and C (projectm_set_texture_load_event_callback) APIs
  • Updated CMakeLists.txt to install new public headers (TextureTypes.hpp, WaveformAligner.hpp, Logging.hpp)

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/libprojectM/Renderer/TextureTypes.hpp Defines TextureLoadData structure and TextureLoadCallback type for the callback interface
src/libprojectM/Renderer/TextureManager.hpp Adds SetTextureLoadCallback method and member variable to store callback
src/libprojectM/Renderer/TextureManager.cpp Implements callback invocation in TryLoadingTexture, checking callback before filesystem loading
src/libprojectM/ProjectM.hpp Exposes SetTextureLoadCallback method in C++ API
src/libprojectM/ProjectM.cpp Stores callback and ensures it's re-applied when TextureManager is recreated
src/libprojectM/ProjectMCWrapper.hpp Adds member variables to store C callback and user data
src/libprojectM/ProjectMCWrapper.cpp Implements C-to-C++ callback bridge with lambda wrapper
src/api/include/projectM-4/callbacks.h Defines C API types and functions for texture loading callback
src/libprojectM/CMakeLists.txt Adds TextureTypes.hpp, WaveformAligner.hpp, and Logging.hpp to installation list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/api/include/projectM-4/callbacks.h
Comment thread src/api/include/projectM-4/callbacks.h Outdated
Comment thread src/libprojectM/Renderer/TextureManager.cpp
Comment thread src/api/include/projectM-4/callbacks.h
Comment thread src/libprojectM/Renderer/TextureManager.cpp Outdated
@kblaschke
Copy link
Copy Markdown
Member

I do not like to talk to Coslop in code reviews...

Comment thread src/libprojectM/Renderer/TextureManager.cpp
Comment thread src/libprojectM/Renderer/TextureManager.cpp Outdated
Adds a callback that allows applications to provide textures from
non-filesystem sources like archives, network, or procedurally
generated content. The callback receives the texture name and can
return either raw pixel data or an existing OpenGL texture ID.

Changes:
- Add SetTextureLoadCallback API for custom texture loading
- Add texture ownership tracking to prevent deletion of app-provided textures
- Update texture creation to use stb_image instead of SOIL
- Add validation and error logging for callback-provided textures

Fixes #870

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@revmischa revmischa force-pushed the feature/texture-callback-870 branch from 74ca73d to 241c279 Compare February 1, 2026 17:50
@revmischa
Copy link
Copy Markdown
Member Author

Addressed the feedback:

  • Rebased on latest master
  • Added m_owned member to Texture class - app-provided texture IDs now have owned=false so projectM won't delete them
  • Replaced SOIL with stb_image/Texture class for creating textures from callback pixel data
  • Added validation for width/height on texture ID path with warning log on failure

@revmischa revmischa merged commit 85b8c08 into master Feb 2, 2026
37 checks passed
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.

[FEATURE] Add callback to API to support loading textures from non-filesystem sources

3 participants