This error occurred because a large texture cannot be quickly created in the memory of the video card.
The glTexImage2D method copies data from normal memory to the memory of the video card.
Copying works during the video card process.
You have to wait
Decision: You need to call glGetError not immediately, but after some time.
I call the method:
C++
WaitOpenGlStatus(GL_NO_ERROR, 5);
This method is waiting for a good status with a time limit of 5 seconds (the time limit is necessary, because if we wait endlessly, the program will freeze)
C++
#include <unistd.h>
...
bool WaitOpenGlStatus(int goodOpenGlStatus, int waitSeonds)
{
timespec timeNow1;
clock_gettime(CLOCK_MONOTONIC, &timeNow1);
while (true)
{
if (glGetError()==goodOpenGlStatus)
return true;
sleep(1); // sleep 1 second
timespec timeNow2;
clock_gettime(CLOCK_MONOTONIC, &timeNow2);
if ((timeNow2.tv_sec- timeNow1.tv_sec)>waitSeonds)
return false;
};
}
C++
File texture_buffer_shader.cpp
...
glTexImage2D(GL_TEXTURE_2D, 0, imgFormat, width, height, 0, imgFormat, GL_UNSIGNED_BYTE, pColorData);
if (WaitOpenGlStatus(GL_NO_ERROR, 5 /*seconds to finish wait*/))
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
}
...