Sign in to follow this  
virtualpaul

Problem uploading textures

Recommended Posts

I am using the following code to upload my textures on the GPU in a loop before starting to render but I get some 'random' out of memory (1285) error returned by glTexStorage2D.  I also got similar results using glTexImage2D.

 

Sometimes a smaller texture (128x128) returns out of memory but the next one, a bigger one (256x256) returns ok. I checked with GPU-Z and only 180MB of the video card memory (1GB) is used. I also used Gdebugger and there is not much memory used (VBOs, Front/Back buffers, Textures, Shaders). The textures are between 32x32 to 2048x2048. I never succeeded loading a 4096x4096 for some reason.  The textures that do load are displaying correctly.

glGenTextures(1, &TextureID);
showGlError();
glBindTexture(GL_TEXTURE_2D, TextureID);
showGlError();

Nof_MipMap = 2;

glTexStorage2D(
GL_TEXTURE_2D,
Nof_MipMap,
GL_RGBA8,
Image_Width, Image_Height);
glError = showGlError();

glTexSubImage2D(
GL_TEXTURE_2D,
0,
0, 0,
Image_Width, Image_Height,
GL_RGB,
GL_UNSIGNED_SHORT_5_6_5_REV,
Image_Address);
glError = showGlError();

glGenerateMipmap(GL_TEXTURE_2D); //Generate num_mipmaps number of mipmaps here.
glError = showGlError();

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
showGlError();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
showGlError();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
showGlError();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
showGlError();

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this