Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


GuyMac111

Member Since 23 Jul 2013
Offline Last Active Aug 08 2013 04:51 AM

Posts I've Made

In Topic: glDeleteTextures does not delete pixel data

24 July 2013 - 08:52 AM

GOT IT! You see above, where i wrote:

 

"But we know i have a legit context, as I draw to it!"

 

Turns out I didn't. Let me explain.

 

In my program, I have TWO OpenGL views. Running on TWO OpenGL contexts. Which i must switch between using WGLMakeCurrent(), in order to make them both flush, swapbuffers individually.

 

The OpenGL view i refer to in this question, is the first to be made current. It has the first texture bound and then it is drawn. At this point the second OGL view is made current, has some stuff happen to it (not important), and then is drawn. 

 

So when I attempt to load and bind a second texture to my first openGL view, I've pulled the "old switcheroo" on myself and am trying to bind it to my second view's context (because it is current at this point). Which explains  why the first context still had the old pixel data in it. As I'd technically never called glDeletetextures on ittongue.png biggrin.png 

A quick call to wglMakeCurrent(handleInHere, parentwindowhere), before myTex->reloadTexture("filename") call, and my textures are loading and replacing themselves at my beckoned call.

 

Thanks for your previous help guys.  


In Topic: glDeleteTextures does not delete pixel data

24 July 2013 - 08:21 AM

Ok I've done some further testing on this matter today. glGetErrors after my glTexImage2d call returns no errors. 

 

Even if, rather than changing the Texture via a call to:

myTex->reloadTexture("filename");

I just create a brand new one like so:

mytex = new Texture("filename");

 It still simply resizes the texture. 

 

Note: that this new method that I've tried means that glDeleteTextures would never even be called. Meaning that OGL would not free the TextureID (or Texture Name) in use for the first texture for re use, therefore openGL would give a unique name to the new Texture when the constructor was called.

 

Knowing this, I have observed the TextureID variable.

 

After the very first call to glGenTextures, textureID[0] = 1    |---->Seems normal.

 

After the myTex = new texture("filename"); call (which calls glGenTextures again), textureID[0] = 1    |----> Woah! hold it!!

 

At this point '1' should no longer be available as a unique texture name, as it was previously created for the first texture and glDeleteTextures was never called.

 

Can anybody tell me why glGenTextures would refuse to give me a unique name? Usually this problem comes because glGenTextures is called before a context is established, and glGenTextures gives you '0' as a name. But we know i have a legit context, as I draw to it!

 

Also, I have put glGetErrors as I have above after glGenTextures. No errors dry.png


In Topic: glDeleteTextures does not delete pixel data

23 July 2013 - 10:32 AM

The only thing that glDeleteTextures promises is that the tetxure name will be available for reuse (via a subsequent call to glGenTextures); it doesn't promise that it will delete the pixel data, and the driver is perfectly free to keep that data hanging around for subsequent reuse.  This can be a good thing as the driver may be able to get away without having to allocate a new block of storage - "here's a block that's no longer being used, just hand it back".
 
So not deleting the pixel data is expected behaviour, but when you make the next call to glTexImage (assuming that you've bound the correct texture, of course) then the texture should be completely respecified.
 
The only sensible explanation here is that your glTexImage call is somehow failing.  As suggested, try a few glGetError calls and double-check your parameters.
 

Are you use the that the pixel alignment is 1 in the texture you are trying to load. Also another thing you can do is put glGetError() between your call and see where it is failing.

 
Check the glPixelStore call in the OP's code...

Ok, thanks v. Much. I wil try more and post results :)

In Topic: glDeleteTextures does not delete pixel data

23 July 2013 - 10:21 AM

I can't see why they wouldn't be. They're both .png files, loaded into openGL using the same image loader. They also both worked on a previous project using the virtually same setup. However in that old project, they were both created at the startup of my program as separate instances of my 'Texture' class. The reason I can't do that here, is because i wish for the user to be able to select a new texture at runtime from a file. 

 

Also placing glGetError after my glDeleteTextures call, returns no errors.  Like so.

void Texture::reloadTexture(string filename)
{
	//first and foremost clear the image and buffer vectors back down to nothing so we can start afresh 
	buffer.clear();
	image.clear();
	w = 0;
	h = 0;
	//also delete the texture name we were using before
	glDeleteTextures(1, &textureID[0]);

	GLenum err;
	while ((err = glGetError()) != GL_NO_ERROR) {
		printf("OpenGL error: %u", err);
	}


	const char* fnPtr = filename.c_str(); //our image loader accepts a ptr to a char, not a string
	//printf(fnPtr);

	lodepng::load_file(buffer, fnPtr);//load the file into a buffer

	unsigned error = lodepng::decode(image,w,h,buffer);//lodepng's decode function will load the pixel data into image vector from the buffer
	//display any errors with the texture
	if(error)
	{
		cout << "\ndecoder error " << error << ": " << lodepng_error_text(error) <<endl;
	}
	//execute the code that'll throw exceptions to do with the images size
	checkPOT(w);
	checkPOT(h);
	


	//loop through and //printf our pixel data
	/*for(GLuint i = 0; i<image.size(); i+=4)
	{
	//printf("\n%i,%i,%i,%i,", image.at(i),image.at(i+1),image.at(i+2),image.at(i+3));

	}*/

	////printf("\nImage size is %i", image.size());

	//image now contains our pixeldata. All ready for  to do its thing

	//let's get this texture up in the video memoryOpenGL
	texGLSecondaryInit();

	Draw_From_Corner = CENTER;
}

The same goes for after the call to glGenTextures in texGLSecondaryInit(). No errors to report.sad.png


In Topic: glDeleteTextures does not delete pixel data

23 July 2013 - 09:44 AM

Also, this is my first post here on GDNet. I was unable to find the forum rules before posting, so apologies if i have violated any of them.


PARTNERS