source file REDRenderCode.h

Go to the documentation of this file.

#ifndef RED_RENDER_CODE_H
#define RED_RENDER_CODE_H

//******************************************************************************
// Copyright (c) 2005 Redway. All rights reserved.
//
// Redway3d is a registered trademark. Any reproduction and / or utilization
// of any material from this document without Redway?s express authorization
// are prohibited.
//******************************************************************************

#include "REDIMeshShape.h"
#include "REDIChunkSaver.h"
#include "REDIChunkInterpreter.h"


//******************************************************************************
//*** Vertex shader channels ***************************************************
//******************************************************************************

enum RED_VSH_INPUT { RED_VSH_VERTEX  = 0,
                     RED_VSH_USER0   = 1,
                     RED_VSH_NORMAL  = 2,
                     RED_VSH_COLOR   = 3,
                     RED_VSH_USER1   = 4,
                     RED_VSH_USER2   = 5,
                     RED_VSH_USER3   = 6,
                     RED_VSH_USER4   = 7,
                     RED_VSH_TEX0    = 8,
                     RED_VSH_TEX1    = 9,
                     RED_VSH_TEX2    = 10,
                     RED_VSH_TEX3    = 11,
                     RED_VSH_TEX4    = 12,
                     RED_VSH_TEX5    = 13,
                     RED_VSH_TEX6    = 14,
                     RED_VSH_TEX7    = 15 };

#define RED_VSH_NB_INPUTS                16
#define RED_RCODE_MAX_LOCAL_BINDINGS     16


//******************************************************************************
//*** Class definition *********************************************************
//******************************************************************************

namespace RED
{
  // RED::RenderCode class:
  // ----------------------
  
  class REDFullExp RenderCode : public RED::Object,
                                public RED::IChunkSaver
  {
    public:
      
      // Typing information:
      // -------------------
      
      SET_CID( CID_class_REDRenderCode ); IMPLEMENT_AS();
      
      SET_CHUNK_SIGNATURE( 0x00000308 ); IMPLEMENT_CHUNKINTERPRETER();
      
      
      // Construction and destruction methods:
      // -------------------------------------
      
      RenderCode();
      
      
      virtual ~RenderCode();
      
      
      void Reset();
      
      
      // Matrix bindings:
      // ----------------
      
      inline void SetViewMatrix( bool iRequest );
      
      
      inline bool HasViewMatrix() const;
      
      
      inline void SetModelMatrix( bool iRequest );
      
      
      inline bool HasModelMatrix() const;
      
      
      inline void SetModelViewProjectionMatrix( bool iRequest );
      
      
      inline bool HasModelViewProjectionMatrix() const;
      
      
      inline void SetModelViewMatrix( bool iRequest );
      
      
      inline bool HasModelViewMatrix() const;
      
      
      // Channel bindings:
      // -----------------
      
      inline void BindChannel( RED_VSH_INPUT     iShaderInput,
                               RED::MESH_CHANNEL iChannel );
      
      
      inline int GetShaderInput( RED_VSH_INPUT iShaderInput ) const;
      
      
      inline void SetNormalizedChannel( RED_VSH_INPUT iShaderInput,
                                        bool          iOnOff = true );
      
      
      inline bool IsChannelNormalized( RED_VSH_INPUT iShaderInput ) const;
      
      
      // Channel binding as program local for indirect lighting:
      // -------------------------------------------------------
      
      RED_RC BindChannelAsLocal( int               iLocal,
                                 RED::MESH_CHANNEL iChannel );
      
      
      inline const int* GetChannelLocalBindings() const;
      
      
      inline int* GetChannelLocalBindings();
      
      
      inline unsigned int GetChannelLocalBindingsCount() const;
      
      
      void ClearChannelLocalBindings ();
      
      
      // I/O operations:
      // ---------------
      
      virtual RED_RC Save( RED::IStream*    iStream, 
                           StreamingPolicy& iPolicy,
                           int              iState = -1 ) const;
      
      
    protected:
      
      bool _iwcs2vcs;
      
      bool _iocs2wcs;
      
      bool _hdmvp;
      
      bool _hdmv;
      
      int _vshinput[ RED_VSH_NB_INPUTS ];
      
      bool _normalized[ RED_VSH_NB_INPUTS ];
      
      int _meshaslocal[ RED_RCODE_MAX_LOCAL_BINDINGS ];

      unsigned int _nb_meshaslocal;
  };
};


//******************************************************************************
//*** RenderCode inlined methods ***********************************************
//******************************************************************************

inline void RED::RenderCode::SetViewMatrix( bool request )
{
  _iwcs2vcs = request;
}


inline bool RED::RenderCode::HasViewMatrix() const
{
  return _iwcs2vcs;
}


inline void RED::RenderCode::SetModelMatrix( bool request )
{
  _iocs2wcs = request;
}


inline bool RED::RenderCode::HasModelMatrix() const
{
  return _iocs2wcs;
}


inline void RED::RenderCode::SetModelViewProjectionMatrix( bool request )
{
  _hdmvp = request;
}


inline bool RED::RenderCode::HasModelViewProjectionMatrix() const
{
  return _hdmvp;
}


inline void RED::RenderCode::SetModelViewMatrix( bool request )
{
  _hdmv = request;
}


inline bool RED::RenderCode::HasModelViewMatrix() const
{
  return _hdmv;
}


inline void RED::RenderCode::BindChannel (RED_VSH_INPUT input,
                                          RED::MESH_CHANNEL channel)
{
  _vshinput[input] = channel;
}


inline int RED::RenderCode::GetShaderInput (RED_VSH_INPUT input) const
{
  return _vshinput[input];
}


inline void RED::RenderCode::SetNormalizedChannel (RED_VSH_INPUT input,
                                                   bool onoff)
{
  _normalized[input] = onoff;
}


inline bool RED::RenderCode::IsChannelNormalized (RED_VSH_INPUT input) const
{
  return _normalized[input];
}


inline const int *RED::RenderCode::GetChannelLocalBindings () const
{
  return _meshaslocal;
}


inline int *RED::RenderCode::GetChannelLocalBindings ()
{
  return _meshaslocal;
}


inline unsigned int RED::RenderCode::GetChannelLocalBindingsCount () const
{
  return _nb_meshaslocal;
}


#endif