diff --git a/cores/libretro-ffmpeg/fft/fft.cpp b/cores/libretro-ffmpeg/fft/fft.cpp index 2aa2c9f4fb..e94084558d 100644 --- a/cores/libretro-ffmpeg/fft/fft.cpp +++ b/cores/libretro-ffmpeg/fft/fft.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #define GLM_SWIZZLE #define GLM_FORCE_RADIANS @@ -148,14 +149,40 @@ static GLuint fft_compile_program(glfft_t *fft, return prog; } +#define USE_GLM + static void fft_render(glfft_t *fft, GLuint backbuffer, unsigned width, unsigned height) { +#ifdef USE_GLM glm::vec3 eye = glm::vec3(0, 80, -60); glm::vec3 center = eye + glm::vec3(0.0f, 0.0f, 1.0f); glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f); - glm::mat4 mvp_persp = glm::perspective((float)M_HALF_PI, (float)width / height, 1.0f, 500.0f); + glm::mat4 mvp_persp = glm::perspective((float)M_HALF_PI, (float)width / height, +1.0f, 500.0f); glm::mat4 mvp_lookat = glm::lookAt(eye, center, up); glm::mat4 mvp = mvp_persp * mvp_lookat; +#else + vec3_t eye, center, up; + math_matrix_4x4 mvp_lookat, mvp, mvp_persp; + + eye[0] = 0.0f; + eye[1] = 80.0f; + eye[2] = -60.0f; + + up[0] = 0.0f; + up[1] = 1.0f; + up[2] = 0.0f; + + center[0] = 0.0f; + center[1] = 0.0f; + center[2] = 1.0f; + + vec3_add(¢er[0], &eye[0]); + + matrix_4x4_projection(&mvp_persp, (float)M_HALF_PI, (float)width / height, 1.0f, 500.0f); + matrix_4x4_lookat(&mvp_lookat, eye, center, up); + matrix_4x4_multiply(&mvp, &mvp_persp, &mvp_lookat); +#endif /* Render scene. */ glBindFramebuffer(GL_FRAMEBUFFER, fft->ms_fbo ? fft->ms_fbo : backbuffer); @@ -164,8 +191,13 @@ static void fft_render(glfft_t *fft, GLuint backbuffer, unsigned width, unsigned glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUseProgram(fft->block.prog); +#ifdef USE_GLM glUniformMatrix4fv(glGetUniformLocation(fft->block.prog, "uMVP"), 1, GL_FALSE, (&mvp[0].x)); +#else + glUniformMatrix4fv(glGetUniformLocation(fft->block.prog, "uMVP"), + 1, GL_FALSE, (&(MAT_ELEM_4X4(mvp, 0, 0)))); +#endif glUniform2i(glGetUniformLocation(fft->block.prog, "uOffset"), (-int(fft->block_size) + 1) / 2, fft->output_ptr); glUniform4f(glGetUniformLocation(fft->block.prog, "uHeightmapParams"), diff --git a/libretro-common/include/gfx/math/matrix_4x4.h b/libretro-common/include/gfx/math/matrix_4x4.h index f440128f40..7216ff3461 100644 --- a/libretro-common/include/gfx/math/matrix_4x4.h +++ b/libretro-common/include/gfx/math/matrix_4x4.h @@ -24,6 +24,9 @@ #define __LIBRETRO_SDK_GFX_MATH_MATRIX_4X4_H__ #include +#include + +#include /* Column-major matrix (OpenGL-style). * Reimplements functionality from FF OpenGL pipeline to be able @@ -32,6 +35,7 @@ #define MAT_ELEM_4X4(mat, row, column) ((mat).data[4 * (column) + (row)]) +RETRO_BEGIN_DECLS typedef struct math_matrix_4x4 { @@ -77,11 +81,18 @@ void matrix_4x4_ortho(math_matrix_4x4 *mat, float bottom, float top, float znear, float zfar); +void matrix_4x4_lookat(math_matrix_4x4 *out, + vec3_t eye, + vec3_t center, + vec3_t up); + void matrix_4x4_multiply(math_matrix_4x4 *out, const math_matrix_4x4 *a, const math_matrix_4x4 *b); void matrix_4x4_scale(math_matrix_4x4 *out, float x, float y, float z); void matrix_4x4_translate(math_matrix_4x4 *out, float x, float y, float z); void matrix_4x4_projection(math_matrix_4x4 *out, float y_fov, float aspect, float znear, float zfar); +RETRO_END_DECLS + #endif diff --git a/libretro-common/include/gfx/math/vector_3.h b/libretro-common/include/gfx/math/vector_3.h index 022401122d..5e2d03b5a7 100644 --- a/libretro-common/include/gfx/math/vector_3.h +++ b/libretro-common/include/gfx/math/vector_3.h @@ -25,6 +25,10 @@ #include +#include + +RETRO_BEGIN_DECLS + typedef float vec3_t[3]; float vec3_dot(const float *a, const float *b); @@ -43,5 +47,7 @@ void vec3_copy(float *dst, const float *src); void vec3_normalize(float *dst); +RETRO_END_DECLS + #endif