00001
00003
00004
00005
00006
00007
00009
00010
00011
00013
00014
00015 #ifndef __HARDWARE_BILLBOARD_LOADER__
00016 #define __HARDWARE_BILLBOARD_LOADER__
00017
00018
00019 #include <OgreResource.h>
00020
00021
00022
00023 class ManualHardwareBillboardMeshLoader : public ManualResourceLoader
00024 {
00025 private :
00026 String mMaterialName;
00027
00028 public :
00029
00030 ManualHardwareBillboardMeshLoader(String materialName)
00031 {
00032 mMaterialName = materialName;
00033 }
00034
00035
00036 void loadResource(Resource *res)
00037 {
00038 Mesh* msh = static_cast<Mesh*>(res);
00039 SubMesh* sm = msh->createSubMesh();
00040 sm->useSharedVertices = false;
00041 sm->vertexData = new VertexData();
00042 sm->vertexData->vertexStart = 0;
00043 sm->vertexData->vertexCount = 4;
00044 VertexDeclaration* dcl = sm->vertexData->vertexDeclaration;
00045 size_t offset = 0;
00046 dcl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
00047 offset += VertexElement::getTypeSize(VET_FLOAT3);
00048 dcl->addElement(0, offset, VET_FLOAT4, VES_TEXTURE_COORDINATES);
00049 offset += VertexElement::getTypeSize(VET_FLOAT4);
00050
00051 HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(offset, 4, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
00052 float* pReal = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
00053
00054
00055
00056
00057 *pReal++ = 0;
00058 *pReal++ = 0;
00059 *pReal++ = 0;
00060
00061 *pReal++ = 1;
00062 *pReal++ = 0;
00063
00064 *pReal++ = 0;
00065 *pReal++ = 0;
00066
00067
00068
00069 *pReal++ = 0;
00070 *pReal++ = 0;
00071 *pReal++ = 0;
00072
00073 *pReal++ = 0;
00074 *pReal++ = 0;
00075
00076 *pReal++ = 0;
00077 *pReal++ = 0;
00078
00079
00080
00081 *pReal++ = 0;
00082 *pReal++ = 0;
00083 *pReal++ = 0;
00084
00085 *pReal++ = 0;
00086 *pReal++ = 1;
00087
00088 *pReal++ = 0;
00089 *pReal++ = 0;
00090
00091
00092
00093 *pReal++ = 0;
00094 *pReal++ = 0;
00095 *pReal++ = 0;
00096
00097 *pReal++ = 1;
00098 *pReal++ = 1;
00099
00100 *pReal++ = 0;
00101 *pReal++ = 0;
00102
00103
00104 vbuf->unlock();
00105
00106 sm->vertexData->vertexBufferBinding->setBinding(0, vbuf);
00107 sm->indexData->indexCount = 6;
00108 sm->indexData->indexBuffer = HardwareBufferManager::getSingleton()
00109 .createIndexBuffer(HardwareIndexBuffer::IT_16BIT, 6,
00110 HardwareBuffer::HBU_STATIC_WRITE_ONLY);
00111 uint16* pI = static_cast<uint16*>(
00112 sm->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD))
00113 ;
00114
00115
00116 *pI++ = 0;
00117 *pI++ = 1;
00118 *pI++ = 2;
00119
00120
00121 *pI++ = 0;
00122 *pI++ = 2;
00123 *pI++ = 3;
00124
00125 sm->indexData->indexBuffer->unlock();
00126
00127 sm->setMaterialName(mMaterialName);
00128
00129
00130 msh->_setBounds(AxisAlignedBox(0,0,0,0,0,0), true);
00131 msh->_setBoundingSphereRadius(1);
00132 }
00133 };
00134
00135
00136 #endif //__HARDWARE_BILLBOARD_LOADER__