more generic transitions impl
This commit is contained in:
parent
d1c392d27d
commit
2363588e88
2 changed files with 38 additions and 32 deletions
|
@ -2,17 +2,17 @@
|
||||||
|
|
||||||
uniform sampler2D tex0;
|
uniform sampler2D tex0;
|
||||||
uniform sampler2D tex1;
|
uniform sampler2D tex1;
|
||||||
uniform float zoom;
|
uniform float progress;
|
||||||
|
|
||||||
in vec2 vsoTexCoord;
|
in vec2 vsoTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec2 center = vec2(0.5);
|
vec2 center = vec2(0.5);
|
||||||
vec2 zoomedTexCoord = mix(center, vsoTexCoord, zoom);
|
vec2 zoomedTexCoord = mix(center, vsoTexCoord, progress);
|
||||||
|
|
||||||
vec4 color1 = texture(tex0, vsoTexCoord);
|
vec4 color1 = texture(tex0, vsoTexCoord);
|
||||||
vec4 color2 = texture(tex1, zoomedTexCoord);
|
vec4 color2 = texture(tex1, zoomedTexCoord);
|
||||||
|
|
||||||
fragColor = mix(color1, color2, smoothstep(0., 1., zoom));
|
fragColor = mix(color1, color2, smoothstep(0., 1., progress));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,11 @@
|
||||||
/* Mise-à-jour des animations en fonction du son */
|
/* Mise-à-jour des animations en fonction du son */
|
||||||
static void update_with_audio(void (*)(int), void (*)(int), int);
|
static void update_with_audio(void (*)(int), void (*)(int), int);
|
||||||
|
|
||||||
static GLuint _zoomin_pId = 0, _zoomin_tId = 0, _zoomin_tex[2], _quadId = 0;
|
static GLuint _transition_pId[2] = {0}, _transition_tId = 0, _quadId = 0;
|
||||||
static void zoomin_init(void);
|
static void transition_init(const char *, const int, GLuint *);
|
||||||
static void zoomin_draw(void (*)(int), void (*)(int), Uint32, Uint32, int);
|
static void transition_draw(void (*)(int), void (*)(int), Uint32, Uint32, int,
|
||||||
static void zoomin_deinit(void);
|
int, GLuint *);
|
||||||
|
static void transition_deinit(GLuint *);
|
||||||
|
|
||||||
static void update_with_audio(void (*a0)(int), void (*a1)(int), int state) {
|
static void update_with_audio(void (*a0)(int), void (*a1)(int), int state) {
|
||||||
if (a0) {
|
if (a0) {
|
||||||
|
@ -26,17 +27,19 @@ void transitionsInit(void) {
|
||||||
|
|
||||||
void zoomIn(void (*a0)(int), void (*a1)(int), Uint32 t, Uint32 et,
|
void zoomIn(void (*a0)(int), void (*a1)(int), Uint32 t, Uint32 et,
|
||||||
const int state) {
|
const int state) {
|
||||||
|
const int gpu = 0;
|
||||||
|
static GLuint tex[2];
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case GL4DH_INIT:
|
case GL4DH_INIT:
|
||||||
zoomin_init();
|
transition_init("zoom_in", gpu, tex);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GL4DH_DRAW:
|
case GL4DH_DRAW:
|
||||||
zoomin_draw(a0, a1, t, et, state);
|
transition_draw(a0, a1, t, et, state, gpu, tex);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GL4DH_FREE:
|
case GL4DH_FREE:
|
||||||
zoomin_deinit();
|
transition_deinit(tex);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GL4DH_UPDATE_WITH_AUDIO:
|
case GL4DH_UPDATE_WITH_AUDIO:
|
||||||
|
@ -48,54 +51,57 @@ void zoomIn(void (*a0)(int), void (*a1)(int), Uint32 t, Uint32 et,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zoomin_init(void) {
|
static void transition_init(const char *fs_shader, const int gpu, GLuint *tex) {
|
||||||
int vp[4];
|
int vp[4];
|
||||||
glGetIntegerv(GL_VIEWPORT, vp);
|
glGetIntegerv(GL_VIEWPORT, vp);
|
||||||
|
|
||||||
glGenTextures(2, _zoomin_tex);
|
glGenTextures(2, tex);
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
glBindTexture(GL_TEXTURE_2D, _zoomin_tex[i]);
|
glBindTexture(GL_TEXTURE_2D, tex[i]);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, vp[2], vp[3], 0, GL_RGBA,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, vp[2], vp[3], 0, GL_RGBA,
|
||||||
GL_UNSIGNED_BYTE, NULL);
|
GL_UNSIGNED_BYTE, NULL);
|
||||||
}
|
}
|
||||||
_zoomin_pId = gl4duCreateProgram("<vs>shaders/basic.vs",
|
char fragment_shader[256];
|
||||||
"<fs>shaders/zoom_in.fs", NULL);
|
sprintf(fragment_shader, "<fs>shaders/%s.fs", fs_shader);
|
||||||
|
_transition_pId[gpu] =
|
||||||
|
gl4duCreateProgram("<vs>shaders/basic.vs", fragment_shader, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zoomin_draw(void (*a0)(int), void (*a1)(int), Uint32 t, Uint32 et,
|
static void transition_draw(void (*a0)(int), void (*a1)(int), Uint32 t,
|
||||||
int state) {
|
Uint32 et, int state, int gpu, GLuint *tex) {
|
||||||
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||||
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
|
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
|
||||||
(GLint *)&_zoomin_tId);
|
(GLint *)&_transition_tId);
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||||
_zoomin_tex[0], 0);
|
tex[0], 0);
|
||||||
if (a0) {
|
if (a0) {
|
||||||
a0(state);
|
a0(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||||
_zoomin_tex[1], 0);
|
tex[1], 0);
|
||||||
if (a1) {
|
if (a1) {
|
||||||
a1(state);
|
a1(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||||
_zoomin_tId, 0);
|
_transition_tId, 0);
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, _zoomin_tex[0]);
|
glBindTexture(GL_TEXTURE_2D, tex[0]);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
glBindTexture(GL_TEXTURE_2D, _zoomin_tex[1]);
|
glBindTexture(GL_TEXTURE_2D, tex[1]);
|
||||||
|
|
||||||
glUseProgram(_zoomin_pId);
|
glUseProgram(_transition_pId[gpu]);
|
||||||
GLfloat zoom = (GLfloat)et / (GLfloat)t;
|
GLfloat progress = (GLfloat)et / (GLfloat)t;
|
||||||
glUniform1f(glGetUniformLocation(_zoomin_pId, "zoom"), (1.f - zoom));
|
glUniform1f(glGetUniformLocation(_transition_pId[gpu], "progress"),
|
||||||
glUniform1i(glGetUniformLocation(_zoomin_pId, "tex1"), 0);
|
(1.f - progress));
|
||||||
glUniform1i(glGetUniformLocation(_zoomin_pId, "tex0"), 1);
|
glUniform1i(glGetUniformLocation(_transition_pId[gpu], "tex1"), 0);
|
||||||
|
glUniform1i(glGetUniformLocation(_transition_pId[gpu], "tex0"), 1);
|
||||||
gl4dgDraw(_quadId);
|
gl4dgDraw(_quadId);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
@ -104,10 +110,10 @@ static void zoomin_draw(void (*a0)(int), void (*a1)(int), Uint32 t, Uint32 et,
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zoomin_deinit(void) {
|
static void transition_deinit(GLuint *tex) {
|
||||||
if (_zoomin_tex[0]) {
|
if (tex[0]) {
|
||||||
glDeleteTextures(2, _zoomin_tex);
|
glDeleteTextures(2, tex);
|
||||||
_zoomin_tex[0] = _zoomin_tex[1] = 0;
|
tex[0] = tex[1] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue