It is currently Fri Apr 28, 2017 8:48 pm

All times are UTC - 5 hours




 Page 1 of 1 [ 9 posts ] 
Author Message
 Post subject: Shader VMK 49 - Batch Class
PostPosted: Wed Jul 23, 2014 5:20 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
In this VMK I show how to create the Batch class which is used to store different types of vertices before sending them to the GPU. The GuiVertex and BatchConfig structs are also created in this video, along with some updates to the ShaderManager.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 49 - Batch Class
PostPosted: Thu Jul 24, 2014 12:32 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
If you are following this series, towards the end of the video when Marek has you add the UT_BOOL in the ShaderVariable class, do not forget to update ShaderManger.cpp getSize() function and ShaderVariable::getShaderTypename() function in ShaderVariable.inl .


Offline
 Profile  
 
 Post subject: Re: Shader VMK 49 - Batch Class
PostPosted: Thu Jul 24, 2014 8:45 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
Thanks skilz80. I forgot to add those bits in.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 49 - Batch Class
PostPosted: Tue Apr 14, 2015 4:43 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
In my second pass of this video series in VS2013 I do not know why but when I go to compile Batch.cpp it is failing and giving me this error that points to the structure defined in CommonStructs.h

>c:\users\skilz80\documents\visual studio 2013\projects\se2\engine\commonstructs.h(34): error C2719: 'colorIn': formal parameter with __declspec(align('16')) won't be aligned
1>c:\users\skilz80\documents\visual studio 2013\projects\se2\engine\commonstructs.h(38): error C2719: 'colorIn': formal parameter with __declspec(align('16')) won't be aligned


And this is how my structures are defined:
#ifndef COMMON_STRUCTS_H
#define COMMON_STRUCTS_H

namespace vmk {

// ----------------------------------------------------------------------------
// TextureInfo - Texture Info Structure For Creating A Textured Object
struct TextureInfo {
   enum FilterQuality {
      FILTER_NONE = 1,
      FILTER_GOOD,
      FILTER_BETTER,
      FILTER_BEST
   }; // FilterQuality

   unsigned   uTextureId;
   bool      hasTransparency;
   glm::uvec2   size;

   TextureInfo() :
      uTextureId( INVALID_UNSIGNED ),
      hasTransparency( false ),
      size( glm::uvec2( 0, 0 ) )
   {}
}; // TextureInfo

// ----------------------------------------------------------------------------
// GuiVertex - Vertex Structure For Gui Elements To Be Used In Batch Rendering
struct GuiVertex {
   glm::vec2 position;   
   glm::vec4 color;
   glm::vec2 texture;   

   GuiVertex( glm::vec2 positionIn, glm::vec4 colorIn, glm::vec2 textureIn = glm::vec2() ) :
      position( positionIn ),
      color( colorIn ),
      texture( textureIn )
   {}   
}; // GuiVertex

// ----------------------------------------------------------------------------
// BatchConfig - Config Structure For Use In Using The Batch & BatchManager Classes
struct BatchConfig {
   unsigned uRenderType;
   int      iPriority;
   unsigned uTextureId;

   BatchConfig( unsigned uRenderTypeIn, int iPriorityIn, unsigned uTextureIdIn/* = INVALID_UNSIGNED*/ ) :
      uRenderType( uRenderTypeIn ),
      iPriority( iPriorityIn ),
      uTextureId( uTextureIdIn )
   {}

   bool operator== ( const BatchConfig& other ) const {
      if ( uRenderType  != other.uRenderType ||
          iPriority    != other.iPriority   ||
          uTextureId   != other.uTextureId )
      {
         return false;
      }
      return true;
   }

   bool operator!=( const BatchConfig& other ) const {
      return !( *this == other );
   }
}; // BatchConfig

} // namespace vmk

#endif // COMMON_STRUCTS_H


Offline
 Profile  
 
 Post subject: Re: Shader VMK 49 - Batch Class
PostPosted: Tue Apr 14, 2015 5:39 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
Try swapping color and position inside the GUI vertex structure so that you have the vec4 defined first followed by 2 vec2's


Offline
 Profile  
 
 Post subject: Re: Shader VMK 49 - Batch Class
PostPosted: Tue Apr 14, 2015 5:57 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
Okay I'll try that. Still not sure why it wouldn't align correctly since each of the elements in glm::vec2 and vec4 are 4bytes each.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 49 - Batch Class
PostPosted: Tue Apr 14, 2015 6:08 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
No matter which order I put it in, even with changing the constructor's signature I am still getting the same exact error message.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 49 - Batch Class
PostPosted: Tue Apr 14, 2015 7:12 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
I went to stackoverlfow and checked their forums and here is a similar but different example with the same error and results.
http://stackoverflow.com/questions/28488986/c-opengl-formal-parameter-with-declspecalign16-wont-be-aligned and the last answer for this question mentions that GLM expects 16 byte alignment with vec4s where openGL doesn't care. So that this is sending the information to the compiler. I am still not sure if this visual studio independent upon versions such as VS2012 or VS2013, or if this is some new implementation within the newer versions of GLM. They suggested to pass by const reference instead of just by value. Would this affect the overall structure of the engine? Or wherever raw data is passed into the GuiVertex Constructor just remember to create populated temp stack variables first?


Offline
 Profile  
 
 Post subject: Re: Shader VMK 49 - Batch Class
PostPosted: Tue Apr 14, 2015 10:13 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
Once I got the BatchManager completed and added in version 2.0 for the Image2d class, I tried using GuiVertex constructor where const references are passed in. I was able to compile without error, however there was a warning message on the building stage that was being generated either in Batch.cpp or BatchManager.cpp referring to the glm::vec4 being allocated on the heap and may not be (16byte) aligned. I was able to run the program without crashing and the executable's return code was 0. The problem at this point, I was not able to see the image being rendered. Instead of seeing the image from the *.tga file, I was seeing a black box in its place.

To do a sanity check to see if this was a compiler issue between VS2012 and VS2013 or if this was an internal implementation issue within the GLM library I changed my environment variable within my VS2013 projects (Engine & Game) from using version 0.9.6.3 to using v0.9.3.4, then I went back into CommonStructs.h and changed the GuiVertex constructor to accept in glm::vec2 and glm::vec4 without being const reference. Then I did a clean solution and build and there were no errors or warnings generated. When I ran the code sure enough there was the rendered image in all of its glory.

This is telling me that it is within the differences between GLM's versions of their library. I will have to check out GLM specs on why this could be happening, and if there are any workarounds to it. I hope that this may help anyone else who decides to follow this series from its beginning but decides to use the newest version of GLM.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 9 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