Ticket #31: vbo.diff

File vbo.diff, 208.2 KB (added by ronsaldo, 22 months ago)

Vertex Buffer Object implementation proposal.

  • CaWE/MapBezierPatch.hpp

     
    180180    unsigned long       GetWidth()        const { return cv_Width; } 
    181181    unsigned long       GetHeight()       const { return cv_Height; } 
    182182    // 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->Meshes.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; } 
    185185 
    186186    // Get the origin of vertice x/y from the rendermesh 
    187187    Vector3fT           GetRenderVertexPos(unsigned long x, unsigned long y) const; 
  • CaWE/Renderer3D.cpp

     
    194194            Mesh.Vertices[2].SetOrigin(V3); Mesh.Vertices[2].SetColor(rSh, gSh, bSh); 
    195195            Mesh.Vertices[3].SetOrigin(V4); Mesh.Vertices[3].SetColor(rSh, gSh, bSh); 
    196196 
     197            Mesh.Invalidate(); 
    197198            MatSys::Renderer->SetCurrentMaterial(GetRMatFlatShaded()); 
    198199            MatSys::Renderer->RenderMesh(Mesh); 
    199200        } 
     
    295296        // mesh, or else the depth offset won't work right (they are probably differently rasterized). 
    296297        MatSys::MeshT Mesh(Pass==1 ? MatSys::MeshT::Polygon : MatSys::MeshT::TriangleFan); 
    297298        Mesh.Vertices.PushBackEmpty(4); 
     299        Mesh.Invalidate(); 
    298300 
    299301        float color[3]={ 0.0f, 0.0f, 0.0f }; 
    300302        color[Depth % 3]=(Pass==1) ? 1.0f : 0.4f; 
     
    338340    Mesh.Vertices[5].SetColor(0, 0, 1); 
    339341    Mesh.Vertices[5].SetOrigin(Pos + Vector3fT(Mat[0][2], Mat[1][2], Mat[2][2])*Length); 
    340342 
     343    Mesh.Invalidate(); 
    341344    MatSys::Renderer->SetCurrentMaterial(GetRMatWireframe()); 
    342345    MatSys::Renderer->RenderMesh(Mesh); 
    343346} 
     
    370373    Mesh.Vertices[10].SetOrigin(Center.x, Center.y-RADIUS-1, 0); Mesh.Vertices[10].SetColor(1, 1, 1); 
    371374    Mesh.Vertices[11].SetOrigin(Center.x, Center.y+RADIUS,   0); Mesh.Vertices[11].SetColor(1, 1, 1); 
    372375 
     376    Mesh.Invalidate(); 
    373377    MatSys::Renderer->SetCurrentMaterial(GetRMatWireframe()); 
    374378    MatSys::Renderer->RenderMesh(Mesh); 
    375379} 
  • CaWE/MapFace.cpp

     
    177177    Mesh.Type=(MatSys::Renderer->GetMaterialFromRM(RenderMat)->PolygonMode==MaterialT::Filled) ? MatSys::MeshT::TriangleFan : MatSys::MeshT::Polygon; 
    178178    Mesh.Vertices.Overwrite(); 
    179179    Mesh.Vertices.PushBackEmpty(m_Vertices.Size()); 
     180    Mesh.Invalidate(); 
    180181 
    181182    for (unsigned long VertexNr=0; VertexNr<m_Vertices.Size(); VertexNr++) 
    182183    { 
  • CaWE/MapBezierPatch.cpp

     
    11761176 
    11771177Vector3fT MapBezierPatchT::GetRenderVertexPos(unsigned long x, unsigned long y) const 
    11781178{ 
    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); 
    11801182    assert(x<=BPRenderMesh->Meshes.Size()); 
    11811183    assert(y<BPRenderMesh->Meshes[0]->Vertices.Size()/2); 
    11821184 
     
    11911193    VertexPos.y=BPRenderMesh->Meshes[x-c]->Vertices[2*y+c].Origin[1]; 
    11921194    VertexPos.z=BPRenderMesh->Meshes[x-c]->Vertices[2*y+c].Origin[2]; 
    11931195 
    1194     return VertexPos; 
     1196    return VertexPos;*/ 
    11951197} 
  • CaWE/MapTerrain.cpp

     
    196196 
    197197    // Finally, draw the terrain. 
    198198    m_TerrainMesh.Vertices.Overwrite(); 
     199    m_TerrainMesh.Invalidate(); 
    199200 
    200201#if 1 
    201202    const ArrayT<Vector3fT>& VectorStrip=GetTerrain().ComputeVectorStrip(VI); 
     
    636637 
    637638void MapTerrainT::TrafoMirror(unsigned int NormalAxis, float Dist) 
    638639{ 
     640 
    639641    Vector3fT Min=m_TerrainBounds.Min; 
    640642    Vector3fT Max=m_TerrainBounds.Max; 
    641643 
  • SConscript

     
    5353    # envTools.Append(LINKFLAGS = ['-Wl,--export-dynamic'])     # Not needed any more, .so libs now link to the required .a libs directly, just as under Windows. 
    5454    # GLU is needed for the TerrainViewerOld *and* for e.g. gluBuild2DMipmaps() in the renderers... 
    5555    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") 
    5757                       + Split("GL GLU")) 
    5858 
    5959envTools.Program('CaSanity', ['CaTools/CaSanity.cpp'] + CommonWorldObject) 
     
    9797    # -Wl,-rpath,.           is so that also the . directory is searched for dynamic libraries when they're opened. 
    9898    # -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. 
    9999    envCafu.Append(LINKFLAGS = ['-Wl,-rpath,.', '-Wl,--export-dynamic']) 
    100     envCafu.Append(LIBS=Split("MatSys SoundSys SceneGraph cfsLib 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")) 
    101101    # We need GLU for e.g. gluBuild2DMipmaps() in the renderers. 
    102102    # pthread is needed because some libraries that we load (possibly indirectly), e.g. the libCg.so and libopenal.so, use functions 
    103103    # 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 
     10using namespace cf::SceneGraph; 
     11 
     12FaceBatchesNodeT::FaceBatchesNodeT(LightMapManT& LMM) 
     13    : LightMapMan(LMM), ShadowVolumeMesh(MatSys::MeshT::Triangles, MatSys::MeshT::CCW), IsStencilShadowsValid(false) 
     14{ 
     15    ShadowVolumeMesh.VertexBuffer = NULL; 
     16} 
     17 
     18FaceBatchesNodeT::~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 
     36void 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 
     62void 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 
     71void 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 
     92void 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 
     115void FaceBatchesNodeT::Reset() 
     116{ 
     117    NewOpaqueFaces.Overwrite(); 
     118    NewTranslucentFaces.Overwrite(); 
     119} 
     120 
     121void FaceBatchesNodeT::AppendOpaqueFace(const FaceNodeT *Face) 
     122{ 
     123    assert(Face); 
     124    NewOpaqueFaces.PushBack(Face); 
     125} 
     126 
     127void FaceBatchesNodeT::AppendTranslucentFace(const FaceNodeT *Face) 
     128{ 
     129    assert(Face); 
     130    NewTranslucentFaces.PushBack(Face); 
     131} 
     132 
     133void FaceBatchesNodeT::InitLight() 
     134{ 
     135    ShadowFaces.Overwrite(); 
     136    LightMaterials.clear(); 
     137    IsStencilShadowsValid = false; 
     138} 
     139 
     140void 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 
     148void FaceBatchesNodeT::AppendBackFace(const FaceNodeT *Face) 
     149{ 
     150    assert(Face); 
     151    ShadowFaces.PushBack(Face); 
     152} 
     153 
     154bool 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 
     284inline 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 
     296void 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 
     322void 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 
     384FaceBatchesNodeT::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 
     472MatSys::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================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     33namespace MatSys 
     34{ 
     35    class RenderMaterialT; 
     36} 
     37 
     38class  MaterialT; 
     39 
     40namespace 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

     
    242242    // ********************** 
    243243 
    244244    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(); 
    246248 
    247249    for (unsigned long VertexNr=0; VertexNr<DrawIndices.Size(); VertexNr++) 
    248250    { 
    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; 
    258254    } 
    259255 
    260256 
     
    299295        const double s=dot(SharedVertices[DrawIndices[VertexNr]], TI_U)/(LengthU*LengthU)+TI.OffsetU-SmallestS; 
    300296        const double t=dot(SharedVertices[DrawIndices[VertexNr]], TI_V)/(LengthV*LengthV)+TI.OffsetV-SmallestT; 
    301297 
    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); 
    304300    } 
    305301 
    306302 
     
    347343        const double s=((dot(SharedVertices[DrawIndices[VertexNr]], U)-SmallestU)/LightMapInfoT::PatchSize+1.0+PosS)/double(cf::SceneGraph::LightMapManT::SIZE_S); 
    348344        const double t=((dot(SharedVertices[DrawIndices[VertexNr]], V)-SmallestV)/LightMapInfoT::PatchSize+1.0+PosT)/double(cf::SceneGraph::LightMapManT::SIZE_T); 
    349345 
    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); 
    352348    } 
    353349 
    354350#if SHL_ENABLED 
     
    363359        const double s=(dot(SharedVertices[DrawIndices[VertexNr]], U)/SHLMapInfoT::PatchSize-floor(SmallestU/SHLMapInfoT::PatchSize)+1.0+PosS)/double(cf::SceneGraph::SHLMapManT::SIZE_S); 
    364360        const double t=(dot(SharedVertices[DrawIndices[VertexNr]], V)/SHLMapInfoT::PatchSize-floor(SmallestV/SHLMapInfoT::PatchSize)+1.0+PosT)/double(cf::SceneGraph::SHLMapManT::SIZE_T); 
    365361 
    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); 
    368364    } 
    369365#endif 
    370366 
     
    381377    const VectorT  TexU     =TI.U.AsVectorOfDouble(); 
    382378    const VectorT  TexV     =TI.V.AsVectorOfDouble(); 
    383379 
    384     // Note that 
     380    // Note thatif(!Mesh.VertexBuffer) 
    385381    // a) our intention here is to compute the proper coordinate axes of the texture-space, 
    386382    // b) the above used 'U' and 'V' span vectors are absolutely useless for this purpose (they are entirely arbitrary and unrelated), and 
    387383    // c) the 'TexU' and 'TexV' vectors (together with 'TexNormal') are not correct either. 
     
    415411    // Fill-in the 'NormalXYZ', 'TangentXYZ', and 'BiNormalXYZ' components of the 'FaceVertexInfos', taking SmoothGroups into account. 
    416412    for (unsigned long VertexNr=0; VertexNr<DrawIndices.Size(); VertexNr++) 
    417413    { 
    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()); 
    421417    } 
    422418 
    423419 
     
    426422    // *********************** 
    427423 
    428424    RenderMat=MatSys::Renderer->RegisterMaterial(Material); 
     425    Mesh.VertexBuffer->Unlock(); 
    429426} 
    430427 
    431428 
     
    487484} 
    488485 
    489486 
     487const MatSys::MeshT &FaceNodeT::GetFaceMesh() const 
     488{ 
     489    return Mesh; 
     490} 
     491 
    490492void FaceNodeT::WriteTo(std::ostream& OutFile, aux::PoolT& Pool) const 
    491493{ 
    492494    aux::Write(OutFile, "Face"); 
     
    605607    assert(MatSys::Renderer!=NULL); 
    606608    assert(MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::STENCILSHADOW); 
    607609 
     610    if(!Mesh.VertexBuffer) 
     611        return; 
     612 
     613    VertexT *Vertices = (VertexT*)Mesh.VertexBuffer->LockRead(); 
     614    unsigned long NrOfVertices = Mesh.VertexBuffer->GetSize(); 
     615 
    608616    // Render the silhouette quads. 
    609617    static MatSys::MeshT SilhouetteMesh(MatSys::MeshT::QuadStrip, MatSys::MeshT::CCW); 
    610618    SilhouetteMesh.Vertices.Overwrite(); 
    611     SilhouetteMesh.Vertices.PushBackEmpty(2*Mesh.Vertices.Size()+2); 
     619    SilhouetteMesh.Vertices.PushBackEmpty(2*NrOfVertices+2); 
     620    SilhouetteMesh.Invalidate(); 
    612621 
    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]); 
    614623    const VectorT LA0=A0-LightPos; 
    615624 
    616625    // Note that the order is reversed because we're dealing with a back-facing polygon as occluder! 
    617626    SilhouetteMesh.Vertices[0].SetOrigin(LA0.x, LA0.y, LA0.z, 0.0); 
    618627    SilhouetteMesh.Vertices[1].SetOrigin( A0.x,  A0.y,  A0.z, 1.0); 
    619628 
    620     for (unsigned long VertexNr=1; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
     629    for (unsigned long VertexNr=1; VertexNr<NrOfVertices; VertexNr++) 
    621630    { 
    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]); 
    623632        const VectorT LA=A-LightPos; 
    624633 
    625634        // Note that the order is reversed because we're dealing with a back-facing polygon as occluder! 
     
    627636        SilhouetteMesh.Vertices[VertexNr*2+1].SetOrigin( A.x,  A.y,  A.z, 1.0); 
    628637    } 
    629638 
    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); 
    632641 
    633642    MatSys::Renderer->RenderMesh(SilhouetteMesh); 
    634643 
     
    639648    //  we have to reverse the order of its vertices in order to turn it into a CCW ordered, front-facing polygon.) 
    640649    static MatSys::MeshT M_front(MatSys::MeshT::TriangleFan, MatSys::MeshT::CCW); 
    641650    M_front.Vertices.Overwrite(); 
    642     M_front.Vertices.PushBackEmpty(Mesh.Vertices.Size()); 
     651    M_front.Vertices.PushBackEmpty(NrOfVertices); 
     652    M_front.Invalidate(); 
    643653 
    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); 
    648658 
    649659    // What a pity the order isn't the other way round. Could then simply write:  MatSys::Renderer->RenderMesh(Mesh); 
    650660    MatSys::Renderer->RenderMesh(M_front); 
     
    655665    // we just have to project them to infinity as seen from the light source. 
    656666    static MatSys::MeshT M_back(MatSys::MeshT::TriangleFan, MatSys::MeshT::CCW); 
    657667    M_back.Vertices.Overwrite(); 
    658     M_back.Vertices.PushBackEmpty(Mesh.Vertices.Size()); 
     668    M_back.Vertices.PushBackEmpty(NrOfVertices); 
     669    M_back.Invalidate(); 
    659670 
    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); 
    664675 
    665676    MatSys::Renderer->RenderMesh(M_back); 
     677    Mesh.VertexBuffer->Unlock(); 
    666678} 
    667679 
    668680 
  • Libs/SceneGraph/BezierPatchNode.cpp

     
    5454      Material(NULL), 
    5555      LightMapInfo(), 
    5656      LightMapMan(LMM), 
    57       RenderMaterial(NULL) 
     57      Mesh(MatSys::MeshT::TriangleStrip), 
     58      RenderMaterial(NULL), 
     59      MeshWidth(1), 
     60      MeshHeight(1) 
    5861{ 
     62    Mesh.VertexBuffer = NULL; 
    5963    Init(); 
    6064} 
    6165 
     
    7175      Material(Material_), 
    7276      LightMapInfo(), 
    7377      LightMapMan(LMM), 
    74       RenderMaterial(NULL) 
     78      Mesh(MatSys::MeshT::TriangleStrip), 
     79      RenderMaterial(NULL), 
     80      MeshWidth(1), 
     81      MeshHeight(1) 
    7582{ 
    7683    for (unsigned long ComponentNr=0; ComponentNr<ControlPoints_.Size(); ComponentNr+=5) 
    7784    { 
     
    7986        ControlPointsUV .PushBack(Vector3fT(ControlPoints_[ComponentNr+3], ControlPoints_[ComponentNr+4], 0.0f)); 
    8087    } 
    8188 
     89    Mesh.VertexBuffer = NULL; 
    8290    Init(); 
    8391} 
    8492 
     
    94102      Material(Material_), 
    95103      LightMapInfo(), 
    96104      LightMapMan(LMM), 
    97       RenderMaterial(NULL) 
     105      Mesh(MatSys::MeshT::TriangleStrip), 
     106      RenderMaterial(NULL), 
     107      MeshWidth(1), 
     108      MeshHeight(1) 
    98109{ 
     110    Mesh.VertexBuffer = NULL; 
    99111    Init(); 
    100112} 
    101113 
     
    272284    // cLOD Überlegungen sind denkbar - siehe "r_lodCurveError" convar im Q3 Quellcode. 
    273285    // Siehe http://xreal.sourceforge.net/xrealwiki/XMapExplanations 
    274286    // 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); 
    277288 
    278289#if 0 
    279290    // Render the tangent-space axes (for debugging). 
     
    322333    assert(MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::LIGHTING); 
    323334 
    324335    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); 
    328337} 
    329338 
    330339 
     
    339348 
    340349void BezierPatchNodeT::UpdateMeshColor(const float red, const float green, const float blue, const float alpha) 
    341350{ 
    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++) 
    343357    { 
    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; 
    352362    } 
     363    Mesh.VertexBuffer->Unlock(); 
    353364} 
    354365 
    355366 
     
    440451    PatchMesh.Height=PatchMesh.WrapsVert ? LightMapInfo.SizeT-1 : LightMapInfo.SizeT; 
    441452    PatchMesh.Patches.PushBackEmpty(PatchMesh.Width*PatchMesh.Height); 
    442453 
     454 
     455 
     456 
     457 
    443458    PatchMesh.Node    =this; 
    444459    PatchMesh.Material=Material; 
    445460 
     
    685700} 
    686701 
    687702 
    688 static void AssignMatSysFromBezierPatchVertex(MatSys::MeshT::VertexT& msV, const cf::math::BezierPatchT<float>::VertexT& bpV) 
     703static void AssignMatSysFromBezierPatchVertex(cf::SceneGraph::BezierPatchNodeT::VertexT& msV, const cf::math::BezierPatchT<float>::VertexT& bpV) 
    689704{ 
    690705    msV.SetOrigin       (bpV.Coord); 
    691706    msV.SetColor        (0.0, 1.0, 1.0);    // For debugging materials that use "useMeshColors". 
     
    733748    GenerateLightMapMesh(CurveMesh, true); 
    734749#endif 
    735750 
    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 
    737765    for (unsigned long ColumnNr=0; ColumnNr+1<CurveMesh.Width; ColumnNr++) 
    738766    { 
    739767        // 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)); 
    743770        for (unsigned long RowNr=0; RowNr<CurveMesh.Height; RowNr++) 
    744771        { 
    745             MatSys::MeshT::VertexT& Left =Meshes[ColumnNr]->Vertices[RowNr*2+0]; 
     772            VertexT& Left =Vertices[Pos + RowNr*2+0]; 
    746773 
    747774            AssignMatSysFromBezierPatchVertex(Left, CurveMesh.GetVertex(ColumnNr, RowNr)); 
    748775 
     
    750777            const float LeftLmT=(float(LightMapInfo.PosT)+0.5f + (float(RowNr   )/(CurveMesh.Height-1))*(LightMapInfo.SizeT-1)) / cf::SceneGraph::LightMapManT::SIZE_T; 
    751778 
    752779            Left.SetLightMapCoord(LeftLmS, LeftLmT); 
     780#if SHL_ENABLED 
    753781            Left.SetSHLMapCoord  (LeftLmS, LeftLmT); 
     782#endif 
    754783 
     784            VertexT& Right=Vertices[Pos + RowNr*2+1]; 
    755785 
    756             MatSys::MeshT::VertexT& Right=Meshes[ColumnNr]->Vertices[RowNr*2+1]; 
    757  
    758786            AssignMatSysFromBezierPatchVertex(Right, CurveMesh.GetVertex(ColumnNr+1, RowNr)); 
    759787 
    760788            const float RightLmS=(float(LightMapInfo.PosS)+0.5f + (float(ColumnNr+1)/(CurveMesh.Width -1))*(LightMapInfo.SizeS-1)) / cf::SceneGraph::LightMapManT::SIZE_S; 
    761789            const float RightLmT=LeftLmT; 
    762790 
    763791            Right.SetLightMapCoord(RightLmS, RightLmT); 
     792#if SHL_ENABLED 
    764793            Right.SetSHLMapCoord  (RightLmS, RightLmT); 
     794#endif 
    765795        } 
    766796    } 
     797 
     798    Mesh.VertexBuffer->Unlock(); 
    767799#else 
    768800    /*** OLD METHOD ***/ 
    769801 
     
    886918                    } 
    887919 
    888920                    if (AbsIndexX<TotalNrOfTriangleColumns) 
     921 
    889922                    { 
    890923                        MatSys::MeshT::VertexT& V=Meshes[AbsIndexX]->Vertices[AbsIndexY*2]; 
    891924 
     
    912945 
    913946void BezierPatchNodeT::Clean() 
    914947{ 
    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    } 
    917954 
    918955    if (RenderMaterial!=NULL) 
    919956    { 
  • Libs/SceneGraph/FaceNode.hpp

     
    4444        class FaceNodeT : public GenericNodeT 
    4545        { 
    4646            public: 
     47            typedef MatSys::StaticVertexT VertexT; 
    4748 
    4849            struct TexInfoT 
    4950            { 
     
    123124            void CreatePatchMeshes(ArrayT<PatchMeshT>& PatchMeshes, ArrayT< ArrayT< ArrayT<Vector3dT> > >& SampleCoords) const; 
    124125            void BackToLightMap(const PatchMeshT& PatchMesh); 
    125126 
     127            /// Returns the face mesh. For FaceBatchesNode 
     128            const MatSys::MeshT &GetFaceMesh() const; 
    126129 
    127130            // TODO: The stuff below should actually be protected or private rather than public. 
    128131            // 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

     
    2424#include "BspTreeNode.hpp" 
    2525#include "_aux.hpp" 
    2626#include "FaceNode.hpp" 
     27#include "FaceBatchesNode.hpp" 
    2728#include "ConsoleCommands/ConVar.hpp" 
    2829#include "MaterialSystem/Material.hpp" 
    2930#include "MaterialSystem/Renderer.hpp" 
     
    3940BspTreeNodeT::BspTreeNodeT() 
    4041    : NextLightNeedsInit(true) 
    4142{ 
     43    FaceBatches = NULL; 
    4244} 
    4345 
    4446 
     
    4648    LightMapManT& LMM, SHLMapManT& SMM, PlantDescrManT& PDM, const ArrayT<const TerrainT*>& ShTe) 
    4749{ 
    4850    BspTreeNodeT* BspTree=new BspTreeNodeT(); 
     51    BspTree->FaceBatches = new FaceBatchesNodeT(LMM); 
    4952 
    5053    // Read the FaceChildren. 
    5154    for (unsigned long Count=aux::ReadUInt32(InFile); Count>0; Count--) 
     
    154157 
    155158    for (unsigned long ChildNr=0; ChildNr<OtherChildren.Size(); ChildNr++) 
    156159        delete OtherChildren[ChildNr]; 
     160 
     161    if(FaceBatches) 
     162        delete FaceBatches; 
    157163} 
    158164 
    159165 
     
    315321    // b) Eine Liste der relevanten, translucent Faces, die anschließend back-to-front gezeichnet werden (für korrektes Blending). 
    316322    BackToFrontListOpaque.Overwrite(); 
    317323    BackToFrontListTranslucent.Overwrite(); 
     324    if(FaceBatches) 
     325        FaceBatches->Reset(); 
    318326 
    319327    for (unsigned long OrderNr=0; OrderNr<OrderedLeaves.Size(); OrderNr++) 
    320328    { 
     
    336344 
    337345            FaceChildIsInViewerPVS[ChildNr]=true; 
    338346 
    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            } 
    341357        } 
    342358 
    343359        // Sort the "regular" children more in front than the faces - it likely gives a better overall back-to-front order. 
     
    362378        } 
    363379    } 
    364380 
     381    if(FaceBatches) 
     382    { 
     383        FaceBatches->Finish(); 
     384        FaceBatches->DrawAmbientContrib(ViewerPos); 
     385    } 
    365386 
    366387    for (unsigned long Count=BackToFrontListOpaque.Size(); Count>0;) 
    367388    { 
     
    393414    FrontFacingList.Overwrite(); 
    394415    BackFacingList.Overwrite(); 
    395416 
     417    if(FaceBatches) 
     418        FaceBatches->InitLight(); 
     419 
    396420    for (unsigned long LeafNr=0; LeafNr<Leaves.Size(); LeafNr++) 
    397421    { 
    398422        const LeafT& L=Leaves[LeafNr]; 
     
    429453             // if (FaceNode->TI.Alpha!=255) continue;                      // Only fully opaque surfaces receive light (even if FLAG_ISWATER is set). 
    430454             // if (FaceNode->Material->NoDynLight) continue;               // [This is not really needed here, just for symmetry. This is no meta keyword as NoShadows should be.] 
    431455 
    432                 FrontFacingList.PushBack(FaceNode); 
     456                if(FaceBatches) 
     457                    FaceBatches->AppendFrontFace(FaceNode); 
     458                else 
     459                    FrontFacingList.PushBack(FaceNode); 
    433460            } 
    434461            else 
    435462            { 
    436463                // Back-facing face wrt. the light (SHADOW CASTER). 
    437464                if (FaceNode->Material->NoShadows) continue;                // Faces with materials that have NoShadows set don't cast shadows. 
    438465 
    439                 BackFacingList.PushBack(FaceNode); 
     466                if(FaceBatches) 
     467                    FaceBatches->AppendBackFace(FaceNode); 
     468                else 
     469                    BackFacingList.PushBack(FaceNode); 
    440470            } 
    441471        } 
    442472 
     
    475505 
    476506    if (NextLightNeedsInit) InitForNextLight(); 
    477507 
     508    if(FaceBatches) 
     509       FaceBatches->DrawStencilShadowVolumes(LightPos, LightRadius); 
     510 
    478511    for (unsigned long Count=0; Count<BackFacingList.Size(); Count++) 
    479512        BackFacingList[Count]->DrawStencilShadowVolumes(LightPos, LightRadius); 
    480513} 
     
    487520 
    488521    if (NextLightNeedsInit) InitForNextLight(); 
    489522 
     523    if(FaceBatches) 
     524        FaceBatches->DrawLightSourceContrib(ViewerPos, LightPos); 
     525 
    490526    for (unsigned long Count=0; Count<FrontFacingList.Size(); Count++) 
    491527        FrontFacingList[Count]->DrawLightSourceContrib(ViewerPos, LightPos); 
    492528 
     
    499535    assert(MatSys::Renderer!=NULL); 
    500536    assert(MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::AMBIENT); 
    501537 
     538    if(FaceBatches) 
     539        FaceBatches->DrawTranslucentContrib(ViewerPos); 
     540 
    502541    // Render translucent nodes back-to-front. 
    503542    for (unsigned long Count=0; Count<BackToFrontListTranslucent.Size(); Count++) 
    504543        BackToFrontListTranslucent[Count]->DrawTranslucentContrib(ViewerPos); 
     
    589628        VB_Trace3T<double> OtherChildrenTrace(1.0); 
    590629 
    591630        for (unsigned long SetNr=0; SetNr<Leaf.OtherChildrenSet.Size(); SetNr++) 
     631 
     632 
    592633        { 
    593634            const unsigned long ChildNr=Leaf.OtherChildrenSet[SetNr]; 
    594635 
  • Libs/SceneGraph/TerrainNode.cpp

     
    212212    static MatSys::MeshT TerrainMesh(MatSys::MeshT::TriangleStrip); 
    213213    TerrainMesh.Vertices.Overwrite(); 
    214214    TerrainMesh.Vertices.PushBackEmpty(VectorStrip.Size()); 
     215    TerrainMesh.Invalidate(); 
    215216 
    216217    for (unsigned long VNr=0; VNr<VectorStrip.Size(); VNr++) 
    217218        TerrainMesh.Vertices[VNr].SetOrigin(VectorStrip[VNr]); 
  • Libs/SceneGraph/BezierPatchNode.hpp

     
    2525#define _CF_SCENEGRAPH_BEZIERPATCHNODE_HPP_ 
    2626 
    2727#include "Node.hpp" 
     28#include "MaterialSystem/Mesh.hpp" 
    2829 
    29  
    3030class MapBezierPatchT; 
    3131 
    3232namespace MatSys 
    3333{ 
    34     class MeshT; 
    3534    class RenderMaterialT; 
    3635} 
    3736 
     
    5251 
    5352 
    5453            public: 
     54            typedef MatSys::StaticVertexColorT VertexT; 
    5555 
    5656            /// The constructor for creating an "empty" bezier patch. 
    5757            /// Needed e.g. by the named constructor CreateFromFile_cw() below. 
     
    9191 
    9292 
    9393            private: 
    94  
    9594            struct LightMapInfoT 
    9695            { 
    9796                unsigned short LightMapNr;  ///< In welcher LightMap liegt unsere Teil-LightMap? 
     
    136135            // Additional information for an entire patch (not only a 3x3 sub-patch). 
    137136            LightMapManT&            LightMapMan; 
    138137            BoundingBox3T<double>    BB;        ///< The BB of this bezier patch. 
    139             ArrayT<MatSys::MeshT*>   Meshes; 
     138            MatSys::MeshT            Mesh; 
    140139            MatSys::RenderMaterialT* RenderMaterial; 
     140            unsigned long            MeshWidth; 
     141            unsigned long            MeshHeight; 
    141142        }; 
    142143    } 
    143144} 
  • Libs/SceneGraph/BspTreeNode.hpp

     
    4040    namespace SceneGraph 
    4141    { 
    4242        class FaceNodeT; 
     43        class FaceBatchesNodeT; 
    4344 
    4445 
    4546        /// The class represents a BSP Tree node, implementing the Composite design pattern. 
     
    172173            mutable ArrayT<cf::SceneGraph::GenericNodeT*> FrontFacingList; 
    173174            mutable ArrayT<cf::SceneGraph::GenericNodeT*> BackFacingList; 
    174175            mutable bool                                  NextLightNeedsInit; 
     176            mutable FaceBatchesNodeT*                     FaceBatches; 
    175177        }; 
    176178    } 
    177179} 
  • Libs/GuiSys/GuiImpl.cpp

     
    337337        static MatSys::MeshT CrossMesh(MatSys::MeshT::Lines); 
    338338        CrossMesh.Vertices.Overwrite(); 
    339339        CrossMesh.Vertices.PushBackEmpty(4);     // Just a single quad for the background rectangle. 
     340        CrossMesh.Invalidate(); 
    340341 
    341342        for (unsigned long VertexNr=0; VertexNr<CrossMesh.Vertices.Size(); VertexNr++) 
    342343        { 
     
    386387    // Note that the processing of the mouse event is orthogonal to (independent of) MouseIsShown. 
    387388    // That is, we may be active and interactive even if the mouse cursor is *not* shown, 
    388389    // as for example with the 3D window of the Cafu engine client, which must receive the 
     390 
    389391    // mouse events even if no mouse cursor is shown! 
    390392 
    391393    bool MEWasProcessed=false;      // If the Lua script handler consumed the event. 
  • Libs/GuiSys/Window.cpp

     
    356356    static MatSys::MeshT BackMesh(MatSys::MeshT::Quads); 
    357357    BackMesh.Vertices.Overwrite(); 
    358358    BackMesh.Vertices.PushBackEmpty(4);     // Just a single quad for the background rectangle. 
     359    BackMesh.Invalidate(); 
    359360 
    360361    for (unsigned long VertexNr=0; VertexNr<BackMesh.Vertices.Size(); VertexNr++) 
    361362    { 
     
    385386        static MatSys::MeshT BorderMesh(MatSys::MeshT::Quads); 
    386387        BorderMesh.Vertices.Overwrite(); 
    387388        BorderMesh.Vertices.PushBackEmpty(4*4);     // One rectangle for each side of the background. 
     389        BorderMesh.Invalidate(); 
    388390 
    389391        for (unsigned long VertexNr=0; VertexNr<BorderMesh.Vertices.Size(); VertexNr++) 
    390392        { 
  • Libs/Models/Model_cmdl.cpp

     
    994994    for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
    995995    { 
    996996        const MeshT& Mesh=m_Meshes[MeshNr]; 
     997        m_Draw_Meshes[MeshNr].Invalidate(); 
    997998 
    998999        for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) 
    9991000        { 
     
    11811182 
    11821183                // Note that we have to cull the following polygons wrt. the *VIEWER* (not the light source)! 
    11831184                static MatSys::MeshT MeshSilhouette(MatSys::MeshT::Quads);  // The default winding order is "CW". 
     1185                MeshSilhouette.Invalidate(); 
    11841186                MeshSilhouette.Vertices.Overwrite(); 
    11851187 
    11861188                for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) 
     
    12151217                    } 
    12161218                } 
    12171219 
    1218                 MatSys::Renderer->RenderMesh(MeshSilhouette); 
     1220                if(MeshSilhouette.Vertices.Size() > 0) MatSys::Renderer->RenderMesh(MeshSilhouette); 
    12191221 
    1220  
    12211222                static MatSys::MeshT MeshCaps(MatSys::MeshT::Triangles);    // The default winding order is "CW". 
     1223                MeshCaps.Invalidate(); 
    12221224                MeshCaps.Vertices.Overwrite(); 
    12231225 
    12241226                for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) 
     
    12511253                    MeshCaps.Vertices[MeshSize-1].SetOrigin(LA, 0.0); 
    12521254                } 
    12531255 
    1254                 MatSys::Renderer->RenderMesh(MeshCaps); 
     1256                if(MeshCaps.Vertices.Size() > 0) MatSys::Renderer->RenderMesh(MeshCaps); 
    12551257            } 
    12561258 
    12571259            break; 
  • Libs/Models/Model_mdl.hpp

     
    5454 
    5555 
    5656    private: 
     57    typedef MatSys::StaticVertexT SoftSkinVertexT; 
     58    typedef MatSys::StaticVertexT HardSkinVertexT; 
    5759 
    5860    struct TriangleInfoT 
    5961    { 
     
    7072    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). 
    7173    ArrayT<MatSys::RenderMaterialT*> RenderMaterials;           ///< The MatSys render materials. 
    7274    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 
    7376    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). 
    7477 
    7578    // Convenient abbreviations into the above data arrays 
  • Libs/Models/Model_mdl.cpp

     
    302302        const int              SkinNr         =0; 
    303303        const short*           SkinRefs       =((short*)((char*)StudioTextureHeader+StudioTextureHeader->SkinIndex)) + (SkinNr<StudioTextureHeader->NumSkinFamilies ? SkinNr*StudioTextureHeader->NumSkinRef : 0); 
    304304 
     305        RenderMeshes.PushBack(ArrayT<MatSys::MeshT*> ()); 
     306 
    305307        for (int MeshNr=0; MeshNr<CurrentModel.NumMesh; MeshNr++) 
    306308        { 
    307309            const StudioMeshT&  CurrentMesh   =StudioMeshes[MeshNr]; 
    308310            const signed short* TriangleStrips=(signed short*)(&ModelData[0]+CurrentMesh.TriIndex); 
    309  
     311            unsigned long NrOfMeshVertices = 0; 
     312            unsigned long NrOfIndices = 0; 
    310313            while (*TriangleStrips) 
    311314            { 
    312315                // Anzahl und Art (FAN vs. STRIP) der Vertices im nächsten TriangleStrip. 
     
    359362                } 
    360363 
    361364                TriangleStrips+=4*NrOfVertices; 
     365                NrOfMeshVertices += NrOfVertices; 
     366                NrOfIndices += 3*(NrOfVertices-2); 
    362367            } 
     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); 
    363435        } 
    364436 
    365437        // Compute additional triangle information (neighbours). 
     
    10701142                else 
    10711143                { 
    10721144                    // Should never occur... 
     1145 
     1146 
    10731147                    TriangleTangents[TriangleNr][0]=1.0; 
    10741148                    TriangleTangents[TriangleNr][1]=0.0; 
    10751149                    TriangleTangents[TriangleNr][2]=0.0; 
     
    11571231            static MatSys::MeshT MeshSilhouette(MatSys::MeshT::Quads); 
    11581232 
    11591233            MeshSilhouette.Vertices.Overwrite(); 
     1234            MeshSilhouette.Invalidate(); 
    11601235 
    11611236            for (unsigned long TriNr=0; TriNr<TriangleInfos[BodyPartNr].Size(); TriNr++) 
    11621237            { 
     
    11961271            static MatSys::MeshT MeshCaps(MatSys::MeshT::Triangles); 
    11971272 
    11981273            MeshCaps.Vertices.Overwrite(); 
     1274            MeshCaps.Invalidate(); 
    11991275 
    12001276            for (unsigned long TriNr=0; TriNr<TriangleInfos[BodyPartNr].Size(); TriNr++) 
    12011277            { 
     
    12381314 
    12391315            MatSys::Renderer->SetCurrentMaterial(RenderMaterials[SkinRefs[CurrentMesh.SkinRef]]); 
    12401316 
    1241             while (*TriangleStrips) 
     1317            MatSys::MeshT *Mesh = RenderMeshes[BodyPartNr][MeshNr]; 
     1318#if ENABLE_OPT_CACHING 
     1319            if(IsUpdateRequired_TransformedVertices) 
     1320#endif 
    12421321            { 
    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; 
    12451329 
    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]; 
    12471333 
    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) 
    12491338 
    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); 
    12511341 
    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                    } 
    12541346 
    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; 
    12701348                } 
    1271  
    1272                 MatSys::Renderer->RenderMesh(Mesh); 
     1349                Mesh->VertexBuffer->Unlock(); 
    12731350            } 
     1351            MatSys::Renderer->RenderMesh(*Mesh); 
    12741352        } 
    12751353    } 
    12761354 
  • Libs/Templates/Array.hpp

     
    6363    ArrayT(const ArrayT<T>& OldArray);                          ///< Copy  constructor 
    6464   ~ArrayT();                                                   ///< Destructor 
    6565    ArrayT<T>& operator = (const ArrayT<T>& OldArray);          ///< Assignment operator 
     66    void          Swap(ArrayT<T> &Other);                       ///< Swaps the arrays data 
    6667 
     68    bool operator==(const ArrayT<T>& Other) const;              ///< Equality operator 
     69    bool operator!=(const ArrayT<T>& Other) const;              ///< Inequality operator 
     70 
    6771    unsigned long Size() const;                                 ///< Get size of array 
    6872    void          Clear();                                      ///< Clear array (and free allocated memory) 
    6973    void          Overwrite();                                  ///< Clear array (but reuse memory) 
     
    7478    void          PushBackEmptyExact(unsigned long Amount=1); 
    7579    void          DeleteBack(unsigned long Amount=1); 
    7680 
     81 
    7782    // "Convenience" methods. 
    7883    void          PushBack(const ArrayT<T>& Other); 
    7984    void          InsertAt(unsigned long Index, const T Element);   // TODO: Rename to InsertAtAndKeepOrder() 
    8085    void          RemoveAt(unsigned long Index); 
    8186    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); 
    8389 // void          QuickSort(unsigned long FirstIndex, unsigned long LastIndex, bool (*IsLess)(const T& E1, const T& E2)); 
    8490    int           Find(const T& Element) const; 
    8591}; 
     
    123129    return *this; 
    124130} 
    125131 
     132template<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; 
    126137 
     138    Other.Elements = Elements; 
     139    Other.NrOfElements = NrOfElements; 
     140    Other.MaxNrOfElements = MaxNrOfElements; 
     141 
     142    Elements = NewElements; 
     143    NrOfElements = NewSize; 
     144    MaxNrOfElements = NewMaxSize; 
     145} 
     146 
     147template<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 
     163template<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 
    127179template<class T> inline unsigned long ArrayT<T>::Size() const 
    128180{ 
    129181    return NrOfElements; 
     
    280332} 
    281333 
    282334 
    283 template<class T> inline void ArrayT<T>::QuickSort(bool (*IsLess)(const T& E1, const T& E2)) 
     335template<class T> template<class Function> inline void ArrayT<T>::QuickSort(Function IsLess) 
    284336{ 
    285337    static ArrayT<unsigned long> ToDoRanges; 
    286338 
  • Libs/MaterialSystem/VertexBufferImpl.hpp

     
     1/* 
     2================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     33namespace 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

     
    3030 
    3131#include "Templates/Array.hpp" 
    3232#include "Math3D/Vector3.hpp" 
     33#include "VertexBuffer.hpp" 
     34#include "PrimitiveBuffer.hpp" 
     35#include "VertexFormats.hpp" 
    3336 
    34  
    3537namespace MatSys 
    3638{ 
    3739    /// This class represents a polygonal mesh. 
     
    5961    //           2. Clarify the exact requirements of VBOs          for each Renderer, inclusive OpenGL 2.0. 
    6062    //           3. Keep the differences/requirements/existance between static and animated meshes in mind. 
    6163    //           4. Armed with that knowledge, revise the meshes. 
    62     class MeshT 
     64    class MeshT: public VertexBufferI 
    6365    { 
    6466        public: 
    6567 
    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 }; 
    6769        enum WindingT { CW, CCW }; 
    6870 
    69         struct VertexT 
     71        struct RangeT 
    7072        { 
    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) {} 
    7375 
    74             float  TextureCoord[2]; 
    75             float  LightMapCoord[2]; 
    76             float  SHLMapCoord[2]; 
     76            unsigned int Start, Count; 
     77            TypeT Type; 
     78        }; 
    7779 
    78             float  Normal[3];           // The normal vector in model space. 
    79             float  Tangent[3]; 
    80             float  BiNormal[3]; 
     80        typedef GenericVertexT VertexT; 
    8181 
    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; 
    8489 
     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(); 
    8597 
    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; 
    99149        }; 
    100150 
     151 
    101152        TypeT           Type; 
    102153        WindingT        Winding;    ///< The orientation (cw or ccw) of front faces. 
    103         ArrayT<VertexT> Vertices; 
     154        ArrayT<RangeT>  SubRanges; 
     155        VertexBufferI   *VertexBuffer; 
     156        PrimitiveBufferI *PrimitiveBuffer; 
    104157 
    105  
    106158        /// 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) 
    108161        { 
    109162        } 
     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; 
    110177    }; 
     178#endif 
    111179} 
    112180 
    113181#endif 
  • Libs/MaterialSystem/PrimitiveBuffer.hpp

     
     1/* 
     2================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     27namespace 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

     
    4848bool cf::GL_EXT_stencil_wrap_AVAIL               =false; 
    4949bool cf::GL_EXT_stencil_two_side_AVAIL           =false; 
    5050bool cf::GL_ARB_vertex_and_fragment_program_AVAIL=false; 
     51bool cf::GL_ARB_vertex_buffer_object_AVAIL = false; 
    5152 
    52  
    5353static bool IsExtensionAvailable(const char* ExtensionName) 
    5454{ 
    5555    // Dies ist im wesentlichen der Code aus dem "OpenGL Programming Guide", Seite 568. 
     
    469469 
    470470    cf::GL_ARB_vertex_and_fragment_program_AVAIL=true; 
    471471} 
     472 
     473PFNGLBINDBUFFERARBPROC           cf::glBindBufferARB           = NULL; // Extension ARB_vertex_buffer_object 
     474PFNGLDELETEBUFFERSARBPROC        cf::glDeleteBuffersARB        = NULL; 
     475PFNGLGENBUFFERSARBPROC           cf::glGenBuffersARB           = NULL; 
     476PFNGLISBUFFERARBPROC             cf::glIsBufferARB             = NULL; 
     477PFNGLBUFFERDATAARBPROC           cf::glBufferDataARB           = NULL; 
     478PFNGLBUFFERSUBDATAARBPROC        cf::glBufferSubDataARB        = NULL; 
     479PFNGLGETBUFFERSUBDATAARBPROC     cf::glGetBufferSubDataARB     = NULL; 
     480PFNGLMAPBUFFERARBPROC            cf::glMapBufferARB            = NULL; 
     481PFNGLUNMAPBUFFERARBPROC          cf::glUnmapBufferARB          = NULL; 
     482PFNGLGETBUFFERPARAMETERIVARBPROC cf::glGetBufferParameterivARB = NULL; 
     483PFNGLGETBUFFERPOINTERVARBPROC    cf::glGetBufferPointervARB    = NULL; 
     484 
     485void 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

     
    501501{ 
    502502    glTexEnvfv(target, pname, param); 
    503503} 
     504 
     505void 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 
     522void 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

     
    5757    extern bool GL_EXT_stencil_wrap_AVAIL; 
    5858    extern bool GL_EXT_stencil_two_side_AVAIL; 
    5959    extern bool GL_ARB_vertex_and_fragment_program_AVAIL; 
     60    extern bool GL_ARB_vertex_buffer_object_AVAIL; 
    6061 
    6162    // Initialize extensions. 
    6263    void Init_GL_ARB_multitexture(); 
     
    6667    void Init_GL_EXT_stencil_wrap(); 
    6768    void Init_GL_EXT_stencil_two_side(); 
    6869    void Init_GL_ARB_vertex_and_fragment_program(); 
     70    void Init_GL_ARB_vertex_buffer_object(); 
    6971 
    70  
    7172    // Pointers to extension functions. 
    7273    extern PFNGLMULTITEXCOORD2DARBPROC           glMultiTexCoord2dARB;      // Extension "GL_ARB_multitexture". 
    7374    extern PFNGLMULTITEXCOORD2FARBPROC           glMultiTexCoord2fARB; 
     
    209210    extern PFNGLGETVERTEXATTRIBIVARBPROC          glGetVertexAttribivARB; 
    210211    extern PFNGLGETVERTEXATTRIBPOINTERVARBPROC    glGetVertexAttribPointervARB; 
    211212    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 
    212226} 
    213227 
    214228#endif 
  • Libs/MaterialSystem/Common/OpenGLState.hpp

     
    8383 // void TexParameter*(); 
    8484 
    8585 
     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 
    8692    static const GLenum MeshToOpenGLType[];             ///< Translates from MeshT primitive types to OpenGL rendering primitives. 
    8793    static const GLenum WindingToOpenGL[];              ///< Translates from MeshT windings to OpenGL windings (cw or ccw). 
    8894    static const GLenum BlendFactorToOpenGL[];          ///< Translates from MaterialT blend factors to OpenGL blend factors. 
  • Libs/MaterialSystem/VertexBuffer.hpp

     
     1/* 
     2================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     33namespace 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

     
    475475} 
    476476 
    477477 
     478void RendererImplT::OnDestroyMesh(MatSys::MeshT *Mesh) 
     479{ 
     480} 
     481 
     482void RendererImplT::OnDestroyVertexBuffer(MatSys::VertexBufferI *Buffer) 
     483{ 
     484} 
     485 
     486void RendererImplT::OnDestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer) 
     487{ 
     488} 
     489 
     490VertexBufferI *RendererImplT::CreateVertexBuffer(const VertexDescriptorT &Format, unsigned int Usage) 
     491{ 
     492    return NULL; 
     493} 
     494 
     495PrimitiveBufferI *RendererImplT::CreatePrimitiveBuffer(PrimitiveBufferI::IndexTypeT IndexType, PrimitiveBufferI::UsageTypeT Usage) 
     496{ 
     497    return NULL; 
     498} 
     499 
    478500RenderMaterialT* RendererImplT::GetCurrentRenderMaterial() const 
    479501{ 
    480502    return NULL; 
  • Libs/MaterialSystem/RendererNull/RendererImpl.hpp

     
    123123    void SetCurrentSHLMaps(const ArrayT<MatSys::TextureMapI*>& SHLMaps); 
    124124    void SetCurrentSHLLookupMap(MatSys::TextureMapI* SHLLookupMap); 
    125125    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); 
    126132 
    127  
    128133    // Internal interface. 
    129134    MatSys::RenderMaterialT* GetCurrentRenderMaterial() const; 
    130135 
  • Libs/MaterialSystem/VertexFormats.cpp

     
     1#include "VertexFormats.hpp" 
     2 
     3namespace 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

     
    2828#ifndef _CA_MATSYS_RENDERER_HPP_ 
    2929#define _CA_MATSYS_RENDERER_HPP_ 
    3030 
     31#include "PrimitiveBuffer.hpp" 
    3132 
    32  
    3333template<class T> class ArrayT; 
    3434class MaterialT; 
    3535class MatrixT; 
    3636 
    37  
    3837namespace MatSys 
    3938{ 
    4039    class MeshT; 
     40    class VertexDescriptorT; 
     41    class VertexBufferI; 
    4142    class RenderMaterialT; 
    4243    class TextureMapI; 
    4344 
    44  
    4545    /// This class provides an interface to a renderer. 
    4646    /// The interface is specified as ABC in order to share the renderer across exe/dll boundaries. 
    4747    class RendererI 
     
    265265        virtual void EndShadowSilhouetteGeom()=0;  */ 
    266266 
    267267        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; 
    268274 
    269275        /// This ABC does neither have nor need a destructor, because no implementation will ever be deleted via a pointer to a RendererI. 
    270276        /// (The implementations are singletons after all.)  See the Singleton pattern and the C++ FAQ 21.05 (the "precise rule") for more information. 
     
    277283    /// Just set this after you loaded the desired renderer DLL to the pointer returned by the DLLs GetRenderer() function. 
    278284    /// (And NULL it on unloading the DLL.) 
    279285    /// An analogous object exists for the TextureMapManager interface, see TextureMap.hpp. 
     286 
    280287    extern RendererI* Renderer; 
    281288} 
    282289 
  • Libs/MaterialSystem/VertexFormats.hpp

     
     1/* 
     2================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     34namespace 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================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     33namespace 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================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     34class VertexBufferImplT: public MatSys::VertexBufferI 
     35{ 
     36public: 
     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 
     64private: 
     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

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    233233        OpenGLState->BindTexture(GL_TEXTURE_2D, RM->UseDefaultLightMap && Renderer.GetCurrentLightMap()!=NULL ? Renderer.GetCurrentLightMap()->GetOpenGLObject() : RM->LightTexMap->GetOpenGLObject()); 
    234234 
    235235 
     236        // Draw the mesh 
    236237        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(); 
    246247    } 
    247248}; 
    248249 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Norm.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    234234        OpenGLState->BindTexture(GL_TEXTURE_2D, RM->NormTexMap->GetOpenGLObject()); 
    235235 
    236236 
     237        // Draw the mesh 
     238        MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 
    237239        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(); 
    246247    } 
    247248}; 
    248249 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Terrain.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    257257        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); 
    258258 
    259259 
     260        // Draw the mesh 
     261        MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 
    260262        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(); 
    267269    } 
    268270}; 
    269271 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light_Norm_Spec.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    175175        return false; 
    176176    } 
    177177 
     178 
     179 
    178180    void Activate() 
    179181    { 
    180182        if (InitCounter<RendererImplT::GetInstance().GetInitCounter()) 
     
    300302            cf::glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, EyePosCache); 
    301303        } 
    302304 
    303  
     305        // Draw the mesh 
    304306        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); 
    310313 
    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(); 
    318320    } 
    319321}; 
    320322 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light_Norm_Luma.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    264264        OpenGLState->BindTexture(GL_TEXTURE_2D, RM->LumaTexMap->GetOpenGLObject()); 
    265265 
    266266 
     267        // Draw the mesh 
    267268        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(); 
    277278    } 
    278279}; 
    279280 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    159159 
    160160    void RenderMesh(const MeshT& Mesh) 
    161161    { 
     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 
    162167        const RendererImplT&         Renderer   =RendererImplT::GetInstance(); 
    163168        RenderMaterialT*             RM         =Renderer.GetCurrentRenderMaterial(); 
    164169        const MaterialT&             Material   =*(RM->Material); 
     
    223228        OpenGLState->Enable(GL_TEXTURE_2D); 
    224229        OpenGLState->BindTexture(GL_TEXTURE_2D, RM->DiffTexMap->GetOpenGLObject()); 
    225230 
    226  
     231        // Draw the mesh 
     232        MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 
    227233        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(); 
    236241    } 
    237242}; 
    238243 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Solid.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    6464        VertexProgram=UploadProgram(GL_VERTEX_PROGRAM_ARB, 
    6565            "!!ARBvp1.0                                        \n" 
    6666            "PARAM mvp[4]={ state.matrix.mvp };                \n" 
     67            "PARAM mcolor=program.local[0];                    \n" 
    6768 
    6869            "DP4 result.position.x, vertex.position, mvp[0];   \n"     // result.position = mul(state.matrix.mvp, vertex.position); 
    6970            "DP4 result.position.y, vertex.position, mvp[1];   \n" 
    7071            "DP4 result.position.z, vertex.position, mvp[2];   \n" 
    7172            "DP4 result.position.w, vertex.position, mvp[3];   \n" 
    7273 
    73             "MOV result.color, vertex.color;                   \n"     // result.color = vertex.color; 
     74            "MUL result.color, vertex.color, mcolor;           \n"     // result.color = vertex.color*mcolor; 
    7475            "END                                               \n"); 
    7576 
    7677 
     
    220221        OpenGLState->Disable(GL_TEXTURE_2D); 
    221222 
    222223 
    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(); 
    230245    } 
    231246}; 
    232247 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_SkyDome.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    242242            EyePosCache_w[2]=VW.m[2][3]; 
    243243        } 
    244244 
    245  
     245        // Draw the mesh 
    246246        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(); 
    253254    } 
    254255}; 
    255256 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light_Luma.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    242242        OpenGLState->BindTexture(GL_TEXTURE_2D, RM->LumaTexMap->GetOpenGLObject()); 
    243243 
    244244 
     245        // Draw the mesh 
    245246        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(); 
    255256    } 
    256257}; 
    257258 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/L_Diff_Norm.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    281281        } 
    282282 
    283283 
    284         glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 
    285             for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    286             { 
    287                 glNormal3fv(Mesh.Vertices[VertexNr].Normal);                                // Normal 
    288                 cf::glMultiTexCoord3fvARB(GL_TEXTURE6_ARB, Mesh.Vertices[VertexNr].Tangent);    // Tangent 
    289                 cf::glMultiTexCoord3fvARB(GL_TEXTURE7_ARB, Mesh.Vertices[VertexNr].BiNormal);   // BiNormal 
     284        // Draw the mesh 
     285        MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 
     286        Drawer->BeginDrawing(Mesh); 
     287        { 
     288            Drawer->SendPositions(); 
     289            Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 
    290290 
    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(); 
    295297    } 
    296298}; 
    297299 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Norm_Luma.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    243243        OpenGLState->BindTexture(GL_TEXTURE_2D, RM->LumaTexMap->GetOpenGLObject()); 
    244244 
    245245 
     246        // Draw the mesh 
     247        MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 
    246248        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(); 
    255256    } 
    256257}; 
    257258 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light_Norm_Luma_Spec.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    307307            cf::glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, EyePosCache); 
    308308        } 
    309309 
    310  
     310        // Draw the mesh 
    311311        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); 
    317318 
    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(); 
    325325    } 
    326326}; 
    327327 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/StencilShadowVolumes.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    172172        OpenGLState->Enable(GL_STENCIL_TEST); 
    173173        OpenGLState->FrontFace(OpenGLStateT::WindingToOpenGL[Mesh.Winding]); 
    174174 
    175  
     175        MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 
    176176        if (cf::GL_EXT_stencil_two_side_AVAIL) 
    177177        { 
    178178            OpenGLState->Disable(GL_CULL_FACE); 
     
    188188            OpenGLState->StencilFunc(GL_ALWAYS, 0, ~0); 
    189189         // OpenGLState->StencilMask(~0);       // This is the default setting anyway. 
    190190 
    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(); 
    195197        } 
    196198        else 
    197199        { 
     
    203205            // We could also render ALL pieces first in the first pass, then all in the second, 
    204206            // taking the OpenGL state changes out of the inner loop. 
    205207            // The good news is that that discussion is obsoleted by the two-sided stencil test extension above. 
     208            Drawer->BeginDrawing(Mesh); 
     209            Drawer->SendPositions4(); 
    206210            for (char PassNr=0; PassNr<2; PassNr++) 
    207211            { 
    208212                // Note that we have to cull the following polygons wrt. the *VIEWER* (not the light source)! 
     
    214218                // 2. Clear the stencil buffer to 128, and compare later to reference value 128. 
    215219                OpenGLState->StencilOp(GL_KEEP, PassNr==0 ? GL_INCR_WRAP : GL_DECR_WRAP, GL_KEEP); 
    216220 
    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(); 
    221222            } 
     223            Drawer->EndDrawing(); 
    222224        } 
    223225    } 
    224226}; 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/L_Diff.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    275275            cf::glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, LightDiffColorCache); 
    276276        } 
    277277 
    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);    // Normal 
    283  
    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(); 
    288288    } 
    289289}; 
    290290 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_WaterCubeReflect.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    342342        } 
    343343 
    344344 
     345        // Draw the mesh 
     346        MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 
    345347        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(); 
    354355    } 
    355356}; 
    356357 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Luma.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    234234        OpenGLState->BindTexture(GL_TEXTURE_2D, RM->LumaTexMap->GetOpenGLObject()); 
    235235 
    236236 
     237        // Draw the mesh 
     238        MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 
    237239        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(); 
    246247    } 
    247248}; 
    248249 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/L_Diff_Norm_Spec.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    348348        } 
    349349 
    350350 
    351         glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 
    352             for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    353             { 
    354                 glNormal3fv(Mesh.Vertices[VertexNr].Normal);                                // Normal 
    355                 cf::glMultiTexCoord3fvARB(GL_TEXTURE6_ARB, Mesh.Vertices[VertexNr].Tangent);    // Tangent 
    356                 cf::glMultiTexCoord3fvARB(GL_TEXTURE7_ARB, Mesh.Vertices[VertexNr].BiNormal);   // BiNormal 
     351        // Draw the mesh 
     352        MeshBufferManagerT *Drawer = MeshBufferManagerT::GetInstance(); 
     353        Drawer->BeginDrawing(Mesh); 
     354        { 
     355            Drawer->SendPositions(); 
     356            Drawer->SendTextureCoords(GL_TEXTURE0_ARB); 
    357357 
    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(); 
    362364    } 
    363365}; 
    364366 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/A_Diff_Light_Norm.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    255255        OpenGLState->BindTexture(GL_TEXTURE_2D, RM->NormTexMap->GetOpenGLObject()); 
    256256 
    257257 
     258        // Draw the mesh 
    258259        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(); 
    268269    } 
    269270}; 
    270271 
  • Libs/MaterialSystem/RendererARBprogs/Shaders/L_Diff_Spec.cpp

     
    4444#include "../../Mesh.hpp" 
    4545#include "_CommonHelpers.hpp" 
    4646#include "../../Common/OpenGLEx.hpp" 
     47#include "../MeshBuffer.hpp" 
    4748 
    48  
    4949using namespace MatSys; 
    5050 
    5151 
     
    339339            cf::glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1, LightSpecColorCache); 
    340340        } 
    341341 
    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);    // Normal 
    347  
    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(); 
    352352    } 
    353353}; 
    354354 
  • Libs/MaterialSystem/RendererARBprogs/PrimitiveBufferImpl.cpp

     
     1/* 
     2================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     36PrimitiveBufferImplT::PrimitiveBufferImplT(IndexTypeT IT, UsageTypeT UT) 
     37  : IndexType(IT), UsageType(UT), IsLocked(false), Size(0) 
     38{ 
     39    cf::glGenBuffersARB(1, &BufferObject); 
     40} 
     41 
     42PrimitiveBufferImplT::~PrimitiveBufferImplT() 
     43{ 
     44    MeshBufferManagerT::GetInstance()->DestroyPrimitiveBuffer(this); 
     45} 
     46 
     47// Primitives buffer access 
     48const 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 
     59void *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 
     72void *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 
     83void 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 
     95unsigned long PrimitiveBufferImplT::GetBufferSize() const 
     96{ 
     97    return Size*MeshBufferManagerT::IndexTypeSize[IndexType]; 
     98} 
     99 
     100unsigned long PrimitiveBufferImplT::GetSize() const 
     101{ 
     102    return Size; 
     103} 
     104 
     105void PrimitiveBufferImplT::SetSize(unsigned long S) 
     106{ 
     107    Size = S; 
     108} 
     109 
     110PrimitiveBufferImplT::IndexTypeT PrimitiveBufferImplT::GetIndexType() const 
     111{ 
     112    return IndexType; 
     113} 
     114 
     115PrimitiveBufferImplT::UsageTypeT PrimitiveBufferImplT::GetUsage() const 
     116{ 
     117    return UsageType; 
     118} 
     119 
     120bool PrimitiveBufferImplT::IsValid() const 
     121{ 
     122    return true; 
     123} 
     124 
     125void PrimitiveBufferImplT::Validated() const 
     126{ 
     127} 
     128 
     129void PrimitiveBufferImplT::Invalidate() 
     130{ 
     131} 
     132 
     133void *PrimitiveBufferImplT::GetRendererData() const 
     134{ 
     135    return (void*)((unsigned long)BufferObject); 
     136} 
     137 
     138void PrimitiveBufferImplT::SetRendererData(void *Data) const 
     139{ 
     140    BufferObject = (unsigned long)Data; 
     141} 
     142 
  • Libs/MaterialSystem/RendererARBprogs/MeshBuffer.cpp

     
     1/* 
     2================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     44using namespace MatSys; 
     45 
     46// Helper template to get the vertex element pointer 
     47template<typename T> 
     48const T *GetElementAddress(const void *buffer, int offset) 
     49{ 
     50    assert(offset >= 0); 
     51    return (const T*)((const char*)buffer + offset); 
     52} 
     53 
     54GLenum MeshBufferManagerT::UsageTypeToOpenGL[3] = 
     55{GL_STATIC_DRAW_ARB, GL_DYNAMIC_DRAW_ARB, GL_STREAM_DRAW_ARB }; 
     56 
     57GLenum MeshBufferManagerT::IndexTypeToOpenGLType[3] = 
     58{GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT}; 
     59 
     60unsigned long MeshBufferManagerT::IndexTypeSize[3] = 
     61{sizeof(unsigned char), sizeof(unsigned short), sizeof(unsigned long)}; 
     62 
     63 
     64MeshBufferManagerT::MeshBufferManagerT() 
     65  : IsSendingMesh(false), Start(true) 
     66{ 
     67} 
     68 
     69MeshBufferManagerT::~MeshBufferManagerT() 
     70{ 
     71} 
     72 
     73MeshBufferManagerT *MeshBufferManagerT::GetInstance() 
     74{ 
     75    static MeshBufferManagerT *Manager = NULL; 
     76    if(!Manager) 
     77        Manager = new MeshBufferManagerT(); 
     78 
     79    return Manager; 
     80} 
     81 
     82void 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 
     101void 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 
     138void 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 
     175void 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 
     194void 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 
     230void 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 
     284void 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 
     306void MeshBufferManagerT::DestroyMesh(MatSys::MeshT *mesh) 
     307{ 
     308} 
     309 
     310// Destroys the vertex buffer 
     311void 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 
     340void 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 
     351void 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 
     379void 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 
     408void 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 
     437void 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 
     466void 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 
     495void 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 
     530void 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 
     565void 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 
     600void 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

     
    4848 
    4949#include "../Common/OpenGLEx.hpp" 
    5050#include "Templates/Array.hpp" 
     51#include "MeshBuffer.hpp" 
     52#include "VertexBufferImpl.hpp" 
     53#include "PrimitiveBufferImpl.hpp" 
    5154 
    52  
    5355using namespace MatSys; 
    5456 
    5557 
     
    289291    cf::Init_GL_EXT_stencil_wrap(); 
    290292    cf::Init_GL_EXT_stencil_two_side(); 
    291293    cf::Init_GL_ARB_vertex_and_fragment_program(); 
     294    cf::Init_GL_ARB_vertex_buffer_object(); 
    292295 
    293296    if (cf::GL_ARB_texture_compression_AVAIL) 
    294297        glHint(GL_TEXTURE_COMPRESSION_HINT_ARB, GL_NICEST); 
     
    10371040    CurrentShader->RenderMesh(Mesh); 
    10381041} 
    10391042 
     1043void RendererImplT::OnDestroyMesh(MatSys::MeshT *Mesh) 
     1044{ 
     1045    MeshBufferManagerT::GetInstance()->DestroyMesh(Mesh); 
     1046} 
    10401047 
     1048void RendererImplT::OnDestroyVertexBuffer(MatSys::VertexBufferI *Buffer) 
     1049{ 
     1050    MeshBufferManagerT::GetInstance()->DestroyVertexBuffer(Buffer); 
     1051} 
     1052 
     1053void RendererImplT::OnDestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer) 
     1054{ 
     1055    MeshBufferManagerT::GetInstance()->DestroyPrimitiveBuffer(Buffer); 
     1056} 
     1057 
     1058MatSys::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 
     1065PrimitiveBufferI *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 
    10411072RenderMaterialT* RendererImplT::GetCurrentRenderMaterial() const 
    10421073{ 
    10431074    return CurrentRenderMaterial; 
  • Libs/MaterialSystem/RendererARBprogs/PrimitiveBufferImpl.hpp

     
     1/* 
     2================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     34class PrimitiveBufferImplT: public MatSys::PrimitiveBufferI 
     35{ 
     36public: 
     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 
     63private: 
     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 
     9using namespace MatSys; 
     10 
     11VertexBufferImplT::VertexBufferImplT(const VertexDescriptorT &VertexFormat, UsageTypeT U) 
     12    : Descriptor(VertexFormat), Usage(U), IsLocked(false), Size(0) 
     13{ 
     14    cf::glGenBuffersARB(1, &BufferObject); 
     15} 
     16 
     17VertexBufferImplT::~VertexBufferImplT() 
     18{ 
     19    MeshBufferManagerT::GetInstance()->DestroyVertexBuffer(this); 
     20} 
     21 
     22const VertexDescriptorT &VertexBufferImplT::GetVertexDescriptor() const 
     23{ 
     24    return Descriptor; 
     25} 
     26 
     27const 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 
     38void *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 
     51void *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 
     62void 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 
     73unsigned long VertexBufferImplT::GetBufferSize() const 
     74{ 
     75    return Size*Descriptor.VertexSize; 
     76} 
     77 
     78unsigned long VertexBufferImplT::GetSize() const 
     79{ 
     80    return Size; 
     81} 
     82 
     83void VertexBufferImplT::SetSize(unsigned long S) 
     84{ 
     85    Size = S; 
     86} 
     87 
     88VertexBufferI::UsageTypeT VertexBufferImplT::GetUsage() const 
     89{ 
     90    return Usage; 
     91} 
     92 
     93bool VertexBufferImplT::IsValid() const 
     94{ 
     95    return true; // Always valid 
     96} 
     97 
     98void VertexBufferImplT::Validated() const 
     99{ 
     100} 
     101 
     102void VertexBufferImplT::Invalidate() 
     103{ 
     104} 
     105 
     106void *VertexBufferImplT::GetRendererData() const 
     107{ 
     108    return (void*)((unsigned long)BufferObject); 
     109} 
     110 
     111void VertexBufferImplT::SetRendererData(void *data) const 
     112{ 
     113    BufferObject = (unsigned long)data; 
     114} 
     115 
  • Libs/MaterialSystem/RendererARBprogs/MeshBuffer.hpp

     
     1/* 
     2================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     34class MeshBufferManagerT 
     35{ 
     36public: 
     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 
     76private: 
     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

     
    127127    void SetCurrentSHLMaps(const ArrayT<MatSys::TextureMapI*>& SHLMaps); 
    128128    void SetCurrentSHLLookupMap(MatSys::TextureMapI* SHLLookupMap); 
    129129    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); 
    130136 
    131  
    132137    // Internal Interface 
    133138    MatSys::RenderMaterialT* GetCurrentRenderMaterial() const; 
    134139    TextureMap2DT*           GetCurrentLightMap() const; 
  • Libs/MaterialSystem/VertexBufferImpl.cpp

     
     1/* 
     2================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     31namespace 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================================================================================= 
     3This file is part of Cafu, the open-source game and graphics engine for 
     4multiplayer, cross-platform, real-time 3D action. 
     5$Id$ 
     6 
     7Copyright (C) 2002-2010 Carsten Fuchs Software. 
     8 
     9Cafu is free software: you can redistribute it and/or modify it under the terms 
     10of the GNU General Public License as published by the Free Software Foundation, 
     11either version 3 of the License, or (at your option) any later version. 
     12 
     13Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
     14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     15PURPOSE. See the GNU General Public License for more details. 
     16 
     17You should have received a copy of the GNU General Public License 
     18along with Cafu. If not, see <http://www.gnu.org/licenses/>. 
     19 
     20For 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 
     33namespace 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

     
    2525/*** Mesh ***/ 
    2626/************/ 
    2727 
     28#include "Mesh.hpp" 
     29#include "Renderer.hpp" 
     30 
     31namespace 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

     
    131131 
    132132            glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 
    133133                for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    134                     glVertex4dv(Mesh.Vertices[VertexNr].Origin); 
     134                    glVertex4fv(Mesh.Vertices[VertexNr].Origin); 
    135135            glEnd(); 
    136136        } 
    137137        else 
     
    157157 
    158158                glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 
    159159                    for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    160                         glVertex4dv(Mesh.Vertices[VertexNr].Origin); 
     160                        glVertex4fv(Mesh.Vertices[VertexNr].Origin); 
    161161                glEnd(); 
    162162            } 
    163163        } 
  • Libs/MaterialSystem/RendererOpenGL12/Shaders/A_Terrain.cpp

     
    187187        glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 
    188188            for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    189189            { 
    190                 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     190                glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    191191            } 
    192192        glEnd(); 
    193193 
     
    224224            glBegin(OpenGLStateT::MeshToOpenGLType[Mesh.Type]); 
    225225                for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    226226                { 
    227                     glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     227                    glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    228228                } 
    229229            glEnd(); 
    230230        } 
  • Libs/MaterialSystem/RendererOpenGL12/Shaders/A_WaterCubeReflect.cpp

     
    167167            for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    168168            { 
    169169                glTexCoord2f(Mesh.Vertices[VertexNr].TextureCoord[0]+0.6f*CurrentTime, Mesh.Vertices[VertexNr].TextureCoord[1]+0.8f*CurrentTime); 
    170                 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     170                glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    171171            } 
    172172        glEnd(); 
    173173    } 
  • Libs/MaterialSystem/RendererOpenGL12/Shaders/A_Diff_Light_Fog.cpp

     
    184184                cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 
    185185                cf::glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, Mesh.Vertices[VertexNr].LightMapCoord); 
    186186 
    187                 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     187                glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    188188            } 
    189189        glEnd(); 
    190190 
  • Libs/MaterialSystem/RendererOpenGL12/Shaders/A_Diff_nLight_oLuma.cpp

     
    167167            for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    168168            { 
    169169                glTexCoord2fv(Mesh.Vertices[VertexNr].TextureCoord); 
    170                 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     170                glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    171171            } 
    172172        glEnd(); 
    173173 
     
    189189                for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    190190                { 
    191191                    glTexCoord2fv(Mesh.Vertices[VertexNr].TextureCoord); 
    192                     glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     192                    glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    193193                } 
    194194            glEnd(); 
    195195        } 
  • Libs/MaterialSystem/RendererOpenGL12/Shaders/A_Solid.cpp

     
    164164            for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    165165            { 
    166166                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                 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     167                glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    168168            } 
    169169        glEnd(); 
    170170    } 
  • Libs/MaterialSystem/RendererOpenGL12/Shaders/A_SkyDome.cpp

     
    172172                const Vector3fT Dir_w  =InPos_w-EyePos_w; 
    173173 
    174174                glTexCoord3f(Dir_w.x, Dir_w.z, Dir_w.y); 
    175                 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     175                glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    176176            } 
    177177        glEnd(); 
    178178    } 
  • Libs/MaterialSystem/RendererOpenGL12/Shaders/A_Diff_Light_oLuma.cpp

     
    174174                cf::glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, Mesh.Vertices[VertexNr].TextureCoord); 
    175175                cf::glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, Mesh.Vertices[VertexNr].LightMapCoord); 
    176176 
    177                 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     177                glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    178178            } 
    179179        glEnd(); 
    180180 
     
    200200                for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    201201                { 
    202202                    glTexCoord2fv(Mesh.Vertices[VertexNr].TextureCoord); 
    203                     glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     203                    glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    204204                } 
    205205            glEnd(); 
    206206        } 
  • Libs/MaterialSystem/RendererOpenGL12/Shaders/L_Diff_oSpec.cpp

     
    172172 
    173173                glColor3f(Attenuation*DiffuseFactor*LightDiffuseColor[0], Attenuation*DiffuseFactor*LightDiffuseColor[1], Attenuation*DiffuseFactor*LightDiffuseColor[2]); 
    174174                glTexCoord2fv(Mesh.Vertices[VertexNr].TextureCoord); 
    175                 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     175                glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    176176            } 
    177177        glEnd(); 
    178178 
     
    215215 
    216216                glColor3f(Attenuation*SpecularFactor*LightSpecularColor[0], Attenuation*SpecularFactor*LightSpecularColor[1], Attenuation*SpecularFactor*LightSpecularColor[2]); 
    217217                glTexCoord2fv(Mesh.Vertices[VertexNr].TextureCoord); 
    218                 glVertex3dv(Mesh.Vertices[VertexNr].Origin); 
     218                glVertex3fv(Mesh.Vertices[VertexNr].Origin); 
    219219            } 
    220220        glEnd(); 
    221221    } 
  • Libs/MaterialSystem/RendererOpenGL12/RendererImpl.cpp

     
    855855    CurrentShader->RenderMesh(Mesh); 
    856856} 
    857857 
     858void RendererImplT::OnDestroyMesh(MatSys::MeshT *Mesh) 
     859{ 
     860} 
    858861 
     862void RendererImplT::OnDestroyVertexBuffer(MatSys::VertexBufferI *Buffer) 
     863{ 
     864} 
     865 
     866void RendererImplT::OnDestroyPrimitiveBuffer(MatSys::PrimitiveBufferI *Buffer) 
     867{ 
     868} 
     869 
     870VertexBufferI *RendererImplT::CreateVertexBuffer(const VertexDescriptorT &Format, unsigned int Usage) 
     871{ 
     872    return NULL; 
     873} 
     874 
     875PrimitiveBufferI *RendererImplT::CreatePrimitiveBuffer(PrimitiveBufferI::IndexTypeT IndexType, PrimitiveBufferI::UsageTypeT Usage) 
     876{ 
     877    return NULL; 
     878} 
     879 
    859880RenderMaterialT* RendererImplT::GetCurrentRenderMaterial() const 
    860881{ 
    861882    return CurrentRenderMaterial; 
  • Libs/MaterialSystem/RendererOpenGL12/RendererImpl.hpp

     
    128128    void SetCurrentSHLMaps(const ArrayT<MatSys::TextureMapI*>& SHLMaps); 
    129129    void SetCurrentSHLLookupMap(MatSys::TextureMapI* SHLLookupMap); 
    130130    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); 
    131137 
    132  
    133138    // Internal interface. 
    134139    MatSys::RenderMaterialT* GetCurrentRenderMaterial() const; 
    135140    TextureMap2DT*           GetCurrentLightMap() const; 
  • Libs/SConscript

     
    5959env.StaticLibrary( 
    6060    target="MatSys", 
    6161    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""")) 
    6365 
    6466 
    6567 
     
    7375    target="SceneGraph", 
    7476    source=Split("""SceneGraph/_aux.cpp SceneGraph/BezierPatchNode.cpp SceneGraph/BspTreeNode.cpp SceneGraph/FaceNode.cpp 
    7577                    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""")) 
    7779 
    7880 
    7981 
     
    9597    target="MaterialSystem/RendererARBprogs", 
    9698    source=[os.path.join("MaterialSystem/RendererARBprogs", x) for x in Split(""" 
    9799               RendererARBprogs.cpp RendererImpl.cpp RenderMaterial.cpp Shader.cpp TextureMapImpl.cpp 
     100               MeshBuffer.cpp VertexBufferImpl.cpp PrimitiveBufferImpl.cpp 
    98101 
    99102               Shaders/A_Terrain.cpp Shaders/A_Diff.cpp Shaders/A_Diff_Luma.cpp Shaders/A_Diff_Norm.cpp Shaders/A_Diff_Norm_Luma.cpp 
    100103               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

     
    235235            ParticleGroupMesh.Vertices[3].SetOrigin(Particle->Origin[0]-BillBoardVecX[0]-BillBoardVecY[0], 
    236236                                                    Particle->Origin[1]-BillBoardVecX[1]-BillBoardVecY[1], 
    237237                                                    Particle->Origin[2]-BillBoardVecX[2]-BillBoardVecY[2]); 
     238            ParticleGroupMesh.Invalidate(); 
    238239 
    239240            // Warning: This testing code requires "twoSided" materials! 
    240241            // ParticleGroupMesh.Vertices[4*ParticleNr+0].SetOrigin(Particle->Origin[0]-300.0, Particle->Origin[1], Particle->Origin[2]+300.0); 
  • Libs/Fonts/FontTT.cpp

     
    276276        GlyphMesh.Vertices[2].SetOrigin(x2, y2); GlyphMesh.Vertices[2].SetTextureCoord(gi.s2, gi.t2); 
    277277        GlyphMesh.Vertices[3].SetOrigin(x1, y2); GlyphMesh.Vertices[3].SetTextureCoord(gi.s1, gi.t2); 
    278278 
     279        GlyphMesh.Invalidate(); 
    279280        MatSys::Renderer->SetCurrentMaterial(gi.RM); 
    280281        MatSys::Renderer->RenderMesh(GlyphMesh); 
    281282 
  • Libs/Fonts/Font.cpp

     
    138138        TextMesh.Vertices[4*c+3].SetOrigin( 0+c*10, 16); TextMesh.Vertices[4*c+3].SetTextureCoord(CoordX     , CoordY+Size); 
    139139    } 
    140140 
     141    TextMesh.Invalidate(); 
    141142    MatSys::Renderer->RenderMesh(TextMesh); 
    142143} 
    143144