I am using ffmpeg to play video files and the project is not able to play multiple files in realtime so i would like to get into threads to update the textures.
Though i have understanding of how to implement threading but i am clueless about what approach i should take in the current situation as i have many questions without answers.
I have a class to update the texture.
class UpdateTexture
{
private:
unsigned int textureID;
std::string stdstrImagePath;
unsigned char* data;
public:
void loadTexture(char const * path)
{
glGenTextures(1, &textureID); // generate the texture here
// All other functions for texture creation like glTexImag2D
}
void Update()
{
glBindTexture(GL_TEXTURE_2D, textureID);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1920, 1080, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
};
one object of this class will update one video file so if i have 3 different video files playing i will have three objects of this class running in the back ground.
This is the code for the main function.
UpdateTexture image;
image.loadTexture("C:\\ShadersOld\\Images\\5rupeecoin.jpg");
while (!glfwWindowShouldClose(window))
{
float time = glfwGetTime();
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
processInput(window);
shader.setMat4("view", view);
shader.setMat4("projection", projection);
shader.setMat4("model", model);
glBindTexture(GL_TEXTURE_2D, 0);
renderQuad(); // render the first rectangle without image
// Draw the second rectangle
glm::mat4 modelPosition = glm::mat4(1.0f);
modelPosition = glm::translate(modelPosition, glm::vec3(-300.0f, 0.0f , 0.0f));
shader.setMat4("model", modelPosition);
// image.Update(); // this process should run in the back ground and only update the texture of this rectangle
renderQuad();
glfwSwapBuffers(window);
glfwPollEvents();
}
i would want to run the updateImage process in the background and only update the texture for the second rectangle not the first one.
i can have a situation where there can be multiple video files playing so each updateTexture should be linked to its respective rectangle.
I am very much confused in how can i link upDateTexture function to its respective rectangle and how would i shut down the upDateTexture threads once their respective rectangles have been destroyed ?