renderMeshExample.h
Engine/source/T3D/examples/renderMeshExample.h
Classes:
class
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 37class BaseMatInstance; 38 39 40//----------------------------------------------------------------------------- 41// This class implements a basic SceneObject that can exist in the world at a 42// 3D position and render itself. There are several valid ways to render an 43// object in Torque. This class implements the preferred rendering method which 44// is to submit a MeshRenderInst along with a Material, vertex buffer, 45// primitive buffer, and transform and allow the RenderMeshMgr handle the 46// actual setup and rendering for you. 47//----------------------------------------------------------------------------- 48 49class RenderMeshExample : public SceneObject 50{ 51 typedef SceneObject Parent; 52 53 // Networking masks 54 // We need to implement a mask specifically to handle 55 // updating our transform from the server object to its 56 // client-side "ghost". We also need to implement a 57 // maks for handling editor updates to our properties 58 // (like material). 59 enum MaskBits 60 { 61 TransformMask = Parent::NextFreeMask << 0, 62 UpdateMask = Parent::NextFreeMask << 1, 63 NextFreeMask = Parent::NextFreeMask << 2 64 }; 65 66 //-------------------------------------------------------------------------- 67 // Rendering variables 68 //-------------------------------------------------------------------------- 69 // The name of the Material we will use for rendering 70 String mMaterialName; 71 // The actual Material instance 72 BaseMatInstance* mMaterialInst; 73 74 // Define our vertex format here so we don't have to 75 // change it in multiple spots later 76 typedef GFXVertexPNT VertexType; 77 78 // The GFX vertex and primitive buffers 79 GFXVertexBufferHandle< VertexType> mVertexBuffer; 80 GFXPrimitiveBufferHandle mPrimitiveBuffer; 81 82public: 83 RenderMeshExample(); 84 virtual ~RenderMeshExample(); 85 86 // Declare this object as a ConsoleObject so that we can 87 // instantiate it into the world and network it 88 DECLARE_CONOBJECT(RenderMeshExample); 89 90 //-------------------------------------------------------------------------- 91 // Object Editing 92 // Since there is always a server and a client object in Torque and we 93 // actually edit the server object we need to implement some basic 94 // networking functions 95 //-------------------------------------------------------------------------- 96 // Set up any fields that we want to be editable (like position) 97 static void initPersistFields(); 98 99 // Allows the object to update its editable settings 100 // from the server object to the client 101 virtual void inspectPostApply(); 102 103 // Handle when we are added to the scene and removed from the scene 104 bool onAdd(); 105 void onRemove(); 106 107 // Override this so that we can dirty the network flag when it is called 108 void setTransform( const MatrixF &mat ); 109 110 // This function handles sending the relevant data from the server 111 // object to the client object 112 U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream ); 113 // This function handles receiving relevant data from the server 114 // object and applying it to the client object 115 void unpackUpdate( NetConnection *conn, BitStream *stream ); 116 117 //-------------------------------------------------------------------------- 118 // Object Rendering 119 // Torque utilizes a "batch" rendering system. This means that it builds a 120 // list of objects that need to render (via RenderInst's) and then renders 121 // them all in one batch. This allows it to optimized on things like 122 // minimizing texture, state, and shader switching by grouping objects that 123 // use the same Materials. 124 //-------------------------------------------------------------------------- 125 // Create the geometry for rendering 126 void createGeometry(); 127 128 // Get the Material instance 129 void updateMaterial(); 130 131 // This is the function that allows this object to submit itself for rendering 132 void prepRenderImage( SceneRenderState *state ); 133}; 134 135#endif // _RENDERMESHEXAMPLE_H_ 136
