FRME cook fixes

This commit is contained in:
Jack Andersen 2017-01-28 17:56:54 -10:00
parent 7cfebe844f
commit c6671b114e
4 changed files with 75 additions and 44 deletions

View File

@ -1,4 +1,5 @@
import bpy, struct, math
from mathutils import Quaternion
def draw(layout, context):
if bpy.context.active_object:
@ -82,7 +83,10 @@ def recursive_cook(buffer, obj, version, path_hasher, parent_name):
obj.retro_widget_color[3],
model_draw_flags_e[obj.retro_widget_model_draw_flags])
angle = Quaternion((1.0, 0.0, 0.0), 0)
if obj.retro_widget_type == 'RETRO_CAMR':
angle = Quaternion((1.0, 0.0, 0.0), math.radians(-90.0))
aspect = bpy.context.scene.render.resolution_x / bpy.context.scene.render.resolution_y
if obj.data.type == 'PERSP':
@ -94,8 +98,8 @@ def recursive_cook(buffer, obj, version, path_hasher, parent_name):
elif obj.data.type == 'ORTHO':
ortho_half = obj.data.ortho_scale / 2.0
buffer += struct.pack('>Iffffff', 1, -ortho_half, ortho_half, -ortho_half / aspect,
ortho_half / aspect, obj.data.clip_start, obj.data.clip_end)
buffer += struct.pack('>Iffffff', 1, -ortho_half, ortho_half, ortho_half / aspect,
-ortho_half / aspect, obj.data.clip_start, obj.data.clip_end)
elif obj.retro_widget_type == 'RETRO_MODL':
if len(obj.children) == 0:
@ -189,6 +193,7 @@ def recursive_cook(buffer, obj, version, path_hasher, parent_name):
obj.retro_meter_worker_count)
elif obj.retro_widget_type == 'RETRO_LITE':
angle = Quaternion((1.0, 0.0, 0.0), math.radians(-90.0))
type_enum = 0
constant = 1.0
linear = 0.0
@ -249,13 +254,14 @@ def recursive_cook(buffer, obj, version, path_hasher, parent_name):
else:
buffer += struct.pack('>b', False)
angMtx = angle.to_matrix() * obj.matrix_local.to_3x3()
buffer += struct.pack('>fffffffffffffffIH',
obj.matrix_local[0][3],
obj.matrix_local[1][3],
obj.matrix_local[2][3],
obj.matrix_local[0][0], obj.matrix_local[0][1], obj.matrix_local[0][2],
obj.matrix_local[1][0], obj.matrix_local[1][1], obj.matrix_local[1][2],
obj.matrix_local[2][0], obj.matrix_local[2][1], obj.matrix_local[2][2],
angMtx[0][0], angMtx[0][1], angMtx[0][2],
angMtx[1][0], angMtx[1][1], angMtx[1][2],
angMtx[2][0], angMtx[2][1], angMtx[2][2],
0.0, 0.0, 0.0, 0, 0)
for ch in obj.children:

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit 7bf2ad48a7b7fa8e5c34d336f5603dcdc8a6ef47
Subproject commit 4be38afef3b4588eb8f7773ab4e6961a7ffa768c

View File

@ -96,35 +96,43 @@ public:
class Token
{
friend class UniformBufferPool;
UniformBufferPool& m_pool;
IndexTp m_index;
UniformBufferPool* m_pool = nullptr;
IndexTp m_index = -1;
DivTp m_div;
Token(UniformBufferPool& pool)
Token(UniformBufferPool* pool)
: m_pool(pool)
{
auto& freeSpaces = pool.m_freeBlocks;
auto& freeSpaces = pool->m_freeBlocks;
int idx = freeSpaces.find_first();
if (idx == -1)
{
pool.m_buckets.push_back(std::make_unique<Bucket>());
pool->m_buckets.push_back(std::make_unique<Bucket>());
m_index = freeSpaces.size();
freeSpaces.resize(freeSpaces.size() + pool.m_countPerBucket, true);
freeSpaces.resize(freeSpaces.size() + pool->m_countPerBucket, true);
}
else
{
m_index = idx;
}
freeSpaces.reset(m_index);
m_div = pool.getBucketDiv(m_index);
m_div = pool->getBucketDiv(m_index);
Bucket& bucket = *m_pool.m_buckets[m_div.quot];
bucket.increment(m_pool);
Bucket& bucket = *m_pool->m_buckets[m_div.quot];
bucket.increment(*m_pool);
}
public:
Token() = default;
Token(const Token& other) = delete;
Token& operator=(const Token& other) = delete;
Token& operator=(Token&& other) = delete;
Token& operator=(Token&& other)
{
m_pool = other.m_pool;
m_index = other.m_index;
m_div = other.m_div;
other.m_index = -1;
return *this;
}
Token(Token&& other)
: m_pool(other.m_pool), m_index(other.m_index),
m_div(other.m_div)
@ -136,26 +144,28 @@ public:
{
if (m_index != -1)
{
m_pool.m_freeBlocks.set(m_index);
Bucket& bucket = *m_pool.m_buckets[m_div.quot];
bucket.decrement(m_pool);
m_pool->m_freeBlocks.set(m_index);
Bucket& bucket = *m_pool->m_buckets[m_div.quot];
bucket.decrement(*m_pool);
}
}
UniformStruct& access()
{
Bucket& bucket = *m_pool.m_buckets[m_div.quot];
Bucket& bucket = *m_pool->m_buckets[m_div.quot];
if (!bucket.cpuBuffer)
bucket.cpuBuffer = reinterpret_cast<uint8_t*>(bucket.buffer->map(m_sizePerBucket));
bucket.dirty = true;
return reinterpret_cast<UniformStruct&>(bucket.cpuBuffer[m_div.rem * m_pool.m_stride]);
return reinterpret_cast<UniformStruct&>(bucket.cpuBuffer[m_div.rem * m_pool->m_stride]);
}
std::pair<boo::IGraphicsBufferD*, IndexTp> getBufferInfo() const
{
Bucket& bucket = *m_pool.m_buckets[m_div.quot];
return {bucket.buffer, m_div.rem * m_pool.m_stride};
Bucket& bucket = *m_pool->m_buckets[m_div.quot];
return {bucket.buffer, m_div.rem * m_pool->m_stride};
}
operator bool() const { return m_pool != nullptr && m_index != -1; }
};
UniformBufferPool() = default;
@ -175,8 +185,10 @@ public:
{
if (!m_token)
m_token = factory->newBufferPool();
return Token(*this);
return Token(this);
}
void doDestroy() { m_token.doDestroy(); }
};
}

View File

@ -96,36 +96,45 @@ public:
class Token
{
friend class VertexBufferPool;
VertexBufferPool& m_pool;
IndexTp m_index;
IndexTp m_count;
VertexBufferPool* m_pool = nullptr;
IndexTp m_index = -1;
IndexTp m_count = 0;
DivTp m_div;
Token(VertexBufferPool& pool, IndexTp count)
Token(VertexBufferPool* pool, IndexTp count)
: m_pool(pool), m_count(count)
{
assert(count <= pool.m_countPerBucket && "unable to fit in bucket");
auto& freeSpaces = pool.m_freeElements;
int idx = freeSpaces.find_first_contiguous(count, pool.m_countPerBucket);
assert(count <= pool->m_countPerBucket && "unable to fit in bucket");
auto& freeSpaces = pool->m_freeElements;
int idx = freeSpaces.find_first_contiguous(count, pool->m_countPerBucket);
if (idx == -1)
{
pool.m_buckets.push_back(std::make_unique<Bucket>());
pool->m_buckets.push_back(std::make_unique<Bucket>());
m_index = freeSpaces.size();
freeSpaces.resize(freeSpaces.size() + pool.m_countPerBucket, true);
freeSpaces.resize(freeSpaces.size() + pool->m_countPerBucket, true);
}
else
{
m_index = idx;
}
freeSpaces.reset(m_index, m_index + count);
m_div = pool.getBucketDiv(m_index);
m_div = pool->getBucketDiv(m_index);
Bucket& bucket = *m_pool.m_buckets[m_div.quot];
bucket.increment(pool);
Bucket& bucket = *m_pool->m_buckets[m_div.quot];
bucket.increment(*pool);
}
public:
Token() = default;
Token(const Token& other) = delete;
Token& operator=(const Token& other) = delete;
Token& operator=(Token&& other) = delete;
Token& operator=(Token&& other)
{
m_pool = other.m_pool;
m_index = other.m_index;
m_count = other.m_count;
m_div = other.m_div;
other.m_index = -1;
return *this;
}
Token(Token&& other)
: m_pool(other.m_pool), m_index(other.m_index),
m_count(other.m_count), m_div(other.m_div)
@ -137,26 +146,28 @@ public:
{
if (m_index != -1)
{
m_pool.m_freeElements.set(m_index, m_index + m_count);
Bucket& bucket = *m_pool.m_buckets[m_div.quot];
bucket.decrement(m_pool);
m_pool->m_freeElements.set(m_index, m_index + m_count);
Bucket& bucket = *m_pool->m_buckets[m_div.quot];
bucket.decrement(*m_pool);
}
}
VertStruct* access()
{
Bucket& bucket = *m_pool.m_buckets[m_div.quot];
Bucket& bucket = *m_pool->m_buckets[m_div.quot];
if (!bucket.cpuBuffer)
bucket.cpuBuffer = reinterpret_cast<uint8_t*>(bucket.buffer->map(m_sizePerBucket));
bucket.dirty = true;
return reinterpret_cast<VertStruct*>(&bucket.cpuBuffer[m_div.rem * m_pool.m_stride]);
return reinterpret_cast<VertStruct*>(&bucket.cpuBuffer[m_div.rem * m_pool->m_stride]);
}
std::pair<boo::IGraphicsBufferD*, IndexTp> getBufferInfo() const
{
Bucket& bucket = *m_pool.m_buckets[m_div.quot];
Bucket& bucket = *m_pool->m_buckets[m_div.quot];
return {bucket.buffer, m_div.rem};
}
operator bool() const { return m_pool != nullptr && m_index != -1; }
};
VertexBufferPool() = default;
@ -176,9 +187,11 @@ public:
{
if (!m_token)
m_token = factory->newBufferPool();
return Token(*this, count);
return Token(this, count);
}
void doDestroy() { m_token.doDestroy(); }
static constexpr IndexTp bucketCapacity() { return m_countPerBucket; }
};