Torque3D Documentation / _generateds / renderMeshExample.h

renderMeshExample.h

Engine/source/T3D/examples/renderMeshExample.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _RENDERMESHEXAMPLE_H_
 25#define _RENDERMESHEXAMPLE_H_
 26
 27#ifndef _SCENEOBJECT_H_
 28#include "scene/sceneObject.h"
 29#endif
 30#ifndef _GFXVERTEXBUFFER_H_
 31#include "gfx/gfxVertexBuffer.h"
 32#endif
 33#ifndef _GFXPRIMITIVEBUFFER_H_
 34#include "gfx/gfxPrimitiveBuffer.h"
 35#endif
 36
 37#include "T3D/assets/MaterialAsset.h"
 38
 39class BaseMatInstance;
 40
 41
 42//-----------------------------------------------------------------------------
 43// This class implements a basic SceneObject that can exist in the world at a
 44// 3D position and render itself. There are several valid ways to render an
 45// object in Torque. This class implements the preferred rendering method which
 46// is to submit a MeshRenderInst along with a Material, vertex buffer,
 47// primitive buffer, and transform and allow the RenderMeshMgr handle the
 48// actual setup and rendering for you.
 49//-----------------------------------------------------------------------------
 50
 51class RenderMeshExample : public SceneObject
 52{
 53   typedef SceneObject Parent;
 54
 55   // Networking masks
 56   // We need to implement a mask specifically to handle
 57   // updating our transform from the server object to its
 58   // client-side "ghost". We also need to implement a
 59   // maks for handling editor updates to our properties
 60   // (like material).
 61   enum MaskBits 
 62   {
 63      TransformMask = Parent::NextFreeMask << 0,
 64      UpdateMask    = Parent::NextFreeMask << 1,
 65      NextFreeMask  = Parent::NextFreeMask << 2
 66   };
 67
 68   //--------------------------------------------------------------------------
 69   // Rendering variables
 70   //--------------------------------------------------------------------------
 71   DECLARE_NET_MATERIALASSET(RenderMeshExample, Material, UpdateMask);
 72
 73   // The actual Material instance
 74   BaseMatInstance*  mMaterialInst;
 75
 76   // Define our vertex format here so we don't have to
 77   // change it in multiple spots later
 78   typedef GFXVertexPNT VertexType;
 79
 80   // The GFX vertex and primitive buffers
 81   GFXVertexBufferHandle< VertexType> mVertexBuffer;
 82   GFXPrimitiveBufferHandle            mPrimitiveBuffer;
 83
 84public:
 85   RenderMeshExample();
 86   virtual ~RenderMeshExample();
 87
 88   // Declare this object as a ConsoleObject so that we can
 89   // instantiate it into the world and network it
 90   DECLARE_CONOBJECT(RenderMeshExample);
 91
 92   //--------------------------------------------------------------------------
 93   // Object Editing
 94   // Since there is always a server and a client object in Torque and we
 95   // actually edit the server object we need to implement some basic
 96   // networking functions
 97   //--------------------------------------------------------------------------
 98   // Set up any fields that we want to be editable (like position)
 99   static void initPersistFields();
100
101   // Allows the object to update its editable settings
102   // from the server object to the client
103   virtual void inspectPostApply();
104
105   // Handle when we are added to the scene and removed from the scene
106   bool onAdd();
107   void onRemove();
108
109   // Override this so that we can dirty the network flag when it is called
110   void setTransform( const MatrixF &mat );
111
112   // This function handles sending the relevant data from the server
113   // object to the client object
114   U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
115   // This function handles receiving relevant data from the server
116   // object and applying it to the client object
117   void unpackUpdate( NetConnection *conn, BitStream *stream );
118
119   //--------------------------------------------------------------------------
120   // Object Rendering
121   // Torque utilizes a "batch" rendering system. This means that it builds a
122   // list of objects that need to render (via RenderInst's) and then renders
123   // them all in one batch. This allows it to optimized on things like
124   // minimizing texture, state, and shader switching by grouping objects that
125   // use the same Materials.
126   //--------------------------------------------------------------------------
127   // Create the geometry for rendering
128   void createGeometry();
129
130   // Get the Material instance
131   void updateMaterial();
132
133   // This is the function that allows this object to submit itself for rendering
134   void prepRenderImage( SceneRenderState *state );
135};
136
137#endif // _RENDERMESHEXAMPLE_H_
138