~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to intern/cycles/render/tables.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2011, Blender Foundation.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 */
 
18
 
 
19
#include "device.h"
 
20
#include "scene.h"
 
21
#include "tables.h"
 
22
 
 
23
#include "util_debug.h"
 
24
 
 
25
CCL_NAMESPACE_BEGIN
 
26
 
 
27
/* Lookup Tables */
 
28
 
 
29
LookupTables::LookupTables()
 
30
{
 
31
        need_update = true;
 
32
}
 
33
 
 
34
LookupTables::~LookupTables()
 
35
{
 
36
        assert(lookup_tables.size() == 0);
 
37
}
 
38
 
 
39
void LookupTables::device_update(Device *device, DeviceScene *dscene)
 
40
{
 
41
        if(!need_update)
 
42
                return;
 
43
 
 
44
        device->tex_alloc("__lookup_table", dscene->lookup_table);
 
45
 
 
46
        need_update = false;
 
47
}
 
48
 
 
49
void LookupTables::device_free(Device *device, DeviceScene *dscene)
 
50
{
 
51
        device->tex_free(dscene->lookup_table);
 
52
        dscene->lookup_table.clear();
 
53
}
 
54
 
 
55
static size_t round_up_to_multiple(size_t size, size_t chunk)
 
56
{
 
57
        return ((size + chunk - 1)/chunk) * chunk;
 
58
}
 
59
 
 
60
size_t LookupTables::add_table(DeviceScene *dscene, vector<float>& data)
 
61
{
 
62
        assert(data.size() > 0);
 
63
 
 
64
        need_update = true;
 
65
 
 
66
        Table new_table;
 
67
        new_table.offset = 0;
 
68
        new_table.size = round_up_to_multiple(data.size(), TABLE_CHUNK_SIZE);
 
69
 
 
70
        /* find space to put lookup table */
 
71
        list<Table>::iterator table;
 
72
 
 
73
        for(table = lookup_tables.begin(); table != lookup_tables.end(); table++) {
 
74
                if(new_table.offset + new_table.size <= table->offset) {
 
75
                        lookup_tables.insert(table, new_table);
 
76
                        break;
 
77
                }
 
78
                else
 
79
                        new_table.offset = table->offset + table->size;
 
80
        }
 
81
 
 
82
        if(table == lookup_tables.end()) {
 
83
                /* add at the end */
 
84
                lookup_tables.push_back(new_table);
 
85
                dscene->lookup_table.resize(new_table.offset + new_table.size);
 
86
        }
 
87
 
 
88
        /* copy table data and return offset */
 
89
        dscene->lookup_table.copy_at(&data[0], new_table.offset, data.size());
 
90
        return new_table.offset;
 
91
}
 
92
 
 
93
void LookupTables::remove_table(size_t offset)
 
94
{
 
95
        need_update = true;
 
96
 
 
97
        list<Table>::iterator table;
 
98
 
 
99
        for(table = lookup_tables.begin(); table != lookup_tables.end(); table++) {
 
100
                if(table->offset == offset) {
 
101
                        lookup_tables.erase(table);
 
102
                        return;
 
103
                }
 
104
        }
 
105
 
 
106
        assert(table != lookup_tables.end());
 
107
}
 
108
 
 
109
CCL_NAMESPACE_END
 
110