texture-rectangle: Make new_from_foreign api public
This adds a new public cogl_texture_rectangle_new_from_foreign() function so that we can look at removing the generic cogl_texture_new_from_foreign(). Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit af02792b336bb492c5bd11afc34a5dcd417503f6)
This commit is contained in:
parent
13f228fe69
commit
0ffad6ba20
@ -294,10 +294,12 @@ cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
CoglTextureRectangle *
|
CoglTextureRectangle *
|
||||||
_cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,
|
cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
|
||||||
GLuint width,
|
unsigned int gl_handle,
|
||||||
GLuint height,
|
int width,
|
||||||
CoglPixelFormat format)
|
int height,
|
||||||
|
CoglPixelFormat format,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
/* NOTE: width, height and internal format are not queriable
|
/* NOTE: width, height and internal format are not queriable
|
||||||
* in GLES, hence such a function prototype.
|
* in GLES, hence such a function prototype.
|
||||||
@ -308,15 +310,19 @@ _cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,
|
|||||||
GLenum gl_int_format = 0;
|
GLenum gl_int_format = 0;
|
||||||
CoglTextureRectangle *tex_rect;
|
CoglTextureRectangle *tex_rect;
|
||||||
|
|
||||||
_COGL_GET_CONTEXT (ctx, NULL);
|
/* Assert that it is a valid GL texture object */
|
||||||
|
g_return_val_if_fail (ctx->glIsTexture (gl_handle), NULL);
|
||||||
|
|
||||||
if (!ctx->texture_driver->allows_foreign_gl_target (ctx,
|
if (!ctx->texture_driver->allows_foreign_gl_target (ctx,
|
||||||
GL_TEXTURE_RECTANGLE_ARB))
|
GL_TEXTURE_RECTANGLE_ARB))
|
||||||
|
{
|
||||||
|
g_set_error (error,
|
||||||
|
COGL_ERROR,
|
||||||
|
COGL_ERROR_UNSUPPORTED,
|
||||||
|
"Foreign GL_TEXTURE_RECTANGLE textures are not "
|
||||||
|
"supported by your system");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
/* Make sure it is a valid GL texture object */
|
|
||||||
if (!ctx->glIsTexture (gl_handle))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* Make sure binding succeeds */
|
/* Make sure binding succeeds */
|
||||||
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
||||||
@ -324,7 +330,13 @@ _cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,
|
|||||||
|
|
||||||
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB, gl_handle, TRUE);
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB, gl_handle, TRUE);
|
||||||
if (ctx->glGetError () != GL_NO_ERROR)
|
if (ctx->glGetError () != GL_NO_ERROR)
|
||||||
|
{
|
||||||
|
g_set_error (error,
|
||||||
|
COGL_ERROR,
|
||||||
|
COGL_ERROR_UNSUPPORTED,
|
||||||
|
"Failed to bind foreign GL_TEXTURE_RECTANGLE texture");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Obtain texture parameters */
|
/* Obtain texture parameters */
|
||||||
|
|
||||||
@ -348,8 +360,14 @@ _cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,
|
|||||||
if (!ctx->driver_vtable->pixel_format_from_gl_internal (ctx,
|
if (!ctx->driver_vtable->pixel_format_from_gl_internal (ctx,
|
||||||
gl_int_format,
|
gl_int_format,
|
||||||
&format))
|
&format))
|
||||||
|
{
|
||||||
|
g_set_error (error,
|
||||||
|
COGL_ERROR,
|
||||||
|
COGL_ERROR_UNSUPPORTED,
|
||||||
|
"Unsupported internal format for foreign texture");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -370,12 +388,17 @@ _cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Validate width and height */
|
/* Validate width and height */
|
||||||
if (width <= 0 || height <= 0)
|
g_return_val_if_fail (width > 0 && height > 0, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* Compressed texture images not supported */
|
/* Compressed texture images not supported */
|
||||||
if (gl_compressed == GL_TRUE)
|
if (gl_compressed == GL_TRUE)
|
||||||
|
{
|
||||||
|
g_set_error (error,
|
||||||
|
COGL_ERROR,
|
||||||
|
COGL_ERROR_UNSUPPORTED,
|
||||||
|
"Compressed foreign textures aren't currently supported");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create new texture */
|
/* Create new texture */
|
||||||
tex_rect = _cogl_texture_rectangle_create_base (ctx, width, height, format);
|
tex_rect = _cogl_texture_rectangle_create_base (ctx, width, height, format);
|
||||||
|
@ -89,6 +89,12 @@ cogl_is_texture_rectangle (void *object);
|
|||||||
* the GPU can sample from directly unlike high-level textures such
|
* the GPU can sample from directly unlike high-level textures such
|
||||||
* as #CoglTexture2DSliced and #CoglAtlasTexture.
|
* as #CoglTexture2DSliced and #CoglAtlasTexture.
|
||||||
*
|
*
|
||||||
|
* <note>Unlike for #CoglTexture2D textures, coordinates for
|
||||||
|
* #CoglTextureRectangle textures should not be normalized. So instead
|
||||||
|
* of using the coordinate (1, 1) to sample the bottom right corner of
|
||||||
|
* a rectangle texture you would use (@width, @height) where @width
|
||||||
|
* and @height are the width and height of the texture.</note>
|
||||||
|
*
|
||||||
* <note>If you want to sample from a rectangle texture from GLSL you
|
* <note>If you want to sample from a rectangle texture from GLSL you
|
||||||
* should use the sampler2DRect sampler type.</note>
|
* should use the sampler2DRect sampler type.</note>
|
||||||
*
|
*
|
||||||
@ -124,6 +130,12 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
|
|||||||
* directly unlike high-level textures such as #CoglTexture2DSliced
|
* directly unlike high-level textures such as #CoglTexture2DSliced
|
||||||
* and #CoglAtlasTexture.
|
* and #CoglAtlasTexture.
|
||||||
*
|
*
|
||||||
|
* <note>Unlike for #CoglTexture2D textures, coordinates for
|
||||||
|
* #CoglTextureRectangle textures should not be normalized. So instead
|
||||||
|
* of using the coordinate (1, 1) to sample the bottom right corner of
|
||||||
|
* a rectangle texture you would use (@width, @height) where @width
|
||||||
|
* and @height are the width and height of the texture.</note>
|
||||||
|
*
|
||||||
* <note>If you want to sample from a rectangle texture from GLSL you
|
* <note>If you want to sample from a rectangle texture from GLSL you
|
||||||
* should use the sampler2DRect sampler type.</note>
|
* should use the sampler2DRect sampler type.</note>
|
||||||
*
|
*
|
||||||
@ -142,6 +154,51 @@ cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap,
|
|||||||
CoglPixelFormat internal_format,
|
CoglPixelFormat internal_format,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cogl_texture_rectangle_new_from_foreign:
|
||||||
|
* @ctx: A #CoglContext
|
||||||
|
* @gl_handle: A GL handle for a GL_TEXTURE_RECTANGLE texture object
|
||||||
|
* @width: Width of the foreign GL texture
|
||||||
|
* @height: Height of the foreign GL texture
|
||||||
|
* @internal_format: The format of the texture
|
||||||
|
* @error: A #GError for exceptions
|
||||||
|
*
|
||||||
|
* Wraps an existing GL_TEXTURE_RECTANGLE texture object as a
|
||||||
|
* #CoglTextureRectangle. This can be used for integrating Cogl with
|
||||||
|
* software using OpenGL directly.
|
||||||
|
*
|
||||||
|
* <note>Unlike for #CoglTexture2D textures, coordinates for
|
||||||
|
* #CoglTextureRectangle textures should not be normalized. So instead
|
||||||
|
* of using the coordinate (1, 1) to sample the bottom right corner of
|
||||||
|
* a rectangle texture you would use (@width, @height) where @width
|
||||||
|
* and @height are the width and height of the texture.</note>
|
||||||
|
*
|
||||||
|
* <note>The results are undefined for passing an invalid @gl_handle
|
||||||
|
* or if @width or @height don't have the correct texture
|
||||||
|
* geometry.</note>
|
||||||
|
*
|
||||||
|
* <note>If you want to sample from a rectangle texture from GLSL you
|
||||||
|
* should use the sampler2DRect sampler type.</note>
|
||||||
|
*
|
||||||
|
* <note>Applications wanting to use #CoglTextureRectangle should
|
||||||
|
* first check for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature
|
||||||
|
* using cogl_has_feature().</note>
|
||||||
|
|
||||||
|
* Returns: A newly allocated #CoglTextureRectangle, or if Cogl could
|
||||||
|
* not validate the @gl_handle in some way (perhaps because
|
||||||
|
* of an unsupported format) it will return %NULL and set
|
||||||
|
* @error.
|
||||||
|
*
|
||||||
|
|
||||||
|
*/
|
||||||
|
CoglTextureRectangle *
|
||||||
|
cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
|
||||||
|
unsigned int gl_handle,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
CoglPixelFormat format,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __COGL_TEXURE_RECTANGLE_H */
|
#endif /* __COGL_TEXURE_RECTANGLE_H */
|
||||||
|
@ -503,10 +503,13 @@ cogl_texture_new_from_foreign (GLuint gl_handle,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
texture_rectangle = _cogl_texture_rectangle_new_from_foreign (gl_handle,
|
texture_rectangle = cogl_texture_rectangle_new_from_foreign (ctx,
|
||||||
|
gl_handle,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
format);
|
format,
|
||||||
|
NULL);
|
||||||
|
|
||||||
/* CoglTextureRectangle textures work with non-normalized
|
/* CoglTextureRectangle textures work with non-normalized
|
||||||
* coordinates, but the semantics for this function that people
|
* coordinates, but the semantics for this function that people
|
||||||
* depend on are that all returned texture works with normalized
|
* depend on are that all returned texture works with normalized
|
||||||
|
Loading…
x
Reference in New Issue
Block a user