From 97f937ec6d4bfaf8149fc45f5e3dcebc30df8f60 Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 26 Oct 2011 10:26:09 +0200 Subject: [PATCH] Use floating point values for uniforms from Python. --- gfx/py_state/py_state.c | 6 +++--- gfx/py_state/py_state.h | 2 +- gfx/shader_glsl.c | 7 +++++-- gfx/snes_state.h | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gfx/py_state/py_state.c b/gfx/py_state/py_state.c index b09888d064..91e542c3be 100644 --- a/gfx/py_state/py_state.c +++ b/gfx/py_state/py_state.c @@ -304,7 +304,7 @@ void py_state_free(py_state_t *handle) Py_Finalize(); } -int py_state_get(py_state_t *handle, const char *id, +float py_state_get(py_state_t *handle, const char *id, unsigned frame_count) { PyObject *ret = PyObject_CallMethod(handle->inst, (char*)id, (char*)"I", frame_count); @@ -313,10 +313,10 @@ int py_state_get(py_state_t *handle, const char *id, if (!handle->warned_ret) SSNES_WARN("Didn't get return value from script! Bug?\n"); handle->warned_ret = true; - return 0; + return 0.0f; } - int retval = PyLong_AsLong(ret); + float retval = (float)PyFloat_AsDouble(ret); Py_DECREF(ret); return retval; } diff --git a/gfx/py_state/py_state.h b/gfx/py_state/py_state.h index d3a1db7af7..4dc4761e7c 100644 --- a/gfx/py_state/py_state.h +++ b/gfx/py_state/py_state.h @@ -26,7 +26,7 @@ typedef struct py_state py_state_t; py_state_t *py_state_new(const char *program, bool is_file, const char *pyclass); void py_state_free(py_state_t *handle); -int py_state_get(py_state_t *handle, +float py_state_get(py_state_t *handle, const char *id, unsigned frame_count); #endif diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c index 766ebf7511..65bf8d7244 100644 --- a/gfx/shader_glsl.c +++ b/gfx/shader_glsl.c @@ -55,6 +55,7 @@ #define pglLinkProgram glLinkProgram #define pglGetUniformLocation glGetUniformLocation #define pglUniform1i glUniform1i +#define pglUniform1f glUniform1f #define pglUniform2fv glUniform2fv #define pglUniform4fv glUniform4fv #define pglGetShaderiv glGetShaderiv @@ -78,6 +79,7 @@ static PFNGLDETACHSHADERPROC pglDetachShader = NULL; static PFNGLLINKPROGRAMPROC pglLinkProgram = NULL; static PFNGLGETUNIFORMLOCATIONPROC pglGetUniformLocation = NULL; static PFNGLUNIFORM1IPROC pglUniform1i = NULL; +static PFNGLUNIFORM1FPROC pglUniform1f = NULL; static PFNGLUNIFORM2FVPROC pglUniform2fv = NULL; static PFNGLUNIFORM4FVPROC pglUniform4fv = NULL; static PFNGLGETSHADERIVPROC pglGetShaderiv = NULL; @@ -842,6 +844,7 @@ bool gl_glsl_init(const char *path) LOAD_GL_SYM(LinkProgram); LOAD_GL_SYM(GetUniformLocation); LOAD_GL_SYM(Uniform1i); + LOAD_GL_SYM(Uniform1f); LOAD_GL_SYM(Uniform2fv); LOAD_GL_SYM(Uniform4fv); LOAD_GL_SYM(GetShaderiv); @@ -862,7 +865,7 @@ bool gl_glsl_init(const char *path) bool shader_support = pglCreateProgram && pglUseProgram && pglCreateShader && pglDeleteShader && pglShaderSource && pglCompileShader && pglAttachShader && pglDetachShader && pglLinkProgram && pglGetUniformLocation - && pglUniform1i && pglUniform2fv && pglUniform4fv + && pglUniform1i && pglUniform1f && pglUniform2fv && pglUniform4fv && pglGetShaderiv && pglGetShaderInfoLog && pglGetProgramiv && pglGetProgramInfoLog && pglDeleteProgram && pglGetAttachedShaders && pglGetAttribLocation && pglEnableVertexAttribArray @@ -1148,7 +1151,7 @@ void gl_glsl_set_params(unsigned width, unsigned height, for (unsigned i = 0; i < cnt; i++) { location = pglGetUniformLocation(gl_program[active_index], info[i].id); - pglUniform1i(location, info[i].value); + pglUniform1f(location, info[i].value); } } } diff --git a/gfx/snes_state.h b/gfx/snes_state.h index 90772aa1f9..a4a2df0282 100644 --- a/gfx/snes_state.h +++ b/gfx/snes_state.h @@ -78,7 +78,7 @@ struct snes_tracker_info struct snes_tracker_uniform { const char *id; - int value; + float value; }; typedef struct snes_tracker snes_tracker_t;