diff --git a/src/api/include/libprojectM/projectM.h b/src/api/include/libprojectM/projectM.h index cce42b693..b69dab4fb 100644 --- a/src/api/include/libprojectM/projectM.h +++ b/src/api/include/libprojectM/projectM.h @@ -172,24 +172,12 @@ typedef void (*projectm_preset_switch_requested_event)(bool is_hard_cut, void* u typedef void (*projectm_preset_switch_failed_event)(const char* preset_filename, const char* message, void* user_data); - /** - * @brief Creates a new projectM instance, reading settings from the given file. - * @param setting_file_path A path to the settings file to read the configuration from. - * If NULL or an empty path are provided, default settings will be used. + * @brief Creates a new projectM instance. * @return A projectM handle for the newly created instance that must be used in subsequent API calls. * NULL if the instance could not be created successfully. */ -PROJECTM_EXPORT projectm_handle projectm_create(const char* setting_file_path); - -/** - * @brief Creates a new projectM instance with given settings. - * @param settings A pointer to a projectm_settings_t with the settings to be used by the new instance. - * If this pointer is NULL, default settings will be used. - * @return A projectM handle for the newly created instance that must be used in subsequent API calls. - * NULL if the instance could not be created successfully. - */ -PROJECTM_EXPORT projectm_handle projectm_create_settings(const projectm_settings* settings); +PROJECTM_EXPORT projectm_handle projectm_create(); /** * @brief Destroys the given instance and frees the resources. @@ -264,10 +252,25 @@ PROJECTM_EXPORT void projectm_set_preset_switch_failed_event_callback(projectm_h projectm_preset_switch_failed_event callback, void* user_data); +/** + * @brief Sets the texture search paths. + * + * Calling this method will clear and reload all textures, including the main rendering texture. + * Can cause a small delay/lag in rendering. Only use if texture paths were changed. + * + * @param instance The projectM instance handle. + * @param texture_search_paths A list of texture search paths. + * @param count The number of paths in the list. + */ +PROJECTM_EXPORT void projectm_set_texture_search_paths(projectm_handle instance, + const char** texture_search_paths, + size_t count); + /** * @brief Reloads all textures. * - * Also resets the OpenGL renderer without changing the viewport size. Useful if preset paths were changed. + * Calling this method will clear and reload all textures, including the main rendering texture. + * Can cause a small delay/lag in rendering. Only use if texture paths were changed. * * @param instance The projectM instance handle. */ diff --git a/src/libprojectM/ProjectM.cpp b/src/libprojectM/ProjectM.cpp index 4c5371841..3abb581d3 100644 --- a/src/libprojectM/ProjectM.cpp +++ b/src/libprojectM/ProjectM.cpp @@ -108,6 +108,12 @@ auto ProjectM::InitRenderToTexture() -> unsigned return m_renderer->initRenderToTexture(); } +void ProjectM::SetTexturePaths(std::vector texturePaths) +{ + m_textureSearchPaths = std::move(texturePaths); + m_renderer->SetTextureSearchPaths(m_textureSearchPaths); +} + void ProjectM::ResetTextures() { m_renderer->ResetTextures(); diff --git a/src/libprojectM/ProjectM.hpp b/src/libprojectM/ProjectM.hpp index ea2cc7cff..be05b8441 100644 --- a/src/libprojectM/ProjectM.hpp +++ b/src/libprojectM/ProjectM.hpp @@ -132,6 +132,16 @@ public: void ResetOpenGL(size_t width, size_t height); + /** + * @brief Sets the texture paths used to find images for presets. + * + * Setting new texture paths will clear the texture manager cache and reload textures. + * This can cause lags in rendering. + * + * @param texturePaths A list of paths projectM will look for texture images, in order. + */ + void SetTexturePaths(std::vector texturePaths); + void ResetTextures(); void RenderFrame(); diff --git a/src/libprojectM/ProjectMCWrapper.cpp b/src/libprojectM/ProjectMCWrapper.cpp index bc69a10ae..3094e220d 100644 --- a/src/libprojectM/ProjectMCWrapper.cpp +++ b/src/libprojectM/ProjectMCWrapper.cpp @@ -176,6 +176,22 @@ void projectm_reset_gl(projectm_handle instance, int width, int height) projectMInstance->ResetOpenGL(width, height); } +void projectm_set_texture_search_paths(projectm_handle instance, + const char** texture_search_paths, + size_t count) +{ + auto projectMInstance = handle_to_instance(instance); + + std::vector texturePaths; + + for (size_t index = 0; index < count; index++) + { + texturePaths.emplace_back(texture_search_paths[index]); + } + + projectMInstance->SetTexturePaths(texturePaths); +} + void projectm_reset_textures(projectm_handle instance) { auto projectMInstance = handle_to_instance(instance); diff --git a/src/libprojectM/Renderer/Renderer.cpp b/src/libprojectM/Renderer/Renderer.cpp index 9336ba3e5..bf8ad15ef 100644 --- a/src/libprojectM/Renderer/Renderer.cpp +++ b/src/libprojectM/Renderer/Renderer.cpp @@ -133,6 +133,8 @@ Renderer::Renderer(int width, int height, int gx, int gy, glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); + + ResetTextures(); } void Renderer::SetPipeline(Pipeline& pipeline) @@ -152,11 +154,13 @@ void Renderer::SetPipeline(Pipeline& pipeline) void Renderer::ResetTextures() { - m_textureManager->Clear(); + m_textureManager = std::make_unique(m_textureSearchPaths, m_textureSizeX, m_textureSizeY); +} - reset(m_viewportWidth, m_viewportHeight); - - m_textureManager->Preload(); +void Renderer::SetTextureSearchPaths(std::vector& textureSearchPaths) +{ + m_textureSearchPaths = textureSearchPaths; + ResetTextures(); } void Renderer::SetupPass1(const Pipeline& pipeline, const PipelineContext& pipelineContext) @@ -403,7 +407,7 @@ void Renderer::reset(int w, int h) InitCompositeShaderVertex(); - m_textureManager = std::make_unique(m_textureSearchPaths, m_textureSizeX, m_textureSizeY); + ResetTextures(); m_shaderEngine.setParams(m_textureSizeX, m_textureSizeY, m_fAspectX, m_fAspectY, m_beatDetect, m_textureManager.get()); m_shaderEngine.reset(); diff --git a/src/libprojectM/Renderer/Renderer.hpp b/src/libprojectM/Renderer/Renderer.hpp index f92921044..a3fd789f8 100644 --- a/src/libprojectM/Renderer/Renderer.hpp +++ b/src/libprojectM/Renderer/Renderer.hpp @@ -70,6 +70,7 @@ public: void RenderFrameOnlyPass1(const Pipeline &pipeline, const PipelineContext &pipelineContext); void RenderFrameOnlyPass2(const Pipeline &pipeline, const PipelineContext &pipelineContext); void ResetTextures(); + void SetTextureSearchPaths(std::vector& textureSearchPaths); void reset(int w, int h); GLuint initRenderToTexture(); diff --git a/src/libprojectM/Renderer/TextureManager.hpp b/src/libprojectM/Renderer/TextureManager.hpp index 44321189d..a4e57af76 100644 --- a/src/libprojectM/Renderer/TextureManager.hpp +++ b/src/libprojectM/Renderer/TextureManager.hpp @@ -21,8 +21,6 @@ public: TextureManager(std::vector& textureSearchPaths, int texSizeX, int texSizeY); ~TextureManager(); - void Clear(); - void Preload(); TextureSamplerDesc tryLoadingTexture(const std::string name); TextureSamplerDesc getTexture(const std::string fullName, const GLenum defaultWrap, const GLenum defaultFilter); const Texture* getMainTexture() const; @@ -32,6 +30,9 @@ public: void clearRandomTextures(); private: + void Clear(); + void Preload(); + TextureSamplerDesc loadTexture(const std::string name, const std::string imageUrl); void ExtractTextureSettings(const std::string qualifiedName, GLint& _wrap_mode, GLint& _filter_mode, std::string& name);