@@ -88,6 +88,79 @@ PROJECTM_EXPORT void projectm_set_preset_switch_failed_event_callback(projectm_h
8888 projectm_preset_switch_failed_event callback ,
8989 void * user_data );
9090
91+ /**
92+ * @brief Structure containing texture data returned by the texture load callback.
93+ *
94+ * Applications can provide texture data in one of two ways:
95+ * 1. Raw pixel data: Set data to a valid pointer, width/height to the dimensions,
96+ * and channels to the number of color channels (3 for RGB, 4 for RGBA).
97+ * 2. Existing OpenGL texture: Set texture_id to a valid OpenGL texture ID.
98+ *
99+ * If both are provided, the texture_id takes precedence.
100+ * If neither is provided (data is NULL and texture_id is 0), projectM will
101+ * attempt to load the texture from the filesystem.
102+ *
103+ * @warning When providing a texture_id, projectM takes ownership of the OpenGL texture
104+ * and will delete it (via glDeleteTextures) when it is no longer needed. Do not
105+ * delete the texture yourself or reuse the texture ID after passing it here.
106+ *
107+ * @since 4.2.0
108+ */
109+ typedef struct projectm_texture_load_data {
110+ const unsigned char * data ; /**< Pointer to raw pixel data in standard OpenGL format (first row is bottom of image). Can be NULL. */
111+ unsigned int width ; /**< Width of the texture in pixels. Must be > 0 when providing data or texture_id. */
112+ unsigned int height ; /**< Height of the texture in pixels. Must be > 0 when providing data or texture_id. */
113+ unsigned int channels ; /**< Number of color channels (3 for RGB, 4 for RGBA). */
114+ unsigned int texture_id ; /**< An existing OpenGL texture ID to use. Set to 0 if not used. */
115+ } projectm_texture_load_data ;
116+
117+ /**
118+ * @brief Callback function that is executed when projectM needs to load a texture.
119+ *
120+ * This callback allows applications to provide textures from sources other than
121+ * the filesystem, such as:
122+ * - Loading textures from archives (e.g., ZIP files)
123+ * - Loading textures over the network
124+ * - Generating textures procedurally
125+ * - Providing pre-loaded textures or video frames
126+ *
127+ * When called, the application should populate the provided data structure with
128+ * either raw pixel data or an OpenGL texture ID. If the application cannot provide
129+ * the requested texture, it should leave the structure unchanged (data = NULL,
130+ * texture_id = 0) and projectM will fall back to loading from the filesystem.
131+ *
132+ * @note The texture_name pointer is only valid inside the callback. Make a copy if
133+ * it needs to be retained for later use.
134+ * @note If providing raw pixel data, the data pointer must remain valid until
135+ * projectM has finished processing it (i.e., until the callback returns).
136+ * @note This callback is always invoked from the same thread that calls projectM
137+ * rendering functions. No additional synchronization is required.
138+ *
139+ * @param texture_name The name of the texture being requested, as used in the preset.
140+ * @param[out] data Pointer to a structure where the application should place texture data.
141+ * @param user_data A user-defined data pointer that was provided when registering the callback.
142+ * @since 4.2.0
143+ */
144+ typedef void (* projectm_texture_load_event )(const char * texture_name ,
145+ projectm_texture_load_data * data ,
146+ void * user_data );
147+
148+ /**
149+ * @brief Sets a callback function that will be called when projectM needs to load a texture.
150+ *
151+ * This allows applications to provide textures from non-filesystem sources.
152+ * Only one callback can be registered per projectM instance. To remove the callback, use NULL.
153+ *
154+ * @param instance The projectM instance handle.
155+ * @param callback A pointer to the callback function.
156+ * @param user_data A pointer to any data that will be sent back in the callback, e.g. context
157+ * information.
158+ * @since 4.2.0
159+ */
160+ PROJECTM_EXPORT void projectm_set_texture_load_event_callback (projectm_handle instance ,
161+ projectm_texture_load_event callback ,
162+ void * user_data );
163+
91164#ifdef __cplusplus
92165} // extern "C"
93166#endif
0 commit comments