Example #1
0
CoglHandle
cogl_texture_new_from_foreign (GLuint           gl_handle,
			       GLenum           gl_target,
			       GLuint           width,
			       GLuint           height,
			       GLuint           x_pot_waste,
			       GLuint           y_pot_waste,
			       CoglPixelFormat  format)
{
#if HAVE_COGL_GL
  if (gl_target == GL_TEXTURE_RECTANGLE_ARB)
    {
      if (x_pot_waste != 0 || y_pot_waste != 0)
        {
          /* It shouldn't be necessary to have waste in this case since
           * the texture isn't limited to power of two sizes. */
          g_warning ("You can't create a foreign GL_TEXTURE_RECTANGLE cogl "
                     "texture with waste\n");
          return COGL_INVALID_HANDLE;
        }

      return _cogl_texture_rectangle_new_from_foreign (gl_handle,
                                                       width,
                                                       height,
                                                       format);
    }
#endif

  if (x_pot_waste != 0 || y_pot_waste != 0)
    return _cogl_texture_2d_sliced_new_from_foreign (gl_handle,
                                                     gl_target,
                                                     width,
                                                     height,
                                                     x_pot_waste,
                                                     y_pot_waste,
                                                     format);
  else
    return _cogl_texture_2d_new_from_foreign (gl_handle,
                                              width,
                                              height,
                                              format);
}
Example #2
0
CoglTexture *
cogl_texture_new_from_foreign (GLuint           gl_handle,
			       GLenum           gl_target,
			       GLuint           width,
			       GLuint           height,
			       GLuint           x_pot_waste,
			       GLuint           y_pot_waste,
			       CoglPixelFormat  format)
{
  _COGL_GET_CONTEXT (ctx, NULL);

#ifdef HAVE_COGL_GL
  if (gl_target == GL_TEXTURE_RECTANGLE_ARB)
    {
      CoglTextureRectangle *texture_rectangle;
      CoglSubTexture *sub_texture;

      if (x_pot_waste != 0 || y_pot_waste != 0)
        {
          /* It shouldn't be necessary to have waste in this case since
           * the texture isn't limited to power of two sizes. */
          g_warning ("You can't create a foreign GL_TEXTURE_RECTANGLE cogl "
                     "texture with waste\n");
          return NULL;
        }

      texture_rectangle = cogl_texture_rectangle_new_from_foreign (ctx,
                                                                   gl_handle,
                                                                   width,
                                                                   height,
                                                                   format);
      _cogl_texture_set_internal_format (COGL_TEXTURE (texture_rectangle),
                                         format);

      /* CoglTextureRectangle textures work with non-normalized
       * coordinates, but the semantics for this function that people
       * depend on are that all returned texture works with normalized
       * coordinates so we wrap with a CoglSubTexture... */
      sub_texture = cogl_sub_texture_new (ctx,
                                          COGL_TEXTURE (texture_rectangle),
                                          0, 0, width, height);
      return COGL_TEXTURE (sub_texture);
    }
#endif

  if (x_pot_waste != 0 || y_pot_waste != 0)
    {
      CoglTexture *tex =
        COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_foreign (ctx,
                                                                gl_handle,
                                                                gl_target,
                                                                width,
                                                                height,
                                                                x_pot_waste,
                                                                y_pot_waste,
                                                                format));
      _cogl_texture_set_internal_format (tex, format);

      cogl_texture_allocate (tex, NULL);
      return tex;
    }
  else
    {
      CoglTexture *tex =
        COGL_TEXTURE (cogl_texture_2d_gl_new_from_foreign (ctx,
                                                           gl_handle,
                                                           width,
                                                           height,
                                                           format));
      _cogl_texture_set_internal_format (tex, format);

      cogl_texture_allocate (tex, NULL);
      return tex;
    }
}
Example #3
0
CoglTexture *
cogl_texture_gl_new_from_foreign (CoglContext *ctx,
                                  unsigned int gl_handle,
                                  unsigned int gl_target,
                                  int width,
                                  int height,
                                  int x_pot_waste,
                                  int y_pot_waste,
                                  CoglPixelFormat format,
                                  CoglError **error)
{
#ifdef HAVE_COGL_GL
  if (gl_target == GL_TEXTURE_RECTANGLE_ARB)
    {
      CoglTextureRectangle *texture_rectangle;
      CoglSubTexture *sub_texture;

      if (x_pot_waste != 0 || y_pot_waste != 0)
        {
          /* It shouldn't be necessary to have waste in this case since
           * the texture isn't limited to power of two sizes. */
          g_warning ("You can't create a foreign GL_TEXTURE_RECTANGLE cogl "
                     "texture with waste\n");
          return NULL;
        }

      texture_rectangle = cogl_texture_rectangle_new_from_foreign (ctx,
                                                                   gl_handle,
                                                                   width,
                                                                   height,
                                                                   format,
                                                                   error);
      if (!texture_rectangle)
        return NULL;

      /* CoglTextureRectangle textures work with non-normalized
       * coordinates, but the semantics for this function that people
       * depend on are that all returned textures work with normalized
       * coordinates so we wrap with a CoglSubTexture... */
      sub_texture = cogl_sub_texture_new (ctx,
                                          COGL_TEXTURE (texture_rectangle),
                                          0, 0, width, height);
      return COGL_TEXTURE (sub_texture);
    }
#endif

  if (x_pot_waste != 0 || y_pot_waste != 0)
    return COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_foreign (ctx,
                                                                   gl_handle,
                                                                   gl_target,
                                                                   width,
                                                                   height,
                                                                   x_pot_waste,
                                                                   y_pot_waste,
                                                                   format,
                                                                   error));
  else
    {
      return COGL_TEXTURE (cogl_texture_2d_gl_new_from_foreign (ctx,
                                                                gl_handle,
                                                                width,
                                                                height,
                                                                format,
                                                                error));
    }
}