Slightly changed rendering code
-renderer draw function now takes struct instead of multiple parameters
This commit is contained in:
parent
8cba2626be
commit
3a7a5b2a21
5 changed files with 199 additions and 72 deletions
|
|
@ -430,13 +430,29 @@ struct Renderer
|
|||
|
||||
}
|
||||
|
||||
void draw(Texture tex, vec2 pos, vec2 size, vec4 coords, short depth = 0, uint color = uint.max, float angle = 0, uint material_id = 0, uint mesh_id = 0, uint thread_id = 0)
|
||||
struct DrawData
|
||||
{
|
||||
if(prepared_items >= MaxObjects)return;
|
||||
__draw(this,tex,pos,size,coords,depth,color,angle,material_id,mesh_id,thread_id);
|
||||
Texture texture;
|
||||
vec2 position;
|
||||
vec2 size;
|
||||
vec4 coords;
|
||||
short depth = 0;
|
||||
uint color = uint.max;
|
||||
float angle = 0;
|
||||
uint material_id = 0;
|
||||
uint mesh_id = 0;
|
||||
uint thread_id = 0;
|
||||
}
|
||||
|
||||
private static void __draw_sdl(ref Renderer this_, Texture tex, vec2 pos, vec2 size, vec4 coords, short depth, uint color, float angle, uint material_id, uint mesh_id, uint thread_id)
|
||||
//void draw(Texture tex, vec2 pos, vec2 size, vec4 coords, short depth = 0, uint color = uint.max, float angle = 0, uint material_id = 0, uint mesh_id = 0, uint thread_id = 0)
|
||||
void draw(scope ref const(DrawData) data)
|
||||
{
|
||||
if(prepared_items >= MaxObjects)return;
|
||||
__draw(this,data);//tex,pos,size,coords,depth,color,angle,material_id,mesh_id,thread_id);
|
||||
}
|
||||
|
||||
//private static void __draw_sdl(ref Renderer this_, Texture tex, vec2 pos, vec2 size, vec4 coords, short depth, uint color, float angle, uint material_id, uint mesh_id, uint thread_id)
|
||||
private static void __draw_sdl(ref Renderer this_, scope ref const(DrawData) data)
|
||||
{
|
||||
/*with(this_)
|
||||
{
|
||||
|
|
@ -456,22 +472,25 @@ struct Renderer
|
|||
}*/
|
||||
}
|
||||
|
||||
private static void __draw_gl(ref Renderer this_, Texture tex, vec2 pos, vec2 size, vec4 coords, short depth, uint color, float angle, uint material_id, uint mesh_id, uint thread_id)
|
||||
// private static void __draw_gl(ref Renderer this_, Texture tex, vec2 pos, vec2 size, vec4 coords, short depth, uint color, float angle, uint material_id, uint mesh_id, uint thread_id)
|
||||
private static void __draw_gl(ref Renderer this_, scope ref const(DrawData) data)
|
||||
{
|
||||
//import core.stdc.string;
|
||||
with(this_)
|
||||
{
|
||||
//pos += view_pos;
|
||||
size.x *= view_size.x;
|
||||
size.y *= view_size.y;
|
||||
pos.x = pos.x * view_size.x + view_pos.x;
|
||||
pos.y = pos.y * view_size.y + view_pos.y;//*/
|
||||
vec2 pos = void;
|
||||
vec2 size = void;
|
||||
size.x = data.size.x * view_size.x;
|
||||
size.y = data.size.y * view_size.y;
|
||||
pos.x = data.position.x * view_size.x + view_pos.x;
|
||||
pos.y = data.position.y * view_size.y + view_pos.y;//*/
|
||||
|
||||
/*version(ver6)void* ptr = ubos[0].mappedPointer() + data_index;
|
||||
else void* ptr = uniform_block.ptr + data_index;*/
|
||||
if(data_ptr is null)return;
|
||||
void* ptr = data_ptr + data_index;
|
||||
if(angle == 0)
|
||||
if(data.angle == 0)
|
||||
{
|
||||
*cast(float*)ptr = size.x;
|
||||
*cast(float*)(ptr+4) = 0;
|
||||
|
|
@ -481,8 +500,8 @@ struct Renderer
|
|||
else
|
||||
{
|
||||
//import core.stdc.math;
|
||||
float sinn = sinf(angle);
|
||||
float coss = cosf(angle);
|
||||
float sinn = sinf(data.angle);
|
||||
float coss = cosf(data.angle);
|
||||
*cast(float*)ptr = coss * size.x;
|
||||
*cast(float*)(ptr+4) = -sinn * size.y;
|
||||
*cast(float*)(ptr+8) = sinn * size.x;
|
||||
|
|
@ -491,12 +510,12 @@ struct Renderer
|
|||
|
||||
//memcpy(ptr,);
|
||||
memcpy(ptr+16,pos.data.ptr,8);
|
||||
memcpy(ptr+32,coords.data.ptr,16);
|
||||
memcpy(ptr+32,data.coords.data.ptr,16);
|
||||
|
||||
//render_list[item_id] = RenderData(tex,material_id,mesh_id);
|
||||
render_list[item_id].texture = tex;
|
||||
render_list[item_id].material_id = material_id;
|
||||
render_list[item_id].mesh_id = mesh_id;
|
||||
render_list[item_id].texture = *cast(Texture*)&data.texture;
|
||||
render_list[item_id].material_id = data.material_id;
|
||||
render_list[item_id].mesh_id = data.mesh_id;
|
||||
|
||||
data_index += data_offset;
|
||||
item_id++;
|
||||
|
|
@ -504,39 +523,43 @@ struct Renderer
|
|||
}
|
||||
}
|
||||
|
||||
private static void __draw_gl_vbo_batch(ref Renderer this_, Texture tex, vec2 pos, vec2 size, vec4 coords, short depth, uint color, float angle, uint material_id, uint mesh_id, uint thread_id = 0)
|
||||
// private static void __draw_gl_vbo_batch(ref Renderer this_, Texture tex, vec2 pos, vec2 size, vec4 coords, short depth, uint color, float angle, uint material_id, uint mesh_id, uint thread_id = 0)
|
||||
private static void __draw_gl_vbo_batch(ref Renderer this_, scope ref const(DrawData) data)
|
||||
{
|
||||
import ecs_utils.gfx.config;
|
||||
|
||||
//import core.stdc.string;
|
||||
with(this_)
|
||||
{
|
||||
uint thread_id = data.thread_id;
|
||||
//if(item_id >= MaxObjects)return;
|
||||
//pos += view_pos;
|
||||
Thread* thread = &threads[thread_id];
|
||||
VertexBlock* block;
|
||||
assert(thread.blocks.length > material_id);
|
||||
block = &thread.blocks[material_id];
|
||||
assert(thread.blocks.length > data.material_id);
|
||||
block = &thread.blocks[data.material_id];
|
||||
if(block.items == 0)
|
||||
{
|
||||
thread.blocks[material_id] = getBlock();
|
||||
block = &thread.blocks[material_id];
|
||||
block.material_id = material_id;
|
||||
thread.blocks[data.material_id] = getBlock();
|
||||
block = &thread.blocks[data.material_id];
|
||||
block.material_id = data.material_id;
|
||||
}
|
||||
else if(block.items >= VertexBlock.max_items)
|
||||
{
|
||||
//pushBlock(thread.block);
|
||||
prepared_items += block.items;
|
||||
thread.filled_blocks.add(*block);
|
||||
thread.blocks[material_id] = getBlock();
|
||||
block = &thread.blocks[material_id];
|
||||
block.material_id = material_id;
|
||||
thread.blocks[data.material_id] = getBlock();
|
||||
block = &thread.blocks[data.material_id];
|
||||
block.material_id = data.material_id;
|
||||
}
|
||||
|
||||
short[3] mem = [depth, *cast(short*)&color, *(cast(short*)&color + 1)];
|
||||
short[3] mem = [data.depth, *cast(short*)&data.color, *(cast(short*)&data.color + 1)];
|
||||
|
||||
pos.x = pos.x * view_size.x + view_pos.x;
|
||||
pos.y = pos.y * view_size.y + view_pos.y;//*/
|
||||
vec2 pos = void;
|
||||
vec2 size = void;
|
||||
pos.x = data.position.x * view_size.x + view_pos.x;
|
||||
pos.y = data.position.y * view_size.y + view_pos.y;//*/
|
||||
|
||||
/*void* ptr = data_ptr + data_index;
|
||||
*cast(float*)ptr = size.x;
|
||||
|
|
@ -550,10 +573,13 @@ struct Renderer
|
|||
short[] verts = cast(short[])block.batch_vertices;
|
||||
uint item_id = block.items;
|
||||
|
||||
if(angle == 0)
|
||||
uint mesh_id = data.mesh_id;
|
||||
vec4 coords = data.coords;
|
||||
|
||||
if(data.angle == 0)
|
||||
{
|
||||
size.x *= view_size.x;
|
||||
size.y *= view_size.y;
|
||||
size.x = data.size.x * view_size.x;
|
||||
size.y = data.size.y * view_size.y;
|
||||
|
||||
verts[item_id*28] = cast(short)((GfxConfig.meshes[mesh_id].vertices[0] * size.x + pos.x) * 8191);
|
||||
verts[item_id*28+1] = cast(short)((GfxConfig.meshes[mesh_id].vertices[1] * size.y + pos.y) * 8191);
|
||||
|
|
@ -585,10 +611,11 @@ struct Renderer
|
|||
else
|
||||
{
|
||||
//import core.stdc.math;
|
||||
float sinx = sinf(angle) * size.x * view_size.y;
|
||||
float cosx = cosf(angle) * size.x * view_size.x;
|
||||
float siny = sinf(angle) * size.y * view_size.x;
|
||||
float cosy = cosf(angle) * size.y * view_size.y;
|
||||
float angle = data.angle;
|
||||
float sinx = sinf(angle) * data.size.x * view_size.y;
|
||||
float cosx = cosf(angle) * data.size.x * view_size.x;
|
||||
float siny = sinf(angle) * data.size.y * view_size.x;
|
||||
float cosy = cosf(angle) * data.size.y * view_size.y;
|
||||
|
||||
/*batch_vertices[item_id*28] = GfxConfig.meshes[mesh_id].vertices[0] * size.x;
|
||||
batch_vertices[item_id*28+1] = GfxConfig.meshes[mesh_id].vertices[1] * size.y;
|
||||
|
|
@ -1088,7 +1115,8 @@ struct Renderer
|
|||
view_pos = (pos - size * 0.5) * view_size;
|
||||
}
|
||||
|
||||
__gshared void function(ref Renderer this_, Texture tex, vec2 pos, vec2 size, vec4 coords, short depth, uint color, float angle, uint material_id, uint mesh_id, uint thread_id) __draw;
|
||||
// __gshared void function(ref Renderer this_, Texture tex, vec2 pos, vec2 size, vec4 coords, short depth, uint color, float angle, uint material_id, uint mesh_id, uint thread_id) __draw;
|
||||
__gshared void function(ref Renderer this_, scope ref const(DrawData) data) __draw;
|
||||
__gshared void function(ref Renderer this_) __present;
|
||||
__gshared void function(ref Renderer this_) __clear;
|
||||
__gshared void function(ref Renderer this_) __initialize;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue