(FFT) Add potential non-GLM code

This commit is contained in:
twinaphex 2016-11-04 21:25:12 +01:00
parent 848db5b1c5
commit 9a9f76d71c
3 changed files with 50 additions and 1 deletions

View File

@ -9,6 +9,7 @@
#include <retro_miscellaneous.h>
#include <filters.h>
#include <math/complex.h>
#include <gfx/math/matrix_4x4.h>
#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(&center[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"),

View File

@ -24,6 +24,9 @@
#define __LIBRETRO_SDK_GFX_MATH_MATRIX_4X4_H__
#include <retro_inline.h>
#include <retro_common_api.h>
#include <gfx/math/vector_3.h>
/* 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

View File

@ -25,6 +25,10 @@
#include <stdint.h>
#include <retro_common_api.h>
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