コード例 #1
0
static gboolean
gst_gl_filter_cube_filter_texture (GstGLFilter * filter, guint in_tex,
    guint out_tex)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);
  GLCB cb = NULL;
  GstGLAPI api;

  api = gst_gl_context_get_gl_api (GST_GL_FILTER (cube_filter)->context);

#if GST_GL_HAVE_OPENGL
  if (api & GST_GL_API_OPENGL)
    cb = _callback_opengl;
#endif
#if GST_GL_HAVE_GLES2
  if (api & GST_GL_API_GLES2)
    cb = _callback_gles2;
#endif

  /* blocking call, use a FBO */
  gst_gl_context_use_fbo (filter->context,
      GST_VIDEO_INFO_WIDTH (&filter->out_info),
      GST_VIDEO_INFO_HEIGHT (&filter->out_info),
      filter->fbo, filter->depthbuffer, out_tex,
      cb,
      GST_VIDEO_INFO_WIDTH (&filter->in_info),
      GST_VIDEO_INFO_HEIGHT (&filter->in_info),
      in_tex, cube_filter->fovy, cube_filter->aspect,
      cube_filter->znear, cube_filter->zfar,
      GST_GL_DISPLAY_PROJECTION_PERSPECTIVE, (gpointer) cube_filter);

  return TRUE;
}
コード例 #2
0
ファイル: gstglfiltercube.c プロジェクト: zsx/ossbuild
static void
gst_gl_filter_cube_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstGLFilterCube *filter = GST_GL_FILTER_CUBE (object);

  switch (prop_id) {
    case PROP_RED:
      filter->red = g_value_get_float (value);
      break;
    case PROP_GREEN:
      filter->green = g_value_get_float (value);
      break;
    case PROP_BLUE:
      filter->blue = g_value_get_float (value);
      break;
    case PROP_FOVY:
      filter->fovy = g_value_get_double (value);
      break;
    case PROP_ASPECT:
      filter->aspect = g_value_get_double (value);
      break;
    case PROP_ZNEAR:
      filter->znear = g_value_get_double (value);
      break;
    case PROP_ZFAR:
      filter->zfar = g_value_get_double (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
コード例 #3
0
static void
gst_gl_filter_cube_gl_stop (GstGLBaseFilter * base_filter)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (base_filter);
  const GstGLFuncs *gl = base_filter->context->gl_vtable;

  if (cube_filter->vao) {
    gl->DeleteVertexArrays (1, &cube_filter->vao);
    cube_filter->vao = 0;
  }

  if (cube_filter->vertex_buffer) {
    gl->DeleteBuffers (1, &cube_filter->vertex_buffer);
    cube_filter->vertex_buffer = 0;
  }

  if (cube_filter->vbo_indices) {
    gl->DeleteBuffers (1, &cube_filter->vbo_indices);
    cube_filter->vbo_indices = 0;
  }

  if (cube_filter->shader) {
    gst_object_unref (cube_filter->shader);
    cube_filter->shader = NULL;
  }

  GST_GL_BASE_FILTER_CLASS (parent_class)->gl_stop (base_filter);
}
コード例 #4
0
ファイル: gstglfiltercube.c プロジェクト: zsx/ossbuild
static void
gst_gl_filter_cube_reset (GstGLFilter * filter)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);

  //blocking call, wait the opengl thread has destroyed the shader
  gst_gl_display_del_shader (filter->display, cube_filter->shader);
}
コード例 #5
0
ファイル: gstglfiltercube.c プロジェクト: zsx/ossbuild
static void
gst_gl_filter_cube_init_shader (GstGLFilter * filter)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);

  //blocking call, wait the opengl thread has compiled the shader
  gst_gl_display_gen_shader (filter->display, cube_v_src, cube_f_src,
      &cube_filter->shader);
}
コード例 #6
0
static gboolean
gst_gl_filter_cube_gl_start (GstGLBaseFilter * filter)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);

  /* blocking call, wait the opengl thread has compiled the shader */
  return gst_gl_context_gen_shader (GST_GL_BASE_FILTER (filter)->context,
      cube_v_src, cube_f_src, &cube_filter->shader);
}
コード例 #7
0
static void
gst_gl_filter_cube_reset (GstGLFilter * filter)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);

  /* blocking call, wait the opengl thread has destroyed the shader */
  if (cube_filter->shader)
    gst_gl_context_del_shader (filter->context, cube_filter->shader);
  cube_filter->shader = NULL;
}
コード例 #8
0
ファイル: gstglfiltercube.c プロジェクト: zsx/ossbuild
static gboolean
gst_gl_filter_cube_set_caps (GstGLFilter * filter, GstCaps * incaps,
    GstCaps * outcaps)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);

  if (cube_filter->aspect == 0)
    cube_filter->aspect = (gdouble) filter->width / (gdouble) filter->height;

  return TRUE;
}
コード例 #9
0
static gboolean
gst_gl_filter_cube_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
    GstGLMemory * out_tex)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);

  cube_filter->in_tex = in_tex;

  return gst_gl_framebuffer_draw_to_texture (filter->fbo, out_tex, _callback,
      cube_filter);
}
コード例 #10
0
static gboolean
gst_gl_filter_cube_init_shader (GstGLFilter * filter)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);

  if (gst_gl_context_get_gl_api (filter->context) & GST_GL_API_GLES2) {
    /* blocking call, wait the opengl thread has compiled the shader */
    return gst_gl_context_gen_shader (filter->context, cube_v_src, cube_f_src,
        &cube_filter->shader);
  }
  return TRUE;
}
コード例 #11
0
static gboolean
gst_gl_filter_cube_set_caps (GstGLFilter * filter, GstCaps * incaps,
    GstCaps * outcaps)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);

  if (cube_filter->aspect == 0)
    cube_filter->aspect = (gdouble) GST_VIDEO_INFO_WIDTH (&filter->out_info) /
        (gdouble) GST_VIDEO_INFO_HEIGHT (&filter->out_info);

  return TRUE;
}
コード例 #12
0
ファイル: gstglfiltercube.c プロジェクト: zsx/ossbuild
static gboolean
gst_gl_filter_cube_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
    GstGLBuffer * outbuf)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);

  //blocking call, use a FBO
  gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
      filter->fbo, filter->depthbuffer, outbuf->texture,
      gst_gl_filter_cube_callback, inbuf->width, inbuf->height, inbuf->texture,
      cube_filter->fovy, cube_filter->aspect, cube_filter->znear,
      cube_filter->zfar, GST_GL_DISPLAY_PROJECTION_PERSPECTIVE,
      (gpointer) cube_filter);

  return TRUE;
}
コード例 #13
0
ファイル: gstglfiltercube.c プロジェクト: zsx/ossbuild
//opengl scene, params: input texture (not the output filter->texture)
static void
gst_gl_filter_cube_callback (gint width, gint height, guint texture,
    gpointer stuff)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (stuff);

  static GLfloat xrot = 0;
  static GLfloat yrot = 0;
  static GLfloat zrot = 0;

#ifndef OPENGL_ES2
  glEnable (GL_DEPTH_TEST);

  glEnable (GL_TEXTURE_RECTANGLE_ARB);
  glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
  glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
      GL_CLAMP_TO_EDGE);
  glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
      GL_CLAMP_TO_EDGE);
  glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  glClearColor (cube_filter->red, cube_filter->green, cube_filter->blue, 0.0);
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glMatrixMode (GL_MODELVIEW);
  glLoadIdentity ();

  glTranslatef (0.0f, 0.0f, -5.0f);

  glRotatef (xrot, 1.0f, 0.0f, 0.0f);
  glRotatef (yrot, 0.0f, 1.0f, 0.0f);
  glRotatef (zrot, 0.0f, 0.0f, 1.0f);

  glBegin (GL_QUADS);
  // Front Face
  glTexCoord2f ((gfloat) width, 0.0f);
  glVertex3f (-1.0f, -1.0f, 1.0f);
  glTexCoord2f (0.0f, 0.0f);
  glVertex3f (1.0f, -1.0f, 1.0f);
  glTexCoord2f (0.0f, (gfloat) height);
  glVertex3f (1.0f, 1.0f, 1.0f);
  glTexCoord2f ((gfloat) width, (gfloat) height);
  glVertex3f (-1.0f, 1.0f, 1.0f);
  // Back Face
  glTexCoord2f (0.0f, 0.0f);
  glVertex3f (-1.0f, -1.0f, -1.0f);
  glTexCoord2f (0.0f, (gfloat) height);
  glVertex3f (-1.0f, 1.0f, -1.0f);
  glTexCoord2f ((gfloat) width, (gfloat) height);
  glVertex3f (1.0f, 1.0f, -1.0f);
  glTexCoord2f ((gfloat) width, 0.0f);
  glVertex3f (1.0f, -1.0f, -1.0f);
  // Top Face
  glTexCoord2f ((gfloat) width, (gfloat) height);
  glVertex3f (-1.0f, 1.0f, -1.0f);
  glTexCoord2f ((gfloat) width, 0.0f);
  glVertex3f (-1.0f, 1.0f, 1.0f);
  glTexCoord2f (0.0f, 0.0f);
  glVertex3f (1.0f, 1.0f, 1.0f);
  glTexCoord2f (0.0f, (gfloat) height);
  glVertex3f (1.0f, 1.0f, -1.0f);
  // Bottom Face
  glTexCoord2f ((gfloat) width, 0.0f);
  glVertex3f (-1.0f, -1.0f, -1.0f);
  glTexCoord2f (0.0f, 0.0f);
  glVertex3f (1.0f, -1.0f, -1.0f);
  glTexCoord2f (0.0f, (gfloat) height);
  glVertex3f (1.0f, -1.0f, 1.0f);
  glTexCoord2f ((gfloat) width, (gfloat) height);
  glVertex3f (-1.0f, -1.0f, 1.0f);
  // Right face
  glTexCoord2f (0.0f, 0.0f);
  glVertex3f (1.0f, -1.0f, -1.0f);
  glTexCoord2f (0.0f, (gfloat) height);
  glVertex3f (1.0f, 1.0f, -1.0f);
  glTexCoord2f ((gfloat) width, (gfloat) height);
  glVertex3f (1.0f, 1.0f, 1.0f);
  glTexCoord2f ((gfloat) width, 0.0f);
  glVertex3f (1.0f, -1.0f, 1.0f);
  // Left Face
  glTexCoord2f ((gfloat) width, 0.0f);
  glVertex3f (-1.0f, -1.0f, -1.0f);
  glTexCoord2f (0.0f, 0.0f);
  glVertex3f (-1.0f, -1.0f, 1.0f);
  glTexCoord2f (0.0f, (gfloat) height);
  glVertex3f (-1.0f, 1.0f, 1.0f);
  glTexCoord2f ((gfloat) width, (gfloat) height);
  glVertex3f (-1.0f, 1.0f, -1.0f);
  glEnd ();
#else
  const GLfloat v_vertices[] = {

    //front face
    1.0f, 1.0f, -1.0f,
    1.0f, 0.0f,
    1.0f, -1.0f, -1.0f,
    1.0f, 1.0f,
    -1.0f, -1.0f, -1.0f,
    0.0f, 1.0f,
    -1.0f, 1.0f, -1.0f,
    0.0f, 0.0f,
    //back face
    1.0f, 1.0f, 1.0f,
    1.0f, 0.0f,
    -1.0f, 1.0f, 1.0f,
    0.0f, 0.0f,
    -1.0f, -1.0f, 1.0f,
    0.0f, 1.0f,
    1.0f, -1.0f, 1.0f,
    1.0f, 1.0f,
    //right face
    1.0f, 1.0f, 1.0f,
    1.0f, 0.0f,
    1.0f, -1.0f, 1.0f,
    0.0f, 0.0f,
    1.0f, -1.0f, -1.0f,
    0.0f, 1.0f,
    1.0f, 1.0f, -1.0f,
    1.0f, 1.0f,
    //left face
    -1.0f, 1.0f, 1.0f,
    1.0f, 0.0f,
    -1.0f, 1.0f, -1.0f,
    1.0f, 1.0f,
    -1.0f, -1.0f, -1.0f,
    0.0f, 1.0f,
    -1.0f, -1.0f, 1.0f,
    0.0f, 0.0f,
    //top face
    1.0f, -1.0f, 1.0f,
    1.0f, 0.0f,
    -1.0f, -1.0f, 1.0f,
    0.0f, 0.0f,
    -1.0f, -1.0f, -1.0f,
    0.0f, 1.0f,
    1.0f, -1.0f, -1.0f,
    1.0f, 1.0f,
    //bottom face
    1.0f, 1.0f, 1.0f,
    1.0f, 0.0f,
    1.0f, 1.0f, -1.0f,
    1.0f, 1.0f,
    -1.0f, 1.0f, -1.0f,
    0.0f, 1.0f,
    -1.0f, 1.0f, 1.0f,
    0.0f, 0.0f
  };

  GLushort indices[] = {
    0, 1, 2,
    0, 2, 3,
    4, 5, 6,
    4, 6, 7,
    8, 9, 10,
    8, 10, 11,
    12, 13, 14,
    12, 14, 15,
    16, 17, 18,
    16, 18, 19,
    20, 21, 22,
    20, 22, 23
  };

  GLint attr_position_loc = 0;
  GLint attr_texture_loc = 0;

  const GLfloat matrix[] = {
    0.5f, 0.0f, 0.0f, 0.0f,
    0.0f, 0.5f, 0.0f, 0.0f,
    0.0f, 0.0f, 0.5f, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f
  };

  glEnable (GL_DEPTH_TEST);

  glClearColor (cube_filter->red, cube_filter->green, cube_filter->blue, 0.0);
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  gst_gl_shader_use (cube_filter->shader);

  attr_position_loc =
      gst_gl_shader_get_attribute_location (cube_filter->shader, "a_position");
  attr_texture_loc =
      gst_gl_shader_get_attribute_location (cube_filter->shader, "a_texCoord");

  //Load the vertex position
  glVertexAttribPointer (attr_position_loc, 3, GL_FLOAT,
      GL_FALSE, 5 * sizeof (GLfloat), v_vertices);

  //Load the texture coordinate
  glVertexAttribPointer (attr_texture_loc, 2, GL_FLOAT,
      GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[3]);

  glEnableVertexAttribArray (attr_position_loc);
  glEnableVertexAttribArray (attr_texture_loc);

  glActiveTexture (GL_TEXTURE0);
  glBindTexture (GL_TEXTURE_2D, texture);
  gst_gl_shader_set_uniform_1i (cube_filter->shader, "s_texture", 0);
  gst_gl_shader_set_uniform_1f (cube_filter->shader, "xrot_degree", xrot);
  gst_gl_shader_set_uniform_1f (cube_filter->shader, "yrot_degree", yrot);
  gst_gl_shader_set_uniform_1f (cube_filter->shader, "zrot_degree", zrot);
  gst_gl_shader_set_uniform_matrix_4fv (cube_filter->shader, "u_matrix", 1,
      GL_FALSE, matrix);

  glDrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices);

  glDisableVertexAttribArray (attr_position_loc);
  glDisableVertexAttribArray (attr_texture_loc);
#endif

  glDisable (GL_DEPTH_TEST);

  xrot += 0.3f;
  yrot += 0.2f;
  zrot += 0.4f;
}
コード例 #14
0
static void
_callback_gles2 (gint width, gint height, guint texture, gpointer stuff)
{
  GstGLFilter *filter = GST_GL_FILTER (stuff);
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);
  GstGLFuncs *gl = filter->context->gl_vtable;

  static GLfloat xrot = 0;
  static GLfloat yrot = 0;
  static GLfloat zrot = 0;

/* *INDENT-OFF* */
  const GLfloat v_vertices[] = {
 /*|     Vertex     | TexCoord |*/ 
    /* front face */
     1.0,  1.0, -1.0, 1.0, 0.0,
     1.0, -1.0, -1.0, 1.0, 1.0,
    -1.0, -1.0, -1.0, 0.0, 1.0,
    -1.0,  1.0, -1.0, 0.0, 0.0,
    /* back face */
     1.0,  1.0,  1.0, 1.0, 0.0,
    -1.0,  1.0,  1.0, 0.0, 0.0,
    -1.0, -1.0,  1.0, 0.0, 1.0,
     1.0, -1.0,  1.0, 1.0, 1.0,
    /* right face */
     1.0,  1.0,  1.0, 1.0, 0.0,
     1.0, -1.0,  1.0, 0.0, 0.0,
     1.0, -1.0, -1.0, 0.0, 1.0,
     1.0,  1.0, -1.0, 1.0, 1.0,
    /* left face */
    -1.0,  1.0,  1.0, 1.0, 0.0,
    -1.0,  1.0, -1.0, 1.0, 1.0,
    -1.0, -1.0, -1.0, 0.0, 1.0,
    -1.0, -1.0,  1.0, 0.0, 0.0,
    /* top face */
     1.0, -1.0,  1.0, 1.0, 0.0,
    -1.0, -1.0,  1.0, 0.0, 0.0,
    -1.0, -1.0, -1.0, 0.0, 1.0,
     1.0, -1.0, -1.0, 1.0, 1.0,
    /* bottom face */
     1.0,  1.0,  1.0, 1.0, 0.0,
     1.0,  1.0, -1.0, 1.0, 1.0,
    -1.0,  1.0, -1.0, 0.0, 1.0,
    -1.0,  1.0,  1.0, 0.0, 0.0
  };
/* *INDENT-ON* */

  GLushort indices[] = {
    0, 1, 2,
    0, 2, 3,
    4, 5, 6,
    4, 6, 7,
    8, 9, 10,
    8, 10, 11,
    12, 13, 14,
    12, 14, 15,
    16, 17, 18,
    16, 18, 19,
    20, 21, 22,
    20, 22, 23
  };

  GLint attr_position_loc = 0;
  GLint attr_texture_loc = 0;

  const GLfloat matrix[] = {
    0.5f, 0.0f, 0.0f, 0.0f,
    0.0f, 0.5f, 0.0f, 0.0f,
    0.0f, 0.0f, 0.5f, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f
  };

  gl->Enable (GL_DEPTH_TEST);

  gl->ClearColor (cube_filter->red, cube_filter->green, cube_filter->blue, 0.0);
  gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  gst_gl_shader_use (cube_filter->shader);

  attr_position_loc =
      gst_gl_shader_get_attribute_location (cube_filter->shader, "a_position");
  attr_texture_loc =
      gst_gl_shader_get_attribute_location (cube_filter->shader, "a_texCoord");

  /* Load the vertex position */
  gl->VertexAttribPointer (attr_position_loc, 3, GL_FLOAT,
      GL_FALSE, 5 * sizeof (GLfloat), v_vertices);

  /* Load the texture coordinate */
  gl->VertexAttribPointer (attr_texture_loc, 2, GL_FLOAT,
      GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[3]);

  gl->EnableVertexAttribArray (attr_position_loc);
  gl->EnableVertexAttribArray (attr_texture_loc);

  gl->ActiveTexture (GL_TEXTURE0);
  gl->BindTexture (GL_TEXTURE_2D, texture);
  gst_gl_shader_set_uniform_1i (cube_filter->shader, "s_texture", 0);
  gst_gl_shader_set_uniform_1f (cube_filter->shader, "xrot_degree", xrot);
  gst_gl_shader_set_uniform_1f (cube_filter->shader, "yrot_degree", yrot);
  gst_gl_shader_set_uniform_1f (cube_filter->shader, "zrot_degree", zrot);
  gst_gl_shader_set_uniform_matrix_4fv (cube_filter->shader, "u_matrix", 1,
      GL_FALSE, matrix);

  gl->DrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices);

  gl->DisableVertexAttribArray (attr_position_loc);
  gl->DisableVertexAttribArray (attr_texture_loc);

  gl->Disable (GL_DEPTH_TEST);

  xrot += 0.3f;
  yrot += 0.2f;
  zrot += 0.4f;
}
コード例 #15
0
static void
_callback_opengl (gint width, gint height, guint texture, gpointer stuff)
{
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (stuff);
  GstGLFilter *filter = GST_GL_FILTER (stuff);
  GstGLFuncs *gl = filter->context->gl_vtable;

  static GLfloat xrot = 0;
  static GLfloat yrot = 0;
  static GLfloat zrot = 0;

/* *INDENT-OFF* */
  const GLfloat v_vertices[] = {
 /*|     Vertex     | TexCoord |*/ 
    /* front face */
     1.0,  1.0, -1.0, 0.0, 0.0,
     1.0, -1.0, -1.0, 1.0, 0.0,
    -1.0, -1.0, -1.0, 1.0, 1.0,
    -1.0,  1.0, -1.0, 0.0, 1.0,
    /* back face */
    -1.0,  1.0,  1.0, 0.0, 0.0,
    -1.0, -1.0,  1.0, 1.0, 0.0,
     1.0, -1.0,  1.0, 1.0, 1.0,
     1.0,  1.0,  1.0, 0.0, 1.0,
    /* right face */
    -1.0,  1.0, -1.0, 0.0, 0.0,
    -1.0, -1.0, -1.0, 1.0, 0.0,
    -1.0, -1.0,  1.0, 1.0, 1.0,
    -1.0,  1.0,  1.0, 0.0, 1.0,
    /* left face */
     1.0,  1.0,  1.0, 0.0, 0.0,
     1.0, -1.0,  1.0, 1.0, 0.0,
     1.0, -1.0, -1.0, 1.0, 1.0,
     1.0,  1.0, -1.0, 0.0, 1.0,
    /* top face */
     1.0,  1.0,  1.0, 0.0, 0.0,
     1.0,  1.0, -1.0, 1.0, 0.0,
    -1.0,  1.0, -1.0, 1.0, 1.0,
    -1.0,  1.0,  1.0, 0.0, 1.0,
    /* bottom face */
     1.0, -1.0,  1.0, 0.0, 0.0,
     1.0, -1.0, -1.0, 1.0, 0.0,
    -1.0, -1.0, -1.0, 1.0, 1.0,
    -1.0, -1.0,  1.0, 0.0, 1.0,
  };
/* *INDENT-ON* */

  GLushort indices[] = {
    0, 1, 2,
    0, 2, 3,
    4, 5, 6,
    4, 6, 7,
    8, 9, 10,
    8, 10, 11,
    12, 13, 14,
    12, 14, 15,
    16, 17, 18,
    16, 18, 19,
    20, 21, 22,
    20, 22, 23
  };

  gl->Enable (GL_DEPTH_TEST);

  gl->Enable (GL_TEXTURE_2D);
  gl->BindTexture (GL_TEXTURE_2D, texture);

  gl->ClearColor (cube_filter->red, cube_filter->green, cube_filter->blue, 0.0);
  gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  gl->MatrixMode (GL_PROJECTION);
  gluLookAt (0.0, 0.0, -6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  gl->MatrixMode (GL_MODELVIEW);
  gl->LoadIdentity ();

//  gl->Translatef (0.0f, 0.0f, -5.0f);

  gl->Rotatef (xrot, 1.0f, 0.0f, 0.0f);
  gl->Rotatef (yrot, 0.0f, 1.0f, 0.0f);
  gl->Rotatef (zrot, 0.0f, 0.0f, 1.0f);

  gl->ClientActiveTexture (GL_TEXTURE0);
  gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
  gl->EnableClientState (GL_VERTEX_ARRAY);

  gl->VertexPointer (3, GL_FLOAT, 5 * sizeof (float), v_vertices);
  gl->TexCoordPointer (2, GL_FLOAT, 5 * sizeof (float), &v_vertices[3]);

  gl->DrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices);

  gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
  gl->DisableClientState (GL_VERTEX_ARRAY);

  gl->Disable (GL_DEPTH_TEST);

  xrot += 0.3f;
  yrot += 0.2f;
  zrot += 0.4f;
}
コード例 #16
0
static gboolean
_callback (gpointer stuff)
{
  GstGLFilter *filter = GST_GL_FILTER (stuff);
  GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);
  GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;

  static GLfloat xrot = 0;
  static GLfloat yrot = 0;
  static GLfloat zrot = 0;

  const GLfloat matrix[] = {
    0.5f, 0.0f, 0.0f, 0.0f,
    0.0f, 0.5f, 0.0f, 0.0f,
    0.0f, 0.0f, 0.5f, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f
  };

  gl->Enable (GL_DEPTH_TEST);

  gl->ClearColor (cube_filter->red, cube_filter->green, cube_filter->blue, 0.0);
  gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  gst_gl_shader_use (cube_filter->shader);

  gl->ActiveTexture (GL_TEXTURE0);
  gl->BindTexture (GL_TEXTURE_2D, cube_filter->in_tex->tex_id);
  gst_gl_shader_set_uniform_1i (cube_filter->shader, "s_texture", 0);
  gst_gl_shader_set_uniform_1f (cube_filter->shader, "xrot_degree", xrot);
  gst_gl_shader_set_uniform_1f (cube_filter->shader, "yrot_degree", yrot);
  gst_gl_shader_set_uniform_1f (cube_filter->shader, "zrot_degree", zrot);
  gst_gl_shader_set_uniform_matrix_4fv (cube_filter->shader, "u_matrix", 1,
      GL_FALSE, matrix);

  if (!cube_filter->vertex_buffer) {
    if (gl->GenVertexArrays) {
      gl->GenVertexArrays (1, &cube_filter->vao);
      gl->BindVertexArray (cube_filter->vao);
    }

    gl->GenBuffers (1, &cube_filter->vertex_buffer);
    gl->BindBuffer (GL_ARRAY_BUFFER, cube_filter->vertex_buffer);
    gl->BufferData (GL_ARRAY_BUFFER, 6 * 4 * 5 * sizeof (GLfloat), vertices,
        GL_STATIC_DRAW);

    gl->GenBuffers (1, &cube_filter->vbo_indices);
    gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, cube_filter->vbo_indices);
    gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices,
        GL_STATIC_DRAW);

    if (gl->GenVertexArrays) {
      _bind_buffer (cube_filter);
      gl->BindVertexArray (0);
    }

    gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
    gl->BindBuffer (GL_ARRAY_BUFFER, 0);
  }

  if (gl->GenVertexArrays)
    gl->BindVertexArray (cube_filter->vao);
  _bind_buffer (cube_filter);

  gl->DrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);

  if (gl->GenVertexArrays)
    gl->BindVertexArray (0);
  _unbind_buffer (cube_filter);

  gl->Disable (GL_DEPTH_TEST);

  xrot += 0.3f;
  yrot += 0.2f;
  zrot += 0.4f;

  return TRUE;
}