ArrayBufferControlFile.cc 2.49 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).   *
 **********************************************************************/
Janis Born's avatar
Janis Born committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include <ACGL/OpenGL/Controller/ArrayBufferControlFile.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>

using namespace ACGL;
using namespace ACGL::OpenGL;

ArrayBufferControlFile::ArrayBufferControlFile(const std::string& _filename)
:   Resource::FileController<ArrayBuffer>(_filename, Base::Settings::the()->getFullGeometryPath()),
    mDataController(GeometryDataControlFileFactory::the()->create(_filename))
{
    if(!mDataController)
        ACGL::Utils::error() << "No valid controller to load the geometry. Perhaps there is no loader for that file extension: " << _filename << std::endl;
}

ArrayBufferControlFile::ArrayBufferControlFile(const char* _filename)
:   Resource::FileController<ArrayBuffer>(std::string(_filename), Base::Settings::the()->getFullGeometryPath()),
    mDataController(GeometryDataControlFileFactory::the()->create(std::string(_filename)))
{
    if(!mDataController)
        ACGL::Utils::error() << "No valid controller to load the geometry. Perhaps there is no loader for that file extension: " << _filename << std::endl;
}

bool ArrayBufferControlFile::load(SharedArrayBuffer& _ab)
{
    if(!mDataController)
        return false;

    SharedGeometryData tempData = mDataController->create();

    if(!tempData)
        return false;

39
    _ab->removeAttributes();
Janis Born's avatar
Janis Born committed
40
41
    for(uint_t i = 0; i < tempData->mAttributes.size(); ++i)
    {
42
43
44
45
46
47
48
        ArrayBuffer::Attribute attribute = tempData->mAttributes[i];

        // Rename attribute if so specified
        if(mAttributeNameMap.find(i) != mAttributeNameMap.end())
            attribute.name = mAttributeNameMap[i];

        _ab->defineAttribute(attribute);
Janis Born's avatar
Janis Born committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    }
    _ab->setDataElements(tempData->getSize()/tempData->getStrideSize(), tempData->getData());

    return true;
}

SharedArrayBuffer ArrayBufferControlFile::create()
{
    updateFileModificationTime();

    SharedArrayBuffer ab(new ArrayBuffer);

    if(!load(ab))
        return SharedArrayBuffer();

    return ab;
}

bool ArrayBufferControlFile::update(SharedArrayBuffer& _ab)
{
    if(fileIsUpToDate())
        return false;

    if(!load(_ab))
        return false;

    updateFileModificationTime();
    return true;
}