static void wiiu_font_render_line( video_frame_info_t *video_info, wiiu_font_t* font, const char* msg, unsigned msg_len, float scale, const unsigned int color, float pos_x, float pos_y, unsigned text_align) { unsigned i; wiiu_video_t* wiiu = (wiiu_video_t*)video_info->userdata; unsigned width = video_info->width; unsigned height = video_info->height; int x = roundf(pos_x * width); int y = roundf((1.0 - pos_y) * height); if( !wiiu || wiiu->vertex_cache.current + (msg_len * 4) > wiiu->vertex_cache.size) return; switch (text_align) { case TEXT_ALIGN_RIGHT: x -= wiiu_font_get_message_width(font, msg, msg_len, scale); break; case TEXT_ALIGN_CENTER: x -= wiiu_font_get_message_width(font, msg, msg_len, scale) / 2; break; } sprite_vertex_t* v = wiiu->vertex_cache.v + wiiu->vertex_cache.current; for (i = 0; i < msg_len; i++) { const char* msg_tmp = &msg[i]; unsigned code = utf8_walk(&msg_tmp); unsigned skip = msg_tmp - &msg[i]; if (skip > 1) i += skip - 1; const struct font_glyph* glyph = font->font_driver->get_glyph(font->font_data, code); if (!glyph) /* Do something smarter here ... */ glyph = font->font_driver->get_glyph(font->font_data, '?'); if (!glyph) continue; v->pos.x = x + glyph->draw_offset_x * scale; v->pos.y = y + glyph->draw_offset_y * scale; v->pos.width = glyph->width * scale; v->pos.height = glyph->height * scale; v->coord.u = glyph->atlas_offset_x; v->coord.v = glyph->atlas_offset_y; v->coord.width = glyph->width; v->coord.height = glyph->height; v->color = color; v++; x += glyph->advance_x * scale; y += glyph->advance_y * scale; } int count = v - wiiu->vertex_cache.v - wiiu->vertex_cache.current; if (!count) return; GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.v + wiiu->vertex_cache.current, count * sizeof(wiiu->vertex_cache.v)); if(font->atlas->dirty) { for (i = 0; (i < font->atlas->height) && (i < font->texture.surface.height); i++) memcpy(font->texture.surface.image + (i * font->texture.surface.pitch), font->atlas->buffer + (i * font->atlas->width), font->atlas->width); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, font->texture.surface.image, font->texture.surface.imageSize); font->atlas->dirty = false; } GX2SetPixelTexture(&font->texture, sprite_shader.ps.samplerVars[0].location); GX2SetVertexUniformBlock(sprite_shader.vs.uniformBlocks[1].offset, sprite_shader.vs.uniformBlocks[1].size, font->ubo_tex); GX2DrawEx(GX2_PRIMITIVE_MODE_POINTS, count, wiiu->vertex_cache.current, 1); GX2SetVertexUniformBlock(sprite_shader.vs.uniformBlocks[1].offset, sprite_shader.vs.uniformBlocks[1].size, wiiu->ubo_tex); wiiu->vertex_cache.current = v - wiiu->vertex_cache.v; }
static bool wiiu_gfx_frame(void* data, const void* frame, unsigned width, unsigned height, uint64_t frame_count, unsigned pitch, const char* msg) { (void)msg; int i; wiiu_video_t* wiiu = (wiiu_video_t*) data; if (!width || !height) { GX2WaitForVsync(); return true; } if(wiiu->vsync) { uint32_t swap_count; uint32_t flip_count; OSTime last_flip; OSTime last_vsync; GX2GetSwapStatus(&swap_count, &flip_count, &last_flip, &last_vsync); if(wiiu->last_vsync >= last_vsync) { GX2WaitForVsync(); wiiu->last_vsync = last_vsync + ms_to_ticks(17); } else wiiu->last_vsync = last_vsync; } GX2WaitForFlip(); static u32 lastTick , currentTick; currentTick = OSGetSystemTick(); u32 diff = currentTick - lastTick; static float fps; static u32 frames; frames++; if(diff > wiiu_timer_clock) { fps = (float)frames * ((float) wiiu_timer_clock / (float) diff); lastTick = currentTick; frames = 0; } #if 0 static u32 last_frame_tick; if (!(wiiu->menu.enable)) printf("\r frame time : %10.6f ms \n", (float)(currentTick - last_frame_tick) * 1000.0f / (float)wiiu_timer_clock); last_frame_tick = currentTick; #endif printf("\rfps: %8.8f frames : %5i", fps, wiiu->frames++); fflush(stdout); static struct retro_perf_counter gfx_frame_perf = {0}; performance_counter_init(&gfx_frame_perf, "gfx_frame"); performance_counter_start(&gfx_frame_perf); if (wiiu->should_resize) wiiu_gfx_update_viewport(wiiu); GX2ClearColor(&wiiu->color_buffer, 0.0f, 0.0f, 0.0f, 1.0f); /* can't call GX2ClearColor after GX2SetContextState for whatever reason */ GX2SetContextState(wiiu->ctx_state); if(frame) { if (width > wiiu->texture.surface.width) width = wiiu->texture.surface.width; if (height > wiiu->texture.surface.height) height = wiiu->texture.surface.height; wiiu->width = width; wiiu->height = height; if(wiiu->rgb32) { const uint32_t* src = frame; uint32_t* dst = (uint32_t*)wiiu->texture.surface.image; for (i = 0; i < height; i++) { int j; for(j = 0; j < width; j++) dst[j] = src[j]; dst += wiiu->texture.surface.pitch; src += pitch / 4; } } else { const uint16_t* src = frame; uint16_t* dst = (uint16_t*)wiiu->texture.surface.image; for (i = 0; i < height; i++) { int j; for(j = 0; j < width; j++) dst[j] = __builtin_bswap16(src[j]); dst += wiiu->texture.surface.pitch; src += pitch / 2; } } GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->texture.surface.image, wiiu->texture.surface.imageSize); wiiu_set_tex_coords(wiiu->tex_coord, &wiiu->texture, 0, 0, width, height); } GX2SetAttribBuffer(0, 4 * sizeof(*wiiu->position), sizeof(*wiiu->position), wiiu->position); GX2SetAttribBuffer(1, 4 * sizeof(*wiiu->tex_coord), sizeof(*wiiu->tex_coord), wiiu->tex_coord); GX2SetPixelTexture(&wiiu->texture, wiiu->shader->sampler.location); GX2SetPixelSampler(wiiu->smooth? &wiiu->sampler_linear : &wiiu->sampler_nearest, wiiu->shader->sampler.location); GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4, 0, 1); if (wiiu->menu.enable) { GX2SetAttribBuffer(0, 4 * sizeof(*wiiu->menu.position), sizeof(*wiiu->menu.position), wiiu->menu.position); GX2SetAttribBuffer(1, 4 * sizeof(*wiiu->menu.tex_coord), sizeof(*wiiu->menu.tex_coord), wiiu->menu.tex_coord); GX2SetPixelTexture(&wiiu->menu.texture, wiiu->shader->sampler.location); GX2SetPixelSampler(&wiiu->sampler_linear, wiiu->shader->sampler.location); GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4, 0, 1); GX2DrawDone(); } GX2CopyColorBufferToScanBuffer(&wiiu->color_buffer, GX2_SCAN_TARGET_DRC); GX2CopyColorBufferToScanBuffer(&wiiu->color_buffer, GX2_SCAN_TARGET_TV); GX2SwapScanBuffers(); GX2Flush(); performance_counter_stop(&gfx_frame_perf); return true; }
static void wiiu_font_render_line( video_frame_info_t *video_info, wiiu_font_t* font, const char* msg, unsigned msg_len, float scale, const unsigned int color, float pos_x, float pos_y, unsigned text_align) { unsigned i; wiiu_video_t* wiiu = (wiiu_video_t*)video_driver_get_ptr(false); unsigned width = video_info->width; unsigned height = video_info->height; int x = roundf(pos_x * width); int y = roundf((1.0f - pos_y) * height); int delta_x = 0; int delta_y = 0; if(wiiu->vertex_cache.current + (msg_len * 4) > wiiu->vertex_cache.size) return; switch (text_align) { case TEXT_ALIGN_RIGHT: x -= wiiu_font_get_message_width(font, msg, msg_len, scale); break; case TEXT_ALIGN_CENTER: x -= wiiu_font_get_message_width(font, msg, msg_len, scale) / 2; break; } position_t* pos = wiiu->vertex_cache.positions + wiiu->vertex_cache.current; tex_coord_t* coord = wiiu->vertex_cache.tex_coords + wiiu->vertex_cache.current; for (i = 0; i < msg_len; i++) { int off_x, off_y, tex_x, tex_y, width, height; const char* msg_tmp = &msg[i]; unsigned code = utf8_walk(&msg_tmp); unsigned skip = msg_tmp - &msg[i]; if (skip > 1) i += skip - 1; const struct font_glyph* glyph = font->font_driver->get_glyph(font->font_data, code); if (!glyph) /* Do something smarter here ... */ glyph = font->font_driver->get_glyph(font->font_data, '?'); if (!glyph) continue; off_x = glyph->draw_offset_x; off_y = glyph->draw_offset_y; tex_x = glyph->atlas_offset_x; tex_y = glyph->atlas_offset_y; width = glyph->width; height = glyph->height; float x0 = x + off_x + delta_x * scale; float y0 = y + off_y + delta_y * scale + height * scale; float u0 = tex_x; float v0 = tex_y; float x1 = x0 + width * scale; float y1 = y0 - height * scale; float u1 = u0 + width; float v1 = v0 + height; pos[0].x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f; pos[0].y = (-2.0f * y0 / wiiu->color_buffer.surface.height) + 1.0f; pos[1].x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;; pos[1].y = (-2.0f * y0 / wiiu->color_buffer.surface.height) + 1.0f; pos[2].x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;; pos[2].y = (-2.0f * y1 / wiiu->color_buffer.surface.height) + 1.0f; pos[3].x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;; pos[3].y = (-2.0f * y1 / wiiu->color_buffer.surface.height) + 1.0f; pos += 4; coord[0].u = u0 / font->texture.surface.width; coord[0].v = v1 / font->texture.surface.height; coord[1].u = u1 / font->texture.surface.width; coord[1].v = v1 / font->texture.surface.height; coord[2].u = u1 / font->texture.surface.width; coord[2].v = v0 / font->texture.surface.height; coord[3].u = u0 / font->texture.surface.width; coord[3].v = v0 / font->texture.surface.height; coord += 4; delta_x += glyph->advance_x; delta_y += glyph->advance_y; } int count = pos - wiiu->vertex_cache.positions - wiiu->vertex_cache.current; if (!count) return; GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.positions + wiiu->vertex_cache.current, count * sizeof(position_t)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.tex_coords + wiiu->vertex_cache.current, count * sizeof(tex_coord_t)); if(font->atlas->dirty) { for (i = 0; (i < font->atlas->height) && (i < font->texture.surface.height); i++) memcpy(font->texture.surface.image + (i * font->texture.surface.pitch), font->atlas->buffer + (i * font->atlas->width), font->atlas->width); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, font->texture.surface.image, font->texture.surface.imageSize); font->atlas->dirty = false; } #if 0 printf("%s\n", msg); DEBUG_VAR(color); #endif GX2SetPixelTexture(&font->texture, wiiu->shader->sampler.location); GX2SetBlendConstantColor(((color >> 0) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, ((color >> 16) & 0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f); GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_BLEND_FACTOR, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD, GX2_ENABLE, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD); GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, count, wiiu->vertex_cache.current, 1); GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD, GX2_ENABLE, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD); wiiu->vertex_cache.current = pos - wiiu->vertex_cache.positions; }