mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-04 22:48:49 +00:00
testegl: do matrix mutlplication in the shader
See https://bugzilla.gnome.org/show_bug.cgi?id=728940
This commit is contained in:
parent
91c6e34217
commit
3d0b891e42
1 changed files with 46 additions and 70 deletions
|
@ -178,60 +178,6 @@ gst_gl_matrix_translate (GstGLMatrix * matrix, GLfloat tx, GLfloat ty,
|
||||||
(matrix->m[0][3] * tx + matrix->m[1][3] * ty + matrix->m[2][3] * tz);
|
(matrix->m[0][3] * tx + matrix->m[1][3] * ty + matrix->m[2][3] * tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gst_gl_matrix_rotate (GstGLMatrix * matrix, GLfloat angle, GLfloat x, GLfloat y,
|
|
||||||
GLfloat z)
|
|
||||||
{
|
|
||||||
GLfloat sinAngle, cosAngle;
|
|
||||||
GLfloat mag = sqrtf (x * x + y * y + z * z);
|
|
||||||
|
|
||||||
sinAngle = sinf (angle * M_PI / 180.0f);
|
|
||||||
cosAngle = cosf (angle * M_PI / 180.0f);
|
|
||||||
|
|
||||||
if (mag > 0.0f) {
|
|
||||||
GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs;
|
|
||||||
GLfloat oneMinusCos;
|
|
||||||
GstGLMatrix rotMat;
|
|
||||||
|
|
||||||
x /= mag;
|
|
||||||
y /= mag;
|
|
||||||
z /= mag;
|
|
||||||
|
|
||||||
xx = x * x;
|
|
||||||
yy = y * y;
|
|
||||||
zz = z * z;
|
|
||||||
xy = x * y;
|
|
||||||
yz = y * z;
|
|
||||||
zx = z * x;
|
|
||||||
xs = x * sinAngle;
|
|
||||||
ys = y * sinAngle;
|
|
||||||
zs = z * sinAngle;
|
|
||||||
oneMinusCos = 1.0f - cosAngle;
|
|
||||||
|
|
||||||
rotMat.m[0][0] = (oneMinusCos * xx) + cosAngle;
|
|
||||||
rotMat.m[0][1] = (oneMinusCos * xy) - zs;
|
|
||||||
rotMat.m[0][2] = (oneMinusCos * zx) + ys;
|
|
||||||
rotMat.m[0][3] = 0.0f;
|
|
||||||
|
|
||||||
rotMat.m[1][0] = (oneMinusCos * xy) + zs;
|
|
||||||
rotMat.m[1][1] = (oneMinusCos * yy) + cosAngle;
|
|
||||||
rotMat.m[1][2] = (oneMinusCos * yz) - xs;
|
|
||||||
rotMat.m[1][3] = 0.0f;
|
|
||||||
|
|
||||||
rotMat.m[2][0] = (oneMinusCos * zx) - ys;
|
|
||||||
rotMat.m[2][1] = (oneMinusCos * yz) + xs;
|
|
||||||
rotMat.m[2][2] = (oneMinusCos * zz) + cosAngle;
|
|
||||||
rotMat.m[2][3] = 0.0f;
|
|
||||||
|
|
||||||
rotMat.m[3][0] = 0.0f;
|
|
||||||
rotMat.m[3][1] = 0.0f;
|
|
||||||
rotMat.m[3][2] = 0.0f;
|
|
||||||
rotMat.m[3][3] = 1.0f;
|
|
||||||
|
|
||||||
gst_gl_matrix_multiply (matrix, &rotMat, matrix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_matrix_frustum (GstGLMatrix * matrix, GLfloat left, GLfloat right,
|
gst_gl_matrix_frustum (GstGLMatrix * matrix, GLfloat left, GLfloat right,
|
||||||
GLfloat bottom, GLfloat top, GLfloat nearZ, GLfloat farZ)
|
GLfloat bottom, GLfloat top, GLfloat nearZ, GLfloat farZ)
|
||||||
|
@ -281,11 +227,34 @@ gst_gl_matrix_perspective (GstGLMatrix * matrix, GLfloat fovy, GLfloat aspect,
|
||||||
static const gchar *cube_v_src =
|
static const gchar *cube_v_src =
|
||||||
"attribute vec4 a_position; \n"
|
"attribute vec4 a_position; \n"
|
||||||
"attribute vec2 a_texCoord; \n"
|
"attribute vec2 a_texCoord; \n"
|
||||||
"uniform mat4 u_matrix; \n"
|
"uniform float u_rotx; \n"
|
||||||
|
"uniform float u_roty; \n"
|
||||||
|
"uniform float u_rotz; \n"
|
||||||
|
"uniform mat4 u_modelview; \n"
|
||||||
|
"uniform mat4 u_projection; \n"
|
||||||
"varying vec2 v_texCoord; \n"
|
"varying vec2 v_texCoord; \n"
|
||||||
"void main() \n"
|
"void main() \n"
|
||||||
"{ \n"
|
"{ \n"
|
||||||
" gl_Position = u_matrix * a_position; \n"
|
" float PI = 3.14159265; \n"
|
||||||
|
" float xrot = u_rotx*2.0*PI/360.0; \n"
|
||||||
|
" float yrot = u_roty*2.0*PI/360.0; \n"
|
||||||
|
" float zrot = u_rotz*2.0*PI/360.0; \n"
|
||||||
|
" mat4 matX = mat4 ( \n"
|
||||||
|
" 1.0, 0.0, 0.0, 0.0, \n"
|
||||||
|
" 0.0, cos(xrot), sin(xrot), 0.0, \n"
|
||||||
|
" 0.0, -sin(xrot), cos(xrot), 0.0, \n"
|
||||||
|
" 0.0, 0.0, 0.0, 1.0 ); \n"
|
||||||
|
" mat4 matY = mat4 ( \n"
|
||||||
|
" cos(yrot), 0.0, -sin(yrot), 0.0, \n"
|
||||||
|
" 0.0, 1.0, 0.0, 0.0, \n"
|
||||||
|
" sin(yrot), 0.0, cos(yrot), 0.0, \n"
|
||||||
|
" 0.0, 0.0, 0.0, 1.0 ); \n"
|
||||||
|
" mat4 matZ = mat4 ( \n"
|
||||||
|
" cos(zrot), sin(zrot), 0.0, 0.0, \n"
|
||||||
|
" -sin(zrot), cos(zrot), 0.0, 0.0, \n"
|
||||||
|
" 0.0, 0.0, 1.0, 0.0, \n"
|
||||||
|
" 0.0, 0.0, 0.0, 1.0 ); \n"
|
||||||
|
" gl_Position = u_projection * u_modelview * matZ * matY * matX * a_position;\n"
|
||||||
" v_texCoord = a_texCoord; \n"
|
" v_texCoord = a_texCoord; \n"
|
||||||
"} \n";
|
"} \n";
|
||||||
|
|
||||||
|
@ -323,8 +292,12 @@ typedef struct
|
||||||
GLint fshader;
|
GLint fshader;
|
||||||
GLint program;
|
GLint program;
|
||||||
|
|
||||||
GLint u_modelviewprojectionmatrix;
|
GLint u_modelviewmatrix;
|
||||||
|
GLint u_projectionmatrix;
|
||||||
GLint s_texture;
|
GLint s_texture;
|
||||||
|
GLint u_rotx;
|
||||||
|
GLint u_roty;
|
||||||
|
GLint u_rotz;
|
||||||
|
|
||||||
GstGLMatrix modelview;
|
GstGLMatrix modelview;
|
||||||
GstGLMatrix projection;
|
GstGLMatrix projection;
|
||||||
|
@ -558,8 +531,15 @@ init_model_proj (APP_STATE_T * state)
|
||||||
|
|
||||||
glUseProgram (state->program);
|
glUseProgram (state->program);
|
||||||
|
|
||||||
state->u_modelviewprojectionmatrix =
|
state->u_rotx = glGetUniformLocation (state->program, "u_rotx");
|
||||||
glGetUniformLocation (state->program, "u_matrix");
|
state->u_roty = glGetUniformLocation (state->program, "u_roty");
|
||||||
|
state->u_rotz = glGetUniformLocation (state->program, "u_rotz");
|
||||||
|
|
||||||
|
state->u_modelviewmatrix =
|
||||||
|
glGetUniformLocation (state->program, "u_modelview");
|
||||||
|
|
||||||
|
state->u_projectionmatrix =
|
||||||
|
glGetUniformLocation (state->program, "u_projection");
|
||||||
|
|
||||||
state->s_texture = glGetUniformLocation (state->program, "s_texture");
|
state->s_texture = glGetUniformLocation (state->program, "s_texture");
|
||||||
|
|
||||||
|
@ -670,9 +650,6 @@ inc_and_wrap_angle (GLfloat angle, GLfloat angle_inc)
|
||||||
static void
|
static void
|
||||||
redraw_scene (APP_STATE_T * state)
|
redraw_scene (APP_STATE_T * state)
|
||||||
{
|
{
|
||||||
GstGLMatrix modelview;
|
|
||||||
GstGLMatrix modelviewprojection;
|
|
||||||
|
|
||||||
glBindFramebuffer (GL_FRAMEBUFFER, 0);
|
glBindFramebuffer (GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
glEnable (GL_CULL_FACE);
|
glEnable (GL_CULL_FACE);
|
||||||
|
@ -694,16 +671,15 @@ redraw_scene (APP_STATE_T * state)
|
||||||
glBindTexture (GL_TEXTURE_2D, state->tex);
|
glBindTexture (GL_TEXTURE_2D, state->tex);
|
||||||
glUniform1i (state->s_texture, 0);
|
glUniform1i (state->s_texture, 0);
|
||||||
|
|
||||||
memcpy (&modelview, &state->modelview, sizeof (GstGLMatrix));
|
glUniform1f (state->u_rotx, state->rot_angle_x);
|
||||||
gst_gl_matrix_rotate (&modelview, state->rot_angle_x, 1.0f, 0.0f, 0.0f);
|
glUniform1f (state->u_roty, state->rot_angle_y);
|
||||||
gst_gl_matrix_rotate (&modelview, state->rot_angle_y, 0.0f, 1.0f, 0.0f);
|
glUniform1f (state->u_rotz, state->rot_angle_z);
|
||||||
gst_gl_matrix_rotate (&modelview, state->rot_angle_z, 0.0f, 0.0f, 1.0f);
|
|
||||||
|
|
||||||
gst_gl_matrix_load_identity (&modelviewprojection);
|
glUniformMatrix4fv (state->u_modelviewmatrix, 1, GL_FALSE,
|
||||||
gst_gl_matrix_multiply (&modelviewprojection, &modelview, &state->projection);
|
&state->modelview.m[0][0]);
|
||||||
|
|
||||||
glUniformMatrix4fv (state->u_modelviewprojectionmatrix, 1, GL_FALSE,
|
glUniformMatrix4fv (state->u_projectionmatrix, 1, GL_FALSE,
|
||||||
&modelviewprojection.m[0][0]);
|
&state->projection.m[0][0]);
|
||||||
|
|
||||||
/* draw first 4 vertices */
|
/* draw first 4 vertices */
|
||||||
glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
Loading…
Reference in a new issue