rename texture shader -> triangle shader
This commit is contained in:
parent
9d745e3475
commit
75c9ff4dbd
@ -710,7 +710,7 @@ struct ase_decode_image_result ase_decode_image(struct arena *arena, struct buff
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
br_seek(&br, chunk_size);
|
br_seek_to(&br, chunk_end_pos);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/draw.c
18
src/draw.c
@ -31,35 +31,35 @@ struct draw_startup_receipt draw_startup(struct renderer_startup_receipt *render
|
|||||||
void draw_quad_texture_ex(struct renderer_cmd_buffer *cmdbuff, struct renderer_texture texture, struct sprite_tag sprite, struct clip_rect clip, u32 tint0, u32 tint1, struct quad quad)
|
void draw_quad_texture_ex(struct renderer_cmd_buffer *cmdbuff, struct renderer_texture texture, struct sprite_tag sprite, struct clip_rect clip, u32 tint0, u32 tint1, struct quad quad)
|
||||||
{
|
{
|
||||||
struct renderer_cmd_parameters cmd_params = ZI;
|
struct renderer_cmd_parameters cmd_params = ZI;
|
||||||
cmd_params.kind = SHADER_TEXTURE;
|
cmd_params.kind = SHADER_TRIANGLE;
|
||||||
cmd_params.texture_params.texture = texture;
|
cmd_params.texture_params.texture = texture;
|
||||||
cmd_params.texture_params.sprite = sprite;
|
cmd_params.texture_params.sprite = sprite;
|
||||||
renderer_cmd_buffer_ensure_cmd(cmdbuff, &cmd_params);
|
renderer_cmd_buffer_ensure_cmd(cmdbuff, &cmd_params);
|
||||||
|
|
||||||
struct texture_shader_vertex *vertices = NULL;
|
struct triangle_shader_vertex *vertices = NULL;
|
||||||
vidx *indices = NULL;
|
vidx *indices = NULL;
|
||||||
u32 offset = renderer_cmd_buffer_push_vertices(cmdbuff, (u8 **)&vertices, &indices, 4, 6);
|
u32 offset = renderer_cmd_buffer_push_vertices(cmdbuff, (u8 **)&vertices, &indices, 4, 6);
|
||||||
|
|
||||||
/* Top left */
|
/* Top left */
|
||||||
vertices[0] = (struct texture_shader_vertex) {
|
vertices[0] = (struct triangle_shader_vertex) {
|
||||||
.pos = quad.p1,
|
.pos = quad.p1,
|
||||||
.uv = { clip.p1.x, clip.p1.y },
|
.uv = { clip.p1.x, clip.p1.y },
|
||||||
.color = tint0
|
.color = tint0
|
||||||
};
|
};
|
||||||
/* Top right */
|
/* Top right */
|
||||||
vertices[1] = (struct texture_shader_vertex) {
|
vertices[1] = (struct triangle_shader_vertex) {
|
||||||
.pos = quad.p2,
|
.pos = quad.p2,
|
||||||
.uv = { clip.p2.x, clip.p1.y },
|
.uv = { clip.p2.x, clip.p1.y },
|
||||||
.color = tint0
|
.color = tint0
|
||||||
};
|
};
|
||||||
/* Bottom right */
|
/* Bottom right */
|
||||||
vertices[2] = (struct texture_shader_vertex) {
|
vertices[2] = (struct triangle_shader_vertex) {
|
||||||
.pos = quad.p3,
|
.pos = quad.p3,
|
||||||
.uv = { clip.p2.x, clip.p2.y },
|
.uv = { clip.p2.x, clip.p2.y },
|
||||||
.color = tint1
|
.color = tint1
|
||||||
};
|
};
|
||||||
/* Bottom left */
|
/* Bottom left */
|
||||||
vertices[3] = (struct texture_shader_vertex) {
|
vertices[3] = (struct triangle_shader_vertex) {
|
||||||
.pos = quad.p4,
|
.pos = quad.p4,
|
||||||
.uv = { clip.p1.x, clip.p2.y },
|
.uv = { clip.p1.x, clip.p2.y },
|
||||||
.color = tint1
|
.color = tint1
|
||||||
@ -92,20 +92,20 @@ void draw_poly(struct renderer_cmd_buffer *cmdbuff, struct v2_array array, u32 c
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct renderer_cmd_parameters cmd_params = ZI;
|
struct renderer_cmd_parameters cmd_params = ZI;
|
||||||
cmd_params.kind = SHADER_TEXTURE;
|
cmd_params.kind = SHADER_TRIANGLE;
|
||||||
cmd_params.texture_params.texture = G.solid_white;
|
cmd_params.texture_params.texture = G.solid_white;
|
||||||
renderer_cmd_buffer_ensure_cmd(cmdbuff, &cmd_params);
|
renderer_cmd_buffer_ensure_cmd(cmdbuff, &cmd_params);
|
||||||
|
|
||||||
u32 num_tris = array.count - 2;
|
u32 num_tris = array.count - 2;
|
||||||
u32 num_indices = num_tris * 3;
|
u32 num_indices = num_tris * 3;
|
||||||
|
|
||||||
struct texture_shader_vertex *vertices = NULL;
|
struct triangle_shader_vertex *vertices = NULL;
|
||||||
vidx *indices = NULL;
|
vidx *indices = NULL;
|
||||||
u32 idx_offset = renderer_cmd_buffer_push_vertices(cmdbuff, (u8 **)&vertices, &indices, array.count, num_indices);
|
u32 idx_offset = renderer_cmd_buffer_push_vertices(cmdbuff, (u8 **)&vertices, &indices, array.count, num_indices);
|
||||||
|
|
||||||
/* Fill vertices */
|
/* Fill vertices */
|
||||||
for (u32 i = 0; i < array.count; ++i) {
|
for (u32 i = 0; i < array.count; ++i) {
|
||||||
vertices[i] = (struct texture_shader_vertex) {
|
vertices[i] = (struct triangle_shader_vertex) {
|
||||||
.pos = array.points[i],
|
.pos = array.points[i],
|
||||||
.color = color
|
.color = color
|
||||||
};
|
};
|
||||||
|
|||||||
@ -21,7 +21,7 @@ struct renderer_texture {
|
|||||||
|
|
||||||
enum shader_kind {
|
enum shader_kind {
|
||||||
SHADER_NONE,
|
SHADER_NONE,
|
||||||
SHADER_TEXTURE,
|
SHADER_TRIANGLE,
|
||||||
SHADER_GRID,
|
SHADER_GRID,
|
||||||
|
|
||||||
NUM_SHADERS
|
NUM_SHADERS
|
||||||
@ -37,7 +37,7 @@ struct renderer_cmd_parameters {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
PACK(struct texture_shader_vertex {
|
PACK(struct triangle_shader_vertex {
|
||||||
struct v2 pos;
|
struct v2 pos;
|
||||||
struct v2 uv;
|
struct v2 uv;
|
||||||
u32 color;
|
u32 color;
|
||||||
|
|||||||
@ -30,6 +30,8 @@
|
|||||||
//#define D3D11_DEBUG RTC
|
//#define D3D11_DEBUG RTC
|
||||||
#define D3D11_DEBUG 0
|
#define D3D11_DEBUG 0
|
||||||
|
|
||||||
|
#define D3D11_SHADER_DEBUG RTC
|
||||||
|
|
||||||
struct dx11_shader {
|
struct dx11_shader {
|
||||||
enum shader_kind kind;
|
enum shader_kind kind;
|
||||||
u32 vertex_size;
|
u32 vertex_size;
|
||||||
@ -206,10 +208,10 @@ INTERNAL void init_shader_table(void)
|
|||||||
{
|
{
|
||||||
MEMZERO_ARRAY(G.shader_info);
|
MEMZERO_ARRAY(G.shader_info);
|
||||||
|
|
||||||
/* Texture shader layout */
|
/* Triangle shader layout */
|
||||||
G.shader_info[SHADER_TEXTURE] = (struct dx11_shader_desc) {
|
G.shader_info[SHADER_TRIANGLE] = (struct dx11_shader_desc) {
|
||||||
"shaders/texture.hlsl",
|
"shaders/triangle.hlsl",
|
||||||
sizeof(struct texture_shader_vertex),
|
sizeof(struct triangle_shader_vertex),
|
||||||
{
|
{
|
||||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||||
@ -242,9 +244,9 @@ INTERNAL void shader_init(struct dx11_shader *shader, enum shader_kind kind)
|
|||||||
shader->kind = kind;
|
shader->kind = kind;
|
||||||
shader->vertex_size = shader_desc->vertex_size;
|
shader->vertex_size = shader_desc->vertex_size;
|
||||||
|
|
||||||
u32 flags = D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR | D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_WARNINGS_ARE_ERRORS;
|
u32 flags = D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR;
|
||||||
#if D3D11_DEBUG
|
#if D3D11_SHADER_DEBUG
|
||||||
flags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
|
flags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_WARNINGS_ARE_ERRORS;
|
||||||
#else
|
#else
|
||||||
flags |= D3DCOMPILE_OPTIMIZATION_LEVEL3;
|
flags |= D3DCOMPILE_OPTIMIZATION_LEVEL3;
|
||||||
#endif
|
#endif
|
||||||
@ -526,11 +528,10 @@ struct renderer_startup_receipt renderer_startup(struct sys_window *window)
|
|||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
/* TODO: Lock cmdbuff or at least global state? (in-case multi-threaded present).
|
/* TODO: Lock cmdbuff or at least global state? (in-case multi-threaded present).
|
||||||
* Another option is to store a separate device on each cmdbuff (need to
|
* Another option is to store a separate device on each cmdbuff?
|
||||||
* research if that is smart first).
|
|
||||||
*
|
*
|
||||||
* I'm thinking we may also just need to lock texture modification access while presenting */
|
* I'm thinking we may also just need to lock texture modification access while presenting */
|
||||||
INTERNAL void dx11_render_to_target(ID3D11RenderTargetView *target, struct renderer_cmd_buffer *cmdbuff, struct xform view, struct rect viewport, struct sprite_scope *sprite_scope)
|
INTERNAL void dx11_render(ID3D11RenderTargetView *target, struct renderer_cmd_buffer *cmdbuff, struct xform view, struct rect viewport, struct sprite_scope *sprite_scope)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
ID3D11DeviceContext_OMSetRenderTargets(G.devcon, 1, &target, NULL);
|
ID3D11DeviceContext_OMSetRenderTargets(G.devcon, 1, &target, NULL);
|
||||||
@ -550,6 +551,7 @@ INTERNAL void dx11_render_to_target(ID3D11RenderTargetView *target, struct rende
|
|||||||
struct mat4x4 vp_matrix = calculate_vp(view, viewport.width, viewport.height);
|
struct mat4x4 vp_matrix = calculate_vp(view, viewport.width, viewport.height);
|
||||||
send_constant_buffer_data(G.vs_constant_buffer, vp_matrix);
|
send_constant_buffer_data(G.vs_constant_buffer, vp_matrix);
|
||||||
ID3D11DeviceContext_VSSetConstantBuffers(G.devcon, 0, 1, &G.vs_constant_buffer);
|
ID3D11DeviceContext_VSSetConstantBuffers(G.devcon, 0, 1, &G.vs_constant_buffer);
|
||||||
|
ID3D11DeviceContext_PSSetConstantBuffers(G.devcon, 0, 1, &G.vs_constant_buffer);
|
||||||
|
|
||||||
struct dx11_shader *last_shader = NULL;
|
struct dx11_shader *last_shader = NULL;
|
||||||
|
|
||||||
@ -575,7 +577,7 @@ INTERNAL void dx11_render_to_target(ID3D11RenderTargetView *target, struct rende
|
|||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case SHADER_TEXTURE:
|
case SHADER_TRIANGLE:
|
||||||
{
|
{
|
||||||
/* FIXME: Texture refcount needs to be increased here to prevent release mid-render */
|
/* FIXME: Texture refcount needs to be increased here to prevent release mid-render */
|
||||||
ID3D11Texture2D *texture = NULL;
|
ID3D11Texture2D *texture = NULL;
|
||||||
@ -797,7 +799,7 @@ void renderer_texture_render(struct renderer_texture texture, struct renderer_cm
|
|||||||
ID3D11RenderTargetView *target_view = NULL;
|
ID3D11RenderTargetView *target_view = NULL;
|
||||||
ID3D11Device_CreateRenderTargetView(G.dev, (ID3D11Resource *)t->texture, NULL, &target_view);
|
ID3D11Device_CreateRenderTargetView(G.dev, (ID3D11Resource *)t->texture, NULL, &target_view);
|
||||||
if (target_view) {
|
if (target_view) {
|
||||||
dx11_render_to_target(target_view, cmdbuff, view, viewport, sprite_scope);
|
dx11_render(target_view, cmdbuff, view, viewport, sprite_scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target_view) {
|
if (target_view) {
|
||||||
@ -942,15 +944,15 @@ void renderer_cmd_buffer_ensure_cmd(struct renderer_cmd_buffer *cmdbuff, struct
|
|||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case SHADER_TEXTURE:
|
case SHADER_TRIANGLE:
|
||||||
{
|
{
|
||||||
if (!last_cmd
|
if (!last_cmd
|
||||||
|| last_cmd->shader->kind != SHADER_TEXTURE
|
|| last_cmd->shader->kind != SHADER_TRIANGLE
|
||||||
|| (last_cmd->texture.handle != params->texture_params.texture.handle)
|
|| (last_cmd->texture.handle != params->texture_params.texture.handle)
|
||||||
|| !sprite_tag_eq(last_cmd->sprite, params->texture_params.sprite)) {
|
|| !sprite_tag_eq(last_cmd->sprite, params->texture_params.sprite)) {
|
||||||
new_cmd = arena_push(&cmdbuff->cpu_cmd_store.arena, struct renderer_cmd);
|
new_cmd = arena_push(&cmdbuff->cpu_cmd_store.arena, struct renderer_cmd);
|
||||||
*new_cmd = (struct renderer_cmd) {
|
*new_cmd = (struct renderer_cmd) {
|
||||||
.shader = &G.shaders[SHADER_TEXTURE],
|
.shader = &G.shaders[SHADER_TRIANGLE],
|
||||||
.texture = params->texture_params.texture,
|
.texture = params->texture_params.texture,
|
||||||
.sprite = params->texture_params.sprite
|
.sprite = params->texture_params.sprite
|
||||||
};
|
};
|
||||||
@ -993,6 +995,7 @@ void renderer_cmd_buffer_send_to_gpu(struct renderer_cmd_buffer *cmdbuff)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create / grow vertex buffer */
|
||||||
if (!buffer->gpu_vertex_buffer || buffer->gpu_vertex_buffer_capacity < buffer->vertex_count) {
|
if (!buffer->gpu_vertex_buffer || buffer->gpu_vertex_buffer_capacity < buffer->vertex_count) {
|
||||||
buffer->gpu_vertex_buffer_capacity = buffer->vertex_count + 5000;
|
buffer->gpu_vertex_buffer_capacity = buffer->vertex_count + 5000;
|
||||||
D3D11_BUFFER_DESC desc = {
|
D3D11_BUFFER_DESC desc = {
|
||||||
|
|||||||
@ -3,6 +3,11 @@ struct {
|
|||||||
Texture2D texture0;
|
Texture2D texture0;
|
||||||
} globals;
|
} globals;
|
||||||
|
|
||||||
|
cbuffer constants : register(b0)
|
||||||
|
{
|
||||||
|
float4x4 projection;
|
||||||
|
};
|
||||||
|
|
||||||
struct vs_input {
|
struct vs_input {
|
||||||
float4 pos : POSITION;
|
float4 pos : POSITION;
|
||||||
float2 uv : TEXCOORD;
|
float2 uv : TEXCOORD;
|
||||||
@ -15,11 +20,6 @@ struct ps_input {
|
|||||||
float4 col : COLOR;
|
float4 col : COLOR;
|
||||||
};
|
};
|
||||||
|
|
||||||
cbuffer vs_constants : register(b0)
|
|
||||||
{
|
|
||||||
float4x4 projection;
|
|
||||||
};
|
|
||||||
|
|
||||||
ps_input vs_main(vs_input input)
|
ps_input vs_main(vs_input input)
|
||||||
{
|
{
|
||||||
ps_input output;
|
ps_input output;
|
||||||
Loading…
Reference in New Issue
Block a user