It is currently Fri May 26, 2017 6:11 am

All times are UTC - 5 hours




 Page 1 of 1 [ 13 posts ] 
Author Message
 Post subject: Shader VMK 47 - Challenge 3 Solution
PostPosted: Wed Jun 25, 2014 11:29 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
In this video I present my solution to Challenge 3 that was presented in VMK46.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Fri Jun 27, 2014 7:44 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
After watching this video. Everything I had originally done was the same as you have except for a few differences. The first was the one about showing the texture info. Instead of creating a function within the Asset Storage class, I was calling the info within the game class but using the AssetStorage. The only other difference was in the case where you delete 1 image2d object and its texture you are using shift + same key, I was using a different key.

For algorithms you have this for both the "D" and "Shift+D" cases:
unsigned numImages = _vImage2d.size();
if ( numImages > 0 ) {
   _pAssetStorage->removeMko( _vImage2d[numImages-1]->getId(), (either false or true) )
   _vImage2d.pop_back();
}
break;


In my source that I have submitted to you I have:
if ( _vImage2d.empty() ) {
   break;
} else {
   _pAssetStorage->removeMko( _vImage2d.back()->getId(), (false or true) );
   _vImage2d.pop_back();
}
break;


Is there any major difference between the two or do they both do the same thing ?
So is there a difference between using container.back() verses container[size-1] ?


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Sat Jun 28, 2014 7:38 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
The above differences that you had were minor. The major difference that your code was missing was the change in the loadImages() function to fix the textureID value after you load 3 new images.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Sat Jun 28, 2014 5:28 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
Yeah, I noticed that. It never dawned on me that I had to reset the id values. Other then that, everything was about the same.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Sat Oct 04, 2014 1:10 am 

Joined: Mon Mar 24, 2014 2:25 pm
Posts: 69
Good evening.

I've been working through my solution to Challenge 3 and have come across a weird situation. When deleting an object and texture associated with it I get 2 black squares remaining on the screen where the two remaining objects are still present, but with no texture file associated. I double checked the base color being shipped to the objects during Image2D construction is COLOR_WHITE which I had assumed allowed the texture values to sign through due to the multiplication in the fragment shader.

I thought this was an artifact of no texture being present in the fragment shader and hence multiplying by 0, giving black, but I tested by adding a 4th object (the TGA non RLE image to ensure another texture is there) and deleting it and it's associated texture and didn't have the same issue. (Second photo you'll notice the large non-RLE image deleted along with it's texture, but the area is white, the black area only shows on an active Image2D object with no texture).

As a second question, I was confused by your solution as it increments a textureId when building 3 new Image2D objects. Prior to adding the Get and SetTextureInfo functions in LoadImage, there should have only been one texture in the first place since the GetOrCreateTextureInfo ignores adding a new texture to AssetStorage if the file names match. (17:30 minute mark of VMK47)

Thanks in advance for any thoughts / help.

Pictures to try and help explain the issue:
Image
Image


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Sat Oct 04, 2014 5:27 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
Hi Mebourne, thanks for your question.

The black squares that you are seeing is 100% correct. As you suspected, this is caused by there being an Image2d object that references a texture id that no longer exists because it was deleted. That means when this gets sent down to the shader for rendering, you'll see that the render call in Image2d says that it has a texture, so textures are enabled, but the textureId is invalid because there is no more texture memory if you deleted the texture. So you get a black space. What you actually see on your screen in this case is video card and graphic driver dependant. Some cards will show a blank space, others will show a black space.

One option you could implement to fix the black squares is when you delete a texture, iterate through your remaining objects and see if any of them are referencing the deleted texture. If they are, reset them, so that they are no longer using a texture so that when you render them, you don't enable textures in the shader. That will mean changing your Image2d.render code.

As for your second question about incrementing the textureId. The reason why the textureId gets incremented is because the previous one was deleted. If you just keep calling loadImages, then the textureId does not get incremented because the AssetStorage sees that the texture exists so it just returns the previously loaded textureId. If you delete the texture, that textureId is no longer valid. So a new texture has to be created when loading in another Image2d object. That auto increments the counter and that is why you are seeing the number go up.

Does that make sense?


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Sat Oct 04, 2014 9:34 am 

Joined: Mon Mar 24, 2014 2:25 pm
Posts: 69
Hey Marek,

Thanks for the quick follow-up. The black square is making sense now, I had originally thought my test with the 4th object non-RLE image proved my original assumption incorrect, but I forgot it was also deleting that single object and that's why the black squares weren't there, only on the smaller two which actually had objects remaining around.

So I'm good on the first part, the second part I'm wondering if "glGenTextures" is card dependent as well. My card GTX680 seems to re-utilize TextureId numbers (ie not a static counter)

For example:
-Query Textures: Tex 1 - TestRLE & Tex 2 - TestNonRLE
-Delete Object 4 & Associated Texture which leaves: Tex 1 - TestRLE and Objects 1-3
-My next subsequent load images (which I test with 4 objects 3 on TestRLE and 1 on TestNonRLE)
-Query Textures: Tex 1 - TestRLE & Tex 2 - TestNonRLE

It seems it reuses the previous texture id numbers, always numbering per how many items are active. This is also the case if I destroy both (2x shift D) and create a new set. This seems consistent with the OpenGL spec on glGenTextures: "Texture names returned by a call to glGenTextures are not returned by subsequent calls, unless they are first deleted with glDeleteTextures." We use glDeleteTextures when removing TextureInfo, I believe then pushing back glGenTexture's counter.

Would that make any sense?

Thanks again for the help


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Sat Oct 04, 2014 11:59 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
:) You are absolutely correct. When the texture is released the textureId should also be released which means when you create a new texture you should get id #1 re-used. I just re-ran the code that I used in the video and I see exactly this behaviour.

I suspect that the video recording software that I was using while recording this VMK was interfering with OpenGL. I see the black squares when I delete objects with the texture, and I see that the textureId value is reused when the texture is deleted.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Sat Oct 04, 2014 5:26 pm 

Joined: Mon Mar 24, 2014 2:25 pm
Posts: 69
Alright, thanks for the follow-up, things are starting to line up.

One odd behavior I noticed was the SetTexture function in ShaderManager, not sure if this gets changed in later VMKs or not. If I utilized two textures on the screen and delete one texture, all remaining objects no matter what TextureId they orginally pointed to are textured with the remaining texture in the list due to the below bold code.

I don't think this is a significant issue at the moment, because I for-see correcting the issue with more finite control of ShaderPrograms down the road, but just an observation I'm curious if anyone else ran into.

void FShaderManager::SetTexture(uint32 InTextureNumber, EUniform InSamplerUniform, int32 InTextureId)
{
if (ActiveTextureNumber != InTextureNumber)
{
ActiveTextureNumber = InTextureNumber;
GLActiveTexture(GL_TEXTURE0 + ActiveTextureNumber);
}


glBindTexture(GL_TEXTURE_2D, InTextureId);
SetUniform(InSamplerUniform, ActiveTextureNumber);
}


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Sat Oct 04, 2014 6:28 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
Yes that can happen. The Image2d object is meant to always be used with a valid texture. An Image2d object with no texture attached to it makes no sense. In a later VMK you'll see we create a different type of class that supports both textured, and untextured modes.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Mon Apr 13, 2015 2:39 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
On my second pass of this series in VS2013 I do not know why, but when I go to delete the mko object along with the texture by pressing shift + d, the texture is deleted and the objects are no longer on the screen. So if the initial 3 are on the screen and I query the loaded objects it shows: Loaded Images: mko1, mko2, mko3 as expected. When I query the texture info, it shows: textureId(1) along with the rest of the parameters. When I Press d to delete one it works as expected and the query loaded items shows mko1, mko2 as expected and the query to texture info is the same. Now, when I press shift + d at this point, the objects are removed however there are a few things here at this point I am trying to fix. There is a black box in the remaining mko object's rendered positions, and when I query the loaded objects it shows mko1 as expected, and when I query the texture info it is blank and it does delete the texture info. However when I press c to create 3 more objects at this point, It does render 4 objects and when I query the loaded images it shows: mko1, 4, 5, & 6 as expected, but when I query the texture info it shows this: textureId(1) and not textureId(2). This is before we added in the two functions to get and set the TextureInfo to the Image2d class and before we added in the extra check and loop in the loadImages function within the Game class. After searching through the code, the only place that I see where the textureId is being assigned is in AssetStorage::add() function when we make a call to glGenTextures( 1, &textureInfo.uTextureId ); I stepped through the code using the debugger and it is going through the correct logical path on creating and removing the mko objects as well as adding and removing textures. I am not sure if this is the appropriate behavior or not. Also after I added in the two set and get textureInfo functions and added in the extra code block within Game::addImages() I am still getting the same behavior and the actual textureId value that is being generated by OpenGL is not incrementing with the same texture file name after it is being deleted and recreated. Any thoughts on this? Are there any other locations throughout the source code I can look through to find out if this behavior is correct? I would like to have this as bug free as possible before I move on to add in the BatchManager.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Mon Apr 13, 2015 3:19 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
Can you run your old VS2010 code to see what you were getting before. The id values that are returned, are video card specific, so your video card may be reusing deleted id's which is fine.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 47 - Challenge 3 Solution
PostPosted: Mon Apr 13, 2015 7:06 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
I have a fairly new video card, NVIDIA GeForce GTX 750 Ti - PCIe/SSE2 hardware support for OpenGL v4.5 it is a 2GB video card with over clocking capabilities.
I wasn't sure if there was a bug in the code or if this was accepted behavior.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 13 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron