VertexArrayObjectCreator.cc 2.42 KB
Newer Older
1
2
3
4
5
/***********************************************************************
 * Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
 * All rights reserved.                                                *
 * Distributed under the terms of the MIT License (see LICENSE.TXT).   *
 **********************************************************************/
6

7
#include <ACGL/OpenGL/Creator/VertexArrayObjectCreator.hh>
8
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>
9
#include <ACGL/OpenGL/Data/GeometryDataLoadStore.hh>
10

11
12
#ifdef ACGL_SUPPORT_VAO

13
using namespace ACGL;
14
15
using namespace ACGL::OpenGL;

16
17
VertexArrayObjectCreator::VertexArrayObjectCreator(const std::string &_filename)
:   Resource::SingleFileBasedCreator<VertexArrayObject>(_filename, Base::Settings::the()->getFullGeometryPath())
18
19
20
{
}

21
22
VertexArrayObjectCreator::VertexArrayObjectCreator(const char *_filename)
:   Resource::SingleFileBasedCreator<VertexArrayObject>(std::string(_filename), Base::Settings::the()->getFullGeometryPath())
23
24
25
{
}

26
bool VertexArrayObjectCreator::load(SharedVertexArrayObject &_vao)
27
{
28
    SharedGeometryData tempData = loadGeometryData( getFullFilePath() );
29
30
31
32
33

    if(!tempData)
        return false;

    SharedArrayBuffer sab = SharedArrayBuffer( new ArrayBuffer() );
34
    for ( uint_t i = 0; i < tempData->mAttributes.size(); ++i ) {
35
36
37
38
        sab->defineAttribute( tempData->mAttributes[i] );
    }
    sab->setDataElements( tempData->getSize()/tempData->getStrideSize(), tempData->getData() );

39
40
    _vao->detachAllAttributes();
    _vao->attachAllAttributes(sab);
41
42
43
44

    // merge the mappings of the new VAO into the linked LocationMappings object, if present
    if(mAttributeLocations)
    {
45
46
        _vao->setAttributeLocations(mAttributeLocations);
        SharedLocationMappings vaoAttributeLocations = _vao->getAttributeLocations();
47
        mAttributeLocations->addLocations(vaoAttributeLocations);
48
        _vao->setAttributeLocations(mAttributeLocations);
49
    }
50
51
52
53

    return true;
}

54
SharedVertexArrayObject VertexArrayObjectCreator::create()
55
56
57
{
    updateFileModificationTime();

58
    SharedVertexArrayObject vao(new VertexArrayObject);
59
60
61

    if(!load(vao))
        return SharedVertexArrayObject();
62

63
64
65
    return vao;
}

66
bool VertexArrayObjectCreator::update(SharedVertexArrayObject &vao)
67
68
69
70
71
72
73
74
75
76
{
    if(fileIsUpToDate())
        return false;

    if(!load(vao))
        return false;

    updateFileModificationTime();
    return true;
}
77
78
79

#endif // #ifdef ACGL_SUPPORT_VAO