rename surface and vertex structs

This commit is contained in:
Anthony Pesch 2017-05-23 19:03:40 -04:00
parent 71032563ea
commit 02b67e56d1
8 changed files with 152 additions and 158 deletions

View File

@ -50,7 +50,7 @@ struct emu {
volatile int video_width;
volatile int video_height;
struct tr_context video_ctx;
struct tr_context video_rc;
int video_fb_width;
int video_fb_height;
framebuffer_handle_t video_fb;
@ -85,7 +85,7 @@ static void emu_render_frame(struct emu *emu) {
/* render the current render context to the video framebuffer */
framebuffer_handle_t original = r_get_framebuffer(r2);
r_bind_framebuffer(r2, emu->video_fb);
tr_render_context(emu->tr, &emu->video_ctx, emu->video_fb_width,
tr_render_context(emu->tr, &emu->video_rc, emu->video_fb_width,
emu->video_fb_height);
r_bind_framebuffer(r2, original);
@ -122,7 +122,7 @@ static void *emu_video_thread(void *data) {
}
/* parse the context, uploading its textures to the render backend */
tr_parse_context(emu->tr, emu->pending_ctx, &emu->video_ctx);
tr_parse_context(emu->tr, emu->pending_ctx, &emu->video_rc);
emu->pending_ctx = NULL;
/* after the context has been parsed, release the mutex to let
@ -152,7 +152,7 @@ static void emu_paint(struct emu *emu) {
/* present the latest frame from the video thread */
{
struct vertex2 verts[6] = {
struct ui_vertex verts[6] = {
/* triangle 1, top left */
{{0.0f, 0.0f}, {0.0f, 1.0f}, 0xffffffff},
/* triangle 1, top right */
@ -167,7 +167,7 @@ static void emu_paint(struct emu *emu) {
{{0.0f, fheight}, {0.0f, 0.0f}, 0xffffffff},
};
struct surface2 quad = {0};
struct ui_surface quad = {0};
quad.prim_type = PRIM_TRIANGLES;
quad.texture = emu->video_tex;
quad.src_blend = BLEND_NONE;
@ -182,11 +182,9 @@ static void emu_paint(struct emu *emu) {
emu->video_sync = 0;
}
r_begin_ortho(emu->r);
r_begin_surfaces2(emu->r, verts, 6, NULL, 0);
r_draw_surface2(emu->r, &quad);
r_end_surfaces2(emu->r);
r_end_ortho(emu->r);
r_begin_ui_surfaces(emu->r, verts, 6, NULL, 0);
r_draw_ui_surface(emu->r, &quad);
r_end_ui_surfaces(emu->r);
}
/* render debug menus */
@ -279,7 +277,7 @@ static void emu_start_render(void *userdata, struct tile_context *ctx) {
mutex_unlock(emu->pending_mutex);
} else {
/* parse the context and immediately render it */
tr_parse_context(emu->tr, ctx, &emu->video_ctx);
tr_parse_context(emu->tr, ctx, &emu->video_rc);
emu_render_frame(emu);
}

View File

@ -353,11 +353,11 @@ static texture_handle_t tr_demand_texture(struct tr *tr,
return entry->handle;
}
static struct surface *tr_alloc_surf(struct tr *tr, struct tr_context *rc,
int copy_from_prev) {
static struct ta_surface *tr_alloc_surf(struct tr *tr, struct tr_context *rc,
int copy_from_prev) {
CHECK_LT(rc->num_surfs, array_size(rc->surfs));
int id = rc->num_surfs++;
struct surface *surf = &rc->surfs[id];
struct ta_surface *surf = &rc->surfs[id];
if (copy_from_prev) {
*surf = rc->surfs[id - 1];
@ -376,14 +376,14 @@ static struct surface *tr_alloc_surf(struct tr *tr, struct tr_context *rc,
return surf;
}
static struct vertex *tr_alloc_vert(struct tr *tr, struct tr_context *rc) {
static struct ta_vertex *tr_alloc_vert(struct tr *tr, struct tr_context *rc) {
CHECK_LT(rc->num_verts, array_size(rc->verts));
int id = rc->num_verts++;
struct vertex *v = &rc->verts[id];
struct ta_vertex *v = &rc->verts[id];
memset(v, 0, sizeof(*v));
/* update vertex count on the current surface */
struct surface *surf = &rc->surfs[rc->num_surfs - 1];
struct ta_surface *surf = &rc->surfs[rc->num_surfs - 1];
surf->num_verts++;
return v;
@ -440,7 +440,7 @@ static void tr_discard_incomplete_surf(struct tr *tr, struct tr_context *rc) {
static int tr_parse_bg_vert(const struct tile_context *ctx,
struct tr_context *rc, int offset,
struct vertex *v) {
struct ta_vertex *v) {
PARSE_XYZ(*(float *)&ctx->bg_vertices[offset],
*(float *)&ctx->bg_vertices[offset + 4],
*(float *)&ctx->bg_vertices[offset + 8], v->xyz);
@ -475,7 +475,7 @@ static void tr_parse_bg(struct tr *tr, const struct tile_context *ctx,
tr->list_type = TA_LIST_OPAQUE;
/* translate the surface */
struct surface *surf = tr_alloc_surf(tr, rc, 0);
struct ta_surface *surf = tr_alloc_surf(tr, rc, 0);
surf->texture = 0;
surf->depth_write = !ctx->bg_isp.z_write_disable;
surf->depth_func = translate_depth_func(ctx->bg_isp.depth_compare_mode);
@ -484,10 +484,10 @@ static void tr_parse_bg(struct tr *tr, const struct tile_context *ctx,
surf->dst_blend = BLEND_NONE;
/* translate the first 3 vertices */
struct vertex *v0 = tr_alloc_vert(tr, rc);
struct vertex *v1 = tr_alloc_vert(tr, rc);
struct vertex *v2 = tr_alloc_vert(tr, rc);
struct vertex *v3 = tr_alloc_vert(tr, rc);
struct ta_vertex *v0 = tr_alloc_vert(tr, rc);
struct ta_vertex *v1 = tr_alloc_vert(tr, rc);
struct ta_vertex *v2 = tr_alloc_vert(tr, rc);
struct ta_vertex *v3 = tr_alloc_vert(tr, rc);
int offset = 0;
offset = tr_parse_bg_vert(ctx, rc, offset, v0);
@ -572,7 +572,7 @@ static void tr_parse_poly_param(struct tr *tr, const struct tile_context *ctx,
}
/* setup the new surface */
struct surface *surf = tr_alloc_surf(tr, rc, 0);
struct ta_surface *surf = tr_alloc_surf(tr, rc, 0);
surf->depth_write = !param->type0.isp_tsp.z_write_disable;
surf->depth_func =
translate_depth_func(param->type0.isp_tsp.depth_compare_mode);
@ -620,7 +620,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
switch (tr->vertex_type) {
case 0: {
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
PARSE_XYZ(param->type0.xyz[0], param->type0.xyz[1], param->type0.xyz[2],
vert->xyz);
PARSE_COLOR(param->type0.base_color, &vert->color);
@ -630,7 +630,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
} break;
case 1: {
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
PARSE_XYZ(param->type1.xyz[0], param->type1.xyz[1], param->type1.xyz[2],
vert->xyz);
PARSE_COLOR_RGBA(param->type1.base_color_r, param->type1.base_color_g,
@ -642,7 +642,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
} break;
case 2: {
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
PARSE_XYZ(param->type2.xyz[0], param->type2.xyz[1], param->type2.xyz[2],
vert->xyz);
PARSE_COLOR_INTENSITY(param->type2.base_intensity, &vert->color);
@ -652,7 +652,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
} break;
case 3: {
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
PARSE_XYZ(param->type3.xyz[0], param->type3.xyz[1], param->type3.xyz[2],
vert->xyz);
PARSE_COLOR(param->type3.base_color, &vert->color);
@ -662,7 +662,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
} break;
case 4: {
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
PARSE_XYZ(param->type4.xyz[0], param->type4.xyz[1], param->type4.xyz[2],
vert->xyz);
PARSE_COLOR(param->type4.base_color, &vert->color);
@ -674,7 +674,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
} break;
case 5: {
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
PARSE_XYZ(param->type5.xyz[0], param->type5.xyz[1], param->type5.xyz[2],
vert->xyz);
PARSE_COLOR_RGBA(param->type5.base_color_r, param->type5.base_color_g,
@ -689,7 +689,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
} break;
case 6: {
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
PARSE_XYZ(param->type6.xyz[0], param->type6.xyz[1], param->type6.xyz[2],
vert->xyz);
PARSE_COLOR_RGBA(param->type6.base_color_r, param->type6.base_color_g,
@ -706,7 +706,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
} break;
case 7: {
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
PARSE_XYZ(param->type7.xyz[0], param->type7.xyz[1], param->type7.xyz[2],
vert->xyz);
PARSE_COLOR_INTENSITY(param->type7.base_intensity, &vert->color);
@ -717,7 +717,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
} break;
case 8: {
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
PARSE_XYZ(param->type8.xyz[0], param->type8.xyz[1], param->type8.xyz[2],
vert->xyz);
PARSE_COLOR_INTENSITY(param->type8.base_intensity, &vert->color);
@ -734,7 +734,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
for (int i = 0, l = array_size(indices); i < l; i++) {
int idx = indices[i];
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
/* FIXME this is assuming all sprites are billboards */
PARSE_XYZ(param->sprite0.xyz[idx][0], param->sprite0.xyz[idx][1],
@ -753,7 +753,7 @@ static void tr_parse_vert_param(struct tr *tr, const struct tile_context *ctx,
for (int i = 0, l = array_size(indices); i < l; i++) {
int idx = indices[i];
struct vertex *vert = tr_alloc_vert(tr, rc);
struct ta_vertex *vert = tr_alloc_vert(tr, rc);
/* FIXME this is assuming all sprites are billboards */
PARSE_XYZ(param->sprite1.xyz[idx][0], param->sprite1.xyz[idx][1],
@ -841,7 +841,7 @@ static void tr_sort_render_list(struct tr *tr, struct tr_context *rc,
for (int i = 0; i < list->num_surfs; i++) {
int idx = list->surfs[i];
struct surface *surf = &rc->surfs[idx];
struct ta_surface *surf = &rc->surfs[idx];
float *minz = &tr->minz[idx];
/* the surf coordinates have 1/w for z, so smaller values are
@ -849,7 +849,7 @@ static void tr_sort_render_list(struct tr *tr, struct tr_context *rc,
*minz = FLT_MAX;
for (int j = 0; j < surf->num_verts; j++) {
struct vertex *v = &rc->verts[surf->first_vert + j];
struct ta_vertex *v = &rc->verts[surf->first_vert + j];
*minz = MIN(*minz, v->xyz[2]);
}
}
@ -925,7 +925,7 @@ static void tr_render_list(struct tr *tr, const struct tr_context *rc,
const int *sorted_surf_end = list->surfs + list->num_surfs;
while (sorted_surf < sorted_surf_end) {
r_draw_surface(tr->r, &rc->surfs[*sorted_surf]);
r_draw_ta_surface(tr->r, &rc->surfs[*sorted_surf]);
sorted_surf++;
}
}
@ -936,13 +936,13 @@ void tr_render_context(struct tr *tr, const struct tr_context *rc,
r_clear_viewport(tr->r, video_width, video_height);
r_begin_surfaces(tr->r, rc->projection, rc->verts, rc->num_verts);
r_begin_ta_surfaces(tr->r, rc->projection, rc->verts, rc->num_verts);
tr_render_list(tr, rc, TA_LIST_OPAQUE);
tr_render_list(tr, rc, TA_LIST_PUNCH_THROUGH);
tr_render_list(tr, rc, TA_LIST_TRANSLUCENT);
r_end_surfaces(tr->r);
r_end_ta_surfaces(tr->r);
PROF_LEAVE();
}

View File

@ -65,10 +65,10 @@ struct tr_context {
float projection[16];
/* parsed surfaces and vertices, ready to be passed to the render backend */
struct surface surfs[TA_MAX_SURFS];
struct ta_surface surfs[TA_MAX_SURFS];
int num_surfs;
struct vertex verts[TA_MAX_VERTS];
struct ta_vertex verts[TA_MAX_VERTS];
int num_verts;
/* sorted list of surfaces corresponding to each of the ta's polygon lists */

View File

@ -333,19 +333,19 @@ static void r_create_vertex_arrays(struct render_backend *r) {
/* xy */
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(struct vertex2),
(void *)offsetof(struct vertex2, xy));
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(struct ui_vertex),
(void *)offsetof(struct ui_vertex, xy));
/* texcoord */
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(struct vertex2),
(void *)offsetof(struct vertex2, uv));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(struct ui_vertex),
(void *)offsetof(struct ui_vertex, uv));
/* color */
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE,
sizeof(struct vertex2),
(void *)offsetof(struct vertex2, color));
sizeof(struct ui_vertex),
(void *)offsetof(struct ui_vertex, color));
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
@ -361,25 +361,25 @@ static void r_create_vertex_arrays(struct render_backend *r) {
/* xyz */
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(struct vertex),
(void *)offsetof(struct vertex, xyz));
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(struct ta_vertex),
(void *)offsetof(struct ta_vertex, xyz));
/* texcoord */
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(struct vertex),
(void *)offsetof(struct vertex, uv));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(struct ta_vertex),
(void *)offsetof(struct ta_vertex, uv));
/* color */
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE,
sizeof(struct vertex),
(void *)offsetof(struct vertex, color));
sizeof(struct ta_vertex),
(void *)offsetof(struct ta_vertex, color));
/* offset color */
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 4, GL_UNSIGNED_BYTE, GL_TRUE,
sizeof(struct vertex),
(void *)offsetof(struct vertex, offset_color));
sizeof(struct ta_vertex),
(void *)offsetof(struct ta_vertex, offset_color));
glBindVertexArray(0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
@ -398,7 +398,7 @@ static void r_set_initial_state(struct render_backend *r) {
}
static struct shader_program *r_get_ta_program(struct render_backend *r,
const struct surface *surf) {
const struct ta_surface *surf) {
int idx = surf->shade;
if (surf->texture) {
idx |= ATTR_TEXTURE;
@ -463,9 +463,10 @@ static struct shader_program *r_get_ta_program(struct render_backend *r,
return program;
}
void r_end_surfaces(struct render_backend *r) {}
void r_end_ta_surfaces(struct render_backend *r) {}
void r_draw_surface(struct render_backend *r, const struct surface *surf) {
void r_draw_ta_surface(struct render_backend *r,
const struct ta_surface *surf) {
glDepthMask(!!surf->depth_write);
if (surf->depth_func == DEPTH_NONE) {
@ -509,21 +510,24 @@ void r_draw_surface(struct render_backend *r, const struct surface *surf) {
glDrawArrays(GL_TRIANGLE_STRIP, surf->first_vert, surf->num_verts);
}
void r_begin_surfaces(struct render_backend *r, const float *projection,
const struct vertex *verts, int num_verts) {
void r_begin_ta_surfaces(struct render_backend *r, const float *projection,
const struct ta_vertex *verts, int num_verts) {
/* uniforms will be lazily bound for each program inside of r_draw_surface */
r->uniform_token++;
r->uniform_mvp = projection;
glBindBuffer(GL_ARRAY_BUFFER, r->ta_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(struct vertex) * num_verts, verts,
glBufferData(GL_ARRAY_BUFFER, sizeof(struct ta_vertex) * num_verts, verts,
GL_DYNAMIC_DRAW);
glBindVertexArray(r->ta_vao);
}
void r_end_surfaces2(struct render_backend *r) {}
void r_end_ui_surfaces(struct render_backend *r) {
glDisable(GL_SCISSOR_TEST);
}
void r_draw_surface2(struct render_backend *r, const struct surface2 *surf) {
void r_draw_ui_surface(struct render_backend *r,
const struct ui_surface *surf) {
if (surf->scissor) {
glEnable(GL_SCISSOR_TEST);
glScissor((int)surf->scissor_rect[0], (int)surf->scissor_rect[1],
@ -555,29 +559,10 @@ void r_draw_surface2(struct render_backend *r, const struct surface2 *surf) {
}
}
void r_begin_surfaces2(struct render_backend *r, const struct vertex2 *verts,
int num_verts, const uint16_t *indices,
int num_indices) {
glBindBuffer(GL_ARRAY_BUFFER, r->ui_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(struct vertex2) * num_verts, verts,
GL_DYNAMIC_DRAW);
if (indices) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, r->ui_ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(uint16_t) * num_indices,
indices, GL_DYNAMIC_DRAW);
r->ui_use_ibo = 1;
} else {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
r->ui_use_ibo = 0;
}
}
void r_end_ortho(struct render_backend *r) {
glDisable(GL_SCISSOR_TEST);
}
void r_begin_ortho(struct render_backend *r) {
void r_begin_ui_surfaces(struct render_backend *r,
const struct ui_vertex *verts, int num_verts,
const uint16_t *indices, int num_indices) {
/* setup projection matrix */
int width = video_width(r->host);
int height = video_height(r->host);
@ -610,6 +595,21 @@ void r_begin_ortho(struct render_backend *r) {
glBindVertexArray(r->ui_vao);
glUseProgram(program->prog);
glUniformMatrix4fv(program->loc[UNIFORM_MVP], 1, GL_FALSE, ortho);
/* bind buffers */
glBindBuffer(GL_ARRAY_BUFFER, r->ui_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(struct ui_vertex) * num_verts, verts,
GL_DYNAMIC_DRAW);
if (indices) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, r->ui_ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(uint16_t) * num_indices,
indices, GL_DYNAMIC_DRAW);
r->ui_use_ibo = 1;
} else {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
r->ui_use_ibo = 0;
}
}
void r_clear_viewport(struct render_backend *r, int width, int height) {

View File

@ -28,9 +28,9 @@ struct microprofile {
struct render_backend *r;
texture_handle_t font_texture;
struct surface2 surfs[MAX_2D_SURFACES];
struct ui_surface surfs[MAX_2D_SURFACES];
int num_surfs;
struct vertex2 verts[MAX_2D_VERTICES];
struct ui_vertex verts[MAX_2D_VERTICES];
int num_verts;
};
@ -45,15 +45,16 @@ static struct microprofile *s_mp;
d[2].member = v; \
d[5].member = v
static struct vertex2 *mp_alloc_verts(struct microprofile *mp,
const struct surface2 &desc, int count) {
static struct ui_vertex *mp_alloc_verts(struct microprofile *mp,
const struct ui_surface &desc,
int count) {
CHECK(mp->num_verts + count <= MAX_2D_VERTICES);
uint32_t first_vert = mp->num_verts;
mp->num_verts += count;
/* try to batch with the last surface if possible */
if (mp->num_surfs) {
struct surface2 &last_surf = mp->surfs[mp->num_surfs - 1];
struct ui_surface &last_surf = mp->surfs[mp->num_surfs - 1];
if (last_surf.prim_type == desc.prim_type &&
last_surf.texture == desc.texture &&
@ -66,7 +67,7 @@ static struct vertex2 *mp_alloc_verts(struct microprofile *mp,
/* else, allocate a new surface */
CHECK(mp->num_surfs < MAX_2D_SURFACES);
struct surface2 &next_surf = mp->surfs[mp->num_surfs];
struct ui_surface &next_surf = mp->surfs[mp->num_surfs];
next_surf.prim_type = desc.prim_type;
next_surf.texture = desc.texture;
next_surf.src_blend = desc.src_blend;
@ -85,15 +86,15 @@ static void mp_draw_text(struct microprofile *mp, int x, int y, uint32_t color,
float fy2 = fy + (MICROPROFILE_TEXT_HEIGHT + 1);
int text_len = static_cast<int>(strlen(text));
struct vertex2 *vertex = mp_alloc_verts(mp, {PRIM_TRIANGLES,
mp->font_texture,
BLEND_SRC_ALPHA,
BLEND_ONE_MINUS_SRC_ALPHA,
false,
{0.0f, 0.0f, 0.0f, 0.0f},
0,
0},
6 * text_len);
struct ui_vertex *vertex = mp_alloc_verts(mp, {PRIM_TRIANGLES,
mp->font_texture,
BLEND_SRC_ALPHA,
BLEND_ONE_MINUS_SRC_ALPHA,
false,
{0.0f, 0.0f, 0.0f, 0.0f},
0,
0},
6 * text_len);
for (int i = 0; i < text_len; i++) {
float fx2 = fx + MICROPROFILE_TEXT_WIDTH;
@ -133,15 +134,15 @@ static void mp_draw_text(struct microprofile *mp, int x, int y, uint32_t color,
static void mp_draw_box(struct microprofile *mp, int x0, int y0, int x1, int y1,
uint32_t color, enum box_type type) {
struct vertex2 *vertex = mp_alloc_verts(mp, {PRIM_TRIANGLES,
0,
BLEND_SRC_ALPHA,
BLEND_ONE_MINUS_SRC_ALPHA,
false,
{0.0f, 0.0f, 0.0f, 0.0f},
0,
0},
6);
struct ui_vertex *vertex = mp_alloc_verts(mp, {PRIM_TRIANGLES,
0,
BLEND_SRC_ALPHA,
BLEND_ONE_MINUS_SRC_ALPHA,
false,
{0.0f, 0.0f, 0.0f, 0.0f},
0,
0},
6);
if (type == BOX_FLAT) {
Q0(vertex, xy[0], (float)x0);
@ -192,15 +193,15 @@ static void mp_draw_line(struct microprofile *mp, float *verts, int num_verts,
uint32_t color) {
CHECK(num_verts);
struct vertex2 *vertex = mp_alloc_verts(mp, {PRIM_LINES,
0,
BLEND_SRC_ALPHA,
BLEND_ONE_MINUS_SRC_ALPHA,
false,
{0.0f, 0.0f, 0.0f, 0.0f},
0,
0},
2 * (num_verts - 1));
struct ui_vertex *vertex = mp_alloc_verts(mp, {PRIM_LINES,
0,
BLEND_SRC_ALPHA,
BLEND_ONE_MINUS_SRC_ALPHA,
false,
{0.0f, 0.0f, 0.0f, 0.0f},
0,
0},
2 * (num_verts - 1));
for (int i = 0; i < num_verts - 1; ++i) {
vertex[0].xy[0] = verts[i * 2];
@ -223,16 +224,14 @@ void mp_render(struct microprofile *mp) {
MicroProfileDraw(width, height);
/* render the surfaces */
r_begin_ortho(mp->r);
r_begin_surfaces2(mp->r, mp->verts, mp->num_verts, nullptr, 0);
r_begin_ui_surfaces(mp->r, mp->verts, mp->num_verts, nullptr, 0);
for (int i = 0; i < mp->num_surfs; i++) {
struct surface2 *surf = &mp->surfs[i];
r_draw_surface2(mp->r, surf);
struct ui_surface *surf = &mp->surfs[i];
r_draw_ui_surface(mp->r, surf);
}
r_end_surfaces2(mp->r);
r_end_ortho(mp->r);
r_end_ui_surfaces(mp->r);
/* reset surfaces */
mp->num_surfs = 0;

View File

@ -21,15 +21,16 @@ void nk_render(struct nuklear *nk) {
/* convert draw list into vertex / element buffers */
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct vertex2, xy)},
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct vertex2, uv)},
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct vertex2, color)},
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct ui_vertex, xy)},
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct ui_vertex, uv)},
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8,
NK_OFFSETOF(struct ui_vertex, color)},
{NK_VERTEX_LAYOUT_END}};
struct nk_convert_config config = {0};
config.vertex_layout = vertex_layout;
config.vertex_size = sizeof(struct vertex2);
config.vertex_alignment = NK_ALIGNOF(struct vertex2);
config.vertex_size = sizeof(struct ui_vertex);
config.vertex_alignment = NK_ALIGNOF(struct ui_vertex);
config.null = nk->null;
config.global_alpha = 1.0f;
config.shape_AA = NK_ANTI_ALIASING_OFF;
@ -40,15 +41,14 @@ void nk_render(struct nuklear *nk) {
/* bind buffers */
const void *vertices = nk_buffer_memory_const(&nk->vbuf);
const void *elements = nk_buffer_memory_const(&nk->ebuf);
r_begin_ortho(nk->r);
r_begin_surfaces2(nk->r, vertices, nk->ctx.draw_list.vertex_count, elements,
nk->ctx.draw_list.element_count);
r_begin_ui_surfaces(nk->r, vertices, nk->ctx.draw_list.vertex_count, elements,
nk->ctx.draw_list.element_count);
/* pass each draw command off to the render backend */
const struct nk_draw_command *cmd = NULL;
int offset = 0;
struct surface2 surf = {0};
struct ui_surface surf = {0};
surf.prim_type = PRIM_TRIANGLES;
surf.src_blend = BLEND_SRC_ALPHA;
surf.dst_blend = BLEND_ONE_MINUS_SRC_ALPHA;
@ -67,14 +67,13 @@ void nk_render(struct nuklear *nk) {
surf.first_vert = offset;
surf.num_verts = cmd->elem_count;
r_draw_surface2(nk->r, &surf);
r_draw_ui_surface(nk->r, &surf);
offset += cmd->elem_count;
}
nk_clear(&nk->ctx);
r_end_surfaces2(nk->r);
r_end_ortho(nk->r);
r_end_ui_surfaces(nk->r);
/* reset mouse wheel state at this point as it won't be reset through an
actual input event */

View File

@ -83,14 +83,14 @@ enum debug_flags {
DEBUG_DEPTH_BUFFER = 0x1,
};
struct vertex {
struct ta_vertex {
float xyz[3];
float uv[2];
uint32_t color;
uint32_t offset_color;
};
struct surface {
struct ta_surface {
texture_handle_t texture;
int depth_write;
enum depth_func depth_func;
@ -109,13 +109,13 @@ struct surface {
int num_verts;
};
struct vertex2 {
struct ui_vertex {
float xy[2];
float uv[2];
uint32_t color;
};
struct surface2 {
struct ui_surface {
enum prim_type prim_type;
texture_handle_t texture;
@ -167,17 +167,15 @@ void r_destroy_sync(struct render_backend *r, sync_handle_t handle);
void r_clear_viewport(struct render_backend *r, int width, int height);
void r_begin_ortho(struct render_backend *r);
void r_end_ortho(struct render_backend *r);
void r_begin_ta_surfaces(struct render_backend *r, const float *projection,
const struct ta_vertex *verts, int num_verts);
void r_draw_ta_surface(struct render_backend *r, const struct ta_surface *surf);
void r_end_ta_surfaces(struct render_backend *r);
void r_begin_surfaces(struct render_backend *r, const float *projection,
const struct vertex *verts, int num_verts);
void r_draw_surface(struct render_backend *r, const struct surface *surf);
void r_end_surfaces(struct render_backend *r);
void r_begin_surfaces2(struct render_backend *r, const struct vertex2 *verts,
int num_verts, const uint16_t *indices, int num_indices);
void r_draw_surface2(struct render_backend *r, const struct surface2 *surf);
void r_end_surfaces2(struct render_backend *r);
void r_begin_ui_surfaces(struct render_backend *r,
const struct ui_vertex *verts, int num_verts,
const uint16_t *indices, int num_indices);
void r_draw_ui_surface(struct render_backend *r, const struct ui_surface *surf);
void r_end_ui_surfaces(struct render_backend *r);
#endif

View File

@ -563,7 +563,7 @@ static void tracer_param_tooltip(struct tracer *tracer, struct tr_param *rp) {
/* always render translated surface information. new surfaces can be created
without receiving a new TA_PARAM_POLY_OR_VOL / TA_PARAM_SPRITE */
if (rp->last_surf >= 0) {
struct surface *surf = &tracer->rc.surfs[rp->last_surf];
struct ta_surface *surf = &tracer->rc.surfs[rp->last_surf];
/* TODO separator */
@ -592,7 +592,7 @@ static void tracer_param_tooltip(struct tracer *tracer, struct tr_param *rp) {
/* render translated vert only when rendering a vertex tooltip */
if (rp->last_vert >= 0) {
struct vertex *vert = &tracer->rc.verts[rp->last_vert];
struct ta_vertex *vert = &tracer->rc.verts[rp->last_vert];
/* TODO separator */
@ -776,7 +776,7 @@ static void tracer_render_list(struct tracer *tracer,
while (sorted_surf < sorted_surf_end) {
int idx = *(sorted_surf++);
r_draw_surface(tracer->r, &tracer->rc.surfs[idx]);
r_draw_ta_surface(tracer->r, &tracer->rc.surfs[idx]);
if (idx == end) {
*stopped = 1;
@ -832,13 +832,13 @@ void tracer_run_frame(struct tracer *tracer) {
end = rp->last_surf;
}
r_begin_surfaces(tracer->r, rc->projection, rc->verts, rc->num_verts);
r_begin_ta_surfaces(tracer->r, rc->projection, rc->verts, rc->num_verts);
tracer_render_list(tracer, rc, TA_LIST_OPAQUE, end, &stopped);
tracer_render_list(tracer, rc, TA_LIST_PUNCH_THROUGH, end, &stopped);
tracer_render_list(tracer, rc, TA_LIST_TRANSLUCENT, end, &stopped);
r_end_surfaces(tracer->r);
r_end_ta_surfaces(tracer->r);
}
nk_render(tracer->nk);