| 1138 | } |
| 1139 | |
| 1140 | void UI_render(UI_Context *ctx) { |
| 1141 | UI_assert(ctx != nullptr && "UI context *ctx is a null pointer!"); |
| 1142 | UI_assert(ctx->initialized && "UI context wasn't initialized!"); |
| 1143 | UI_assert(ctx->backend != UI_Render_Backend_Type::None && "No render backend is initialized!"); |
| 1144 | // prepare render data |
| 1145 | auto buffer = UI_get_current_frame_buffer(ctx); |
| 1146 | for (int i = 0; i < buffer->count; i++) { |
| 1147 | UI_Vertex vertex = { 0 }; |
| 1148 | UI_Block *block = &buffer->data[i]; |
| 1149 | // TODO(Wassim): vertex.texture_id = |
| 1150 | vertex.rotation = 0; |
| 1151 | vertex.dst_p0 = block->position; |
| 1152 | vertex.dst_p1 = vertex.dst_p0 + v2(block->size.e[axis_x], |
| 1153 | block->size.e[axis_y]); |
| 1154 | if (vertex.dst_p0.x > WW || vertex.dst_p0.y > WH || |
| 1155 | vertex.dst_p1.x < 0 || vertex.dst_p1.y < 0) |
| 1156 | continue; |
| 1157 | vertex.texture_id = -1; |
| 1158 | if (block->flags & UI_Block_Flags_draw_image) { |
| 1159 | vertex.texture_id = block->style.texture_handle; |
| 1160 | vertex.src_p0 = block->style.texture_uv; |
| 1161 | vertex.src_p1 = vertex.src_p0 + block->style.texture_src_size; |
| 1162 | vertex.rotation = block->style.texture_rotation; |
| 1163 | } |
| 1164 | vertex.roundness = block->style.roundness; |
| 1165 | vertex.softness = block->style.softness; |
| 1166 | //vertex.softness = 1.5; |
| 1167 | if (block->flags & UI_Block_Flags_draw_background) { |
| 1168 | vertex.colors[0] = UI_u32_to_v4(block->style.color[c_background].c[0]); |
| 1169 | vertex.colors[1] = UI_u32_to_v4(block->style.color[c_background].c[1]); |
| 1170 | vertex.colors[2] = UI_u32_to_v4(block->style.color[c_background].c[2]); |
| 1171 | vertex.colors[3] = UI_u32_to_v4(block->style.color[c_background].c[3]); |
| 1172 | } |
| 1173 | vertex.flags = 0; |
| 1174 | |
| 1175 | if (block->flags & UI_Block_Flags_render_srgb) vertex.flags |= UI_Vertex_Flags_srgb; |
| 1176 | if (block->flags & UI_Block_Flags_thumb) vertex.flags |= UI_Vertex_Flags_thumb; |
| 1177 | |
| 1178 | vertex.misc = block->style.misc; |
| 1179 | |
| 1180 | vertex.depth = 1 - (f32)block->depth_level / ctx->parents.capacity; |
| 1181 | vertex.clp_p0 = v2(-1,-1); |
| 1182 | vertex.clp_p1 = v2(-1,-1); |
| 1183 | if (!(block->flags & UI_Block_Flags_no_clip)) |
| 1184 | if (block->clip_rect.w >= 0 && block->clip_rect.h >= 0) { |
| 1185 | vertex.clp_p0 = block->clip_rect.pos; |
| 1186 | vertex.clp_p1 = block->clip_rect.pos + block->clip_rect.size; |
| 1187 | } |
| 1188 | vertex.ui_block = block->hash; |
| 1189 | UI_push_vertex(ctx, vertex); |
| 1190 | if (block->flags & UI_Block_Flags_draw_border) { |
| 1191 | vertex.depth = 1 - (f32)(block->depth_level + 0.5) / ctx->parents.capacity; |
| 1192 | UI_assert(block->style.border_size > 0 && "Block set to have a border with a border size of 0!") |
| 1193 | vertex.border_size = block->style.border_size; |
| 1194 | vertex.colors[0] = UI_u32_to_v4(block->style.color[c_border].c[0]); |
| 1195 | vertex.colors[1] = UI_u32_to_v4(block->style.color[c_border].c[1]); |
| 1196 | vertex.colors[2] = UI_u32_to_v4(block->style.color[c_border].c[2]); |
| 1197 | vertex.colors[3] = UI_u32_to_v4(block->style.color[c_border].c[3]); |
no test coverage detected