0

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 ?

Summit
  • 2,112
  • 2
  • 12
  • 36
  • 1
    Before you use multiple threads in OpenGL pleas read [Multithreaded Rendering on OpenGL](https://stackoverflow.com/questions/11097170/multithreaded-rendering-on-opengl) and [Im trying to use OpenGL with the windows API on different threads](https://stackoverflow.com/questions/59694432/im-trying-to-use-opengl-with-the-windows-api-on-different-threads). – Rabbid76 Jul 24 '20 at 14:32
  • @Rabbid76 Thank you as usual , i have really learnt a lot from you and of cousre in a way you have been my teacher. – Summit Jul 25 '20 at 03:42
  • I have done more work on this please check this question. https://stackoverflow.com/questions/63084077/is-this-the-correct-way-to-implement-a-thread – Summit Jul 25 '20 at 03:42

0 Answers0