Ticket #31: vbo.diff
| File vbo.diff, 208.2 KB (added by ronsaldo, 22 months ago) |
|---|
-
CaWE/MapBezierPatch.hpp
180 180 unsigned long GetWidth() const { return cv_Width; } 181 181 unsigned long GetHeight() const { return cv_Height; } 182 182 // Get the number of vertices in width or height of the rendermesh representation of the bezier patch. 183 unsigned long GetRenderWidth() const { UpdateRenderMesh(); return BPRenderMesh->Mesh es.Size()+1; }184 unsigned long GetRenderHeight() const { UpdateRenderMesh(); assert(BPRenderMesh->Meshes.Size()>0); return BPRenderMesh->Meshes[0]->Vertices.Size()/2; }183 unsigned long GetRenderWidth() const { UpdateRenderMesh(); return BPRenderMesh->MeshWidth; } 184 unsigned long GetRenderHeight() const { UpdateRenderMesh(); return BPRenderMesh->MeshHeight; } 185 185 186 186 // Get the origin of vertice x/y from the rendermesh 187 187 Vector3fT GetRenderVertexPos(unsigned long x, unsigned long y) const; -
CaWE/Renderer3D.cpp
194 194 Mesh.Vertices[2].SetOrigin(V3); Mesh.Vertices[2].SetColor(rSh, gSh, bSh); 195 195 Mesh.Vertices[3].SetOrigin(V4); Mesh.Vertices[3].SetColor(rSh, gSh, bSh); 196 196 197 Mesh.Invalidate(); 197 198 MatSys::Renderer->SetCurrentMaterial(GetRMatFlatShaded()); 198 199 MatSys::Renderer->RenderMesh(Mesh); 199 200 } … … 295 296 // mesh, or else the depth offset won't work right (they are probably differently rasterized). 296 297 MatSys::MeshT Mesh(Pass==1 ? MatSys::MeshT::Polygon : MatSys::MeshT::TriangleFan); 297 298 Mesh.Vertices.PushBackEmpty(4); 299 Mesh.Invalidate(); 298 300 299 301 float color[3]={ 0.0f, 0.0f, 0.0f }; 300 302 color[Depth % 3]=(Pass==1) ? 1.0f : 0.4f; … … 338 340 Mesh.Vertices[5].SetColor(0, 0, 1); 339 341 Mesh.Vertices[5].SetOrigin(Pos + Vector3fT(Mat[0][2], Mat[1][2], Mat[2][2])*Length); 340 342 343 Mesh.Invalidate(); 341 344 MatSys::Renderer->SetCurrentMaterial(GetRMatWireframe()); 342 345 MatSys::Renderer->RenderMesh(Mesh); 343 346 } … … 370 373 Mesh.Vertices[10].SetOrigin(Center.x, Center.y-RADIUS-1, 0); Mesh.Vertices[10].SetColor(1, 1, 1); 371 374 Mesh.Vertices[11].SetOrigin(Center.x, Center.y+RADIUS, 0); Mesh.Vertices[11].SetColor(1, 1, 1); 372 375 376 Mesh.Invalidate(); 373 377 MatSys::Renderer->SetCurrentMaterial(GetRMatWireframe()); 374 378 MatSys::Renderer->RenderMesh(Mesh); 375 379 } -
CaWE/MapFace.cpp
177 177 Mesh.Type=(MatSys::Renderer->GetMaterialFromRM(RenderMat)->PolygonMode==MaterialT::Filled) ? MatSys::MeshT::TriangleFan : MatSys::MeshT::Polygon; 178 178 Mesh.Vertices.Overwrite(); 179 179 Mesh.Vertices.PushBackEmpty(m_Vertices.Size()); 180 Mesh.Invalidate(); 180 181 181 182 for (unsigned long VertexNr=0; VertexNr<m_Vertices.Size(); VertexNr++) 182 183 { -
CaWE/MapBezierPatch.cpp
1176 1176 1177 1177 Vector3fT MapBezierPatchT::GetRenderVertexPos(unsigned long x, unsigned long y) const 1178 1178 { 1179 assert(BPRenderMesh->Meshes.Size()>0); 1179 assert(false); // Unimplemented 1180 return Vector3fT(0.0f, 0.0f, 0.0f); 1181 /*assert(BPRenderMesh->Meshes.Size()>0); 1180 1182 assert(x<=BPRenderMesh->Meshes.Size()); 1181 1183 assert(y<BPRenderMesh->Meshes[0]->Vertices.Size()/2); 1182 1184 … … 1191 1193 VertexPos.y=BPRenderMesh->Meshes[x-c]->Vertices[2*y+c].Origin[1]; 1192 1194 VertexPos.z=BPRenderMesh->Meshes[x-c]->Vertices[2*y+c].Origin[2]; 1193 1195 1194 return VertexPos; 1196 return VertexPos;*/ 1195 1197 } -
CaWE/MapTerrain.cpp
196 196 197 197 // Finally, draw the terrain. 198 198 m_TerrainMesh.Vertices.Overwrite(); 199 m_TerrainMesh.Invalidate(); 199 200 200 201 #if 1 201 202 const ArrayT<Vector3fT>& VectorStrip=GetTerrain().ComputeVectorStrip(VI); … … 636 637 637 638 void MapTerrainT::TrafoMirror(unsigned int NormalAxis, float Dist) 638 639 { 640 639 641 Vector3fT Min=m_TerrainBounds.Min; 640 642 Vector3fT Max=m_TerrainBounds.Max; 641 643 -
SConscript
53 53 # envTools.Append(LINKFLAGS = ['-Wl,--export-dynamic']) # Not needed any more, .so libs now link to the required .a libs directly, just as under Windows. 54 54 # GLU is needed for the TerrainViewerOld *and* for e.g. gluBuild2DMipmaps() in the renderers... 55 55 envTools.Append(CPPPATH=['/usr/include/freetype2']) # As of 2009-09-10, this line is to become unnecessary in the future, see /usr/include/ftbuild.h for details. 56 envTools.Append(LIBS=Split("SceneGraph MatSys cfsLib cfsCoreLib cfsLib ClipSys cfs_png cfs_jpeg bulletcollision lua minizip lightwave z")56 envTools.Append(LIBS=Split("SceneGraph MatSys cfsLib cfsCoreLib cfsLib MatSys ClipSys cfs_png cfs_jpeg bulletcollision lua minizip lightwave z") 57 57 + Split("GL GLU")) 58 58 59 59 envTools.Program('CaSanity', ['CaTools/CaSanity.cpp'] + CommonWorldObject) … … 97 97 # -Wl,-rpath,. is so that also the . directory is searched for dynamic libraries when they're opened. 98 98 # -Wl,--export-dynamic is so that the exe exports its symbols so that the MatSys, SoundSys and game .so libs can in turn resolve theirs. 99 99 envCafu.Append(LINKFLAGS = ['-Wl,-rpath,.', '-Wl,--export-dynamic']) 100 envCafu.Append(LIBS=Split(" MatSys SoundSys SceneGraphcfsLib cfsCoreLib cfs_png cfs_jpeg bulletdynamics bulletcollision bulletmath openal alut mpg123 ogg vorbis vorbisfile minizip z lua lightwave ClipSys GuiSysNullEditor"))100 envCafu.Append(LIBS=Split("SoundSys SceneGraph MatSys cfsLib cfsCoreLib cfs_png cfs_jpeg bulletdynamics bulletcollision bulletmath openal alut mpg123 ogg vorbis vorbisfile minizip z lua lightwave ClipSys GuiSysNullEditor")) 101 101 # We need GLU for e.g. gluBuild2DMipmaps() in the renderers. 102 102 # pthread is needed because some libraries that we load (possibly indirectly), e.g. the libCg.so and libopenal.so, use functions 103 103 # from the pthread library, but have not been linked themselves against it. They rely on the executable to be linked appropriately -
Libs/SceneGraph/FaceBatchesNode.cpp
1 #include "FaceBatchesNode.hpp" 2 #include "LightMapMan.hpp" 3 #include "FaceNode.hpp" 4 #include "ConsoleCommands/ConVar.hpp" 5 #include "MaterialSystem/Material.hpp" 6 #include "MaterialSystem/Renderer.hpp" 7 8 #include <cassert> 9 10 using namespace cf::SceneGraph; 11 12 FaceBatchesNodeT::FaceBatchesNodeT(LightMapManT& LMM) 13 : LightMapMan(LMM), ShadowVolumeMesh(MatSys::MeshT::Triangles, MatSys::MeshT::CCW), IsStencilShadowsValid(false) 14 { 15 ShadowVolumeMesh.VertexBuffer = NULL; 16 } 17 18 FaceBatchesNodeT::~FaceBatchesNodeT() 19 { 20 // Delete the meshes 21 for(unsigned long Nr=0; Nr<OpaqueMeshes.Size(); Nr++) 22 delete OpaqueMeshes[Nr].Mesh; 23 24 for(unsigned long Nr=0; Nr<TranslucentMeshes.Size(); Nr++) 25 delete TranslucentMeshes[Nr].Mesh; 26 27 // Free the render materials 28 MaterialMapT::iterator it2 = MaterialMap.begin(); 29 for(; it2 != MaterialMap.end(); it2++) 30 { 31 MatSys::RenderMaterialT *RenderMat = it2->second; 32 MatSys::Renderer->FreeMaterial(RenderMat); 33 } 34 } 35 36 void FaceBatchesNodeT::DrawAmbientContrib(const Vector3dT& ViewerPos) const 37 { 38 assert(MatSys::Renderer!=NULL); 39 assert(MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::AMBIENT); 40 41 for(unsigned long Nr=0; Nr<OpaqueMeshes.Size(); Nr++) 42 { 43 const MeshDataT &Data = OpaqueMeshes[Nr]; 44 const MeshKeyT &Key = Data.MeshKey; 45 const MatSys::MeshT *Mesh = Data.Mesh; 46 47 // Ignore empty meshes 48 if(Data.Empty || Mesh->VertexBuffer->GetSize() == 0) 49 continue; 50 51 if (Key.LightMapNr<LightMapMan.Textures.Size()) 52 { 53 MatSys::Renderer->SetCurrentLightMap (LightMapMan.Textures [Key.LightMapNr]); 54 MatSys::Renderer->SetCurrentLightDirMap(LightMapMan.Textures2[Key.LightMapNr]); 55 } 56 57 MatSys::Renderer->SetCurrentMaterial(Key.RenderMat); 58 MatSys::Renderer->RenderMesh(*Mesh); 59 } 60 } 61 62 void FaceBatchesNodeT::DrawStencilShadowVolumes(const Vector3dT& LightPos, const float LightRadius) const 63 { 64 assert(MatSys::Renderer!=NULL); 65 assert(MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::STENCILSHADOW); 66 67 if(PrepareStencilShadows(LightPos, LightRadius)) 68 MatSys::Renderer->RenderMesh(ShadowVolumeMesh); 69 } 70 71 void FaceBatchesNodeT::DrawLightSourceContrib(const Vector3dT& ViewerPos, const Vector3dT& LightPos) const 72 { 73 assert(MatSys::Renderer!=NULL); 74 assert(MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::LIGHTING); 75 76 for(unsigned long Nr=0; Nr<OpaqueMeshes.Size(); Nr++) 77 { 78 const MeshDataT &Data = OpaqueMeshes[Nr]; 79 const MeshKeyT &Key = Data.MeshKey; 80 const MatSys::MeshT *Mesh = Data.Mesh; 81 82 // Ignore empty meshes 83 if(Data.Empty || Mesh->VertexBuffer->GetSize() == 0 || 84 LightMaterials.find(Key) == LightMaterials.end()) 85 continue; 86 87 MatSys::Renderer->SetCurrentMaterial(Key.RenderMat); 88 MatSys::Renderer->RenderMesh(*Mesh); 89 } 90 } 91 92 void FaceBatchesNodeT::DrawTranslucentContrib(const Vector3dT& ViewerPos) const 93 { 94 for(unsigned long Nr=0; Nr<TranslucentMeshes.Size(); Nr++) 95 { 96 const MeshDataT &Data = TranslucentMeshes[Nr]; 97 const MeshKeyT &Key = Data.MeshKey; 98 const MatSys::MeshT *Mesh = Data.Mesh; 99 100 // Ignore empty meshes 101 if(Data.Empty || Mesh->VertexBuffer->GetSize() == 0) 102 continue; 103 104 if (Key.LightMapNr<LightMapMan.Textures.Size()) 105 { 106 MatSys::Renderer->SetCurrentLightMap (LightMapMan.Textures [Key.LightMapNr]); 107 MatSys::Renderer->SetCurrentLightDirMap(LightMapMan.Textures2[Key.LightMapNr]); 108 } 109 110 MatSys::Renderer->SetCurrentMaterial(Key.RenderMat); 111 MatSys::Renderer->RenderMesh(*Mesh); 112 } 113 } 114 115 void FaceBatchesNodeT::Reset() 116 { 117 NewOpaqueFaces.Overwrite(); 118 NewTranslucentFaces.Overwrite(); 119 } 120 121 void FaceBatchesNodeT::AppendOpaqueFace(const FaceNodeT *Face) 122 { 123 assert(Face); 124 NewOpaqueFaces.PushBack(Face); 125 } 126 127 void FaceBatchesNodeT::AppendTranslucentFace(const FaceNodeT *Face) 128 { 129 assert(Face); 130 NewTranslucentFaces.PushBack(Face); 131 } 132 133 void FaceBatchesNodeT::InitLight() 134 { 135 ShadowFaces.Overwrite(); 136 LightMaterials.clear(); 137 IsStencilShadowsValid = false; 138 } 139 140 void FaceBatchesNodeT::AppendFrontFace(const FaceNodeT *Face) 141 { 142 assert(Face); 143 MatSys::RenderMaterialT *RenderMaterial = GetRenderMaterial(Face->Material); 144 unsigned short LightMapNr = Face->LightMapInfo.LightMapNr; 145 LightMaterials.insert(MeshKeyT(RenderMaterial, LightMapNr)); 146 } 147 148 void FaceBatchesNodeT::AppendBackFace(const FaceNodeT *Face) 149 { 150 assert(Face); 151 ShadowFaces.PushBack(Face); 152 } 153 154 bool FaceBatchesNodeT::PrepareStencilShadows(const Vector3dT& LightPos, const float LightRadius) const 155 { 156 if(IsStencilShadowsValid) 157 return true; 158 159 unsigned long NrOfFaces = ShadowFaces.Size(); 160 if(NrOfFaces == 0) 161 return false; 162 163 // Count the number of vertices and the faces with vertices 164 unsigned long NrOfVertices = 0; 165 unsigned long NrOfIndices = 0; 166 unsigned long NrOfUsableFaces = 0; 167 for(unsigned long Nr=0; Nr < NrOfFaces; Nr++) 168 { 169 const FaceNodeT *Face = ShadowFaces[Nr]; 170 const MatSys::MeshT &FaceMesh = Face->GetFaceMesh(); 171 172 unsigned long NrOfFaceVertices = FaceMesh.VertexBuffer->GetSize(); 173 if(NrOfFaceVertices == 0) 174 continue; 175 176 NrOfVertices += NrOfFaceVertices; 177 //NrOfIndices += /*Caps*/6*(NrOfFaceVertices-2) + /*Silhouette*/NrOfFaceVertices*6; 178 NrOfIndices += 12*NrOfFaceVertices-12; 179 //NrOfIndices += NrOfFaceVertices*6; 180 NrOfUsableFaces++; 181 } 182 183 if(NrOfUsableFaces == 0) 184 return false; 185 186 // Allocate the space 187 if(!ShadowVolumeMesh.VertexBuffer) 188 { 189 ShadowVolumeMesh.VertexBuffer = MatSys::CreateVertexBuffer<StencilVertexT> (MatSys::VertexBufferI::Stream); 190 ShadowVolumeMesh.PrimitiveBuffer = MatSys::CreatePrimitiveBuffer(MatSys::PrimitiveBufferI::UnsignedShort, 191 MatSys::PrimitiveBufferI::Stream); 192 } 193 194 ShadowVolumeMesh.VertexBuffer->SetSize(NrOfVertices*2); 195 ShadowVolumeMesh.PrimitiveBuffer->SetSize(NrOfIndices); 196 StencilVertexT *Vertices = (StencilVertexT*)ShadowVolumeMesh.VertexBuffer->LockWrite(); 197 unsigned short *Indices = (unsigned short*)ShadowVolumeMesh.PrimitiveBuffer->LockWrite(); 198 199 unsigned long VPos = 0; 200 unsigned long IPos = 0; 201 unsigned long FVPos; 202 for(unsigned long Nr=0; Nr < NrOfFaces; Nr++) 203 { 204 const FaceNodeT *Face = ShadowFaces[Nr]; 205 const MatSys::MeshT &FaceMesh = Face->GetFaceMesh(); 206 207 // Ignore empty faces 208 unsigned long NrOfFaceVertices = FaceMesh.VertexBuffer->GetSize(); 209 if(NrOfFaceVertices == 0) 210 continue; 211 212 VertexT *FaceVertices =(VertexT*)FaceMesh.VertexBuffer->LockRead(); 213 214 // Store the front and back caps 215 for (unsigned long VertexNr=0; VertexNr<NrOfFaceVertices; VertexNr++) 216 { 217 const VectorT A=VectorT(FaceVertices[VertexNr].Origin[0], FaceVertices[VertexNr].Origin[1], 218 FaceVertices[VertexNr].Origin[2]); 219 const VectorT LA=A-LightPos; 220 Vertices[VPos + VertexNr*2+0].SetOrigin(LA.x, LA.y, LA.z, 0.0); 221 Vertices[VPos + VertexNr*2+1].SetOrigin(A.x, A.y, A.z, 1.0); 222 } 223 224 // Store the front cap indices. Reverse the order 225 for(FVPos = 0; FVPos < NrOfFaceVertices-2; FVPos++) 226 { 227 Indices[IPos + FVPos*3+2] = VPos + 1; 228 Indices[IPos + FVPos*3+1] = VPos + 2*FVPos+3; 229 Indices[IPos + FVPos*3+0] = VPos + 2*FVPos+5; 230 } 231 232 IPos += 3*(NrOfFaceVertices-2); 233 234 // Store the back cap indices 235 for(FVPos = 0; FVPos < NrOfFaceVertices-2; FVPos++) 236 { 237 Indices[IPos + FVPos*3+0] = VPos + 0; 238 Indices[IPos + FVPos*3+1] = VPos + 2*FVPos+2; 239 Indices[IPos + FVPos*3+2] = VPos + 2*FVPos+4; 240 } 241 242 IPos += 3*(NrOfFaceVertices-2); 243 244 // Store the silhoutte indices 245 for(FVPos = 0; FVPos < NrOfFaceVertices-1; FVPos++) 246 { 247 // First quad 248 Indices[IPos + FVPos*6+0] = VPos + 2*FVPos+0; 249 Indices[IPos + FVPos*6+1] = VPos + 2*FVPos+1; 250 Indices[IPos + FVPos*6+2] = VPos + 2*FVPos+2; 251 // Second quad 252 Indices[IPos + FVPos*6+3] = VPos + 2*FVPos+1; 253 Indices[IPos + FVPos*6+4] = VPos + 2*FVPos+3; 254 Indices[IPos + FVPos*6+5] = VPos + 2*FVPos+2; 255 256 } 257 258 // Close the silhoutte 259 // First quad 260 Indices[IPos + FVPos*6+0] = VPos + 2*FVPos+0; 261 Indices[IPos + FVPos*6+1] = VPos + 2*FVPos+1; 262 Indices[IPos + FVPos*6+2] = VPos + 0; 263 // Second quad 264 Indices[IPos + FVPos*6+3] = VPos + 2*FVPos+1; 265 Indices[IPos + FVPos*6+4] = VPos + 1; 266 Indices[IPos + FVPos*6+5] = VPos + 0; 267 268 IPos += NrOfFaceVertices*6; 269 VPos += NrOfFaceVertices*2; 270 271 FaceMesh.VertexBuffer->Unlock(); 272 } 273 274 //printf("NI %d IP %d\n", int(NrOfIndices), int(IPos)); 275 // Unlock the buffers 276 ShadowVolumeMesh.VertexBuffer->Unlock(); 277 ShadowVolumeMesh.PrimitiveBuffer->Unlock(); 278 279 // Prepare the meshes 280 IsStencilShadowsValid = true; 281 return true; 282 } 283 284 inline bool IsLessFace(const FaceNodeT *F1, const FaceNodeT *F2) 285 { 286 // Check if one of the faces is null 287 if(F1 == NULL || F2 == NULL) 288 return F1 < F2; 289 290 if(F1->Material == F2->Material) 291 return F1->LightMapInfo.LightMapNr < F2->LightMapInfo.LightMapNr; 292 293 return F1->Material < F2->Material; 294 } 295 296 void FaceBatchesNodeT::Finish() 297 { 298 // Sort the new opaque faces by material. 299 NewOpaqueFaces.QuickSort(IsLessFace); 300 301 // Check if the opaque faces changed 302 if(OldOpaqueFaces != NewOpaqueFaces) 303 { 304 // Prepare the opaque faces 305 PrepareFaces(NewOpaqueFaces, OpaqueMeshes); 306 307 // Swap the arrays data 308 OldOpaqueFaces.Swap(NewOpaqueFaces); 309 } 310 311 // Check if the translucent face changed 312 if(OldTranslucentFaces != NewTranslucentFaces) 313 { 314 // Prepare the translucent faces 315 PrepareFaces(NewTranslucentFaces, TranslucentMeshes); 316 317 // Swap the arrays data 318 OldTranslucentFaces.Swap(NewTranslucentFaces); 319 } 320 } 321 322 void FaceBatchesNodeT::PrepareFaces(const FaceListT &Faces, MeshesDataT &Meshes) 323 { 324 static MeshesDataT Temp; 325 Temp.Overwrite(); 326 327 unsigned long MeshNr = 0; 328 MeshKeyT CurrentKey; 329 unsigned long FaceStart = 0; 330 unsigned long NrOfVertices = 0; 331 unsigned long NrOfIndices = 0; 332 unsigned long Nr; 333 for(Nr=0; Nr < Faces.Size(); Nr++) 334 { 335 const FaceNodeT *Face = Faces[Nr]; 336 const MatSys::MeshT &FaceMesh = Face->GetFaceMesh(); 337 338 // Ignore empty faces 339 unsigned long NrOfFaceVertices = FaceMesh.VertexBuffer->GetSize(); 340 if(NrOfFaceVertices == 0) 341 continue; 342 343 // Extract face key 344 MatSys::RenderMaterialT *RenderMaterial = GetRenderMaterial(Face->Material); 345 unsigned short LightMapNr = Face->LightMapInfo.LightMapNr; 346 MeshKeyT Key(RenderMaterial, LightMapNr); 347 348 // Ignore meshes without material 349 if(!Face->Material) 350 continue; 351 352 // Change current mesh, only if it isn't the first. 353 if(Key != CurrentKey && Nr > 0) 354 { 355 CurrentKey = Key; 356 if(NrOfVertices > 0 && NrOfIndices > 0) 357 Temp.PushBack(PrepareFaceRange(Faces, Meshes, FaceStart, Nr, NrOfVertices, NrOfIndices, MeshNr)); 358 FaceStart = Nr; 359 NrOfVertices = 0; 360 NrOfIndices = 0; 361 } 362 363 // Increase the number of vertices 364 NrOfVertices += NrOfFaceVertices; 365 NrOfIndices += 3*(NrOfFaceVertices-2); 366 } 367 368 // Append the last mesh 369 if(NrOfVertices > 0 && NrOfIndices > 0) 370 Temp.PushBack(PrepareFaceRange(Faces, Meshes, FaceStart, Nr, NrOfVertices, NrOfIndices, MeshNr)); 371 372 // Append the remaining meshes into the recycling list, avoids memory leaks 373 for(; MeshNr < Meshes.Size(); MeshNr++) 374 { 375 MeshDataT &MeshData = Meshes[MeshNr]; 376 MeshData.Empty = true; 377 Temp.PushBack(MeshData); 378 } 379 380 // Swap the meshes 381 Meshes.Swap(Temp); 382 } 383 384 FaceBatchesNodeT::MeshDataT FaceBatchesNodeT::PrepareFaceRange(const FaceListT &Faces, MeshesDataT &Meshes, 385 unsigned long Start, unsigned long End, unsigned long NrOfVertices, unsigned long NrOfIndices, 386 unsigned long &MeshNr) 387 { 388 // Extract face key 389 const FaceNodeT *Face = Faces[Start]; 390 MatSys::RenderMaterialT *RenderMaterial = GetRenderMaterial(Face->Material); 391 unsigned short LightMapNr = Face->LightMapInfo.LightMapNr; 392 MeshKeyT Key(RenderMaterial, LightMapNr); 393 394 MeshDataT MeshData; 395 MeshData.MeshKey = Key; 396 MeshData.Empty = false; 397 398 MatSys::MeshT *Mesh; 399 MatSys::VertexBufferI *VertexBuffer; 400 MatSys::PrimitiveBufferI *PrimitiveBuffer; 401 402 // Recycle meshes 403 if(MeshNr < Meshes.Size()) 404 { 405 // Prepare the mesh 406 Mesh = Meshes[MeshNr++].Mesh; 407 MeshData.Mesh = Mesh; 408 VertexBuffer = Mesh->VertexBuffer; 409 PrimitiveBuffer = Mesh->PrimitiveBuffer; 410 } 411 else 412 { 413 // Create a new mesh 414 Mesh = new MatSys::MeshT(); 415 VertexBuffer = MatSys::CreateVertexBuffer<VertexT> (MatSys::VertexBufferI::Dynamic); 416 PrimitiveBuffer = MatSys::CreatePrimitiveBuffer(MatSys::PrimitiveBufferI::UnsignedShort, 417 MatSys::PrimitiveBufferI::Dynamic); 418 Mesh->VertexBuffer = VertexBuffer; 419 Mesh->PrimitiveBuffer = PrimitiveBuffer; 420 Mesh->Type = MatSys::MeshT::Triangles; 421 422 // Store the mesh 423 MeshData.Mesh = Mesh; 424 } 425 426 // Lock the buffer 427 VertexBuffer->SetSize(NrOfVertices); 428 VertexT *Vertices = (VertexT*) VertexBuffer->LockWrite(); 429 430 PrimitiveBuffer->SetSize(NrOfIndices); 431 unsigned short *Indices = (unsigned short*)PrimitiveBuffer->LockWrite(); 432 433 unsigned long VPos = 0; 434 unsigned long IPos = 0; 435 for(unsigned long Nr = Start; Nr < End; Nr++) 436 { 437 // Retrieve the face 438 Face = Faces[Nr]; 439 const MatSys::MeshT &FaceMesh = Face->GetFaceMesh(); 440 const MatSys::VertexBufferI* FaceVertices = FaceMesh.VertexBuffer; 441 442 unsigned long NrOfFaceVertices = FaceVertices->GetSize(); 443 if(NrOfFaceVertices == 0) // Ignore empty faces 444 continue; 445 446 // Copy the face vertices 447 VertexT *FVertices = (VertexT *)FaceVertices->LockRead(); 448 449 for(unsigned long FVPos = 0; FVPos < NrOfFaceVertices; FVPos++) 450 Vertices[VPos+FVPos] = FVertices[FVPos]; 451 452 FaceVertices->Unlock(); 453 454 // Store the indices 455 for(unsigned long FVPos = 0; FVPos < NrOfFaceVertices-2; FVPos++) 456 { 457 Indices[IPos + FVPos*3+0] = VPos; 458 Indices[IPos + FVPos*3+1] = VPos + FVPos+1; 459 Indices[IPos + FVPos*3+2] = VPos + FVPos+2; 460 } 461 462 IPos += 3*(NrOfFaceVertices-2); 463 VPos += NrOfFaceVertices; 464 } 465 466 // Unlock the buffers 467 PrimitiveBuffer->Unlock(); 468 VertexBuffer->Unlock(); 469 return MeshData; 470 } 471 472 MatSys::RenderMaterialT* FaceBatchesNodeT::GetRenderMaterial(MaterialT* Material) 473 { 474 // Retrieve the render material from the map 475 MaterialMapT::const_iterator it = MaterialMap.find(Material); 476 if(it != MaterialMap.end()) 477 return it->second; 478 479 // Register the material and store the render material 480 MatSys::RenderMaterialT *RenderMaterial = MatSys::Renderer->RegisterMaterial(Material); 481 MaterialMap[Material] = RenderMaterial; 482 return RenderMaterial; 483 } 484 485 -
Libs/SceneGraph/FaceBatchesNode.hpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 #ifndef _CF_SCENEGRAPH_FACEBATCHESNODE_HPP_ 25 #define _CF_SCENEGRAPH_FACEBATCHESNODE_HPP_ 26 27 #include <map> 28 #include <set> 29 #include "Node.hpp" 30 #include "MaterialSystem/Mesh.hpp" 31 #include "MaterialSystem/VertexFormats.hpp" 32 33 namespace MatSys 34 { 35 class RenderMaterialT; 36 } 37 38 class MaterialT; 39 40 namespace cf 41 { 42 namespace SceneGraph 43 { 44 class FaceNodeT; 45 46 class FaceBatchesNodeT: public GenericNodeT 47 { 48 public: 49 FaceBatchesNodeT(LightMapManT& LMM); 50 ~FaceBatchesNodeT(); 51 52 virtual void DrawAmbientContrib(const Vector3dT& ViewerPos) const; 53 virtual void DrawStencilShadowVolumes(const Vector3dT& LightPos, const float LightRadius) const; 54 virtual void DrawLightSourceContrib(const Vector3dT& ViewerPos, const Vector3dT& LightPos) const; 55 virtual void DrawTranslucentContrib(const Vector3dT& ViewerPos) const; 56 57 // Reset the batch generation 58 void Reset(); 59 60 void AppendOpaqueFace(const FaceNodeT *Face); 61 void AppendTranslucentFace(const FaceNodeT *Face); 62 63 // Finish the batch generation 64 void Finish(); 65 66 // Lighting 67 void InitLight(); 68 void AppendFrontFace(const FaceNodeT *Face); 69 void AppendBackFace(const FaceNodeT *Face); 70 71 private: 72 struct MeshKeyT 73 { 74 MeshKeyT(MatSys::RenderMaterialT *RM = NULL, unsigned short LM = 0) 75 : RenderMat(RM), LightMapNr(LM) {} 76 77 bool operator<(const MeshKeyT &o) const 78 { 79 if(RenderMat == o.RenderMat) 80 return LightMapNr < o.LightMapNr; 81 return RenderMat < o.RenderMat; 82 } 83 84 bool operator==(const MeshKeyT &o) const 85 { 86 return RenderMat==o.RenderMat && LightMapNr==o.LightMapNr; 87 } 88 89 bool operator!=(const MeshKeyT &o) const 90 { 91 return RenderMat!=o.RenderMat || LightMapNr!=o.LightMapNr; 92 } 93 94 MatSys::RenderMaterialT *RenderMat; 95 unsigned short LightMapNr; 96 97 }; 98 99 struct MeshDataT 100 { 101 MeshDataT() 102 : Mesh(NULL), Empty(true) {} 103 104 MatSys::MeshT *Mesh; 105 bool Empty; 106 MeshKeyT MeshKey; 107 }; 108 109 typedef MatSys::StaticVertexT VertexT; 110 typedef MatSys::StencilShadowCpuT StencilVertexT; 111 112 typedef std::map<MaterialT*, MatSys::RenderMaterialT*> MaterialMapT; 113 typedef ArrayT<const FaceNodeT*> FaceListT; 114 typedef ArrayT<MeshDataT> MeshesDataT; 115 typedef std::set<MeshKeyT> FaceSetT; 116 117 MatSys::RenderMaterialT* GetRenderMaterial(MaterialT* Material); 118 119 void PrepareFaces(const FaceListT &Faces, MeshesDataT &Meshes); 120 MeshDataT PrepareFaceRange(const FaceListT &Faces, MeshesDataT &Meshes, 121 unsigned long Start, unsigned long End, unsigned long NrOfVertices, unsigned long NrOfIndices, 122 unsigned long &MeshNr); 123 bool PrepareStencilShadows(const Vector3dT& LightPos, const float LightRadius) const; 124 125 LightMapManT& LightMapMan; 126 MaterialMapT MaterialMap; 127 128 // Opaque meshes 129 FaceListT OldOpaqueFaces; 130 FaceListT NewOpaqueFaces; 131 MeshesDataT OpaqueMeshes; 132 133 // Translucent meshes 134 FaceListT OldTranslucentFaces; 135 FaceListT NewTranslucentFaces; 136 MeshesDataT TranslucentMeshes; 137 138 // Shadow volumes 139 FaceListT ShadowFaces; 140 mutable MatSys::MeshT ShadowVolumeMesh; 141 mutable bool IsStencilShadowsValid; 142 143 // Lighting. Recycle ambient faces 144 FaceSetT LightMaterials; 145 }; 146 } 147 } 148 149 #endif // _CF_SCENEGRAPH_FACEBATCHESNODE_HPP_H 150 -
Libs/SceneGraph/FaceNode.cpp
242 242 // ********************** 243 243 244 244 Mesh.Type=MatSys::MeshT::TriangleFan; 245 Mesh.Vertices.PushBackEmpty(DrawIndices.Size()); 245 Mesh.VertexBuffer = MatSys::CreateVertexBuffer<VertexT> (MatSys::VertexBufferI::Temporal); 246 Mesh.VertexBuffer->SetSize(DrawIndices.Size()); 247 VertexT *Vertices = (VertexT*)Mesh.VertexBuffer->LockWrite(); 246 248 247 249 for (unsigned long VertexNr=0; VertexNr<DrawIndices.Size(); VertexNr++) 248 250 { 249 Mesh.Vertices[VertexNr].Origin[0]=SharedVertices[DrawIndices[VertexNr]].x; 250 Mesh.Vertices[VertexNr].Origin[1]=SharedVertices[DrawIndices[VertexNr]].y; 251 Mesh.Vertices[VertexNr].Origin[2]=SharedVertices[DrawIndices[VertexNr]].z; 252 Mesh.Vertices[VertexNr].Origin[3]=1.0; 253 254 Mesh.Vertices[VertexNr].Color[0]=1.0; 255 Mesh.Vertices[VertexNr].Color[1]=1.0; 256 Mesh.Vertices[VertexNr].Color[2]=1.0; 257 Mesh.Vertices[VertexNr].Color[3]=1.0; 251 Vertices[VertexNr].Origin[0]=SharedVertices[DrawIndices[VertexNr]].x; 252 Vertices[VertexNr].Origin[1]=SharedVertices[DrawIndices[VertexNr]].y; 253 Vertices[VertexNr].Origin[2]=SharedVertices[DrawIndices[VertexNr]].z; 258 254 } 259 255 260 256 … … 299 295 const double s=dot(SharedVertices[DrawIndices[VertexNr]], TI_U)/(LengthU*LengthU)+TI.OffsetU-SmallestS; 300 296 const double t=dot(SharedVertices[DrawIndices[VertexNr]], TI_V)/(LengthV*LengthV)+TI.OffsetV-SmallestT; 301 297 302 Mesh.Vertices[VertexNr].TextureCoord[0]=float(s);303 Mesh.Vertices[VertexNr].TextureCoord[1]=float(t);298 Vertices[VertexNr].TextureCoord[0]=float(s); 299 Vertices[VertexNr].TextureCoord[1]=float(t); 304 300 } 305 301 306 302 … … 347 343 const double s=((dot(SharedVertices[DrawIndices[VertexNr]], U)-SmallestU)/LightMapInfoT::PatchSize+1.0+PosS)/double(cf::SceneGraph::LightMapManT::SIZE_S); 348 344 const double t=((dot(SharedVertices[DrawIndices[VertexNr]], V)-SmallestV)/LightMapInfoT::PatchSize+1.0+PosT)/double(cf::SceneGraph::LightMapManT::SIZE_T); 349 345 350 Mesh.Vertices[VertexNr].LightMapCoord[0]=float(s);351 Mesh.Vertices[VertexNr].LightMapCoord[1]=float(t);346 Vertices[VertexNr].LightMapCoord[0]=float(s); 347 Vertices[VertexNr].LightMapCoord[1]=float(t); 352 348 } 353 349 354 350 #if SHL_ENABLED … … 363 359 const double s=(dot(SharedVertices[DrawIndices[VertexNr]], U)/SHLMapInfoT::PatchSize-floor(SmallestU/SHLMapInfoT::PatchSize)+1.0+PosS)/double(cf::SceneGraph::SHLMapManT::SIZE_S); 364 360 const double t=(dot(SharedVertices[DrawIndices[VertexNr]], V)/SHLMapInfoT::PatchSize-floor(SmallestV/SHLMapInfoT::PatchSize)+1.0+PosT)/double(cf::SceneGraph::SHLMapManT::SIZE_T); 365 361 366 Mesh.Vertices[VertexNr].SHLMapCoord[0]=float(s);367 Mesh.Vertices[VertexNr].SHLMapCoord[1]=float(t);362 Vertices[VertexNr].SHLMapCoord[0]=float(s); 363 Vertices[VertexNr].SHLMapCoord[1]=float(t); 368 364 } 369 365 #endif 370 366 … … 381 377 const VectorT TexU =TI.U.AsVectorOfDouble(); 382 378 const VectorT TexV =TI.V.AsVectorOfDouble(); 383 379 384 // Note that 380 // Note thatif(!Mesh.VertexBuffer) 385 381 // a) our intention here is to compute the proper coordinate axes of the texture-space, 386 382 // b) the above used 'U' and 'V' span vectors are absolutely useless for this purpose (they are entirely arbitrary and unrelated), and 387 383 // c) the 'TexU' and 'TexV' vectors (together with 'TexNormal') are not correct either. … … 415 411 // Fill-in the 'NormalXYZ', 'TangentXYZ', and 'BiNormalXYZ' components of the 'FaceVertexInfos', taking SmoothGroups into account. 416 412 for (unsigned long VertexNr=0; VertexNr<DrawIndices.Size(); VertexNr++) 417 413 { 418 Mesh.Vertices[VertexNr].SetNormal (TexNormal .AsVectorOfFloat());419 Mesh.Vertices[VertexNr].SetTangent (FaceTangent .AsVectorOfFloat());420 Mesh.Vertices[VertexNr].SetBiNormal(FaceBiNormal.AsVectorOfFloat());414 Vertices[VertexNr].SetNormal (TexNormal .AsVectorOfFloat()); 415 Vertices[VertexNr].SetTangent (FaceTangent .AsVectorOfFloat()); 416 Vertices[VertexNr].SetBiNormal(FaceBiNormal.AsVectorOfFloat()); 421 417 } 422 418 423 419 … … 426 422 // *********************** 427 423 428 424 RenderMat=MatSys::Renderer->RegisterMaterial(Material); 425 Mesh.VertexBuffer->Unlock(); 429 426 } 430 427 431 428 … … 487 484 } 488 485 489 486 487 const MatSys::MeshT &FaceNodeT::GetFaceMesh() const 488 { 489 return Mesh; 490 } 491 490 492 void FaceNodeT::WriteTo(std::ostream& OutFile, aux::PoolT& Pool) const 491 493 { 492 494 aux::Write(OutFile, "Face"); … … 605 607 assert(MatSys::Renderer!=NULL); 606 608 assert(MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::STENCILSHADOW); 607 609 610 if(!Mesh.VertexBuffer) 611 return; 612 613 VertexT *Vertices = (VertexT*)Mesh.VertexBuffer->LockRead(); 614 unsigned long NrOfVertices = Mesh.VertexBuffer->GetSize(); 615 608 616 // Render the silhouette quads. 609 617 static MatSys::MeshT SilhouetteMesh(MatSys::MeshT::QuadStrip, MatSys::MeshT::CCW); 610 618 SilhouetteMesh.Vertices.Overwrite(); 611 SilhouetteMesh.Vertices.PushBackEmpty(2*Mesh.Vertices.Size()+2); 619 SilhouetteMesh.Vertices.PushBackEmpty(2*NrOfVertices+2); 620 SilhouetteMesh.Invalidate(); 612 621 613 const VectorT A0=VectorT( Mesh.Vertices[0].Origin[0], Mesh.Vertices[0].Origin[1], Mesh.Vertices[0].Origin[2]);622 const VectorT A0=VectorT(Vertices[0].Origin[0], Vertices[0].Origin[1], Vertices[0].Origin[2]); 614 623 const VectorT LA0=A0-LightPos; 615 624 616 625 // Note that the order is reversed because we're dealing with a back-facing polygon as occluder! 617 626 SilhouetteMesh.Vertices[0].SetOrigin(LA0.x, LA0.y, LA0.z, 0.0); 618 627 SilhouetteMesh.Vertices[1].SetOrigin( A0.x, A0.y, A0.z, 1.0); 619 628 620 for (unsigned long VertexNr=1; VertexNr< Mesh.Vertices.Size(); VertexNr++)629 for (unsigned long VertexNr=1; VertexNr<NrOfVertices; VertexNr++) 621 630 { 622 const VectorT A=VectorT( Mesh.Vertices[VertexNr].Origin[0], Mesh.Vertices[VertexNr].Origin[1], Mesh.Vertices[VertexNr].Origin[2]);631 const VectorT A=VectorT(Vertices[VertexNr].Origin[0], Vertices[VertexNr].Origin[1], Vertices[VertexNr].Origin[2]); 623 632 const VectorT LA=A-LightPos; 624 633 625 634 // Note that the order is reversed because we're dealing with a back-facing polygon as occluder! … … 627 636 SilhouetteMesh.Vertices[VertexNr*2+1].SetOrigin( A.x, A.y, A.z, 1.0); 628 637 } 629 638 630 SilhouetteMesh.Vertices[ Mesh.Vertices.Size()*2+0].SetOrigin(LA0.x, LA0.y, LA0.z, 0.0); // Close the silhouette for this occluder.631 SilhouetteMesh.Vertices[ Mesh.Vertices.Size()*2+1].SetOrigin( A0.x, A0.y, A0.z, 1.0);639 SilhouetteMesh.Vertices[NrOfVertices*2+0].SetOrigin(LA0.x, LA0.y, LA0.z, 0.0); // Close the silhouette for this occluder. 640 SilhouetteMesh.Vertices[NrOfVertices*2+1].SetOrigin( A0.x, A0.y, A0.z, 1.0); 632 641 633 642 MatSys::Renderer->RenderMesh(SilhouetteMesh); 634 643 … … 639 648 // we have to reverse the order of its vertices in order to turn it into a CCW ordered, front-facing polygon.) 640 649 static MatSys::MeshT M_front(MatSys::MeshT::TriangleFan, MatSys::MeshT::CCW); 641 650 M_front.Vertices.Overwrite(); 642 M_front.Vertices.PushBackEmpty(Mesh.Vertices.Size()); 651 M_front.Vertices.PushBackEmpty(NrOfVertices); 652 M_front.Invalidate(); 643 653 644 for (unsigned long VertexNr=0; VertexNr< Mesh.Vertices.Size(); VertexNr++)645 M_front.Vertices[M_front.Vertices.Size()-VertexNr-1].SetOrigin( Mesh.Vertices[VertexNr].Origin[0],646 Mesh.Vertices[VertexNr].Origin[1],647 Mesh.Vertices[VertexNr].Origin[2], 1.0);654 for (unsigned long VertexNr=0; VertexNr<NrOfVertices; VertexNr++) 655 M_front.Vertices[M_front.Vertices.Size()-VertexNr-1].SetOrigin(Vertices[VertexNr].Origin[0], 656 Vertices[VertexNr].Origin[1], 657 Vertices[VertexNr].Origin[2], 1.0); 648 658 649 659 // What a pity the order isn't the other way round. Could then simply write: MatSys::Renderer->RenderMesh(Mesh); 650 660 MatSys::Renderer->RenderMesh(M_front); … … 655 665 // we just have to project them to infinity as seen from the light source. 656 666 static MatSys::MeshT M_back(MatSys::MeshT::TriangleFan, MatSys::MeshT::CCW); 657 667 M_back.Vertices.Overwrite(); 658 M_back.Vertices.PushBackEmpty(Mesh.Vertices.Size()); 668 M_back.Vertices.PushBackEmpty(NrOfVertices); 669 M_back.Invalidate(); 659 670 660 for (unsigned long VertexNr=0; VertexNr< Mesh.Vertices.Size(); VertexNr++)661 M_back.Vertices[VertexNr].SetOrigin( Mesh.Vertices[VertexNr].Origin[0]-LightPos.x,662 Mesh.Vertices[VertexNr].Origin[1]-LightPos.y,663 Mesh.Vertices[VertexNr].Origin[2]-LightPos.z, 0.0);671 for (unsigned long VertexNr=0; VertexNr<NrOfVertices; VertexNr++) 672 M_back.Vertices[VertexNr].SetOrigin(Vertices[VertexNr].Origin[0]-LightPos.x, 673 Vertices[VertexNr].Origin[1]-LightPos.y, 674 Vertices[VertexNr].Origin[2]-LightPos.z, 0.0); 664 675 665 676 MatSys::Renderer->RenderMesh(M_back); 677 Mesh.VertexBuffer->Unlock(); 666 678 } 667 679 668 680 -
Libs/SceneGraph/BezierPatchNode.cpp
54 54 Material(NULL), 55 55 LightMapInfo(), 56 56 LightMapMan(LMM), 57 RenderMaterial(NULL) 57 Mesh(MatSys::MeshT::TriangleStrip), 58 RenderMaterial(NULL), 59 MeshWidth(1), 60 MeshHeight(1) 58 61 { 62 Mesh.VertexBuffer = NULL; 59 63 Init(); 60 64 } 61 65 … … 71 75 Material(Material_), 72 76 LightMapInfo(), 73 77 LightMapMan(LMM), 74 RenderMaterial(NULL) 78 Mesh(MatSys::MeshT::TriangleStrip), 79 RenderMaterial(NULL), 80 MeshWidth(1), 81 MeshHeight(1) 75 82 { 76 83 for (unsigned long ComponentNr=0; ComponentNr<ControlPoints_.Size(); ComponentNr+=5) 77 84 { … … 79 86 ControlPointsUV .PushBack(Vector3fT(ControlPoints_[ComponentNr+3], ControlPoints_[ComponentNr+4], 0.0f)); 80 87 } 81 88 89 Mesh.VertexBuffer = NULL; 82 90 Init(); 83 91 } 84 92 … … 94 102 Material(Material_), 95 103 LightMapInfo(), 96 104 LightMapMan(LMM), 97 RenderMaterial(NULL) 105 Mesh(MatSys::MeshT::TriangleStrip), 106 RenderMaterial(NULL), 107 MeshWidth(1), 108 MeshHeight(1) 98 109 { 110 Mesh.VertexBuffer = NULL; 99 111 Init(); 100 112 } 101 113 … … 272 284 // cLOD Überlegungen sind denkbar - siehe "r_lodCurveError" convar im Q3 Quellcode. 273 285 // Siehe http://xreal.sourceforge.net/xrealwiki/XMapExplanations 274 286 // Aber: Sind wg. Tangent-Space viel aufwendiger als bei Q3... Performance? 275 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 276 MatSys::Renderer->RenderMesh(*Meshes[MeshNr]); 287 MatSys::Renderer->RenderMesh(Mesh); 277 288 278 289 #if 0 279 290 // Render the tangent-space axes (for debugging). … … 322 333 assert(MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::LIGHTING); 323 334 324 335 MatSys::Renderer->SetCurrentMaterial(RenderMaterial); 325 326 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 327 MatSys::Renderer->RenderMesh(*Meshes[MeshNr]); 336 MatSys::Renderer->RenderMesh(Mesh); 328 337 } 329 338 330 339 … … 339 348 340 349 void BezierPatchNodeT::UpdateMeshColor(const float red, const float green, const float blue, const float alpha) 341 350 { 342 for (unsigned int i=0; i<Meshes.Size(); i++) 351 if(!Mesh.VertexBuffer) 352 return; 353 354 // WARNING: This is a potential performance bottleneck 355 VertexT *Vertices = (VertexT*)Mesh.VertexBuffer->LockReadWrite(); 356 for(unsigned int j=0; j<Mesh.VertexBuffer->GetSize(); j++) 343 357 { 344 MatSys::MeshT* currentMesh=Meshes[i]; 345 for(unsigned int j=0; j<currentMesh->Vertices.Size(); j++) 346 { 347 currentMesh->Vertices[j].Color[0]=red; 348 currentMesh->Vertices[j].Color[1]=green; 349 currentMesh->Vertices[j].Color[2]=blue; 350 currentMesh->Vertices[j].Color[3]=alpha; 351 } 358 Vertices[j].Color[0]=red; 359 Vertices[j].Color[1]=green; 360 Vertices[j].Color[2]=blue; 361 Vertices[j].Color[3]=alpha; 352 362 } 363 Mesh.VertexBuffer->Unlock(); 353 364 } 354 365 355 366 … … 440 451 PatchMesh.Height=PatchMesh.WrapsVert ? LightMapInfo.SizeT-1 : LightMapInfo.SizeT; 441 452 PatchMesh.Patches.PushBackEmpty(PatchMesh.Width*PatchMesh.Height); 442 453 454 455 456 457 443 458 PatchMesh.Node =this; 444 459 PatchMesh.Material=Material; 445 460 … … 685 700 } 686 701 687 702 688 static void AssignMatSysFromBezierPatchVertex( MatSys::MeshT::VertexT& msV, const cf::math::BezierPatchT<float>::VertexT& bpV)703 static void AssignMatSysFromBezierPatchVertex(cf::SceneGraph::BezierPatchNodeT::VertexT& msV, const cf::math::BezierPatchT<float>::VertexT& bpV) 689 704 { 690 705 msV.SetOrigin (bpV.Coord); 691 706 msV.SetColor (0.0, 1.0, 1.0); // For debugging materials that use "useMeshColors". … … 733 748 GenerateLightMapMesh(CurveMesh, true); 734 749 #endif 735 750 736 // Copy the curve mesh into MatSys meshes. 751 // Allocate the vertex buffr 752 if(!Mesh.VertexBuffer) 753 Mesh.VertexBuffer = MatSys::CreateVertexBuffer<VertexT> (MatSys::VertexBufferI::Static); 754 755 // Store the mesh size 756 MeshWidth = CurveMesh.Width; 757 MeshHeight = CurveMesh.Height; 758 759 // Calculate mesh sizes 760 const unsigned long RangeCount = 2*CurveMesh.Height; 761 const unsigned long NrOfVertices =RangeCount*(CurveMesh.Width-1); 762 Mesh.VertexBuffer->SetSize(NrOfVertices); 763 VertexT *Vertices = (VertexT*)Mesh.VertexBuffer->LockWrite(); 764 737 765 for (unsigned long ColumnNr=0; ColumnNr+1<CurveMesh.Width; ColumnNr++) 738 766 { 739 767 // There is one triangle strip for each column of the curve mesh. 740 Meshes.PushBack(new MatSys::MeshT(MatSys::MeshT::TriangleStrip)); 741 Meshes[ColumnNr]->Vertices.PushBackEmpty(2*CurveMesh.Height); 742 768 const unsigned long Pos = RangeCount*ColumnNr; 769 Mesh.SubRanges.PushBack(MatSys::MeshT::RangeT(Pos, RangeCount)); 743 770 for (unsigned long RowNr=0; RowNr<CurveMesh.Height; RowNr++) 744 771 { 745 MatSys::MeshT::VertexT& Left =Meshes[ColumnNr]->Vertices[RowNr*2+0];772 VertexT& Left =Vertices[Pos + RowNr*2+0]; 746 773 747 774 AssignMatSysFromBezierPatchVertex(Left, CurveMesh.GetVertex(ColumnNr, RowNr)); 748 775 … … 750 777 const float LeftLmT=(float(LightMapInfo.PosT)+0.5f + (float(RowNr )/(CurveMesh.Height-1))*(LightMapInfo.SizeT-1)) / cf::SceneGraph::LightMapManT::SIZE_T; 751 778 752 779 Left.SetLightMapCoord(LeftLmS, LeftLmT); 780 #if SHL_ENABLED 753 781 Left.SetSHLMapCoord (LeftLmS, LeftLmT); 782 #endif 754 783 784 VertexT& Right=Vertices[Pos + RowNr*2+1]; 755 785 756 MatSys::MeshT::VertexT& Right=Meshes[ColumnNr]->Vertices[RowNr*2+1];757 758 786 AssignMatSysFromBezierPatchVertex(Right, CurveMesh.GetVertex(ColumnNr+1, RowNr)); 759 787 760 788 const float RightLmS=(float(LightMapInfo.PosS)+0.5f + (float(ColumnNr+1)/(CurveMesh.Width -1))*(LightMapInfo.SizeS-1)) / cf::SceneGraph::LightMapManT::SIZE_S; 761 789 const float RightLmT=LeftLmT; 762 790 763 791 Right.SetLightMapCoord(RightLmS, RightLmT); 792 #if SHL_ENABLED 764 793 Right.SetSHLMapCoord (RightLmS, RightLmT); 794 #endif 765 795 } 766 796 } 797 798 Mesh.VertexBuffer->Unlock(); 767 799 #else 768 800 /*** OLD METHOD ***/ 769 801 … … 886 918 } 887 919 888 920 if (AbsIndexX<TotalNrOfTriangleColumns) 921 889 922 { 890 923 MatSys::MeshT::VertexT& V=Meshes[AbsIndexX]->Vertices[AbsIndexY*2]; 891 924 … … 912 945 913 946 void BezierPatchNodeT::Clean() 914 947 { 915 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) delete Meshes[MeshNr]; 916 Meshes.Clear(); 948 if(Mesh.VertexBuffer) 949 { 950 delete Mesh.VertexBuffer; 951 Mesh.VertexBuffer = NULL; 952 Mesh.SubRanges.Overwrite(); 953 } 917 954 918 955 if (RenderMaterial!=NULL) 919 956 { -
Libs/SceneGraph/FaceNode.hpp
44 44 class FaceNodeT : public GenericNodeT 45 45 { 46 46 public: 47 typedef MatSys::StaticVertexT VertexT; 47 48 48 49 struct TexInfoT 49 50 { … … 123 124 void CreatePatchMeshes(ArrayT<PatchMeshT>& PatchMeshes, ArrayT< ArrayT< ArrayT<Vector3dT> > >& SampleCoords) const; 124 125 void BackToLightMap(const PatchMeshT& PatchMesh); 125 126 127 /// Returns the face mesh. For FaceBatchesNode 128 const MatSys::MeshT &GetFaceMesh() const; 126 129 127 130 // TODO: The stuff below should actually be protected or private rather than public. 128 131 // However, it used to be in the obsolete FaceT struct that I used earlier, and a lot of Code (CaBSP, CaLight etc.) -
Libs/SceneGraph/BspTreeNode.cpp
24 24 #include "BspTreeNode.hpp" 25 25 #include "_aux.hpp" 26 26 #include "FaceNode.hpp" 27 #include "FaceBatchesNode.hpp" 27 28 #include "ConsoleCommands/ConVar.hpp" 28 29 #include "MaterialSystem/Material.hpp" 29 30 #include "MaterialSystem/Renderer.hpp" … … 39 40 BspTreeNodeT::BspTreeNodeT() 40 41 : NextLightNeedsInit(true) 41 42 { 43 FaceBatches = NULL; 42 44 } 43 45 44 46 … … 46 48 LightMapManT& LMM, SHLMapManT& SMM, PlantDescrManT& PDM, const ArrayT<const TerrainT*>& ShTe) 47 49 { 48 50 BspTreeNodeT* BspTree=new BspTreeNodeT(); 51 BspTree->FaceBatches = new FaceBatchesNodeT(LMM); 49 52 50 53 // Read the FaceChildren. 51 54 for (unsigned long Count=aux::ReadUInt32(InFile); Count>0; Count--) … … 154 157 155 158 for (unsigned long ChildNr=0; ChildNr<OtherChildren.Size(); ChildNr++) 156 159 delete OtherChildren[ChildNr]; 160 161 if(FaceBatches) 162 delete FaceBatches; 157 163 } 158 164 159 165 … … 315 321 // b) Eine Liste der relevanten, translucent Faces, die anschließend back-to-front gezeichnet werden (für korrektes Blending). 316 322 BackToFrontListOpaque.Overwrite(); 317 323 BackToFrontListTranslucent.Overwrite(); 324 if(FaceBatches) 325 FaceBatches->Reset(); 318 326 319 327 for (unsigned long OrderNr=0; OrderNr<OrderedLeaves.Size(); OrderNr++) 320 328 { … … 336 344 337 345 FaceChildIsInViewerPVS[ChildNr]=true; 338 346 339 if (FaceNode->IsOpaque()) BackToFrontListOpaque .PushBack(FaceNode); 340 else BackToFrontListTranslucent.PushBack(FaceNode); 347 if(FaceBatches) 348 { 349 if (FaceNode->IsOpaque()) FaceBatches->AppendOpaqueFace(FaceNode); 350 else FaceBatches->AppendTranslucentFace(FaceNode); 351 } 352 else 353 { 354 if (FaceNode->IsOpaque()) BackToFrontListOpaque .PushBack(FaceNode); 355 else BackToFrontListTranslucent.PushBack(FaceNode); 356 } 341 357 } 342 358 343 359 // Sort the "regular" children more in front than the faces - it likely gives a better overall back-to-front order. … … 362 378 } 363 379 } 364 380 381 if(FaceBatches) 382 { 383 FaceBatches->Finish(); 384 FaceBatches->DrawAmbientContrib(ViewerPos); 385 } 365 386 366 387 for (unsigned long Count=BackToFrontListOpaque.Size(); Count>0;) 367 388 { … … 393 414 FrontFacingList.Overwrite(); 394 415 BackFacingList.Overwrite(); 395 416 417 if(FaceBatches) 418 FaceBatches->InitLight(); 419 396 420 for (unsigned long LeafNr=0; LeafNr<Leaves.Size(); LeafNr++) 397 421 { 398 422 const LeafT& L=Leaves[LeafNr]; … … 429 453 // if (FaceNode->TI.Alpha!=255) continue; // Only fully opaque surfaces receive light (even if FLAG_ISWATER is set). 430 454 // if (FaceNode->Material->NoDynLight) continue; // [This is not really needed here, just for symmetry. This is no meta keyword as NoShadows should be.] 431 455 432 FrontFacingList.PushBack(FaceNode); 456 if(FaceBatches) 457 FaceBatches->AppendFrontFace(FaceNode); 458 else 459 FrontFacingList.PushBack(FaceNode); 433 460 } 434 461 else 435 462 { 436 463 // Back-facing face wrt. the light (SHADOW CASTER). 437 464 if (FaceNode->Material->NoShadows) continue; // Faces with materials that have NoShadows set don't cast shadows. 438 465 439 BackFacingList.PushBack(FaceNode); 466 if(FaceBatches) 467 FaceBatches->AppendBackFace(FaceNode); 468 else 469 BackFacingList.PushBack(FaceNode); 440 470 } 441 471 } 442 472 … … 475 505 476 506 if (NextLightNeedsInit) InitForNextLight(); 477 507 508 if(FaceBatches) 509 FaceBatches->DrawStencilShadowVolumes(LightPos, LightRadius); 510 478 511 for (unsigned long Count=0; Count<BackFacingList.Size(); Count++) 479 512 BackFacingList[Count]->DrawStencilShadowVolumes(LightPos, LightRadius); 480 513 } … … 487 520 488 521 if (NextLightNeedsInit) InitForNextLight(); 489 522 523 if(FaceBatches) 524 FaceBatches->DrawLightSourceContrib(ViewerPos, LightPos); 525 490 526 for (unsigned long Count=0; Count<FrontFacingList.Size(); Count++) 491 527 FrontFacingList[Count]->DrawLightSourceContrib(ViewerPos, LightPos); 492 528 … … 499 535 assert(MatSys::Renderer!=NULL); 500 536 assert(MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::AMBIENT); 501 537 538 if(FaceBatches) 539 FaceBatches->DrawTranslucentContrib(ViewerPos); 540 502 541 // Render translucent nodes back-to-front. 503 542 for (unsigned long Count=0; Count<BackToFrontListTranslucent.Size(); Count++) 504 543 BackToFrontListTranslucent[Count]->DrawTranslucentContrib(ViewerPos); … … 589 628 VB_Trace3T<double> OtherChildrenTrace(1.0); 590 629 591 630 for (unsigned long SetNr=0; SetNr<Leaf.OtherChildrenSet.Size(); SetNr++) 631 632 592 633 { 593 634 const unsigned long ChildNr=Leaf.OtherChildrenSet[SetNr]; 594 635 -
Libs/SceneGraph/TerrainNode.cpp
212 212 static MatSys::MeshT TerrainMesh(MatSys::MeshT::TriangleStrip); 213 213 TerrainMesh.Vertices.Overwrite(); 214 214 TerrainMesh.Vertices.PushBackEmpty(VectorStrip.Size()); 215 TerrainMesh.Invalidate(); 215 216 216 217 for (unsigned long VNr=0; VNr<VectorStrip.Size(); VNr++) 217 218 TerrainMesh.Vertices[VNr].SetOrigin(VectorStrip[VNr]); -
Libs/SceneGraph/BezierPatchNode.hpp
25 25 #define _CF_SCENEGRAPH_BEZIERPATCHNODE_HPP_ 26 26 27 27 #include "Node.hpp" 28 #include "MaterialSystem/Mesh.hpp" 28 29 29 30 30 class MapBezierPatchT; 31 31 32 32 namespace MatSys 33 33 { 34 class MeshT;35 34 class RenderMaterialT; 36 35 } 37 36 … … 52 51 53 52 54 53 public: 54 typedef MatSys::StaticVertexColorT VertexT; 55 55 56 56 /// The constructor for creating an "empty" bezier patch. 57 57 /// Needed e.g. by the named constructor CreateFromFile_cw() below. … … 91 91 92 92 93 93 private: 94 95 94 struct LightMapInfoT 96 95 { 97 96 unsigned short LightMapNr; ///< In welcher LightMap liegt unsere Teil-LightMap? … … 136 135 // Additional information for an entire patch (not only a 3x3 sub-patch). 137 136 LightMapManT& LightMapMan; 138 137 BoundingBox3T<double> BB; ///< The BB of this bezier patch. 139 ArrayT<MatSys::MeshT*> Meshes;138 MatSys::MeshT Mesh; 140 139 MatSys::RenderMaterialT* RenderMaterial; 140 unsigned long MeshWidth; 141 unsigned long MeshHeight; 141 142 }; 142 143 } 143 144 } -
Libs/SceneGraph/BspTreeNode.hpp
40 40 namespace SceneGraph 41 41 { 42 42 class FaceNodeT; 43 class FaceBatchesNodeT; 43 44 44 45 45 46 /// The class represents a BSP Tree node, implementing the Composite design pattern. … … 172 173 mutable ArrayT<cf::SceneGraph::GenericNodeT*> FrontFacingList; 173 174 mutable ArrayT<cf::SceneGraph::GenericNodeT*> BackFacingList; 174 175 mutable bool NextLightNeedsInit; 176 mutable FaceBatchesNodeT* FaceBatches; 175 177 }; 176 178 } 177 179 } -
Libs/GuiSys/GuiImpl.cpp
337 337 static MatSys::MeshT CrossMesh(MatSys::MeshT::Lines); 338 338 CrossMesh.Vertices.Overwrite(); 339 339 CrossMesh.Vertices.PushBackEmpty(4); // Just a single quad for the background rectangle. 340 CrossMesh.Invalidate(); 340 341 341 342 for (unsigned long VertexNr=0; VertexNr<CrossMesh.Vertices.Size(); VertexNr++) 342 343 { … … 386 387 // Note that the processing of the mouse event is orthogonal to (independent of) MouseIsShown. 387 388 // That is, we may be active and interactive even if the mouse cursor is *not* shown, 388 389 // as for example with the 3D window of the Cafu engine client, which must receive the 390 389 391 // mouse events even if no mouse cursor is shown! 390 392 391 393 bool MEWasProcessed=false; // If the Lua script handler consumed the event. -
Libs/GuiSys/Window.cpp
356 356 static MatSys::MeshT BackMesh(MatSys::MeshT::Quads); 357 357 BackMesh.Vertices.Overwrite(); 358 358 BackMesh.Vertices.PushBackEmpty(4); // Just a single quad for the background rectangle. 359 BackMesh.Invalidate(); 359 360 360 361 for (unsigned long VertexNr=0; VertexNr<BackMesh.Vertices.Size(); VertexNr++) 361 362 { … … 385 386 static MatSys::MeshT BorderMesh(MatSys::MeshT::Quads); 386 387 BorderMesh.Vertices.Overwrite(); 387 388 BorderMesh.Vertices.PushBackEmpty(4*4); // One rectangle for each side of the background. 389 BorderMesh.Invalidate(); 388 390 389 391 for (unsigned long VertexNr=0; VertexNr<BorderMesh.Vertices.Size(); VertexNr++) 390 392 { -
Libs/Models/Model_cmdl.cpp
994 994 for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 995 995 { 996 996 const MeshT& Mesh=m_Meshes[MeshNr]; 997 m_Draw_Meshes[MeshNr].Invalidate(); 997 998 998 999 for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) 999 1000 { … … 1181 1182 1182 1183 // Note that we have to cull the following polygons wrt. the *VIEWER* (not the light source)! 1183 1184 static MatSys::MeshT MeshSilhouette(MatSys::MeshT::Quads); // The default winding order is "CW". 1185 MeshSilhouette.Invalidate(); 1184 1186 MeshSilhouette.Vertices.Overwrite(); 1185 1187 1186 1188 for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) … … 1215 1217 } 1216 1218 } 1217 1219 1218 MatSys::Renderer->RenderMesh(MeshSilhouette);1220 if(MeshSilhouette.Vertices.Size() > 0) MatSys::Renderer->RenderMesh(MeshSilhouette); 1219 1221 1220 1221 1222 static MatSys::MeshT MeshCaps(MatSys::MeshT::Triangles); // The default winding order is "CW". 1223 MeshCaps.Invalidate(); 1222 1224 MeshCaps.Vertices.Overwrite(); 1223 1225 1224 1226 for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) … … 1251 1253 MeshCaps.Vertices[MeshSize-1].SetOrigin(LA, 0.0); 1252 1254 } 1253 1255 1254 MatSys::Renderer->RenderMesh(MeshCaps);1256 if(MeshCaps.Vertices.Size() > 0) MatSys::Renderer->RenderMesh(MeshCaps); 1255 1257 } 1256 1258 1257 1259 break; -
Libs/Models/Model_mdl.hpp
54 54 55 55 56 56 private: 57 typedef MatSys::StaticVertexT SoftSkinVertexT; 58 typedef MatSys::StaticVertexT HardSkinVertexT; 57 59 58 60 struct TriangleInfoT 59 61 { … … 70 72 ArrayT<MaterialT*> Materials; ///< The MatSys materials (only needed for the ugly optimization below, in order to see whether the Normal-Map is empty or not). 71 73 ArrayT<MatSys::RenderMaterialT*> RenderMaterials; ///< The MatSys render materials. 72 74 ArrayT< ArrayT<TriangleInfoT> > TriangleInfos; ///< For the first model of each body part, this contains information about each triangle across all meshes of that model. 75 ArrayT< ArrayT<MatSys::MeshT*> > RenderMeshes; ///< Each boypart sub meshes 73 76 ArrayT< ArrayT< ArrayT<int> > > TrianglesReferingToNormal; ///< For each normal of the first model of each body part, this is a list of triangle indices into TriangleInfos of triangles that refer to this normal (with one vertex). 74 77 75 78 // Convenient abbreviations into the above data arrays -
Libs/Models/Model_mdl.cpp
302 302 const int SkinNr =0; 303 303 const short* SkinRefs =((short*)((char*)StudioTextureHeader+StudioTextureHeader->SkinIndex)) + (SkinNr<StudioTextureHeader->NumSkinFamilies ? SkinNr*StudioTextureHeader->NumSkinRef : 0); 304 304 305 RenderMeshes.PushBack(ArrayT<MatSys::MeshT*> ()); 306 305 307 for (int MeshNr=0; MeshNr<CurrentModel.NumMesh; MeshNr++) 306 308 { 307 309 const StudioMeshT& CurrentMesh =StudioMeshes[MeshNr]; 308 310 const signed short* TriangleStrips=(signed short*)(&ModelData[0]+CurrentMesh.TriIndex); 309 311 unsigned long NrOfMeshVertices = 0; 312 unsigned long NrOfIndices = 0; 310 313 while (*TriangleStrips) 311 314 { 312 315 // Anzahl und Art (FAN vs. STRIP) der Vertices im nächsten TriangleStrip. … … 359 362 } 360 363 361 364 TriangleStrips+=4*NrOfVertices; 365 NrOfMeshVertices += NrOfVertices; 366 NrOfIndices += 3*(NrOfVertices-2); 362 367 } 368 369 // Compute triangle indices information. 370 // Create the render mesh. 371 MatSys::MeshT *RenderMesh = new MatSys::MeshT(MatSys::MeshT::Triangles); 372 373 // Create the vertex buffer. 374 RenderMesh->VertexBuffer = MatSys::CreateVertexBuffer<SoftSkinVertexT> (MatSys::VertexBufferI::Dynamic); 375 RenderMesh->VertexBuffer->SetSize(NrOfMeshVertices); 376 377 // Create the index buffer. 378 RenderMesh->PrimitiveBuffer = MatSys::CreatePrimitiveBuffer (MatSys::PrimitiveBufferI::UnsignedShort, MatSys::PrimitiveBufferI::Static); 379 RenderMesh->PrimitiveBuffer->SetSize(NrOfIndices); 380 381 // Fill the index buffer. 382 unsigned short *Indices = (unsigned short*)RenderMesh->PrimitiveBuffer->LockWrite(); 383 TriangleStrips=(signed short*)(&ModelData[0]+CurrentMesh.TriIndex); 384 unsigned long VPos = 0; 385 unsigned long IPos = 0; 386 while (*TriangleStrips) 387 { 388 signed short NrOfVertices=*(TriangleStrips++); 389 bool IsTriangleFan =false; 390 391 if (NrOfVertices<0) 392 { 393 // Triangle fan. 394 NrOfVertices = -NrOfVertices; // Use a positive sign. 395 IsTriangleFan = true; 396 } 397 398 // Triangle strip. 399 for(unsigned long StripPos = 0; StripPos < (unsigned long)NrOfVertices-2; StripPos++) 400 { 401 if(IsTriangleFan) 402 { 403 Indices[IPos + StripPos*3+0] = VPos; 404 Indices[IPos + StripPos*3+1] = VPos + StripPos+1; 405 Indices[IPos + StripPos*3+2] = VPos + StripPos+2; 406 } 407 else 408 { 409 if(StripPos & 1) 410 { 411 // Odd position 412 Indices[IPos + StripPos*3+0] = VPos + StripPos+1; 413 Indices[IPos + StripPos*3+1] = VPos + StripPos; 414 Indices[IPos + StripPos*3+2] = VPos + StripPos+2; 415 } 416 else 417 { 418 // Even Position 419 Indices[IPos + StripPos*3+0] = VPos + StripPos; 420 Indices[IPos + StripPos*3+1] = VPos + StripPos+1; 421 Indices[IPos + StripPos*3+2] = VPos + StripPos+2; 422 } 423 } 424 } 425 426 // Increase the dest positions 427 VPos += NrOfVertices; 428 IPos += 3*(NrOfVertices-2); 429 TriangleStrips+=4*NrOfVertices; 430 } 431 432 // Unlock the index buffer and store th render mesh. 433 RenderMesh->PrimitiveBuffer->Unlock(); 434 RenderMeshes[BodyPartNr].PushBack(RenderMesh); 363 435 } 364 436 365 437 // Compute additional triangle information (neighbours). … … 1070 1142 else 1071 1143 { 1072 1144 // Should never occur... 1145 1146 1073 1147 TriangleTangents[TriangleNr][0]=1.0; 1074 1148 TriangleTangents[TriangleNr][1]=0.0; 1075 1149 TriangleTangents[TriangleNr][2]=0.0; … … 1157 1231 static MatSys::MeshT MeshSilhouette(MatSys::MeshT::Quads); 1158 1232 1159 1233 MeshSilhouette.Vertices.Overwrite(); 1234 MeshSilhouette.Invalidate(); 1160 1235 1161 1236 for (unsigned long TriNr=0; TriNr<TriangleInfos[BodyPartNr].Size(); TriNr++) 1162 1237 { … … 1196 1271 static MatSys::MeshT MeshCaps(MatSys::MeshT::Triangles); 1197 1272 1198 1273 MeshCaps.Vertices.Overwrite(); 1274 MeshCaps.Invalidate(); 1199 1275 1200 1276 for (unsigned long TriNr=0; TriNr<TriangleInfos[BodyPartNr].Size(); TriNr++) 1201 1277 { … … 1238 1314 1239 1315 MatSys::Renderer->SetCurrentMaterial(RenderMaterials[SkinRefs[CurrentMesh.SkinRef]]); 1240 1316 1241 while (*TriangleStrips) 1317 MatSys::MeshT *Mesh = RenderMeshes[BodyPartNr][MeshNr]; 1318 #if ENABLE_OPT_CACHING 1319 if(IsUpdateRequired_TransformedVertices) 1320 #endif 1242 1321 { 1243 // Anzahl und Art (FAN vs. STRIP) der Vertices im nächsten TriangleStrip. 1244 signed short NrOfVertices=*(TriangleStrips++); 1322 SoftSkinVertexT *Vertices = (SoftSkinVertexT*)Mesh->VertexBuffer->LockWrite(); 1323 unsigned long VPos = 0; 1324 while (*TriangleStrips) 1325 { 1326 // Anzahl und Art (FAN vs. STRIP) der Vertices im nächsten TriangleStrip. 1327 signed short NrOfVertices=*(TriangleStrips++); 1328 if (NrOfVertices<0) NrOfVertices=-NrOfVertices; 1245 1329 1246 static MatSys::MeshT Mesh; 1330 for (unsigned long VertexNr=0; VertexNr<(unsigned long)NrOfVertices; VertexNr++, TriangleStrips+=4) 1331 { 1332 SoftSkinVertexT& V=Vertices[VertexNr + VPos]; 1247 1333 1248 Mesh.Type=NrOfVertices<0 ? MatSys::MeshT::TriangleFan : MatSys::MeshT::TriangleStrip; 1334 // TriangleStrips[0] -- Index ins (Transformed-)Vertices-Array 1335 // TriangleStrips[1] -- Index ins (Transformed-)Normals-Array 1336 // TriangleStrips[2] -- s-Texture-Coord (in Pixel) 1337 // TriangleStrips[3] -- t-Texture-Coord (in Pixel) 1249 1338 1250 if (NrOfVertices<0) NrOfVertices=-NrOfVertices; 1339 V.SetOrigin (TransformedVertices[TriangleStrips[0]][0], TransformedVertices[TriangleStrips[0]][1], TransformedVertices[TriangleStrips[0]][2]); 1340 V.SetTextureCoord(TriangleStrips[2]*s, TriangleStrips[3]*t); 1251 1341 1252 Mesh.Vertices.Overwrite(); 1253 Mesh.Vertices.PushBackEmpty(NrOfVertices); 1342 if (IsNeeded_TransformedNormals ) V.SetNormal (TransformedNormals [TriangleStrips[1]][0], TransformedNormals [TriangleStrips[1]][1], TransformedNormals [TriangleStrips[1]][2]); 1343 if (IsNeeded_TransformedTangents) V.SetTangent (TransformedTangents [TriangleStrips[1]][0], TransformedTangents [TriangleStrips[1]][1], TransformedTangents [TriangleStrips[1]][2]); 1344 if (IsNeeded_TransformedTangents) V.SetBiNormal(TransformedBiNormals[TriangleStrips[1]][0], TransformedBiNormals[TriangleStrips[1]][1], TransformedBiNormals[TriangleStrips[1]][2]); 1345 } 1254 1346 1255 for (unsigned long VertexNr=0; VertexNr<(unsigned long)NrOfVertices; VertexNr++, TriangleStrips+=4) 1256 { 1257 MatSys::MeshT::VertexT& V=Mesh.Vertices[VertexNr]; 1258 1259 // TriangleStrips[0] -- Index ins (Transformed-)Vertices-Array 1260 // TriangleStrips[1] -- Index ins (Transformed-)Normals-Array 1261 // TriangleStrips[2] -- s-Texture-Coord (in Pixel) 1262 // TriangleStrips[3] -- t-Texture-Coord (in Pixel) 1263 1264 V.SetOrigin (TransformedVertices[TriangleStrips[0]][0], TransformedVertices[TriangleStrips[0]][1], TransformedVertices[TriangleStrips[0]][2]); 1265 V.SetTextureCoord(TriangleStrips[2]*s, TriangleStrips[3]*t); 1266 1267 if (IsNeeded_TransformedNormals ) V.SetNormal (TransformedNormals [TriangleStrips[1]][0], TransformedNormals [TriangleStrips[1]][1], TransformedNormals [TriangleStrips[1]][2]); 1268 if (IsNeeded_TransformedTangents) V.SetTangent (TransformedTangents [TriangleStrips[1]][0], TransformedTangents [TriangleStrips[1]][1], TransformedTangents [TriangleStrips[1]][2]); 1269 if (IsNeeded_TransformedTangents) V.SetBiNormal(TransformedBiNormals[TriangleStrips[1]][0], TransformedBiNormals[TriangleStrips[1]][1], TransformedBiNormals[TriangleStrips[1]][2]); 1347 VPos += NrOfVertices; 1270 1348 } 1271 1272 MatSys::Renderer->RenderMesh(Mesh); 1349 Mesh->VertexBuffer->Unlock(); 1273 1350 } 1351 MatSys::Renderer->RenderMesh(*Mesh); 1274 1352 } 1275 1353 } 1276 1354 -
Libs/Templates/Array.hpp
63 63 ArrayT(const ArrayT<T>& OldArray); ///< Copy constructor 64 64 ~ArrayT(); ///< Destructor 65 65 ArrayT<T>& operator = (const ArrayT<T>& OldArray); ///< Assignment operator 66 void Swap(ArrayT<T> &Other); ///< Swaps the arrays data 66 67 68 bool operator==(const ArrayT<T>& Other) const; ///< Equality operator 69 bool operator!=(const ArrayT<T>& Other) const; ///< Inequality operator 70 67 71 unsigned long Size() const; ///< Get size of array 68 72 void Clear(); ///< Clear array (and free allocated memory) 69 73 void Overwrite(); ///< Clear array (but reuse memory) … … 74 78 void PushBackEmptyExact(unsigned long Amount=1); 75 79 void DeleteBack(unsigned long Amount=1); 76 80 81 77 82 // "Convenience" methods. 78 83 void PushBack(const ArrayT<T>& Other); 79 84 void InsertAt(unsigned long Index, const T Element); // TODO: Rename to InsertAtAndKeepOrder() 80 85 void RemoveAt(unsigned long Index); 81 86 void RemoveAtAndKeepOrder(unsigned long Index); 82 void QuickSort(bool (*IsLess)(const T& E1, const T& E2)); 87 template<class Function> 88 void QuickSort(Function IsLess); 83 89 // void QuickSort(unsigned long FirstIndex, unsigned long LastIndex, bool (*IsLess)(const T& E1, const T& E2)); 84 90 int Find(const T& Element) const; 85 91 }; … … 123 129 return *this; 124 130 } 125 131 132 template<class T> inline void ArrayT<T>::Swap(ArrayT<T> &Other) // Swaps arrays data 133 { 134 T* NewElements = Other.Elements; 135 unsigned long NewSize = Other.NrOfElements; 136 unsigned long NewMaxSize = Other.MaxNrOfElements; 126 137 138 Other.Elements = Elements; 139 Other.NrOfElements = NrOfElements; 140 Other.MaxNrOfElements = MaxNrOfElements; 141 142 Elements = NewElements; 143 NrOfElements = NewSize; 144 MaxNrOfElements = NewMaxSize; 145 } 146 147 template<class T> inline bool ArrayT<T>::operator==(const ArrayT<T>& Other) const // Equality operator 148 { 149 // Check if the arrays are of the same size 150 if(NrOfElements != Other.NrOfElements) 151 return false; 152 153 // Check each element 154 for(unsigned long Nr=0; Nr<NrOfElements; Nr++) 155 { 156 if(Elements[Nr] != Other.Elements[Nr]) 157 return false; 158 } 159 160 return true; 161 } 162 163 template<class T> inline bool ArrayT<T>::operator!=(const ArrayT<T>& Other) const // Inequality operator 164 { 165 // Check if the arrays are of the same size 166 if(NrOfElements != Other.NrOfElements) 167 return true; 168 169 // Check each element 170 for(unsigned long Nr=0; Nr<NrOfElements; Nr++) 171 { 172 if(Elements[Nr] != Other.Elements[Nr]) 173 return true; 174 } 175 176 return false; 177 } 178 127 179 template<class T> inline unsigned long ArrayT<T>::Size() const 128 180 { 129 181 return NrOfElements; … … 280 332 } 281 333 282 334 283 template<class T> inline void ArrayT<T>::QuickSort(bool (*IsLess)(const T& E1, const T& E2))335 template<class T> template<class Function> inline void ArrayT<T>::QuickSort(Function IsLess) 284 336 { 285 337 static ArrayT<unsigned long> ToDoRanges; 286 338 -
Libs/MaterialSystem/VertexBufferImpl.hpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /************************/ 25 /*** VertexBufferImpl ***/ 26 /************************/ 27 28 #ifndef _CA_MATSYS_VERTEX_BUFFER_IMPLEMENTATION_HPP_ 29 #define _CA_MATSYS_VERTEX_BUFFER_IMPLEMENTATION_HPP_ 30 31 #include "VertexBuffer.hpp" 32 33 namespace MatSys 34 { 35 class VertexBufferImplT: public VertexBufferI 36 { 37 public: 38 VertexBufferImplT(const VertexDescriptorT &VertexFormat); 39 ~VertexBufferImplT(); 40 41 // Vertex format descriptor 42 virtual const VertexDescriptorT &GetVertexDescriptor() const; 43 44 // Vertex data access 45 virtual const void *LockRead() const; 46 virtual void *LockWrite(); 47 virtual void *LockReadWrite(); 48 virtual void Unlock() const; 49 50 // Number of vertices 51 virtual unsigned long GetBufferSize() const; 52 virtual unsigned long GetSize() const; 53 virtual void SetSize(unsigned long size); 54 virtual UsageTypeT GetUsage() const; 55 56 // Those are used to synchronize the version in the main memory 57 // with the video card 58 virtual bool IsValid() const; 59 virtual void Validated() const; 60 virtual void Invalidate(); 61 62 virtual void *GetRendererData() const; 63 virtual void SetRendererData(void *data) const; 64 65 private: 66 const VertexDescriptorT &Descriptor; 67 unsigned long Size; 68 void *Data; 69 mutable bool IsLocked; 70 mutable bool IsValidBuffer; 71 mutable void *RendererData; 72 }; 73 74 }; 75 76 #endif 77 -
Libs/MaterialSystem/Mesh.hpp
30 30 31 31 #include "Templates/Array.hpp" 32 32 #include "Math3D/Vector3.hpp" 33 #include "VertexBuffer.hpp" 34 #include "PrimitiveBuffer.hpp" 35 #include "VertexFormats.hpp" 33 36 34 35 37 namespace MatSys 36 38 { 37 39 /// This class represents a polygonal mesh. … … 59 61 // 2. Clarify the exact requirements of VBOs for each Renderer, inclusive OpenGL 2.0. 60 62 // 3. Keep the differences/requirements/existance between static and animated meshes in mind. 61 63 // 4. Armed with that knowledge, revise the meshes. 62 class MeshT 64 class MeshT: public VertexBufferI 63 65 { 64 66 public: 65 67 66 enum TypeT { Points, Lines, LineStrip, LineLoop, Triangles, TriangleStrip, TriangleFan, Quads, QuadStrip, Polygon };68 enum TypeT { Points, Lines, LineStrip, LineLoop, Triangles, TriangleStrip, TriangleFan, Quads, QuadStrip, Polygon, Inherit }; 67 69 enum WindingT { CW, CCW }; 68 70 69 struct VertexT71 struct RangeT 70 72 { 71 double Origin[4]; // The position (xyzw) in model space.72 float Color[4]; // The color (rgba).73 RangeT(unsigned int S=0, unsigned int C=0, TypeT T=Inherit) 74 : Start(S), Count(C), Type(T) {} 73 75 74 float TextureCoord[2];75 float LightMapCoord[2];76 float SHLMapCoord[2];76 unsigned int Start, Count; 77 TypeT Type; 78 }; 77 79 78 float Normal[3]; // The normal vector in model space. 79 float Tangent[3]; 80 float BiNormal[3]; 80 typedef GenericVertexT VertexT; 81 81 82 float UserAttribF[4]; 83 int UserAttribI[4]; 82 TypeT Type; 83 WindingT Winding; ///< The orientation (cw or ccw) of front faces. 84 ArrayT<VertexT> Vertices; 85 ArrayT<RangeT> SubRanges; 86 UsageTypeT UsageType; 87 VertexBufferI *VertexBuffer; 88 PrimitiveBufferI *PrimitiveBuffer; 84 89 90 /// Constructor. 91 MeshT(TypeT T=Points, WindingT W=CW, UsageTypeT UT= Dynamic) : Type(T), Winding(W), 92 UsageType(UT), VertexBuffer(this), PrimitiveBuffer(NULL), 93 Mutex(false), IsValidMesh(false), RendererData(NULL) 94 { 95 } 96 ~MeshT(); 85 97 86 // Methods for conveniently setting the components. 87 void SetOrigin(double x=0.0, double y=0.0, double z=0.0, double w=1.0) { Origin[0]=x; Origin[1]=y; Origin[2]=z; Origin[3]=w; } 88 void SetOrigin(const Vector3fT& Pos, float w=1.0) { Origin[0]=Pos.x; Origin[1]=Pos.y; Origin[2]=Pos.z; Origin[3]=w; } 89 void SetColor(float r, float g, float b, float a=1.0) { Color[0]=r; Color[1]=g; Color[2]=b; Color[3]=a; } 90 void SetTextureCoord(float s, float t) { TextureCoord[0]=s; TextureCoord[1]=t; } 91 void SetLightMapCoord(float s, float t) { LightMapCoord[0]=s; LightMapCoord[1]=t; } 92 void SetSHLMapCoord(float s, float t) { SHLMapCoord[0]=s; SHLMapCoord[1]=t; } 93 void SetNormal(float x, float y, float z) { Normal[0]=x; Normal[1]=y; Normal[2]=z; } 94 void SetNormal(const Vector3T<float>& N) { Normal[0]=N.x; Normal[1]=N.y; Normal[2]=N.z; } 95 void SetTangent(float x, float y, float z) { Tangent[0]=x; Tangent[1]=y; Tangent[2]=z; } 96 void SetTangent(const Vector3T<float>& T) { Tangent[0]=T.x; Tangent[1]=T.y; Tangent[2]=T.z; } 97 void SetBiNormal(float x, float y, float z) { BiNormal[0]=x; BiNormal[1]=y; BiNormal[2]=z; } 98 void SetBiNormal(const Vector3T<float>& B) { BiNormal[0]=B.x; BiNormal[1]=B.y; BiNormal[2]=B.z; } 98 // Vertex format descriptor 99 const VertexDescriptorT &GetVertexDescriptor() const; 100 101 // Vertex data access 102 const void *LockRead() const; 103 void *LockWrite(); 104 void *LockReadWrite(); 105 void Unlock() const; 106 107 // Number of vertices 108 unsigned long GetBufferSize() const; 109 unsigned long GetSize() const; 110 void SetSize(unsigned long size); 111 UsageTypeT GetUsage() const; 112 113 // Those are used to synchronize the version in the main memory 114 // with the video card 115 bool IsValid() const; 116 void Validated() const; 117 void Invalidate(); 118 119 void *GetRendererData() const; 120 void SetRendererData(void *data) const; 121 122 123 private: 124 mutable bool Mutex; // Is the mesh locked? 125 mutable bool IsValidMesh; // Is the mesh valid 126 mutable void *RendererData; 127 }; 128 129 #if 0 130 // This is the new mesh proposal. Vertex formats are described using a VertexDescriptorT 131 // structure associated with each vertex buffer. 132 // This approach can be directly mapped into OpenGL VBOs(or vertex arrays) but not sure about Direct3D. 133 // I decided to use this approach because Cafu could be gradually adapted using the temporal MeshT structure above 134 // which retains backward compatibility with the old approach, except in the dynamic meshes where it's required 135 // to call the Invalidate() method. 136 class MeshT 137 { 138 public: 139 140 enum TypeT { Points, Lines, LineStrip, LineLoop, Triangles, TriangleStrip, TriangleFan, Quads, QuadStrip, Polygon, Inherit }; 141 enum WindingT { CW, CCW }; 142 143 struct RangeT 144 { 145 RangeT(unsigned int S=0, unsigned int C=0) 146 : Start(S), Count(C) {} 147 148 unsigned int Start, Count; 99 149 }; 100 150 151 101 152 TypeT Type; 102 153 WindingT Winding; ///< The orientation (cw or ccw) of front faces. 103 ArrayT<VertexT> Vertices; 154 ArrayT<RangeT> SubRanges; 155 VertexBufferI *VertexBuffer; 156 PrimitiveBufferI *PrimitiveBuffer; 104 157 105 106 158 /// Constructor. 107 MeshT(TypeT T=Points, WindingT W=CW) : Type(T), Winding(W) 159 MeshT(TypeT T=Points, WindingT W=CW, UsageTypeT UT= Dynamic) : Type(T), Winding(W), 160 UsageType(UT), VertexBuffer(NULL), PrimitiveBuffer(NULL), RendererData(NULL) 108 161 { 109 162 } 163 ~MeshT(); 164 165 void *GetRendererData() const 166 { 167 return RendererData; 168 } 169 170 void SetRendererData(void *data) const 171 { 172 RendererData = data; 173 } 174 175 private: 176 mutable void *RendererData; 110 177 }; 178 #endif 111 179 } 112 180 113 181 #endif -
Libs/MaterialSystem/PrimitiveBuffer.hpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 #ifndef _CA_MATSYS_PRIMITIVE_BUFFER_HPP_ 25 #define _CA_MATSYS_PRIMITIVE_BUFFER_HPP_ 26 27 namespace MatSys 28 { 29 class PrimitiveBufferI 30 { 31 public: 32 enum UsageTypeT { Static, Dynamic, Stream, Temporal }; 33 enum IndexTypeT {UnsignedByte, UnsignedShort, UnsignedInt}; 34 virtual ~PrimitiveBufferI() {} 35 36 // Primitives buffer access 37 virtual const void *LockRead() const = 0; 38 virtual void *LockWrite() = 0; 39 virtual void *LockReadWrite() = 0; 40 virtual void Unlock() const = 0; 41 42 // Buffer description 43 virtual unsigned long GetBufferSize() const = 0; 44 virtual unsigned long GetSize() const = 0; 45 virtual void SetSize(unsigned long size) = 0; 46 47 virtual IndexTypeT GetIndexType() const = 0; 48 virtual UsageTypeT GetUsage() const = 0; 49 50 51 // Those are used to synchronize the version in the main memory 52 // with the video card 53 virtual bool IsValid() const = 0; 54 virtual void Validated() const = 0; 55 virtual void Invalidate() = 0; 56 57 virtual void *GetRendererData() const = 0; 58 virtual void SetRendererData(void *data) const = 0; 59 }; 60 61 extern PrimitiveBufferI *CreatePrimitiveBuffer(PrimitiveBufferI::IndexTypeT IndexType, 62 PrimitiveBufferI::UsageTypeT Usage); 63 64 } // namespace MatSys 65 66 #endif //_CA_MATSYS_PRIMITIVE_BUFFER_HPP_ 67 -
Libs/MaterialSystem/Common/OpenGLEx.cpp
48 48 bool cf::GL_EXT_stencil_wrap_AVAIL =false; 49 49 bool cf::GL_EXT_stencil_two_side_AVAIL =false; 50 50 bool cf::GL_ARB_vertex_and_fragment_program_AVAIL=false; 51 bool cf::GL_ARB_vertex_buffer_object_AVAIL = false; 51 52 52 53 53 static bool IsExtensionAvailable(const char* ExtensionName) 54 54 { 55 55 // Dies ist im wesentlichen der Code aus dem "OpenGL Programming Guide", Seite 568. … … 469 469 470 470 cf::GL_ARB_vertex_and_fragment_program_AVAIL=true; 471 471 } 472 473 PFNGLBINDBUFFERARBPROC cf::glBindBufferARB = NULL; // Extension ARB_vertex_buffer_object 474 PFNGLDELETEBUFFERSARBPROC cf::glDeleteBuffersARB = NULL; 475 PFNGLGENBUFFERSARBPROC cf::glGenBuffersARB = NULL; 476 PFNGLISBUFFERARBPROC cf::glIsBufferARB = NULL; 477 PFNGLBUFFERDATAARBPROC cf::glBufferDataARB = NULL; 478 PFNGLBUFFERSUBDATAARBPROC cf::glBufferSubDataARB = NULL; 479 PFNGLGETBUFFERSUBDATAARBPROC cf::glGetBufferSubDataARB = NULL; 480 PFNGLMAPBUFFERARBPROC cf::glMapBufferARB = NULL; 481 PFNGLUNMAPBUFFERARBPROC cf::glUnmapBufferARB = NULL; 482 PFNGLGETBUFFERPARAMETERIVARBPROC cf::glGetBufferParameterivARB = NULL; 483 PFNGLGETBUFFERPOINTERVARBPROC cf::glGetBufferPointervARB = NULL; 484 485 void cf::Init_GL_ARB_vertex_buffer_object() 486 { 487 cf::GL_ARB_vertex_buffer_object_AVAIL=false; 488 489 if (!IsExtensionAvailable("GL_ARB_vertex_buffer_object" )) return; 490 491 cf::glBindBufferARB = (PFNGLBINDBUFFERARBPROC ) GetProcAddress((StringPtr)"glBindBufferARB"); if (!cf::glBindBufferARB ) return; 492 cf::glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC ) GetProcAddress((StringPtr)"glDeleteBuffersARB"); if (!cf::glDeleteBuffersARB ) return; 493 cf::glGenBuffersARB = (PFNGLGENBUFFERSARBPROC ) GetProcAddress((StringPtr)"glGenBuffersARB"); if (!cf::glGenBuffersARB ) return; 494 cf::glIsBufferARB = (PFNGLISBUFFERARBPROC ) GetProcAddress((StringPtr)"glIsBufferARB"); if (!cf::glIsBufferARB ) return; 495 cf::glBufferDataARB = (PFNGLBUFFERDATAARBPROC ) GetProcAddress((StringPtr)"glBufferDataARB"); if (!cf::glBufferDataARB ) return; 496 cf::glBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC ) GetProcAddress((StringPtr)"glBufferSubDataARB"); if (!cf::glBufferSubDataARB ) return; 497 cf::glGetBufferSubDataARB = (PFNGLGETBUFFERSUBDATAARBPROC ) GetProcAddress((StringPtr)"glGetBufferSubDataARB"); if (!cf::glGetBufferSubDataARB ) return; 498 cf::glMapBufferARB = (PFNGLMAPBUFFERARBPROC ) GetProcAddress((StringPtr)"glMapBufferARB"); if (!cf::glMapBufferARB ) return; 499 cf::glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC ) GetProcAddress((StringPtr)"glUnmapBufferARB"); if (!cf::glUnmapBufferARB ) return; 500 cf::glGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC) GetProcAddress((StringPtr)"glGetBufferParameterivARB"); if (!cf::glGetBufferParameterivARB) return; 501 cf::glGetBufferPointervARB = (PFNGLGETBUFFERPOINTERVARBPROC ) GetProcAddress((StringPtr)"glGetBufferPointervARB"); if (!cf::glGetBufferPointervARB ) return; 502 503 cf::GL_ARB_vertex_buffer_object_AVAIL=true; 504 } 505 -
Libs/MaterialSystem/Common/OpenGLState.cpp
501 501 { 502 502 glTexEnvfv(target, pname, param); 503 503 } 504 505 void OpenGLStateT::BindBuffer(GLenum target, GLuint vbo) 506 { 507 static GLuint ArrayBuffer = 0; 508 static GLuint ElementArrayBuffer = 0; 509 510 if(target == GL_ARRAY_BUFFER_ARB /*&& vbo != ArrayBuffer*/) 511 { 512 ArrayBuffer = vbo; 513 cf::glBindBufferARB(target, vbo); 514 } 515 else if(target == GL_ELEMENT_ARRAY_BUFFER_ARB /*&& vbo != ElementArrayBuffer*/) 516 { 517 ElementArrayBuffer = vbo; 518 cf::glBindBufferARB(target, vbo); 519 } 520 } 521 522 void OpenGLStateT::ClientActiveTexture(GLenum Unit) 523 { 524 static GLenum CurrentUnit = GL_TEXTURE0_ARB; 525 if(Unit != CurrentUnit) 526 { 527 CurrentUnit = Unit; 528 glClientActiveTexture(Unit); 529 } 530 } 531 -
Libs/MaterialSystem/Common/OpenGLEx.hpp
57 57 extern bool GL_EXT_stencil_wrap_AVAIL; 58 58 extern bool GL_EXT_stencil_two_side_AVAIL; 59 59 extern bool GL_ARB_vertex_and_fragment_program_AVAIL; 60 extern bool GL_ARB_vertex_buffer_object_AVAIL; 60 61 61 62 // Initialize extensions. 62 63 void Init_GL_ARB_multitexture(); … … 66 67 void Init_GL_EXT_stencil_wrap(); 67 68 void Init_GL_EXT_stencil_two_side(); 68 69 void Init_GL_ARB_vertex_and_fragment_program(); 70 void Init_GL_ARB_vertex_buffer_object(); 69 71 70 71 72 // Pointers to extension functions. 72 73 extern PFNGLMULTITEXCOORD2DARBPROC glMultiTexCoord2dARB; // Extension "GL_ARB_multitexture". 73 74 extern PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB; … … 209 210 extern PFNGLGETVERTEXATTRIBIVARBPROC glGetVertexAttribivARB; 210 211 extern PFNGLGETVERTEXATTRIBPOINTERVARBPROC glGetVertexAttribPointervARB; 211 212 extern PFNGLISPROGRAMARBPROC glIsProgramARB; 213 214 extern PFNGLBINDBUFFERARBPROC glBindBufferARB; // ARB_vertex_buffer_object 215 extern PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB; 216 extern PFNGLGENBUFFERSARBPROC glGenBuffersARB; 217 extern PFNGLISBUFFERARBPROC glIsBufferARB; 218 extern PFNGLBUFFERDATAARBPROC glBufferDataARB; 219 extern PFNGLBUFFERSUBDATAARBPROC glBufferSubDataARB; 220 extern PFNGLGETBUFFERSUBDATAARBPROC glGetBufferSubDataARB; 221 extern PFNGLMAPBUFFERARBPROC glMapBufferARB; 222 extern PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB; 223 extern PFNGLGETBUFFERPARAMETERIVARBPROC glGetBufferParameterivARB; 224 extern PFNGLGETBUFFERPOINTERVARBPROC glGetBufferPointervARB; 225 212 226 } 213 227 214 228 #endif -
Libs/MaterialSystem/Common/OpenGLState.hpp
83 83 // void TexParameter*(); 84 84 85 85 86 // Functions that apply only the current vertex buffer object. 87 void BindBuffer(GLenum target, GLuint vbo); 88 89 // Client side functions 90 void ClientActiveTexture(GLenum Unit); 91 86 92 static const GLenum MeshToOpenGLType[]; ///< Translates from MeshT primitive types to OpenGL rendering primitives. 87 93 static const GLenum WindingToOpenGL[]; ///< Translates from MeshT windings to OpenGL windings (cw or ccw). 88 94 static const GLenum BlendFactorToOpenGL[]; ///< Translates from MaterialT blend factors to OpenGL blend factors. -
Libs/MaterialSystem/VertexBuffer.hpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /********************/ 25 /*** VertexBuffer ***/ 26 /********************/ 27 28 #ifndef _CA_MATSYS_VERTEX_BUFFER_HPP_ 29 #define _CA_MATSYS_VERTEX_BUFFER_HPP_ 30 31 #include "Math3D/Vector3.hpp" 32 33 namespace MatSys 34 { 35 // Data type of a memory offset to get the location into a vertex member 36 typedef long VertexOffset; 37 38 // Macro to facilitate vertex attribute memory offset 39 #define VertexElementOffset(s, elm) ((VertexOffset)&((s*)NULL)->elm) 40 41 // This class represents a vertex format description 42 struct VertexDescriptorT 43 { 44 VertexDescriptorT(unsigned int size=0, VertexOffset origin = -1, VertexOffset origin4 = -1, 45 VertexOffset color = -1, VertexOffset textureCoord = -1, VertexOffset lightMapCoord = -1, 46 VertexOffset shlMapCoord = -1, VertexOffset normal = -1, VertexOffset tangent = -1, 47 VertexOffset binormal = -1, VertexOffset userAttribF = -1, VertexOffset userAttribI = -1) 48 : VertexSize(size), Origin(origin), Origin4(origin4), Color(color), 49 TextureCoord(textureCoord), LightMapCoord(lightMapCoord), SHLMapCoord(shlMapCoord), 50 Normal(normal), Tangent(tangent), BiNormal(binormal), UserAttribF(userAttribF), 51 UserAttribI(userAttribI) 52 { 53 } 54 55 unsigned int VertexSize; // Vertex size in bytes 56 57 // Vertex elements offsets. -1 means no presence 58 VertexOffset Origin; // float[3] 59 VertexOffset Origin4; // float[4] 60 VertexOffset Color; // float[4] 61 VertexOffset TextureCoord; // float[2] 62 VertexOffset LightMapCoord; // float[2] 63 VertexOffset SHLMapCoord; // float[2] 64 65 VertexOffset Normal; // float[3] 66 VertexOffset Tangent; // float[3] 67 VertexOffset BiNormal; // float[3] 68 69 VertexOffset UserAttribF; // float[4] 70 VertexOffset UserAttribI; // int[4] 71 }; 72 73 // This class represents a vertex buffer 74 class VertexBufferI 75 { 76 public: 77 enum UsageTypeT { Static, Dynamic, Stream, Temporal }; 78 79 virtual ~VertexBufferI() {} 80 81 // Vertex format descriptor 82 virtual const VertexDescriptorT &GetVertexDescriptor() const = 0; 83 84 // Vertex data access 85 virtual const void *LockRead() const = 0; 86 virtual void *LockWrite() = 0; 87 virtual void *LockReadWrite() = 0; 88 virtual void Unlock() const = 0; 89 90 // Number of vertices 91 virtual unsigned long GetBufferSize() const = 0; 92 virtual unsigned long GetSize() const = 0; 93 virtual void SetSize(unsigned long size) = 0; 94 virtual UsageTypeT GetUsage() const = 0; 95 96 // Those are used to synchronize the version in the main memory 97 // with the video card 98 virtual bool IsValid() const = 0; 99 virtual void Validated() const = 0; 100 virtual void Invalidate() = 0; 101 102 virtual void *GetRendererData() const = 0; 103 virtual void SetRendererData(void *data) const = 0; 104 }; 105 106 extern VertexBufferI *CreateVertexBuffer(const VertexDescriptorT &VertexFormat, 107 VertexBufferI::UsageTypeT Usage); 108 109 template<typename T> inline VertexBufferI *CreateVertexBuffer(VertexBufferI::UsageTypeT Usage) 110 { 111 return CreateVertexBuffer(T::VertexDescriptor, Usage); 112 } 113 }; 114 115 #endif 116 -
Libs/MaterialSystem/RendererNull/RendererImpl.cpp
475 475 } 476 476 477 477 478 void RendererImplT::OnDestroyMesh(MatSys::MeshT *Mesh) 479 { 480 } 481 482 void RendererImplT::OnDestroyVertexBuffer(MatSys::VertexBufferI *Buffer) 483 { 484 } 485 486 void RendererImplT::OnDestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer) 487 { 488 } 489 490 VertexBufferI *RendererImplT::CreateVertexBuffer(const VertexDescriptorT &Format, unsigned int Usage) 491 { 492 return NULL; 493 } 494 495 PrimitiveBufferI *RendererImplT::CreatePrimitiveBuffer(PrimitiveBufferI::IndexTypeT IndexType, PrimitiveBufferI::UsageTypeT Usage) 496 { 497 return NULL; 498 } 499 478 500 RenderMaterialT* RendererImplT::GetCurrentRenderMaterial() const 479 501 { 480 502 return NULL; -
Libs/MaterialSystem/RendererNull/RendererImpl.hpp
123 123 void SetCurrentSHLMaps(const ArrayT<MatSys::TextureMapI*>& SHLMaps); 124 124 void SetCurrentSHLLookupMap(MatSys::TextureMapI* SHLLookupMap); 125 125 void RenderMesh(const MatSys::MeshT& Mesh); 126 void OnDestroyMesh(MatSys::MeshT *Mesh); 127 void OnDestroyVertexBuffer(MatSys::VertexBufferI *Buffer); 128 void OnDestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer); 129 MatSys::VertexBufferI *CreateVertexBuffer(const MatSys::VertexDescriptorT &Format, unsigned int Usage); 130 MatSys::PrimitiveBufferI *CreatePrimitiveBuffer(MatSys::PrimitiveBufferI::IndexTypeT IndexType, 131 MatSys::PrimitiveBufferI::UsageTypeT Usage); 126 132 127 128 133 // Internal interface. 129 134 MatSys::RenderMaterialT* GetCurrentRenderMaterial() const; 130 135 -
Libs/MaterialSystem/VertexFormats.cpp
1 #include "VertexFormats.hpp" 2 3 namespace MatSys 4 { 5 // GenericVertexT descriptor. 6 VertexDescriptorT GenericVertexT::VertexDescriptor ( 7 /*VertexSize*/ sizeof(GenericVertexT), 8 /*Origin*/ VertexElementOffset(GenericVertexT, Origin[0]), 9 /*Origin4*/ VertexElementOffset(GenericVertexT, Origin[0]), 10 /*Color*/ VertexElementOffset(GenericVertexT, Color[0]), 11 /*TextureCoord*/ VertexElementOffset(GenericVertexT, TextureCoord[0]), 12 /*LightMapCoord*/ VertexElementOffset(GenericVertexT, LightMapCoord[0]), 13 /*SHLMapCoord*/ VertexElementOffset(GenericVertexT, SHLMapCoord[0]), 14 15 /*Normal*/ VertexElementOffset(GenericVertexT, Normal[0]), 16 /*Tangent*/ VertexElementOffset(GenericVertexT, Tangent[0]), 17 /*BiNormal*/ VertexElementOffset(GenericVertexT, BiNormal[0]), 18 19 /*UserAttribF*/ VertexElementOffset(GenericVertexT, UserAttribF[0]), 20 /*UserAttribI*/ VertexElementOffset(GenericVertexT, UserAttribI[0]) 21 ); 22 23 // StaticVertexT descriptor. 24 VertexDescriptorT StaticVertexT::VertexDescriptor ( 25 /*VertexSize*/ sizeof(StaticVertexT), 26 /*Origin*/ VertexElementOffset(StaticVertexT, Origin[0]), 27 /*Origin4*/ -1, 28 /*Color*/ -1, 29 /*TextureCoord*/ VertexElementOffset(StaticVertexT, TextureCoord[0]), 30 /*LightMapCoord*/ VertexElementOffset(StaticVertexT, LightMapCoord[0]), 31 #ifdef SHL_ENABLED 32 /*SHLMapCoord*/ VertexElementOffset(StaticVertexT, SHLMapCoord[0]), 33 #else 34 /*SHLMapCoord*/ -1, 35 #endif 36 /*Normal*/ VertexElementOffset(StaticVertexT, Normal[0]), 37 /*Tangent*/ VertexElementOffset(StaticVertexT, Tangent[0]), 38 /*BiNormal*/ VertexElementOffset(StaticVertexT, BiNormal[0]), 39 40 /*UserAttribF*/ -1, 41 /*UserAttribI*/ -1 42 ); 43 44 // StaticVertexColorT descriptor. 45 VertexDescriptorT StaticVertexColorT::VertexDescriptor ( 46 /*VertexSize*/ sizeof(StaticVertexColorT), 47 /*Origin*/ VertexElementOffset(StaticVertexColorT, Origin[0]), 48 /*Origin4*/ -1, 49 /*Color*/ VertexElementOffset(StaticVertexColorT, Color[0]), 50 /*TextureCoord*/ VertexElementOffset(StaticVertexColorT, TextureCoord[0]), 51 /*LightMapCoord*/ VertexElementOffset(StaticVertexColorT, LightMapCoord[0]), 52 #ifdef SHL_ENABLED 53 /*SHLMapCoord*/ VertexElementOffset(StaticVertexColorT, SHLMapCoord[0]), 54 #else 55 /*SHLMapCoord*/ -1, 56 #endif 57 /*Normal*/ VertexElementOffset(StaticVertexColorT, Normal[0]), 58 /*Tangent*/ VertexElementOffset(StaticVertexColorT, Tangent[0]), 59 /*BiNormal*/ VertexElementOffset(StaticVertexColorT, BiNormal[0]), 60 61 /*UserAttribF*/ -1, 62 /*UserAttribI*/ -1 63 ); 64 65 // StencilShadowCpuT descriptor. 66 VertexDescriptorT StencilShadowCpuT::VertexDescriptor ( 67 /*VertexSize*/ sizeof(StencilShadowCpuT), 68 /*Origin*/ VertexElementOffset(StencilShadowCpuT, Origin[0]), 69 /*Origin4*/ VertexElementOffset(StencilShadowCpuT, Origin[0]), 70 /*Color*/ -1, 71 /*TextureCoord*/ -1, 72 /*LightMapCoord*/ -1, 73 /*SHLMapCoord*/ -1, 74 75 /*Normal*/ -1, 76 /*Tangent*/ -1, 77 /*BiNormal*/ -1, 78 79 /*UserAttribF*/ -1, 80 /*UserAttribI*/ -1 81 ); 82 }; 83 -
Libs/MaterialSystem/Renderer.hpp
28 28 #ifndef _CA_MATSYS_RENDERER_HPP_ 29 29 #define _CA_MATSYS_RENDERER_HPP_ 30 30 31 #include "PrimitiveBuffer.hpp" 31 32 32 33 33 template<class T> class ArrayT; 34 34 class MaterialT; 35 35 class MatrixT; 36 36 37 38 37 namespace MatSys 39 38 { 40 39 class MeshT; 40 class VertexDescriptorT; 41 class VertexBufferI; 41 42 class RenderMaterialT; 42 43 class TextureMapI; 43 44 44 45 45 /// This class provides an interface to a renderer. 46 46 /// The interface is specified as ABC in order to share the renderer across exe/dll boundaries. 47 47 class RendererI … … 265 265 virtual void EndShadowSilhouetteGeom()=0; */ 266 266 267 267 virtual void RenderMesh(const MatSys::MeshT& Mesh)=0; 268 virtual void OnDestroyMesh(MatSys::MeshT *Mesh) = 0; 269 virtual void OnDestroyVertexBuffer(MatSys::VertexBufferI *Buffer) = 0; 270 virtual void OnDestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer) = 0; 271 virtual VertexBufferI *CreateVertexBuffer(const VertexDescriptorT &Format, unsigned int Usage) = 0; 272 virtual PrimitiveBufferI *CreatePrimitiveBuffer(PrimitiveBufferI::IndexTypeT IndexType, 273 PrimitiveBufferI::UsageTypeT Usage) = 0; 268 274 269 275 /// This ABC does neither have nor need a destructor, because no implementation will ever be deleted via a pointer to a RendererI. 270 276 /// (The implementations are singletons after all.) See the Singleton pattern and the C++ FAQ 21.05 (the "precise rule") for more information. … … 277 283 /// Just set this after you loaded the desired renderer DLL to the pointer returned by the DLLs GetRenderer() function. 278 284 /// (And NULL it on unloading the DLL.) 279 285 /// An analogous object exists for the TextureMapManager interface, see TextureMap.hpp. 286 280 287 extern RendererI* Renderer; 281 288 } 282 289 -
Libs/MaterialSystem/VertexFormats.hpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /************/ 25 /*** GenericVertex ***/ 26 /************/ 27 28 #ifndef _CA_MATSYS_VERTEX_FORMATS_HPP_ 29 #define _CA_MATSYS_VERTEX_FORMATS_HPP_ 30 31 #include "Math3D/Vector3.hpp" 32 #include "VertexBuffer.hpp" 33 34 namespace MatSys 35 { 36 37 // Generic vertex layout capable of storing any vertex data. 38 struct GenericVertexT 39 { 40 static VertexDescriptorT VertexDescriptor; 41 42 float Origin[4]; // The position (xyzw) in model space. 43 float Color[4]; // The color (rgba). 44 45 float TextureCoord[2]; 46 float LightMapCoord[2]; 47 float SHLMapCoord[2]; 48 49 float Normal[3]; // The normal vector in model space. 50 float Tangent[3]; 51 float BiNormal[3]; 52 53 float UserAttribF[4]; 54 int UserAttribI[4]; 55 56 57 // Methods for conveniently setting the components. 58 void SetOrigin(float x=0.0, float y=0.0, float z=0.0, float w=1.0) { Origin[0]=x; Origin[1]=y; Origin[2]=z; Origin[3]=w; } 59 void SetOrigin(const Vector3fT& Pos, float w=1.0) { Origin[0]=Pos.x; Origin[1]=Pos.y; Origin[2]=Pos.z; Origin[3]=w; } 60 void SetColor(float r, float g, float b, float a=1.0) { Color[0]=r; Color[1]=g; Color[2]=b; Color[3]=a; } 61 void SetTextureCoord(float s, float t) { TextureCoord[0]=s; TextureCoord[1]=t; } 62 void SetLightMapCoord(float s, float t) { LightMapCoord[0]=s; LightMapCoord[1]=t; } 63 void SetSHLMapCoord(float s, float t) { SHLMapCoord[0]=s; SHLMapCoord[1]=t; } 64 void SetNormal(float x, float y, float z) { Normal[0]=x; Normal[1]=y; Normal[2]=z; } 65 void SetNormal(const Vector3T<float>& N) { Normal[0]=N.x; Normal[1]=N.y; Normal[2]=N.z; } 66 void SetTangent(float x, float y, float z) { Tangent[0]=x; Tangent[1]=y; Tangent[2]=z; } 67 void SetTangent(const Vector3T<float>& T) { Tangent[0]=T.x; Tangent[1]=T.y; Tangent[2]=T.z; } 68 void SetBiNormal(float x, float y, float z) { BiNormal[0]=x; BiNormal[1]=y; BiNormal[2]=z; } 69 void SetBiNormal(const Vector3T<float>& B) { BiNormal[0]=B.x; BiNormal[1]=B.y; BiNormal[2]=B.z; } 70 }; 71 72 // Static vertex face layout. Used by BSP based faces 73 struct StaticVertexT 74 { 75 static VertexDescriptorT VertexDescriptor; 76 77 float Origin[3]; // The position (xyz) in model space. 78 79 float TextureCoord[2]; 80 float LightMapCoord[2]; 81 82 #ifdef SHL_ENABLED 83 float SHLMapCoord[2]; 84 #endif 85 86 float Normal[3]; // The normal vector in model space. 87 float Tangent[3]; 88 float BiNormal[3]; 89 90 // Methods for conveniently setting the components. 91 void SetOrigin(float x=0.0, float y=0.0, float z=0.0) { Origin[0]=x; Origin[1]=y; Origin[2]=z; } 92 void SetOrigin(const Vector3fT& Pos, float w=1.0) { Origin[0]=Pos.x; Origin[1]=Pos.y; Origin[2]=Pos.z; } 93 void SetTextureCoord(float s, float t) { TextureCoord[0]=s; TextureCoord[1]=t; } 94 void SetLightMapCoord(float s, float t) { LightMapCoord[0]=s; LightMapCoord[1]=t; } 95 #ifdef SHL_ENABLED 96 void SetSHLMapCoord(float s, float t) { SHLMapCoord[0]=s; SHLMapCoord[1]=t; } 97 #endif 98 void SetNormal(float x, float y, float z) { Normal[0]=x; Normal[1]=y; Normal[2]=z; } 99 void SetNormal(const Vector3T<float>& N) { Normal[0]=N.x; Normal[1]=N.y; Normal[2]=N.z; } 100 void SetTangent(float x, float y, float z) { Tangent[0]=x; Tangent[1]=y; Tangent[2]=z; } 101 void SetTangent(const Vector3T<float>& T) { Tangent[0]=T.x; Tangent[1]=T.y; Tangent[2]=T.z; } 102 void SetBiNormal(float x, float y, float z) { BiNormal[0]=x; BiNormal[1]=y; BiNormal[2]=z; } 103 void SetBiNormal(const Vector3T<float>& B) { BiNormal[0]=B.x; BiNormal[1]=B.y; BiNormal[2]=B.z; } 104 }; 105 106 // Static vertex with colors. 107 struct StaticVertexColorT 108 { 109 static VertexDescriptorT VertexDescriptor; 110 111 float Origin[3]; // The position (xyz) in model space. 112 float Color[4]; // The color (rgba). 113 114 float TextureCoord[2]; 115 float LightMapCoord[2]; 116 117 #ifdef SHL_ENABLED 118 float SHLMapCoord[2]; 119 #endif 120 121 float Normal[3]; // The normal vector in model space. 122 float Tangent[3]; 123 float BiNormal[3]; 124 125 // Methods for conveniently setting the components. 126 void SetOrigin(float x=0.0, float y=0.0, float z=0.0) { Origin[0]=x; Origin[1]=y; Origin[2]=z; } 127 void SetOrigin(const Vector3fT& Pos, float w=1.0) { Origin[0]=Pos.x; Origin[1]=Pos.y; Origin[2]=Pos.z; } 128 void SetColor(float r, float g, float b, float a=1.0) { Color[0]=r; Color[1]=g; Color[2]=b; Color[3]=a; } 129 void SetTextureCoord(float s, float t) { TextureCoord[0]=s; TextureCoord[1]=t; } 130 void SetLightMapCoord(float s, float t) { LightMapCoord[0]=s; LightMapCoord[1]=t; } 131 #ifdef SHL_ENABLED 132 void SetSHLMapCoord(float s, float t) { SHLMapCoord[0]=s; SHLMapCoord[1]=t; } 133 #endif 134 void SetNormal(float x, float y, float z) { Normal[0]=x; Normal[1]=y; Normal[2]=z; } 135 void SetNormal(const Vector3T<float>& N) { Normal[0]=N.x; Normal[1]=N.y; Normal[2]=N.z; } 136 void SetTangent(float x, float y, float z) { Tangent[0]=x; Tangent[1]=y; Tangent[2]=z; } 137 void SetTangent(const Vector3T<float>& T) { Tangent[0]=T.x; Tangent[1]=T.y; Tangent[2]=T.z; } 138 void SetBiNormal(float x, float y, float z) { BiNormal[0]=x; BiNormal[1]=y; BiNormal[2]=z; } 139 void SetBiNormal(const Vector3T<float>& B) { BiNormal[0]=B.x; BiNormal[1]=B.y; BiNormal[2]=B.z; } 140 }; 141 142 // Stencil shadow(CPU) vertex layout. 143 struct StencilShadowCpuT 144 { 145 static VertexDescriptorT VertexDescriptor; 146 147 float Origin[4]; // The position (xyzw) in model space. 148 149 // Methods for conveniently setting the components. 150 void SetOrigin(float x=0.0, float y=0.0, float z=0.0, float w=1.0) { Origin[0]=x; Origin[1]=y; Origin[2]=z; Origin[3]=w; } 151 void SetOrigin(const Vector3fT& Pos, float w=1.0) { Origin[0]=Pos.x; Origin[1]=Pos.y; Origin[2]=Pos.z; Origin[3]=w; } 152 }; 153 } 154 155 #endif 156 -
Libs/MaterialSystem/PrimitiveBufferImpl.cpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /***************************/ 25 /*** PrimitiveBufferImpl ***/ 26 /***************************/ 27 28 #include <cassert> 29 #include <stdlib.h> 30 #include "PrimitiveBufferImpl.hpp" 31 #include "Renderer.hpp" 32 33 namespace MatSys 34 { 35 unsigned long PrimitiveBufferImplT::IndexTypeToSize[3] = 36 {sizeof(unsigned char), sizeof(unsigned short), sizeof(unsigned int)}; 37 38 PrimitiveBufferImplT::PrimitiveBufferImplT(IndexTypeT IT) 39 : IndexType(IT), IsLocked(false), IsValidBuffer(false), RendererData(NULL), Size(0), Buffer(NULL) 40 { 41 } 42 43 PrimitiveBufferImplT::~PrimitiveBufferImplT() 44 { 45 if(Buffer) 46 delete [] (unsigned char*)Buffer; 47 48 if(Renderer && RendererData) 49 Renderer->OnDestroyPrimitiveBuffer(this); 50 } 51 52 const void *PrimitiveBufferImplT::LockRead() const 53 { 54 assert(!IsLocked); 55 IsLocked = true; 56 return Buffer; 57 } 58 59 void *PrimitiveBufferImplT::LockWrite() 60 { 61 assert(!IsLocked); 62 IsLocked = true; 63 IsValidBuffer = false; 64 return Buffer; 65 } 66 67 void *PrimitiveBufferImplT::LockReadWrite() 68 { 69 assert(!IsLocked); 70 IsLocked = true; 71 IsValidBuffer = false; 72 return Buffer; 73 } 74 75 void PrimitiveBufferImplT::Unlock() const 76 { 77 assert(IsLocked); 78 IsLocked = false; 79 } 80 81 unsigned long PrimitiveBufferImplT::GetBufferSize() const 82 { 83 return Size*IndexTypeToSize[IndexType]; 84 } 85 86 unsigned long PrimitiveBufferImplT::GetSize() const 87 { 88 return Size; 89 } 90 91 void PrimitiveBufferImplT::SetSize(unsigned long S) 92 { 93 Size = S; 94 95 if(Buffer) 96 delete [] (unsigned char*)Buffer; 97 Buffer = new unsigned char[GetBufferSize()]; 98 } 99 100 PrimitiveBufferI::IndexTypeT PrimitiveBufferImplT::GetIndexType() const 101 { 102 return IndexType; 103 } 104 105 PrimitiveBufferI::UsageTypeT PrimitiveBufferImplT::GetUsage() const 106 { 107 return Stream; 108 } 109 110 bool PrimitiveBufferImplT::IsValid() const 111 { 112 return IsValidBuffer; 113 } 114 115 void PrimitiveBufferImplT::Validated() const 116 { 117 IsValidBuffer = true; 118 } 119 120 void PrimitiveBufferImplT::Invalidate() 121 { 122 IsValidBuffer = false; 123 } 124 125 void *PrimitiveBufferImplT::GetRendererData() const 126 { 127 return RendererData; 128 } 129 130 void PrimitiveBufferImplT::SetRendererData(void *Data) const 131 { 132 RendererData = Data; 133 } 134 135 PrimitiveBufferI *CreatePrimitiveBuffer(PrimitiveBufferI::IndexTypeT IndexType, 136 PrimitiveBufferI::UsageTypeT Usage) 137 { 138 if(Renderer && Usage != PrimitiveBufferI::Temporal) 139 { 140 PrimitiveBufferI *Ret = Renderer->CreatePrimitiveBuffer(IndexType, Usage); 141 if(Ret) 142 return Ret; 143 } 144 return new PrimitiveBufferImplT(IndexType); 145 } 146 147 }; 148 -
Libs/MaterialSystem/RendererARBprogs/VertexBufferImpl.hpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /************************/ 25 /*** VertexBufferImpl ***/ 26 /************************/ 27 28 #ifndef _CA_MATSYS_VERTEX_BUFFER_IMPLEMENTATION_HPP_ 29 #define _CA_MATSYS_VERTEX_BUFFER_IMPLEMENTATION_HPP_ 30 31 #include <GL/gl.h> 32 #include "../VertexBuffer.hpp" 33 34 class VertexBufferImplT: public MatSys::VertexBufferI 35 { 36 public: 37 VertexBufferImplT(const MatSys::VertexDescriptorT &VertexFormat, UsageTypeT Usage); 38 ~VertexBufferImplT(); 39 40 // Vertex format descriptor 41 virtual const MatSys::VertexDescriptorT &GetVertexDescriptor() const; 42 43 // Vertex data access 44 virtual const void *LockRead() const; 45 virtual void *LockWrite(); 46 virtual void *LockReadWrite(); 47 virtual void Unlock() const; 48 49 // Number of vertices 50 virtual unsigned long GetBufferSize() const; 51 virtual unsigned long GetSize() const; 52 virtual void SetSize(unsigned long size); 53 virtual UsageTypeT GetUsage() const; 54 55 // Those are used to synchronize the version in the main memory 56 // with the video card 57 virtual bool IsValid() const; 58 virtual void Validated() const; 59 virtual void Invalidate(); 60 61 virtual void *GetRendererData() const; 62 virtual void SetRendererData(void *data) const; 63 64 private: 65 const MatSys::VertexDescriptorT &Descriptor; 66 UsageTypeT Usage; 67 mutable GLuint BufferObject; 68 mutable bool IsLocked; 69 unsigned long Size; 70 }; 71 72 #endif 73 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 233 233 OpenGLState->BindTexture(GL_TEXTURE_2D, RM->UseDefaultLightMap && Renderer.GetCurrentLightMap()!=NULL ? Renderer.GetCurrentLightMap()->GetOpenGLObject() : RM->LightTexMap->GetOpenGLObject()); 234 234 235 235 236 // Draw the mesh 236 237 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 237 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]);238 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++)239 {240 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord);241 cf::glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, Mesh.Vertices[VertexNr].LightMapCoord);242 243 glVertex3dv(Mesh.Vertices[VertexNr].Origin);244 }245 glEnd();238 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 239 Drawer->BeginDrawing(Mesh); 240 { 241 Drawer->SendPositions(); 242 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 243 Drawer->SendLightMapCoords(GL_TEXTURE1_ARB); 244 Drawer->DrawMesh(); 245 } 246 Drawer->EndDrawing(); 246 247 } 247 248 }; 248 249 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Norm.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 234 234 OpenGLState->BindTexture(GL_TEXTURE_2D, RM->NormTexMap->GetOpenGLObject()); 235 235 236 236 237 // Draw the mesh 238 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 237 239 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 238 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 239 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 240 { 241 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 242 243 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 244 } 245 glEnd(); 240 Drawer->BeginDrawing(Mesh); 241 { 242 Drawer->SendPositions(); 243 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 244 Drawer->DrawMesh(); 245 } 246 Drawer->EndDrawing(); 246 247 } 247 248 }; 248 249 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Terrain.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 257 257 cf::glProgramLocalParameter4fARB (GL_VERTEX_PROGRAM_ARB, 2, Material.ShaderParamExpr.Size()>=9 ? Material.ShaderParamExpr[8].Evaluate(Sym).GetAsFloat() : 4.0f, 0.0f, 0.0f, 0.0f); 258 258 259 259 260 // Draw the mesh 261 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 260 262 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 261 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]);262 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++)263 {264 glVertex3dv(Mesh.Vertices[VertexNr].Origin);265 }266 glEnd();263 Drawer->BeginDrawing(Mesh); 264 { 265 Drawer->SendPositions(); 266 Drawer->DrawMesh(); 267 } 268 Drawer->EndDrawing(); 267 269 } 268 270 }; 269 271 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light_Norm_Spec.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 175 175 return false; 176 176 } 177 177 178 179 178 180 void Activate() 179 181 { 180 182 if (InitCounter<RendererImplT::GetInstance().GetInitCounter()) … … 300 302 cf::glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, EyePosCache); 301 303 } 302 304 303 305 // Draw the mesh 304 306 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 305 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 306 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 307 { 308 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 309 cf::glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, Mesh.Vertices[VertexNr].LightMapCoord); 307 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 308 Drawer->BeginDrawing(Mesh); 309 { 310 Drawer->SendPositions(); 311 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 312 Drawer->SendLightMapCoords(GL_TEXTURE1_ARB); 310 313 311 glNormal3fv(Mesh.Vertices[VertexNr].Normal); // Normal 312 cf::glMultiTexCoord3fvARB(GL_TEXTURE6_ARB, Mesh.Vertices[VertexNr].Tangent); // Tangent 313 cf::glMultiTexCoord3fvARB(GL_TEXTURE7_ARB, Mesh.Vertices[VertexNr].BiNormal); // BiNormal 314 315 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 316 } 317 glEnd(); 314 Drawer->SendNormals(); 315 Drawer->SendTangents(GL_TEXTURE6_ARB); 316 Drawer->SendBiNormals(GL_TEXTURE7_ARB); 317 Drawer->DrawMesh(); 318 } 319 Drawer->EndDrawing(); 318 320 } 319 321 }; 320 322 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light_Norm_Luma.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 264 264 OpenGLState->BindTexture(GL_TEXTURE_2D, RM->LumaTexMap->GetOpenGLObject()); 265 265 266 266 267 // Draw the mesh 267 268 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 268 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]);269 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++)270 {271 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord);272 cf::glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, Mesh.Vertices[VertexNr].LightMapCoord);273 274 glVertex3dv(Mesh.Vertices[VertexNr].Origin);275 }276 glEnd();269 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 270 Drawer->BeginDrawing(Mesh); 271 { 272 Drawer->SendPositions(); 273 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 274 Drawer->SendLightMapCoords(GL_TEXTURE1_ARB); 275 Drawer->DrawMesh(); 276 } 277 Drawer->EndDrawing(); 277 278 } 278 279 }; 279 280 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 159 159 160 160 void RenderMesh(const MeshT& Mesh) 161 161 { 162 // Check if the mesh format is acceptable 163 const VertexDescriptorT &Descriptor = Mesh.GetVertexDescriptor(); 164 if(Descriptor.Origin < 0 || Descriptor.TextureCoord < 0) 165 return; 166 162 167 const RendererImplT& Renderer =RendererImplT::GetInstance(); 163 168 RenderMaterialT* RM =Renderer.GetCurrentRenderMaterial(); 164 169 const MaterialT& Material =*(RM->Material); … … 223 228 OpenGLState->Enable(GL_TEXTURE_2D); 224 229 OpenGLState->BindTexture(GL_TEXTURE_2D, RM->DiffTexMap->GetOpenGLObject()); 225 230 226 231 // Draw the mesh 232 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 227 233 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 228 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 229 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 230 { 231 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 232 233 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 234 } 235 glEnd(); 234 Drawer->BeginDrawing(Mesh); 235 { 236 Drawer->SendPositions(); 237 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 238 Drawer->DrawMesh(); 239 } 240 Drawer->EndDrawing(); 236 241 } 237 242 }; 238 243 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Solid.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 64 64 VertexProgram=UploadProgram(GL_VERTEX_PROGRAM_ARB, 65 65 "!!ARBvp1.0 \n" 66 66 "PARAM mvp[4]={ state.matrix.mvp }; \n" 67 "PARAM mcolor=program.local[0]; \n" 67 68 68 69 "DP4 result.position.x, vertex.position, mvp[0]; \n" // result.position = mul(state.matrix.mvp, vertex.position); 69 70 "DP4 result.position.y, vertex.position, mvp[1]; \n" 70 71 "DP4 result.position.z, vertex.position, mvp[2]; \n" 71 72 "DP4 result.position.w, vertex.position, mvp[3]; \n" 72 73 73 "M OV result.color, vertex.color; \n" // result.color = vertex.color;74 "MUL result.color, vertex.color, mcolor; \n" // result.color = vertex.color*mcolor; 74 75 "END \n"); 75 76 76 77 … … 220 221 OpenGLState->Disable(GL_TEXTURE_2D); 221 222 222 223 223 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 224 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 225 { 226 glColor4f(RedValue*Mesh.Vertices[VertexNr].Color[0], GreenValue*Mesh.Vertices[VertexNr].Color[1], BlueValue*Mesh.Vertices[VertexNr].Color[2], AlphaValue*Mesh.Vertices[VertexNr].Color[3]); 227 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 228 } 229 glEnd(); 224 // The cgGLSetParameter*() functions are very slow, so cache their parameters in order to call them as little as possible. 225 static float MeshColorCache[4]={ 0.0, 0.0, 0.0, 1.0 }; 226 if (RedValue!=MeshColorCache[0] || GreenValue!=MeshColorCache[1] || BlueValue!=MeshColorCache[2] 227 || AlphaValue != MeshColorCache[3]) 228 { 229 MeshColorCache[0]=RedValue; 230 MeshColorCache[1]=GreenValue; 231 MeshColorCache[2]=BlueValue; 232 MeshColorCache[3]=AlphaValue; 233 cf::glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, MeshColorCache); 234 } 235 236 // Draw the mesh 237 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 238 Drawer->BeginDrawing(Mesh); 239 { 240 Drawer->SendPositions(); 241 Drawer->SendColors(); 242 Drawer->DrawMesh(); 243 } 244 Drawer->EndDrawing(); 230 245 } 231 246 }; 232 247 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_SkyDome.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 242 242 EyePosCache_w[2]=VW.m[2][3]; 243 243 } 244 244 245 245 // Draw the mesh 246 246 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 247 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 248 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 249 { 250 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 251 } 252 glEnd(); 247 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 248 Drawer->BeginDrawing(Mesh); 249 { 250 Drawer->SendPositions(); 251 Drawer->DrawMesh(); 252 } 253 Drawer->EndDrawing(); 253 254 } 254 255 }; 255 256 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light_Luma.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 242 242 OpenGLState->BindTexture(GL_TEXTURE_2D, RM->LumaTexMap->GetOpenGLObject()); 243 243 244 244 245 // Draw the mesh 245 246 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 246 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]);247 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++)248 {249 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord);250 cf::glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, Mesh.Vertices[VertexNr].LightMapCoord);251 252 glVertex3dv(Mesh.Vertices[VertexNr].Origin);253 }254 glEnd();247 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 248 Drawer->BeginDrawing(Mesh); 249 { 250 Drawer->SendPositions(); 251 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 252 Drawer->SendLightMapCoords(GL_TEXTURE1_ARB); 253 Drawer->DrawMesh(); 254 } 255 Drawer->EndDrawing(); 255 256 } 256 257 }; 257 258 -
Libs/MaterialSystem/RendererARBprogs/Shaders/L_Diff_Norm.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 281 281 } 282 282 283 283 284 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]);285 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++)286 {287 glNormal3fv(Mesh.Vertices[VertexNr].Normal); // Normal288 cf::glMultiTexCoord3fvARB(GL_TEXTURE6_ARB, Mesh.Vertices[VertexNr].Tangent); // Tangent289 cf::glMultiTexCoord3fvARB(GL_TEXTURE7_ARB, Mesh.Vertices[VertexNr].BiNormal); // BiNormal284 // Draw the mesh 285 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 286 Drawer->BeginDrawing(Mesh); 287 { 288 Drawer->SendPositions(); 289 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 290 290 291 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 292 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 293 } 294 glEnd(); 291 Drawer->SendNormals(); 292 Drawer->SendTangents(GL_TEXTURE6_ARB); 293 Drawer->SendBiNormals(GL_TEXTURE7_ARB); 294 Drawer->DrawMesh(); 295 } 296 Drawer->EndDrawing(); 295 297 } 296 298 }; 297 299 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Norm_Luma.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 243 243 OpenGLState->BindTexture(GL_TEXTURE_2D, RM->LumaTexMap->GetOpenGLObject()); 244 244 245 245 246 // Draw the mesh 247 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 246 248 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 247 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 248 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 249 { 250 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 251 252 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 253 } 254 glEnd(); 249 Drawer->BeginDrawing(Mesh); 250 { 251 Drawer->SendPositions(); 252 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 253 Drawer->DrawMesh(); 254 } 255 Drawer->EndDrawing(); 255 256 } 256 257 }; 257 258 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light_Norm_Luma_Spec.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 307 307 cf::glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, EyePosCache); 308 308 } 309 309 310 310 // Draw the mesh 311 311 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 312 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 313 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 314 { 315 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 316 cf::glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, Mesh.Vertices[VertexNr].LightMapCoord); 312 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 313 Drawer->BeginDrawing(Mesh); 314 { 315 Drawer->SendPositions(); 316 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 317 Drawer->SendLightMapCoords(GL_TEXTURE1_ARB); 317 318 318 glNormal3fv(Mesh.Vertices[VertexNr].Normal); // Normal 319 cf::glMultiTexCoord3fvARB(GL_TEXTURE6_ARB, Mesh.Vertices[VertexNr].Tangent); // Tangent 320 cf::glMultiTexCoord3fvARB(GL_TEXTURE7_ARB, Mesh.Vertices[VertexNr].BiNormal); // BiNormal 321 322 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 323 } 324 glEnd(); 319 Drawer->SendNormals(); 320 Drawer->SendTangents(GL_TEXTURE6_ARB); 321 Drawer->SendBiNormals(GL_TEXTURE7_ARB); 322 Drawer->DrawMesh(); 323 } 324 Drawer->EndDrawing(); 325 325 } 326 326 }; 327 327 -
Libs/MaterialSystem/RendererARBprogs/Shaders/StencilShadowVolumes.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 172 172 OpenGLState->Enable(GL_STENCIL_TEST); 173 173 OpenGLState->FrontFace(OpenGLStateT::WindingToOpenGL[Mesh.Winding]); 174 174 175 175 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 176 176 if (cf::GL_EXT_stencil_two_side_AVAIL) 177 177 { 178 178 OpenGLState->Disable(GL_CULL_FACE); … … 188 188 OpenGLState->StencilFunc(GL_ALWAYS, 0, ~0); 189 189 // OpenGLState->StencilMask(~0); // This is the default setting anyway. 190 190 191 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 192 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 193 glVertex4dv(Mesh.Vertices[VertexNr].Origin); 194 glEnd(); 191 Drawer->BeginDrawing(Mesh); 192 { 193 Drawer->SendPositions4(); 194 Drawer->DrawMesh(); 195 } 196 Drawer->EndDrawing(); 195 197 } 196 198 else 197 199 { … … 203 205 // We could also render ALL pieces first in the first pass, then all in the second, 204 206 // taking the OpenGL state changes out of the inner loop. 205 207 // The good news is that that discussion is obsoleted by the two-sided stencil test extension above. 208 Drawer->BeginDrawing(Mesh); 209 Drawer->SendPositions4(); 206 210 for (char PassNr=0; PassNr<2; PassNr++) 207 211 { 208 212 // Note that we have to cull the following polygons wrt. the *VIEWER* (not the light source)! … … 214 218 // 2. Clear the stencil buffer to 128, and compare later to reference value 128. 215 219 OpenGLState->StencilOp(GL_KEEP, PassNr==0 ? GL_INCR_WRAP : GL_DECR_WRAP, GL_KEEP); 216 220 217 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 218 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 219 glVertex4dv(Mesh.Vertices[VertexNr].Origin); 220 glEnd(); 221 Drawer->DrawMesh(); 221 222 } 223 Drawer->EndDrawing(); 222 224 } 223 225 } 224 226 }; -
Libs/MaterialSystem/RendererARBprogs/Shaders/L_Diff.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 275 275 cf::glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, LightDiffColorCache); 276 276 } 277 277 278 279 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]);280 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++)281 {282 glNormal3fv(Mesh.Vertices[VertexNr].Normal); // Normal283 284 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord);285 glVertex3dv(Mesh.Vertices[VertexNr].Origin);286 }287 glEnd();278 // Draw the mesh 279 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 280 Drawer->BeginDrawing(Mesh); 281 { 282 Drawer->SendPositions(); 283 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 284 Drawer->SendNormals(); 285 Drawer->DrawMesh(); 286 } 287 Drawer->EndDrawing(); 288 288 } 289 289 }; 290 290 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_WaterCubeReflect.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 342 342 } 343 343 344 344 345 // Draw the mesh 346 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 345 347 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 346 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 347 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 348 { 349 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 350 351 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 352 } 353 glEnd(); 348 Drawer->BeginDrawing(Mesh); 349 { 350 Drawer->SendPositions(); 351 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 352 Drawer->DrawMesh(); 353 } 354 Drawer->EndDrawing(); 354 355 } 355 356 }; 356 357 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Luma.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 234 234 OpenGLState->BindTexture(GL_TEXTURE_2D, RM->LumaTexMap->GetOpenGLObject()); 235 235 236 236 237 // Draw the mesh 238 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 237 239 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 238 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 239 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 240 { 241 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 242 243 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 244 } 245 glEnd(); 240 Drawer->BeginDrawing(Mesh); 241 { 242 Drawer->SendPositions(); 243 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 244 Drawer->DrawMesh(); 245 } 246 Drawer->EndDrawing(); 246 247 } 247 248 }; 248 249 -
Libs/MaterialSystem/RendererARBprogs/Shaders/L_Diff_Norm_Spec.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 348 348 } 349 349 350 350 351 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]);352 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++)353 {354 glNormal3fv(Mesh.Vertices[VertexNr].Normal); // Normal355 cf::glMultiTexCoord3fvARB(GL_TEXTURE6_ARB, Mesh.Vertices[VertexNr].Tangent); // Tangent356 cf::glMultiTexCoord3fvARB(GL_TEXTURE7_ARB, Mesh.Vertices[VertexNr].BiNormal); // BiNormal351 // Draw the mesh 352 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 353 Drawer->BeginDrawing(Mesh); 354 { 355 Drawer->SendPositions(); 356 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 357 357 358 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 359 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 360 } 361 glEnd(); 358 Drawer->SendNormals(); 359 Drawer->SendTangents(GL_TEXTURE6_ARB); 360 Drawer->SendBiNormals(GL_TEXTURE7_ARB); 361 Drawer->DrawMesh(); 362 } 363 Drawer->EndDrawing(); 362 364 } 363 365 }; 364 366 -
Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light_Norm.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 255 255 OpenGLState->BindTexture(GL_TEXTURE_2D, RM->NormTexMap->GetOpenGLObject()); 256 256 257 257 258 // Draw the mesh 258 259 glColor4f(RedValue, GreenValue, BlueValue, AlphaValue); 259 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]);260 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++)261 {262 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord);263 cf::glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, Mesh.Vertices[VertexNr].LightMapCoord);264 265 glVertex3dv(Mesh.Vertices[VertexNr].Origin);266 }267 glEnd();260 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 261 Drawer->BeginDrawing(Mesh); 262 { 263 Drawer->SendPositions(); 264 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 265 Drawer->SendLightMapCoords(GL_TEXTURE1_ARB); 266 Drawer->DrawMesh(); 267 } 268 Drawer->EndDrawing(); 268 269 } 269 270 }; 270 271 -
Libs/MaterialSystem/RendererARBprogs/Shaders/L_Diff_Spec.cpp
44 44 #include "../../Mesh.hpp" 45 45 #include "_CommonHelpers.hpp" 46 46 #include "../../Common/OpenGLEx.hpp" 47 #include "../MeshBuffer.hpp" 47 48 48 49 49 using namespace MatSys; 50 50 51 51 … … 339 339 cf::glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1, LightSpecColorCache); 340 340 } 341 341 342 343 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]);344 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++)345 {346 glNormal3fv(Mesh.Vertices[VertexNr].Normal); // Normal347 348 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord);349 glVertex3dv(Mesh.Vertices[VertexNr].Origin);350 }351 glEnd();342 // Draw the mesh 343 MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 344 Drawer->BeginDrawing(Mesh); 345 { 346 Drawer->SendPositions(); 347 Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 348 Drawer->SendNormals(); 349 Drawer->DrawMesh(); 350 } 351 Drawer->EndDrawing(); 352 352 } 353 353 }; 354 354 -
Libs/MaterialSystem/RendererARBprogs/PrimitiveBufferImpl.cpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /***************************/ 25 /*** PrimitiveBufferImpl ***/ 26 /***************************/ 27 28 #include <GL/gl.h> 29 #include <cassert> 30 #include <stdio.h> 31 #include "../Common/OpenGLEx.hpp" 32 #include "../Common/OpenGLState.hpp" 33 #include "MeshBuffer.hpp" 34 #include "PrimitiveBufferImpl.hpp" 35 36 PrimitiveBufferImplT::PrimitiveBufferImplT(IndexTypeT IT, UsageTypeT UT) 37 : IndexType(IT), UsageType(UT), IsLocked(false), Size(0) 38 { 39 cf::glGenBuffersARB(1, &BufferObject); 40 } 41 42 PrimitiveBufferImplT::~PrimitiveBufferImplT() 43 { 44 MeshBufferManagerT::GetInstance()->DestroyPrimitiveBuffer(this); 45 } 46 47 // Primitives buffer access 48 const void *PrimitiveBufferImplT::LockRead() const 49 { 50 assert(!IsLocked); 51 IsLocked = true; 52 53 MeshBufferManagerT::GetInstance()->InvalidateClientState(); 54 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 55 OpenGLState->BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, BufferObject); 56 return cf::glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_READ_ONLY_ARB); 57 } 58 59 void *PrimitiveBufferImplT::LockWrite() 60 { 61 assert(!IsLocked); 62 IsLocked = true; 63 64 MeshBufferManagerT::GetInstance()->InvalidateClientState(); 65 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 66 OpenGLState->BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, BufferObject); 67 cf::glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GetBufferSize(), NULL, 68 MeshBufferManagerT::UsageTypeToOpenGL[UsageType]); 69 return cf::glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); 70 } 71 72 void *PrimitiveBufferImplT::LockReadWrite() 73 { 74 assert(!IsLocked); 75 IsLocked = true; 76 77 MeshBufferManagerT::GetInstance()->InvalidateClientState(); 78 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 79 OpenGLState->BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, BufferObject); 80 return cf::glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_READ_WRITE_ARB); 81 } 82 83 void PrimitiveBufferImplT::Unlock() const 84 { 85 assert(IsLocked); 86 IsLocked = false; 87 88 MeshBufferManagerT::GetInstance()->InvalidateClientState(); 89 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 90 OpenGLState->BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, BufferObject); 91 cf::glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); 92 } 93 94 // Buffer description 95 unsigned long PrimitiveBufferImplT::GetBufferSize() const 96 { 97 return Size*MeshBufferManagerT::IndexTypeSize[IndexType]; 98 } 99 100 unsigned long PrimitiveBufferImplT::GetSize() const 101 { 102 return Size; 103 } 104 105 void PrimitiveBufferImplT::SetSize(unsigned long S) 106 { 107 Size = S; 108 } 109 110 PrimitiveBufferImplT::IndexTypeT PrimitiveBufferImplT::GetIndexType() const 111 { 112 return IndexType; 113 } 114 115 PrimitiveBufferImplT::UsageTypeT PrimitiveBufferImplT::GetUsage() const 116 { 117 return UsageType; 118 } 119 120 bool PrimitiveBufferImplT::IsValid() const 121 { 122 return true; 123 } 124 125 void PrimitiveBufferImplT::Validated() const 126 { 127 } 128 129 void PrimitiveBufferImplT::Invalidate() 130 { 131 } 132 133 void *PrimitiveBufferImplT::GetRendererData() const 134 { 135 return (void*)((unsigned long)BufferObject); 136 } 137 138 void PrimitiveBufferImplT::SetRendererData(void *Data) const 139 { 140 BufferObject = (unsigned long)Data; 141 } 142 -
Libs/MaterialSystem/RendererARBprogs/MeshBuffer.cpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /*******************************/ 25 /*** Renderer Implementation ***/ 26 /*******************************/ 27 28 // Required for #include <GL/gl.h> with MS VC++. 29 #if defined(_WIN32) && defined(_MSC_VER) 30 #define WIN32_LEAN_AND_MEAN 31 #include <windows.h> 32 #if (_MSC_VER<1300) 33 #define for if (false) ; else for 34 #endif 35 #endif 36 37 #include <GL/gl.h> 38 #include <cassert> 39 #include <stdio.h> 40 #include "../Common/OpenGLEx.hpp" 41 #include "../Common/OpenGLState.hpp" 42 #include "MeshBuffer.hpp" 43 44 using namespace MatSys; 45 46 // Helper template to get the vertex element pointer 47 template<typename T> 48 const T *GetElementAddress(const void *buffer, int offset) 49 { 50 assert(offset >= 0); 51 return (const T*)((const char*)buffer + offset); 52 } 53 54 GLenum MeshBufferManagerT::UsageTypeToOpenGL[3] = 55 {GL_STATIC_DRAW_ARB, GL_DYNAMIC_DRAW_ARB, GL_STREAM_DRAW_ARB }; 56 57 GLenum MeshBufferManagerT::IndexTypeToOpenGLType[3] = 58 {GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT}; 59 60 unsigned long MeshBufferManagerT::IndexTypeSize[3] = 61 {sizeof(unsigned char), sizeof(unsigned short), sizeof(unsigned long)}; 62 63 64 MeshBufferManagerT::MeshBufferManagerT() 65 : IsSendingMesh(false), Start(true) 66 { 67 } 68 69 MeshBufferManagerT::~MeshBufferManagerT() 70 { 71 } 72 73 MeshBufferManagerT *MeshBufferManagerT::GetInstance() 74 { 75 static MeshBufferManagerT *Manager = NULL; 76 if(!Manager) 77 Manager = new MeshBufferManagerT(); 78 79 return Manager; 80 } 81 82 void MeshBufferManagerT::ClientStateT::Clear() 83 { 84 Mesh = NULL; 85 VertexBuffer = NULL; 86 VertexBufferData = NULL; 87 88 PrimitiveBuffer = NULL; 89 PrimitiveBufferData = NULL; 90 91 IsEnabled_Positions = false; 92 IsEnabled_Positions4 = false; 93 IsEnabled_Colors = false; 94 IsEnabled_Normals = false; 95 UseVBO = false; 96 for(int i = 0; i < 8; i++) 97 IsEnabled_Texcoords[i] = false; 98 } 99 100 // Revalidate the VertexBuffer 101 void MeshBufferManagerT::RevalidateVertexBuffer() 102 { 103 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 104 const VertexBufferI *buffer = ClientState.VertexBuffer; 105 if(!buffer) 106 return; 107 108 void *renderData = buffer->GetRendererData(); 109 GLuint vbo; 110 if(renderData == NULL) 111 { 112 // Create the vertex buffer object and bind it 113 cf::glGenBuffersARB(1, &vbo); 114 OpenGLState->BindBuffer(GL_ARRAY_BUFFER_ARB, vbo); 115 renderData = (void*)vbo; 116 buffer->SetRendererData(renderData); 117 } 118 else 119 { 120 // Retrieve the buffer object and bind it 121 vbo = (unsigned long)renderData; 122 OpenGLState->BindBuffer(GL_ARRAY_BUFFER_ARB, vbo); 123 if(buffer->IsValid()) 124 return; 125 } 126 127 // Upload the buffer data 128 unsigned long size = buffer->GetBufferSize(); 129 const void *data = buffer->LockRead(); 130 cf::glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, data, UsageTypeToOpenGL[buffer->GetUsage()]); 131 132 // Unlock the buffer 133 buffer->Unlock(); 134 buffer->Validated(); 135 } 136 137 // Revalidate the primitive buffer 138 void MeshBufferManagerT::RevalidatePrimitiveBuffer() 139 { 140 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 141 const PrimitiveBufferI *buffer = ClientState.PrimitiveBuffer; 142 if(!buffer) 143 return; 144 145 void *renderData = buffer->GetRendererData(); 146 GLuint vbo; 147 if(!renderData) 148 { 149 // Create the vertex buffer object and bind it 150 cf::glGenBuffersARB(1, &vbo); 151 OpenGLState->BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, vbo); 152 renderData = (void*)vbo; 153 buffer->SetRendererData(renderData); 154 } 155 else 156 { 157 // Retrieve the buffer object and bind it 158 vbo = (long)renderData; 159 OpenGLState->BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, vbo); 160 if(buffer->IsValid()) 161 return; 162 } 163 164 // Upload the buffer data 165 unsigned long size = buffer->GetBufferSize(); 166 const void *data = buffer->LockRead(); 167 cf::glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, size, data, UsageTypeToOpenGL[ClientState.Mesh->UsageType]); 168 169 // Unlock the buffer 170 buffer->Unlock(); 171 buffer->Validated(); 172 } 173 174 // Revalidate the vertex buffer objects 175 void MeshBufferManagerT::RevalidateBufferObjects() 176 { 177 if(cf::GL_ARB_vertex_buffer_object_AVAIL) 178 { 179 RevalidateVertexBuffer(); 180 RevalidatePrimitiveBuffer(); 181 ClientState.UseVBO = true; 182 } 183 else 184 { 185 if(ClientState.VertexBuffer) 186 ClientState.VertexBufferData = ClientState.VertexBuffer->LockRead(); 187 if(ClientState.PrimitiveBuffer) 188 ClientState.PrimitiveBufferData = ClientState.PrimitiveBuffer->LockRead(); 189 ClientState.UseVBO = false; 190 } 191 } 192 193 // Begin mesh data transfer 194 void MeshBufferManagerT::BeginDrawing(const MatSys::MeshT &Mesh) 195 { 196 assert(!IsSendingMesh); 197 198 // Check if the mesh is valid and is already sended 199 if(ClientState.Mesh == &Mesh && Mesh.IsValid()) 200 { 201 IsSendingMesh = true; 202 return; 203 } 204 205 // Prevent OpenGL stack errors 206 if(!Start) 207 glPopClientAttrib(); // Pop the old client attribute 208 else 209 Start = false; 210 211 // Clear the client data 212 ClientState.Clear(); 213 214 // Store the mesh metadata 215 ClientState.Mesh = &Mesh; 216 ClientState.VertexBuffer = Mesh.VertexBuffer; 217 ClientState.PrimitiveBuffer = Mesh.PrimitiveBuffer; 218 219 // Store the current client attributes 220 glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); 221 222 // Set the sending flag 223 IsSendingMesh = true; 224 225 // Revalidate the vertex buffer objects 226 RevalidateBufferObjects(); 227 } 228 229 // Draw the mesh 230 void MeshBufferManagerT::DrawMesh() 231 { 232 GLenum Mode = OpenGLStateT::MeshToOpenGLType[ClientState.Mesh->Type]; 233 const ArrayT<MeshT::RangeT> &SubRanges = ClientState.Mesh->SubRanges; 234 unsigned long NumSubRanges = SubRanges.Size(); 235 unsigned long NumVertices = ClientState.VertexBuffer->GetSize(); 236 if(ClientState.PrimitiveBuffer) 237 { 238 GLenum IndexType = IndexTypeToOpenGLType[ClientState.PrimitiveBuffer->GetIndexType()]; 239 unsigned long IndexSize = IndexTypeSize[ClientState.PrimitiveBuffer->GetIndexType()]; 240 if(NumSubRanges == 0) 241 { 242 // Draw all of the elements. 243 glDrawRangeElements(Mode, 0, NumVertices, ClientState.PrimitiveBuffer->GetSize(), 244 IndexType, ClientState.PrimitiveBufferData); 245 } 246 else 247 { 248 // Draw each sub range primitives. 249 for(unsigned long i = 0; i < NumSubRanges; i++) 250 { 251 GLenum SubMode = Mode; 252 if(SubRanges[i].Type != MeshT::Inherit) 253 SubMode = OpenGLStateT::MeshToOpenGLType[SubRanges[i].Type]; 254 255 // Adjust the start pointer 256 char *BufferStart = ((char*)ClientState.PrimitiveBufferData) + SubRanges[i].Start*IndexSize; 257 glDrawRangeElements(SubMode, 0, NumVertices, SubRanges[i].Count, 258 IndexType, BufferStart); 259 } 260 } 261 } 262 else if(ClientState.VertexBuffer) 263 { 264 if(NumSubRanges == 0) 265 { 266 // Draw all of the array. 267 glDrawArrays(Mode, 0, NumVertices); 268 } 269 else 270 { 271 // Draw each sub range primitives. 272 for(unsigned long i = 0; i < NumSubRanges; i++) 273 { 274 GLenum SubMode = Mode; 275 if(SubRanges[i].Type != MeshT::Inherit) 276 SubMode = OpenGLStateT::MeshToOpenGLType[SubRanges[i].Type]; 277 glDrawArrays(SubMode, SubRanges[i].Start, SubRanges[i].Count); 278 } 279 } 280 } 281 } 282 283 // End mesh data transfer 284 void MeshBufferManagerT::EndDrawing() 285 { 286 assert(IsSendingMesh); 287 288 // Unset the sending flag 289 IsSendingMesh = false; 290 291 // Unlock buffers if VBOs is not supported 292 if(!ClientState.UseVBO && ClientState.VertexBufferData) 293 { 294 ClientState.VertexBufferData = NULL; 295 ClientState.VertexBuffer->Unlock(); 296 } 297 298 if(!ClientState.UseVBO && ClientState.PrimitiveBufferData) 299 { 300 ClientState.PrimitiveBufferData = NULL; 301 ClientState.PrimitiveBuffer->Unlock(); 302 } 303 } 304 305 // Destroys the mesh buffer 306 void MeshBufferManagerT::DestroyMesh(MatSys::MeshT *mesh) 307 { 308 } 309 310 // Destroys the vertex buffer 311 void MeshBufferManagerT::DestroyVertexBuffer(MatSys::VertexBufferI *Buffer) 312 { 313 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 314 315 // Check the extension 316 if(!cf::GL_ARB_vertex_buffer_object_AVAIL) 317 return; 318 319 // Retrieve the vertex buffer object name 320 void *renderData = Buffer->GetRendererData(); 321 if(renderData) 322 { 323 GLuint vbo = (long)renderData; 324 if(ClientState.VertexBuffer == Buffer) // Unbind the vertex buffer object 325 OpenGLState->BindBuffer(GL_ARRAY_BUFFER_ARB, 0); 326 327 // Delete the vertex buffer object 328 cf::glDeleteBuffersARB(1, &vbo); 329 } 330 331 if(ClientState.VertexBuffer == Buffer) 332 { 333 glPopClientAttrib(); // Pops the client state 334 Start = true; 335 ClientState.Clear(); 336 } 337 338 } 339 340 void MeshBufferManagerT::InvalidateClientState() 341 { 342 if(!Start) 343 { 344 glPopClientAttrib(); // Pops the client state 345 Start = true; 346 ClientState.Clear(); 347 } 348 } 349 350 // Destroys the primitive buffer 351 void MeshBufferManagerT::DestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer) 352 { 353 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 354 355 // Check the extension 356 if(!cf::GL_ARB_vertex_buffer_object_AVAIL) 357 return; 358 359 // Retrieve the vertex buffer object name 360 void *renderData = Buffer->GetRendererData(); 361 if(renderData) 362 { 363 GLuint vbo = (long)renderData; 364 if(ClientState.PrimitiveBuffer == Buffer) // Unbind the vertex buffer object 365 OpenGLState->BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); 366 367 // Delete the vertex buffer object 368 cf::glDeleteBuffersARB(1, &vbo); 369 } 370 371 if(ClientState.PrimitiveBuffer == Buffer) 372 { 373 glPopClientAttrib(); // Pops the client state 374 Start = true; 375 ClientState.Clear(); 376 } 377 } 378 379 void MeshBufferManagerT::SendPositions() 380 { 381 // Extract the descriptor 382 if(ClientState.IsEnabled_Positions || !ClientState.VertexBuffer) 383 return; 384 385 const VertexDescriptorT &Format = ClientState.VertexBuffer->GetVertexDescriptor(); 386 387 // For debugging. Check the presence of the origin 388 assert(Format.Origin >= 0); 389 390 // Update enabled flags 391 glEnableClientState(GL_VERTEX_ARRAY); 392 ClientState.IsEnabled_Positions = true; 393 394 // Send the data 395 if(ClientState.UseVBO) 396 { 397 // Use VBOs. The pointer is just an offset 398 glVertexPointer(3, GL_FLOAT, Format.VertexSize, (const void*)Format.Origin); 399 } 400 else if(ClientState.VertexBufferData) 401 { 402 // Use vertex arrays 403 glVertexPointer(3, GL_FLOAT, Format.VertexSize, 404 GetElementAddress<const void*> (ClientState.VertexBufferData, Format.Origin)); 405 } 406 } 407 408 void MeshBufferManagerT::SendPositions4() 409 { 410 // Extract the descriptor 411 if(ClientState.IsEnabled_Positions4 || !ClientState.VertexBuffer) 412 return; 413 414 const VertexDescriptorT &Format = ClientState.VertexBuffer->GetVertexDescriptor(); 415 416 // For debugging. Check the presence of the origin 417 assert(Format.Origin4 >= 0); 418 419 // Update enabled flags 420 glEnableClientState(GL_VERTEX_ARRAY); 421 ClientState.IsEnabled_Positions4 = true; 422 423 // Send the data 424 if(ClientState.UseVBO) 425 { 426 // Use VBOs. The pointer is just an offset 427 glVertexPointer(4, GL_FLOAT, Format.VertexSize, (const void*)Format.Origin4); 428 } 429 else if(ClientState.VertexBufferData) 430 { 431 // Use vertex arrays 432 glVertexPointer(4, GL_FLOAT, Format.VertexSize, 433 GetElementAddress<const void*> (ClientState.VertexBufferData, Format.Origin4)); 434 } 435 } 436 437 void MeshBufferManagerT::SendNormals() 438 { 439 // Extract the descriptor 440 if(ClientState.IsEnabled_Normals || !ClientState.VertexBuffer) 441 return; 442 443 const VertexDescriptorT &Format = ClientState.VertexBuffer->GetVertexDescriptor(); 444 445 // For debugging. Check the presence of the origin 446 assert(Format.Normal >= 0); 447 448 // Update enabled flags 449 glEnableClientState(GL_NORMAL_ARRAY); 450 ClientState.IsEnabled_Normals = true; 451 452 // Send the data 453 if(ClientState.UseVBO) 454 { 455 // Use VBOs. The pointer is just an offset 456 glNormalPointer(GL_FLOAT, Format.VertexSize, (const void*)Format.Normal); 457 } 458 else if(ClientState.VertexBufferData) 459 { 460 // Use vertex arrays 461 glNormalPointer(GL_FLOAT, Format.VertexSize, 462 GetElementAddress<const void*> (ClientState.VertexBufferData, Format.Normal)); 463 } 464 } 465 466 void MeshBufferManagerT::SendColors() 467 { 468 // Extract the descriptor 469 if(ClientState.IsEnabled_Colors || !ClientState.VertexBuffer) 470 return; 471 472 const VertexDescriptorT &Format = ClientState.VertexBuffer->GetVertexDescriptor(); 473 474 // For debugging. Check the presence of the origin 475 assert(Format.Color >= 0); 476 477 // Update enabled flags 478 glEnableClientState(GL_COLOR_ARRAY); 479 ClientState.IsEnabled_Colors = true; 480 481 // Send the data 482 if(ClientState.UseVBO) 483 { 484 // Use VBOs. The pointer is just an offset 485 glColorPointer(4, GL_FLOAT, Format.VertexSize, (const void*)Format.Color); 486 } 487 else if(ClientState.VertexBufferData) 488 { 489 // Use vertex arrays 490 glColorPointer(4, GL_FLOAT, Format.VertexSize, 491 GetElementAddress<const void*> (ClientState.VertexBufferData, Format.Color)); 492 } 493 } 494 495 void MeshBufferManagerT::SendTextureCoords(GLenum Unit) 496 { 497 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 498 499 // Check if the state is laready setted 500 int Id = Unit - GL_TEXTURE0_ARB; 501 assert(Id < 8); 502 if(ClientState.IsEnabled_Texcoords[Id] || !ClientState.VertexBuffer) 503 return; 504 505 // Extract the descriptor 506 const VertexDescriptorT &Format = ClientState.VertexBuffer->GetVertexDescriptor(); 507 508 // For debugging. Check the presence of the origin 509 assert(Format.TextureCoord >= 0); 510 511 // Update enabled flags 512 OpenGLState->ClientActiveTexture(Unit); 513 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 514 ClientState.IsEnabled_Texcoords[Id] = true; 515 516 // Send the data 517 if(ClientState.UseVBO) 518 { 519 // Use VBOs. The pointer is just an offset 520 glTexCoordPointer(2, GL_FLOAT, Format.VertexSize, (const void*)Format.TextureCoord); 521 } 522 else if(ClientState.VertexBufferData) 523 { 524 // Use vertex arrays 525 glTexCoordPointer(2, GL_FLOAT, Format.VertexSize, 526 GetElementAddress<const void*> (ClientState.VertexBufferData, Format.TextureCoord)); 527 } 528 } 529 530 void MeshBufferManagerT::SendLightMapCoords(GLenum Unit) 531 { 532 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 533 534 // Check if the state is laready setted 535 int Id = Unit - GL_TEXTURE0_ARB; 536 assert(Id < 8); 537 if(ClientState.IsEnabled_Texcoords[Id] || !ClientState.VertexBuffer) 538 return; 539 540 // Extract the descriptor 541 const VertexDescriptorT &Format = ClientState.VertexBuffer->GetVertexDescriptor(); 542 543 // For debugging. Check the presence of the origin 544 assert(Format.LightMapCoord >= 0); 545 546 // Update enabled flags 547 OpenGLState->ClientActiveTexture(Unit); 548 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 549 ClientState.IsEnabled_Texcoords[Id] = true; 550 551 // Send the data 552 if(ClientState.UseVBO) 553 { 554 // Use VBOs. The pointer is just an offset 555 glTexCoordPointer(2, GL_FLOAT, Format.VertexSize, (const void*)Format.LightMapCoord); 556 } 557 else if(ClientState.VertexBufferData) 558 { 559 // Use vertex arrays 560 glTexCoordPointer(2, GL_FLOAT, Format.VertexSize, 561 GetElementAddress<const void*> (ClientState.VertexBufferData, Format.LightMapCoord)); 562 } 563 } 564 565 void MeshBufferManagerT::SendBiNormals(GLenum Unit) 566 { 567 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 568 569 // Check if the state is laready setted 570 int Id = Unit - GL_TEXTURE0_ARB; 571 assert(Id < 8); 572 if(ClientState.IsEnabled_Texcoords[Id] || !ClientState.VertexBuffer) 573 return; 574 575 // Extract the descriptor 576 const VertexDescriptorT &Format = ClientState.VertexBuffer->GetVertexDescriptor(); 577 578 // For debugging. Check the presence of the origin 579 assert(Format.BiNormal >= 0); 580 581 // Update enabled flags 582 OpenGLState->ClientActiveTexture(Unit); 583 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 584 ClientState.IsEnabled_Texcoords[Id] = true; 585 586 // Send the data 587 if(ClientState.UseVBO) 588 { 589 // Use VBOs. The pointer is just an offset 590 glTexCoordPointer(3, GL_FLOAT, Format.VertexSize, (const void*)Format.BiNormal); 591 } 592 else if(ClientState.VertexBufferData) 593 { 594 // Use vertex arrays 595 glTexCoordPointer(3, GL_FLOAT, Format.VertexSize, 596 GetElementAddress<const void*> (ClientState.VertexBufferData, Format.BiNormal)); 597 } 598 } 599 600 void MeshBufferManagerT::SendTangents(GLenum Unit) 601 { 602 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 603 604 // Check if the state is laready setted 605 int Id = Unit - GL_TEXTURE0_ARB; 606 assert(Id < 8); 607 if(ClientState.IsEnabled_Texcoords[Id] || !ClientState.VertexBuffer) 608 return; 609 610 // Extract the descriptor 611 const VertexDescriptorT &Format = ClientState.VertexBuffer->GetVertexDescriptor(); 612 613 // For debugging. Check the presence of the origin 614 assert(Format.Tangent >= 0); 615 616 // Update enabled flags 617 OpenGLState->ClientActiveTexture(Unit); 618 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 619 ClientState.IsEnabled_Texcoords[Id] = true; 620 621 // Send the data 622 if(ClientState.UseVBO) 623 { 624 // Use VBOs. The pointer is just an offset 625 glTexCoordPointer(3, GL_FLOAT, Format.VertexSize, (const void*)Format.Tangent); 626 } 627 else if(ClientState.VertexBufferData) 628 { 629 // Use vertex arrays 630 glTexCoordPointer(3, GL_FLOAT, Format.VertexSize, 631 GetElementAddress<const void*> (ClientState.VertexBufferData, Format.Tangent)); 632 } 633 } 634 635 -
Libs/MaterialSystem/RendererARBprogs/RendererImpl.cpp
48 48 49 49 #include "../Common/OpenGLEx.hpp" 50 50 #include "Templates/Array.hpp" 51 #include "MeshBuffer.hpp" 52 #include "VertexBufferImpl.hpp" 53 #include "PrimitiveBufferImpl.hpp" 51 54 52 53 55 using namespace MatSys; 54 56 55 57 … … 289 291 cf::Init_GL_EXT_stencil_wrap(); 290 292 cf::Init_GL_EXT_stencil_two_side(); 291 293 cf::Init_GL_ARB_vertex_and_fragment_program(); 294 cf::Init_GL_ARB_vertex_buffer_object(); 292 295 293 296 if (cf::GL_ARB_texture_compression_AVAIL) 294 297 glHint(GL_TEXTURE_COMPRESSION_HINT_ARB, GL_NICEST); … … 1037 1040 CurrentShader->RenderMesh(Mesh); 1038 1041 } 1039 1042 1043 void RendererImplT::OnDestroyMesh(MatSys::MeshT *Mesh) 1044 { 1045 MeshBufferManagerT::GetInstance()->DestroyMesh(Mesh); 1046 } 1040 1047 1048 void RendererImplT::OnDestroyVertexBuffer(MatSys::VertexBufferI *Buffer) 1049 { 1050 MeshBufferManagerT::GetInstance()->DestroyVertexBuffer(Buffer); 1051 } 1052 1053 void RendererImplT::OnDestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer) 1054 { 1055 MeshBufferManagerT::GetInstance()->DestroyPrimitiveBuffer(Buffer); 1056 } 1057 1058 MatSys::VertexBufferI *RendererImplT::CreateVertexBuffer(const VertexDescriptorT &Format, unsigned int Usage) 1059 { 1060 if(cf::GL_ARB_vertex_buffer_object_AVAIL) 1061 return new VertexBufferImplT(Format, (VertexBufferI::UsageTypeT)Usage); 1062 return NULL; 1063 } 1064 1065 PrimitiveBufferI *RendererImplT::CreatePrimitiveBuffer(PrimitiveBufferI::IndexTypeT IndexType, PrimitiveBufferI::UsageTypeT Usage) 1066 { 1067 if(cf::GL_ARB_vertex_buffer_object_AVAIL) 1068 return new PrimitiveBufferImplT(IndexType, Usage); 1069 return NULL; 1070 } 1071 1041 1072 RenderMaterialT* RendererImplT::GetCurrentRenderMaterial() const 1042 1073 { 1043 1074 return CurrentRenderMaterial; -
Libs/MaterialSystem/RendererARBprogs/PrimitiveBufferImpl.hpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /************************/ 25 /*** PrimitiveBufferImpl ***/ 26 /************************/ 27 28 #ifndef _CA_MATSYS_PRIMITIVE_BUFFER_IMPLEMENTATION_HPP_ 29 #define _CA_MATSYS_PRIMITIVE_BUFFER_IMPLEMENTATION_HPP_ 30 31 #include <GL/gl.h> 32 #include "../PrimitiveBuffer.hpp" 33 34 class PrimitiveBufferImplT: public MatSys::PrimitiveBufferI 35 { 36 public: 37 PrimitiveBufferImplT(IndexTypeT IT, UsageTypeT UT); 38 virtual ~PrimitiveBufferImplT(); 39 40 // Primitives buffer access 41 virtual const void *LockRead() const; 42 virtual void *LockWrite(); 43 virtual void *LockReadWrite(); 44 virtual void Unlock() const; 45 46 // Buffer description 47 virtual unsigned long GetBufferSize() const; 48 virtual unsigned long GetSize() const; 49 virtual void SetSize(unsigned long S); 50 51 virtual IndexTypeT GetIndexType() const; 52 virtual UsageTypeT GetUsage() const; 53 54 // Those are used to synchronize the version in the main memory 55 // with the video card 56 virtual bool IsValid() const; 57 virtual void Validated() const; 58 virtual void Invalidate(); 59 60 virtual void *GetRendererData() const; 61 virtual void SetRendererData(void *Data) const; 62 63 private: 64 IndexTypeT IndexType; 65 UsageTypeT UsageType; 66 mutable bool IsLocked; 67 mutable GLuint BufferObject; 68 unsigned long Size; 69 }; 70 71 #endif -
Libs/MaterialSystem/RendererARBprogs/VertexBufferImpl.cpp
1 #include <GL/gl.h> 2 #include <cassert> 3 #include <stdio.h> 4 #include "../Common/OpenGLEx.hpp" 5 #include "../Common/OpenGLState.hpp" 6 #include "MeshBuffer.hpp" 7 #include "VertexBufferImpl.hpp" 8 9 using namespace MatSys; 10 11 VertexBufferImplT::VertexBufferImplT(const VertexDescriptorT &VertexFormat, UsageTypeT U) 12 : Descriptor(VertexFormat), Usage(U), IsLocked(false), Size(0) 13 { 14 cf::glGenBuffersARB(1, &BufferObject); 15 } 16 17 VertexBufferImplT::~VertexBufferImplT() 18 { 19 MeshBufferManagerT::GetInstance()->DestroyVertexBuffer(this); 20 } 21 22 const VertexDescriptorT &VertexBufferImplT::GetVertexDescriptor() const 23 { 24 return Descriptor; 25 } 26 27 const void *VertexBufferImplT::LockRead() const 28 { 29 assert(!IsLocked); 30 IsLocked = true; 31 32 MeshBufferManagerT::GetInstance()->InvalidateClientState(); 33 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 34 OpenGLState->BindBuffer(GL_ARRAY_BUFFER_ARB, BufferObject); 35 return cf::glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_ONLY_ARB); 36 } 37 38 void *VertexBufferImplT::LockWrite() 39 { 40 assert(!IsLocked); 41 IsLocked = true; 42 43 MeshBufferManagerT::GetInstance()->InvalidateClientState(); 44 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 45 OpenGLState->BindBuffer(GL_ARRAY_BUFFER_ARB, BufferObject); 46 cf::glBufferDataARB(GL_ARRAY_BUFFER_ARB, GetBufferSize(), NULL, 47 MeshBufferManagerT::UsageTypeToOpenGL[Usage]); 48 return cf::glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); 49 } 50 51 void *VertexBufferImplT::LockReadWrite() 52 { 53 assert(!IsLocked); 54 IsLocked = true; 55 56 MeshBufferManagerT::GetInstance()->InvalidateClientState(); 57 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 58 OpenGLState->BindBuffer(GL_ARRAY_BUFFER_ARB, BufferObject); 59 return cf::glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_WRITE_ARB); 60 } 61 62 void VertexBufferImplT::Unlock() const 63 { 64 assert(IsLocked); 65 IsLocked = false; 66 67 MeshBufferManagerT::GetInstance()->InvalidateClientState(); 68 OpenGLStateT *OpenGLState = OpenGLStateT::GetInstance(); 69 OpenGLState->BindBuffer(GL_ARRAY_BUFFER_ARB, BufferObject); 70 cf::glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); 71 } 72 73 unsigned long VertexBufferImplT::GetBufferSize() const 74 { 75 return Size*Descriptor.VertexSize; 76 } 77 78 unsigned long VertexBufferImplT::GetSize() const 79 { 80 return Size; 81 } 82 83 void VertexBufferImplT::SetSize(unsigned long S) 84 { 85 Size = S; 86 } 87 88 VertexBufferI::UsageTypeT VertexBufferImplT::GetUsage() const 89 { 90 return Usage; 91 } 92 93 bool VertexBufferImplT::IsValid() const 94 { 95 return true; // Always valid 96 } 97 98 void VertexBufferImplT::Validated() const 99 { 100 } 101 102 void VertexBufferImplT::Invalidate() 103 { 104 } 105 106 void *VertexBufferImplT::GetRendererData() const 107 { 108 return (void*)((unsigned long)BufferObject); 109 } 110 111 void VertexBufferImplT::SetRendererData(void *data) const 112 { 113 BufferObject = (unsigned long)data; 114 } 115 -
Libs/MaterialSystem/RendererARBprogs/MeshBuffer.hpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /**********************/ 25 /*** MeshBuffer ***/ 26 /**********************/ 27 28 #ifndef _CA_MATSYS_BUFFERMAN_HPP_ 29 #define _CA_MATSYS_BUFFERMAN_HPP_ 30 31 #include <GL/gl.h> 32 #include "../Mesh.hpp" 33 34 class MeshBufferManagerT 35 { 36 public: 37 MeshBufferManagerT(); 38 ~MeshBufferManagerT(); 39 40 // Begin mesh data transfer 41 void BeginDrawing(const MatSys::MeshT &Mesh); 42 43 // Draw the mesh 44 void DrawMesh(); 45 46 // End mesh data transfer 47 void EndDrawing(); 48 49 // Destroys the mesh buffer 50 void DestroyMesh(MatSys::MeshT *mesh); 51 52 // Invalidates the client state 53 void InvalidateClientState(); 54 55 // Destroys the vertex buffer 56 void DestroyVertexBuffer(MatSys::VertexBufferI *Buffer); 57 58 // Destroys the primitive buffer 59 void DestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer); 60 61 // Functions to send mesh data 62 void SendPositions(); 63 void SendPositions4(); 64 void SendNormals(); 65 void SendColors(); 66 void SendTextureCoords(GLenum Unit); 67 void SendLightMapCoords(GLenum Unit); 68 void SendBiNormals(GLenum Unit); 69 void SendTangents(GLenum Unit); 70 71 static MeshBufferManagerT *GetInstance(); 72 static GLenum UsageTypeToOpenGL[3]; 73 static GLenum IndexTypeToOpenGLType[3]; 74 static unsigned long IndexTypeSize[3]; 75 76 private: 77 struct ClientStateT 78 { 79 ClientStateT() 80 : Mesh(NULL), VertexBuffer(NULL), VertexBufferData(NULL), 81 PrimitiveBuffer(NULL), PrimitiveBufferData(NULL), 82 IsEnabled_Positions(false), IsEnabled_Positions4(false), 83 IsEnabled_Colors(false), IsEnabled_Normals(false), UseVBO(false) 84 { 85 for(int i = 0; i < 8; i++) 86 IsEnabled_Texcoords[i] = false; 87 } 88 89 void Clear(); 90 91 const MatSys::MeshT *Mesh; 92 const MatSys::VertexBufferI *VertexBuffer; 93 const void *VertexBufferData; 94 95 const MatSys::PrimitiveBufferI *PrimitiveBuffer; 96 const void *PrimitiveBufferData; 97 98 bool IsEnabled_Positions; 99 bool IsEnabled_Positions4; 100 bool IsEnabled_Colors; 101 bool IsEnabled_Normals; 102 bool IsEnabled_Texcoords[8]; 103 bool UseVBO; 104 }; 105 106 ClientStateT ClientState; 107 bool IsSendingMesh; 108 bool Start; 109 110 void RevalidateVertexBuffer(); 111 void RevalidatePrimitiveBuffer(); 112 void RevalidateBufferObjects(); 113 }; 114 115 116 117 #endif 118 -
Libs/MaterialSystem/RendererARBprogs/RendererImpl.hpp
127 127 void SetCurrentSHLMaps(const ArrayT<MatSys::TextureMapI*>& SHLMaps); 128 128 void SetCurrentSHLLookupMap(MatSys::TextureMapI* SHLLookupMap); 129 129 void RenderMesh(const MatSys::MeshT& Mesh); 130 void OnDestroyMesh(MatSys::MeshT *Mesh); 131 void OnDestroyVertexBuffer(MatSys::VertexBufferI *Buffer); 132 void OnDestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer); 133 MatSys::VertexBufferI *CreateVertexBuffer(const MatSys::VertexDescriptorT &Format, unsigned int Usage); 134 MatSys::PrimitiveBufferI *CreatePrimitiveBuffer(MatSys::PrimitiveBufferI::IndexTypeT IndexType, 135 MatSys::PrimitiveBufferI::UsageTypeT Usage); 130 136 131 132 137 // Internal Interface 133 138 MatSys::RenderMaterialT* GetCurrentRenderMaterial() const; 134 139 TextureMap2DT* GetCurrentLightMap() const; -
Libs/MaterialSystem/VertexBufferImpl.cpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /************************/ 25 /*** VertexBufferImpl ***/ 26 /************************/ 27 28 #include "VertexBufferImpl.hpp" 29 #include "Renderer.hpp" 30 31 namespace MatSys 32 { 33 34 VertexBufferImplT::VertexBufferImplT(const VertexDescriptorT &VertexFormat) 35 : Descriptor(VertexFormat), Size(0), Data(NULL), IsLocked(false), IsValidBuffer(false), RendererData(NULL) 36 { 37 } 38 39 VertexBufferImplT::~VertexBufferImplT() 40 { 41 if(Data) 42 delete [] (unsigned char*)Data; 43 44 if(Renderer && RendererData) 45 Renderer->OnDestroyVertexBuffer(this); 46 } 47 48 // Vertex format descriptor 49 const VertexDescriptorT &VertexBufferImplT::GetVertexDescriptor() const 50 { 51 return Descriptor; 52 } 53 54 // Vertex data access 55 const void *VertexBufferImplT::LockRead() const 56 { 57 assert(!IsLocked); 58 IsLocked = true; 59 return Data; 60 } 61 62 void *VertexBufferImplT::LockWrite() 63 { 64 assert(!IsLocked); 65 IsLocked = true; 66 IsValidBuffer = false; 67 return Data; 68 } 69 70 void *VertexBufferImplT::LockReadWrite() 71 { 72 assert(!IsLocked); 73 IsLocked = true; 74 IsValidBuffer = false; 75 return Data; 76 } 77 78 void VertexBufferImplT::Unlock() const 79 { 80 assert(IsLocked); 81 IsLocked = false; 82 } 83 84 // Number of vertices 85 unsigned long VertexBufferImplT::GetBufferSize() const 86 { 87 return Size*Descriptor.VertexSize; 88 } 89 90 unsigned long VertexBufferImplT::GetSize() const 91 { 92 return Size; 93 } 94 95 void VertexBufferImplT::SetSize(unsigned long S) 96 { 97 if(Size != S) 98 { 99 Size = S; 100 if(Data) 101 delete [] (unsigned char*)Data; 102 Data = new unsigned char[GetBufferSize()]; 103 } 104 } 105 106 VertexBufferI::UsageTypeT VertexBufferImplT::GetUsage() const 107 { 108 return Stream; 109 } 110 111 112 // Those are used to synchronize the version in the main memory 113 // with the video card 114 bool VertexBufferImplT::IsValid() const 115 { 116 return IsValidBuffer; 117 } 118 119 void VertexBufferImplT::Validated() const 120 { 121 IsValidBuffer = true; 122 } 123 124 void VertexBufferImplT::Invalidate() 125 { 126 IsValidBuffer = false; 127 } 128 129 void *VertexBufferImplT::GetRendererData() const 130 { 131 return RendererData; 132 } 133 134 void VertexBufferImplT::SetRendererData(void *RD) const 135 { 136 RendererData = RD; 137 } 138 139 VertexBufferI *CreateVertexBuffer(const VertexDescriptorT &VertexFormat, 140 VertexBufferI::UsageTypeT Usage) 141 { 142 if(MatSys::Renderer && Usage != VertexBufferI::Temporal) 143 { 144 VertexBufferI *Ret = MatSys::Renderer->CreateVertexBuffer(VertexFormat, Usage); 145 if(Ret) 146 return Ret; 147 } 148 return new VertexBufferImplT(VertexFormat); 149 } 150 } 151 -
Libs/MaterialSystem/PrimitiveBufferImpl.hpp
1 /* 2 ================================================================================= 3 This file is part of Cafu, the open-source game and graphics engine for 4 multiplayer, cross-platform, real-time 3D action. 5 $Id$ 6 7 Copyright (C) 2002-2010 Carsten Fuchs Software. 8 9 Cafu is free software: you can redistribute it and/or modify it under the terms 10 of the GNU General Public License as published by the Free Software Foundation, 11 either version 3 of the License, or (at your option) any later version. 12 13 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Cafu. If not, see <http://www.gnu.org/licenses/>. 19 20 For support and more information about Cafu, visit us at <http://www.cafu.de>. 21 ================================================================================= 22 */ 23 24 /************************/ 25 /*** PrimitiveBufferImpl ***/ 26 /************************/ 27 28 #ifndef _CA_MATSYS_PRIMITIVE_BUFFER_IMPLEMENTATION_HPP_ 29 #define _CA_MATSYS_PRIMITIVE_BUFFER_IMPLEMENTATION_HPP_ 30 31 #include "PrimitiveBuffer.hpp" 32 33 namespace MatSys 34 { 35 class PrimitiveBufferImplT: public PrimitiveBufferI 36 { 37 public: 38 PrimitiveBufferImplT(IndexTypeT IT); 39 virtual ~PrimitiveBufferImplT(); 40 41 // Primitives buffer access 42 virtual const void *LockRead() const; 43 virtual void *LockWrite(); 44 virtual void *LockReadWrite(); 45 virtual void Unlock() const; 46 47 // Buffer description 48 virtual unsigned long GetBufferSize() const; 49 virtual unsigned long GetSize() const; 50 virtual void SetSize(unsigned long size); 51 52 virtual IndexTypeT GetIndexType() const; 53 virtual UsageTypeT GetUsage() const; 54 55 // Those are used to synchronize the version in the main memory 56 // with the video card 57 virtual bool IsValid() const; 58 virtual void Validated() const; 59 virtual void Invalidate(); 60 61 virtual void *GetRendererData() const; 62 virtual void SetRendererData(void *Data) const; 63 64 static unsigned long IndexTypeToSize[3]; 65 66 private: 67 IndexTypeT IndexType; 68 mutable bool IsLocked; 69 mutable bool IsValidBuffer; 70 mutable void* RendererData; 71 unsigned long Size; 72 void* Buffer; 73 74 }; 75 }; 76 77 #endif -
Libs/MaterialSystem/Mesh.cpp
25 25 /*** Mesh ***/ 26 26 /************/ 27 27 28 #include "Mesh.hpp" 29 #include "Renderer.hpp" 30 31 namespace MatSys 32 { 33 34 MeshT::~MeshT() 35 { 36 if(Renderer && RendererData) 37 Renderer->OnDestroyMesh(this); 38 if(VertexBuffer && VertexBuffer != this) 39 delete VertexBuffer; 40 if(PrimitiveBuffer) 41 delete PrimitiveBuffer; 42 } 43 44 const VertexDescriptorT &MeshT::GetVertexDescriptor() const 45 { 46 return VertexT::VertexDescriptor; 47 } 48 49 const void *MeshT::LockRead() const 50 { 51 assert(Mutex == false); 52 Mutex = true; 53 return (const void*)&Vertices[0]; 54 } 55 56 void *MeshT::LockWrite() 57 { 58 assert(Mutex == false); 59 IsValidMesh = false; 60 Mutex = true; 61 return (void*)&Vertices[0]; 62 } 63 64 void *MeshT::LockReadWrite() 65 { 66 assert(Mutex == false); 67 IsValidMesh = false; 68 Mutex = true; 69 return (void*)&Vertices[0]; 70 } 71 72 void MeshT::Unlock() const 73 { 74 assert(Mutex); 75 Mutex = false; 76 } 77 78 unsigned long MeshT::GetSize() const 79 { 80 return Vertices.Size(); 81 } 82 83 unsigned long MeshT::GetBufferSize() const 84 { 85 return Vertices.Size()*GetVertexDescriptor().VertexSize; 86 } 87 88 void MeshT::SetSize(unsigned long size) 89 { 90 // Do nothing 91 } 92 93 VertexBufferI::UsageTypeT MeshT::GetUsage() const 94 { 95 return UsageType; 96 } 97 98 bool MeshT::IsValid() const 99 { 100 return IsValidMesh; 101 } 102 103 void MeshT::Validated() const 104 { 105 IsValidMesh = true; 106 } 107 108 void MeshT::Invalidate() 109 { 110 IsValidMesh = false; 111 } 112 113 void *MeshT::GetRendererData() const 114 { 115 return RendererData; 116 } 117 118 void MeshT::SetRendererData(void *data) const 119 { 120 RendererData = data; 121 } 122 }; -
Libs/MaterialSystem/RendererOpenGL12/Shaders/StencilShadowVolumes.cpp
131 131 132 132 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 133 133 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 134 glVertex4 dv(Mesh.Vertices[VertexNr].Origin);134 glVertex4fv(Mesh.Vertices[VertexNr].Origin); 135 135 glEnd(); 136 136 } 137 137 else … … 157 157 158 158 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 159 159 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 160 glVertex4 dv(Mesh.Vertices[VertexNr].Origin);160 glVertex4fv(Mesh.Vertices[VertexNr].Origin); 161 161 glEnd(); 162 162 } 163 163 } -
Libs/MaterialSystem/RendererOpenGL12/Shaders/A_Terrain.cpp
187 187 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 188 188 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 189 189 { 190 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);190 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 191 191 } 192 192 glEnd(); 193 193 … … 224 224 glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 225 225 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 226 226 { 227 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);227 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 228 228 } 229 229 glEnd(); 230 230 } -
Libs/MaterialSystem/RendererOpenGL12/Shaders/A_WaterCubeReflect.cpp
167 167 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 168 168 { 169 169 glTexCoord2f(Mesh.Vertices[VertexNr].TextureCoord[0]+0.6f*CurrentTime, Mesh.Vertices[VertexNr].TextureCoord[1]+0.8f*CurrentTime); 170 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);170 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 171 171 } 172 172 glEnd(); 173 173 } -
Libs/MaterialSystem/RendererOpenGL12/Shaders/A_Diff_Light_Fog.cpp
184 184 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 185 185 cf::glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, Mesh.Vertices[VertexNr].LightMapCoord); 186 186 187 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);187 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 188 188 } 189 189 glEnd(); 190 190 -
Libs/MaterialSystem/RendererOpenGL12/Shaders/A_Diff_nLight_oLuma.cpp
167 167 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 168 168 { 169 169 glTexCoord2fv(Mesh.Vertices[VertexNr].TextureCoord); 170 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);170 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 171 171 } 172 172 glEnd(); 173 173 … … 189 189 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 190 190 { 191 191 glTexCoord2fv(Mesh.Vertices[VertexNr].TextureCoord); 192 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);192 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 193 193 } 194 194 glEnd(); 195 195 } -
Libs/MaterialSystem/RendererOpenGL12/Shaders/A_Solid.cpp
164 164 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 165 165 { 166 166 glColor4f(RedValue*Mesh.Vertices[VertexNr].Color[0], GreenValue*Mesh.Vertices[VertexNr].Color[1], BlueValue*Mesh.Vertices[VertexNr].Color[2], AlphaValue*Mesh.Vertices[VertexNr].Color[3]); 167 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);167 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 168 168 } 169 169 glEnd(); 170 170 } -
Libs/MaterialSystem/RendererOpenGL12/Shaders/A_SkyDome.cpp
172 172 const Vector3fT Dir_w =InPos_w-EyePos_w; 173 173 174 174 glTexCoord3f(Dir_w.x, Dir_w.z, Dir_w.y); 175 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);175 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 176 176 } 177 177 glEnd(); 178 178 } -
Libs/MaterialSystem/RendererOpenGL12/Shaders/A_Diff_Light_oLuma.cpp
174 174 cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 175 175 cf::glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, Mesh.Vertices[VertexNr].LightMapCoord); 176 176 177 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);177 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 178 178 } 179 179 glEnd(); 180 180 … … 200 200 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 201 201 { 202 202 glTexCoord2fv(Mesh.Vertices[VertexNr].TextureCoord); 203 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);203 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 204 204 } 205 205 glEnd(); 206 206 } -
Libs/MaterialSystem/RendererOpenGL12/Shaders/L_Diff_oSpec.cpp
172 172 173 173 glColor3f(Attenuation*DiffuseFactor*LightDiffuseColor[0], Attenuation*DiffuseFactor*LightDiffuseColor[1], Attenuation*DiffuseFactor*LightDiffuseColor[2]); 174 174 glTexCoord2fv(Mesh.Vertices[VertexNr].TextureCoord); 175 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);175 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 176 176 } 177 177 glEnd(); 178 178 … … 215 215 216 216 glColor3f(Attenuation*SpecularFactor*LightSpecularColor[0], Attenuation*SpecularFactor*LightSpecularColor[1], Attenuation*SpecularFactor*LightSpecularColor[2]); 217 217 glTexCoord2fv(Mesh.Vertices[VertexNr].TextureCoord); 218 glVertex3 dv(Mesh.Vertices[VertexNr].Origin);218 glVertex3fv(Mesh.Vertices[VertexNr].Origin); 219 219 } 220 220 glEnd(); 221 221 } -
Libs/MaterialSystem/RendererOpenGL12/RendererImpl.cpp
855 855 CurrentShader->RenderMesh(Mesh); 856 856 } 857 857 858 void RendererImplT::OnDestroyMesh(MatSys::MeshT *Mesh) 859 { 860 } 858 861 862 void RendererImplT::OnDestroyVertexBuffer(MatSys::VertexBufferI *Buffer) 863 { 864 } 865 866 void RendererImplT::OnDestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer) 867 { 868 } 869 870 VertexBufferI *RendererImplT::CreateVertexBuffer(const VertexDescriptorT &Format, unsigned int Usage) 871 { 872 return NULL; 873 } 874 875 PrimitiveBufferI *RendererImplT::CreatePrimitiveBuffer(PrimitiveBufferI::IndexTypeT IndexType, PrimitiveBufferI::UsageTypeT Usage) 876 { 877 return NULL; 878 } 879 859 880 RenderMaterialT* RendererImplT::GetCurrentRenderMaterial() const 860 881 { 861 882 return CurrentRenderMaterial; -
Libs/MaterialSystem/RendererOpenGL12/RendererImpl.hpp
128 128 void SetCurrentSHLMaps(const ArrayT<MatSys::TextureMapI*>& SHLMaps); 129 129 void SetCurrentSHLLookupMap(MatSys::TextureMapI* SHLLookupMap); 130 130 void RenderMesh(const MatSys::MeshT& Mesh); 131 void OnDestroyMesh(MatSys::MeshT *Mesh); 132 void OnDestroyVertexBuffer(MatSys::VertexBufferI *Buffer); 133 void OnDestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer); 134 MatSys::VertexBufferI *CreateVertexBuffer(const MatSys::VertexDescriptorT &Format, unsigned int Usage); 135 MatSys::PrimitiveBufferI *CreatePrimitiveBuffer(MatSys::PrimitiveBufferI::IndexTypeT IndexType, 136 MatSys::PrimitiveBufferI::UsageTypeT Usage); 131 137 132 133 138 // Internal interface. 134 139 MatSys::RenderMaterialT* GetCurrentRenderMaterial() const; 135 140 TextureMap2DT* GetCurrentLightMap() const; -
Libs/SConscript
59 59 env.StaticLibrary( 60 60 target="MatSys", 61 61 source=Split("""MaterialSystem/Expression.cpp MaterialSystem/MapComposition.cpp MaterialSystem/Material.cpp MaterialSystem/MaterialManager.cpp 62 MaterialSystem/MaterialManagerImpl.cpp MaterialSystem/Renderer.cpp MaterialSystem/TextureMap.cpp""")) 62 MaterialSystem/MaterialManagerImpl.cpp MaterialSystem/Renderer.cpp MaterialSystem/TextureMap.cpp 63 MaterialSystem/Mesh.cpp MaterialSystem/VertexFormats.cpp MaterialSystem/VertexBufferImpl.cpp 64 MaterialSystem/PrimitiveBufferImpl.cpp""")) 63 65 64 66 65 67 … … 73 75 target="SceneGraph", 74 76 source=Split("""SceneGraph/_aux.cpp SceneGraph/BezierPatchNode.cpp SceneGraph/BspTreeNode.cpp SceneGraph/FaceNode.cpp 75 77 SceneGraph/LightMapMan.cpp SceneGraph/Node.cpp SceneGraph/SHLMapMan.cpp SceneGraph/TerrainNode.cpp 76 SceneGraph/PlantNode.cpp SceneGraph/ModelNode.cpp """))78 SceneGraph/PlantNode.cpp SceneGraph/ModelNode.cpp SceneGraph/FaceBatchesNode.cpp""")) 77 79 78 80 79 81 … … 95 97 target="MaterialSystem/RendererARBprogs", 96 98 source=[os.path.join("MaterialSystem/RendererARBprogs", x) for x in Split(""" 97 99 RendererARBprogs.cpp RendererImpl.cpp RenderMaterial.cpp Shader.cpp TextureMapImpl.cpp 100 MeshBuffer.cpp VertexBufferImpl.cpp PrimitiveBufferImpl.cpp 98 101 99 102 Shaders/A_Terrain.cpp Shaders/A_Diff.cpp Shaders/A_Diff_Luma.cpp Shaders/A_Diff_Norm.cpp Shaders/A_Diff_Norm_Luma.cpp 100 103 Shaders/A_Diff_Light.cpp Shaders/A_Diff_Light_Luma.cpp Shaders/A_Diff_Light_Norm.cpp Shaders/A_Diff_Light_Norm_Spec.cpp -
Libs/ParticleEngine/ParticleEngineMS.cpp
235 235 ParticleGroupMesh.Vertices[3].SetOrigin(Particle->Origin[0]-BillBoardVecX[0]-BillBoardVecY[0], 236 236 Particle->Origin[1]-BillBoardVecX[1]-BillBoardVecY[1], 237 237 Particle->Origin[2]-BillBoardVecX[2]-BillBoardVecY[2]); 238 ParticleGroupMesh.Invalidate(); 238 239 239 240 // Warning: This testing code requires "twoSided" materials! 240 241 // ParticleGroupMesh.Vertices[4*ParticleNr+0].SetOrigin(Particle->Origin[0]-300.0, Particle->Origin[1], Particle->Origin[2]+300.0); -
Libs/Fonts/FontTT.cpp
276 276 GlyphMesh.Vertices[2].SetOrigin(x2, y2); GlyphMesh.Vertices[2].SetTextureCoord(gi.s2, gi.t2); 277 277 GlyphMesh.Vertices[3].SetOrigin(x1, y2); GlyphMesh.Vertices[3].SetTextureCoord(gi.s1, gi.t2); 278 278 279 GlyphMesh.Invalidate(); 279 280 MatSys::Renderer->SetCurrentMaterial(gi.RM); 280 281 MatSys::Renderer->RenderMesh(GlyphMesh); 281 282 -
Libs/Fonts/Font.cpp
138 138 TextMesh.Vertices[4*c+3].SetOrigin( 0+c*10, 16); TextMesh.Vertices[4*c+3].SetTextureCoord(CoordX , CoordY+Size); 139 139 } 140 140 141 TextMesh.Invalidate(); 141 142 MatSys::Renderer->RenderMesh(TextMesh); 142 143 } 143 144
