- Turn rotation arrows static where possible

- Don't call matrix_4x4_rotate_z - inline the code instead
This commit is contained in:
libretroadmin 2022-07-04 15:28:08 +02:00
parent 0b2be028ca
commit 9dd1fb895b
11 changed files with 151 additions and 28 deletions

View File

@ -287,14 +287,26 @@ static void d3d10_set_filtering(void* data, unsigned index, bool smooth, bool ct
static void d3d10_gfx_set_rotation(void* data, unsigned rotation)
{
math_matrix_4x4 rot;
static math_matrix_4x4 rot = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
float radians, cosine, sine;
void* mapped_ubo = NULL;
d3d10_video_t* d3d10 = (d3d10_video_t*)data;
if (!d3d10)
return;
matrix_4x4_rotate_z(rot, rotation * (M_PI / 2.0f));
radians = rotation * (M_PI / 2.0f);
cosine = cosf(radians);
sine = sinf(radians);
MAT_ELEM_4X4(rot, 0, 0) = cosine;
MAT_ELEM_4X4(rot, 0, 1) = -sine;
MAT_ELEM_4X4(rot, 1, 0) = sine;
MAT_ELEM_4X4(rot, 1, 1) = cosine;
matrix_4x4_multiply(d3d10->mvp, rot, d3d10->ubo_values.mvp);
d3d10->frame.ubo->lpVtbl->Map(d3d10->frame.ubo,

View File

@ -433,14 +433,26 @@ static void d3d11_set_filtering(void* data, unsigned index,
static void d3d11_gfx_set_rotation(void* data, unsigned rotation)
{
math_matrix_4x4 rot;
float radians, cosine, sine;
D3D11_MAPPED_SUBRESOURCE mapped_ubo;
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
static math_matrix_4x4 rot = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
if (!d3d11)
return;
matrix_4x4_rotate_z(rot, rotation * (M_PI / 2.0f));
radians = rotation * (M_PI / 2.0f);
cosine = cosf(radians);
sine = sinf(radians);
MAT_ELEM_4X4(rot, 0, 0) = cosine;
MAT_ELEM_4X4(rot, 0, 1) = -sine;
MAT_ELEM_4X4(rot, 1, 0) = sine;
MAT_ELEM_4X4(rot, 1, 1) = cosine;
matrix_4x4_multiply(d3d11->mvp, rot, d3d11->ubo_values.mvp);
d3d11->context->lpVtbl->Map(

View File

@ -441,8 +441,14 @@ static void d3d12_set_filtering(void* data, unsigned index, bool smooth, bool ct
static void d3d12_gfx_set_rotation(void* data, unsigned rotation)
{
math_matrix_4x4 rot;
math_matrix_4x4* mvp;
static math_matrix_4x4 rot = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
float radians, cosine, sine;
D3D12_RANGE read_range;
d3d12_video_t* d3d12 = (d3d12_video_t*)data;
@ -452,13 +458,19 @@ static void d3d12_gfx_set_rotation(void* data, unsigned rotation)
d3d12_gfx_sync(d3d12);
d3d12->frame.rotation = rotation;
matrix_4x4_rotate_z(rot, d3d12->frame.rotation * (M_PI / 2.0f));
radians = d3d12->frame.rotation * (M_PI / 2.0f);
cosine = cosf(radians);
sine = sinf(radians);
MAT_ELEM_4X4(rot, 0, 0) = cosine;
MAT_ELEM_4X4(rot, 0, 1) = -sine;
MAT_ELEM_4X4(rot, 1, 0) = sine;
MAT_ELEM_4X4(rot, 1, 1) = cosine;
matrix_4x4_multiply(d3d12->mvp, rot, d3d12->mvp_no_rot);
read_range.Begin = 0;
read_range.End = 0;
D3D12Map(d3d12->frame.ubo, 0, &read_range, (void**)&mvp);
*mvp = d3d12->mvp;
*mvp = d3d12->mvp;
D3D12Unmap(d3d12->frame.ubo, 0, NULL);
}

View File

@ -451,7 +451,13 @@ error:
static void gl1_set_projection(gl1_t *gl1,
struct video_ortho *ortho, bool allow_rotate)
{
math_matrix_4x4 rot;
static math_matrix_4x4 rot = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
float radians, cosine, sine;
/* Calculate projection. */
matrix_4x4_ortho(gl1->mvp_no_rot, ortho->left, ortho->right,
@ -463,7 +469,13 @@ static void gl1_set_projection(gl1_t *gl1,
return;
}
matrix_4x4_rotate_z(rot, M_PI * gl1->rotation / 180.0f);
radians = M_PI * gl1->rotation / 180.0f;
cosine = cosf(radians);
sine = sinf(radians);
MAT_ELEM_4X4(rot, 0, 0) = cosine;
MAT_ELEM_4X4(rot, 0, 1) = -sine;
MAT_ELEM_4X4(rot, 1, 0) = sine;
MAT_ELEM_4X4(rot, 1, 1) = cosine;
matrix_4x4_multiply(gl1->mvp, rot, gl1->mvp_no_rot);
}

View File

@ -371,7 +371,13 @@ static bool gl2_recreate_fbo(
static void gl2_set_projection(gl2_t *gl,
struct video_ortho *ortho, bool allow_rotate)
{
math_matrix_4x4 rot;
static math_matrix_4x4 rot = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
float radians, cosine, sine;
/* Calculate projection. */
matrix_4x4_ortho(gl->mvp_no_rot, ortho->left, ortho->right,
@ -383,7 +389,13 @@ static void gl2_set_projection(gl2_t *gl,
return;
}
matrix_4x4_rotate_z(rot, M_PI * gl->rotation / 180.0f);
radians = M_PI * gl->rotation / 180.0f;
cosine = cosf(radians);
sine = sinf(radians);
MAT_ELEM_4X4(rot, 0, 0) = cosine;
MAT_ELEM_4X4(rot, 0, 1) = -sine;
MAT_ELEM_4X4(rot, 1, 0) = sine;
MAT_ELEM_4X4(rot, 1, 1) = cosine;
matrix_4x4_multiply(gl->mvp, rot, gl->mvp_no_rot);
}

View File

@ -723,7 +723,13 @@ static const gfx_ctx_driver_t *gl3_get_context(gl3_t *gl)
static void gl3_set_projection(gl3_t *gl,
const struct video_ortho *ortho, bool allow_rotate)
{
math_matrix_4x4 rot;
static math_matrix_4x4 rot = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
float radians, cosine, sine;
/* Calculate projection. */
matrix_4x4_ortho(gl->mvp_no_rot, ortho->left, ortho->right,
@ -735,7 +741,13 @@ static void gl3_set_projection(gl3_t *gl,
return;
}
matrix_4x4_rotate_z(rot, M_PI * gl->rotation / 180.0f);
radians = M_PI * gl->rotation / 180.0f;
cosine = cosf(radians);
sine = sinf(radians);
MAT_ELEM_4X4(rot, 0, 0) = cosine;
MAT_ELEM_4X4(rot, 0, 1) = -sine;
MAT_ELEM_4X4(rot, 1, 0) = sine;
MAT_ELEM_4X4(rot, 1, 1) = cosine;
matrix_4x4_multiply(gl->mvp, rot, gl->mvp_no_rot);
memcpy(gl->mvp_no_rot_yflip.data, gl->mvp_no_rot.data, sizeof(gl->mvp_no_rot.data));

View File

@ -86,9 +86,23 @@ static void wiiu_set_tex_coords(frame_vertex_t *v,
static void wiiu_set_projection(wiiu_video_t *wiiu)
{
math_matrix_4x4 proj, rot;
static math_matrix_4x4 rot = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
float radians, cosine, sine;
math_matrix_4x4 proj;
matrix_4x4_ortho(proj, 0, 1, 1, 0, -1, 1);
matrix_4x4_rotate_z(rot, wiiu->rotation * M_PI_2);
radians = wiiu->rotation * M_PI_2;
cosine = cosf(radians);
sine = sinf(radians);
MAT_ELEM_4X4(rot, 0, 0) = cosine;
MAT_ELEM_4X4(rot, 0, 1) = -sine;
MAT_ELEM_4X4(rot, 1, 0) = sine;
MAT_ELEM_4X4(rot, 1, 1) = cosine;
matrix_4x4_multiply((*wiiu->ubo_mvp), rot, proj);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, wiiu->ubo_mvp, sizeof(*wiiu->ubo_mvp));
}

View File

@ -445,7 +445,8 @@ static void* rsx_init(const video_info_t* video,
rsx_context_bind_hw_render(rsx, true);
if (video->font_enable) {
if (video->font_enable)
{
font_driver_init_osd(rsx,
video,
false,
@ -460,7 +461,13 @@ static void* rsx_init(const video_info_t* video,
static void rsx_set_projection(rsx_t *rsx,
struct video_ortho *ortho, bool allow_rotate)
{
math_matrix_4x4 rot;
static math_matrix_4x4 rot = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
float radians, cosine, sine;
/* Calculate projection. */
matrix_4x4_ortho(rsx->mvp_no_rot, ortho->left, ortho->right,
@ -472,7 +479,13 @@ static void rsx_set_projection(rsx_t *rsx,
return;
}
matrix_4x4_rotate_z(rot, M_PI * rsx->rotation / 180.0f);
radians = M_PI * rsx->rotation / 180.0f;
cosine = cosf(radians);
sine = sinf(radians);
MAT_ELEM_4X4(rot, 0, 0) = cosine;
MAT_ELEM_4X4(rot, 0, 1) = -sine;
MAT_ELEM_4X4(rot, 1, 0) = sine;
MAT_ELEM_4X4(rot, 1, 1) = cosine;
matrix_4x4_multiply(rsx->mvp, rot, rsx->mvp_no_rot);
}

View File

@ -370,7 +370,13 @@ static bool vita2d_gfx_set_shader(void *data,
static void vita2d_set_projection(vita_video_t *vita,
struct video_ortho *ortho, bool allow_rotate)
{
math_matrix_4x4 rot;
static math_matrix_4x4 rot = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
float radians, cosine, sine;
/* Calculate projection. */
matrix_4x4_ortho(vita->mvp_no_rot, ortho->left, ortho->right,
@ -382,7 +388,13 @@ static void vita2d_set_projection(vita_video_t *vita,
return;
}
matrix_4x4_rotate_z(rot, M_PI * vita->rotation / 180.0f);
radians = M_PI * vita->rotation / 180.0f;
cosine = cosf(radians);
sine = sinf(radians);
MAT_ELEM_4X4(rot, 0, 0) = cosine;
MAT_ELEM_4X4(rot, 0, 1) = -sine;
MAT_ELEM_4X4(rot, 1, 0) = sine;
MAT_ELEM_4X4(rot, 1, 1) = cosine;
matrix_4x4_multiply(vita->mvp, rot, vita->mvp_no_rot);
}

View File

@ -1757,7 +1757,13 @@ static bool vulkan_set_shader(void *data,
static void vulkan_set_projection(vk_t *vk,
struct video_ortho *ortho, bool allow_rotate)
{
math_matrix_4x4 rot;
float radians, cosine, sine;
static math_matrix_4x4 rot = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
/* Calculate projection. */
matrix_4x4_ortho(vk->mvp_no_rot, ortho->left, ortho->right,
@ -1769,7 +1775,13 @@ static void vulkan_set_projection(vk_t *vk,
return;
}
matrix_4x4_rotate_z(rot, M_PI * vk->rotation / 180.0f);
radians = M_PI * vk->rotation / 180.0f;
cosine = cosf(radians);
sine = sinf(radians);
MAT_ELEM_4X4(rot, 0, 0) = cosine;
MAT_ELEM_4X4(rot, 0, 1) = -sine;
MAT_ELEM_4X4(rot, 1, 0) = sine;
MAT_ELEM_4X4(rot, 1, 1) = cosine;
matrix_4x4_multiply(vk->mvp, rot, vk->mvp_no_rot);
}

View File

@ -960,7 +960,7 @@ void gfx_display_rotate_z(gfx_display_t *p_disp,
gfx_display_ctx_rotate_draw_t *draw, void *data)
{
float cosine, sine, radians;
math_matrix_4x4 matrix_rotated = {
static math_matrix_4x4 matrix_rotated = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 1.0f, 0.0f ,
@ -988,15 +988,15 @@ void gfx_display_rotate_z(gfx_display_t *p_disp,
if (draw->scale_enable)
{
math_matrix_4x4 matrix_scaled = {
static math_matrix_4x4 matrix_scaled = {
{ 0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 0.0f ,
0.0f, 0.0f, 0.0f, 1.0f }
};
MAT_ELEM_4X4(matrix_scaled, 0, 0) = draw->scale_x;
MAT_ELEM_4X4(matrix_scaled, 1, 1) = draw->scale_y;
MAT_ELEM_4X4(matrix_scaled, 2, 2) = draw->scale_z;
MAT_ELEM_4X4(matrix_scaled, 0, 0) = draw->scale_x;
MAT_ELEM_4X4(matrix_scaled, 1, 1) = draw->scale_y;
MAT_ELEM_4X4(matrix_scaled, 2, 2) = draw->scale_z;
matrix_4x4_multiply(*draw->matrix, matrix_scaled, *draw->matrix);
}
}