2
* Copyright 2011, Blender Foundation.
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.
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.
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.
23
#include "util_debug.h"
29
LookupTables::LookupTables()
34
LookupTables::~LookupTables()
36
assert(lookup_tables.size() == 0);
39
void LookupTables::device_update(Device *device, DeviceScene *dscene)
44
device->tex_alloc("__lookup_table", dscene->lookup_table);
49
void LookupTables::device_free(Device *device, DeviceScene *dscene)
51
device->tex_free(dscene->lookup_table);
52
dscene->lookup_table.clear();
55
static size_t round_up_to_multiple(size_t size, size_t chunk)
57
return ((size + chunk - 1)/chunk) * chunk;
60
size_t LookupTables::add_table(DeviceScene *dscene, vector<float>& data)
62
assert(data.size() > 0);
68
new_table.size = round_up_to_multiple(data.size(), TABLE_CHUNK_SIZE);
70
/* find space to put lookup table */
71
list<Table>::iterator table;
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);
79
new_table.offset = table->offset + table->size;
82
if(table == lookup_tables.end()) {
84
lookup_tables.push_back(new_table);
85
dscene->lookup_table.resize(new_table.offset + new_table.size);
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;
93
void LookupTables::remove_table(size_t offset)
97
list<Table>::iterator table;
99
for(table = lookup_tables.begin(); table != lookup_tables.end(); table++) {
100
if(table->offset == offset) {
101
lookup_tables.erase(table);
106
assert(table != lookup_tables.end());