ArrayBufferControlFile.cc 2.56 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
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
Janis Born's avatar
Janis Born committed
7
8
9
10
11
12
#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)
13
:   Resource::SingleFileBasedCreator<ArrayBuffer>(_filename, Base::Settings::the()->getFullGeometryPath()),
Janis Born's avatar
Janis Born committed
14
15
16
17
18
19
20
    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)
21
:   Resource::SingleFileBasedCreator<ArrayBuffer>(std::string(_filename), Base::Settings::the()->getFullGeometryPath()),
Janis Born's avatar
Janis Born committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    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;

38
    _ab->removeAttributes();
Janis Born's avatar
Janis Born committed
39
40
    for(uint_t i = 0; i < tempData->mAttributes.size(); ++i)
    {
41
42
43
44
45
46
47
        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
48
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
    }
    _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;
}
77
#endif