GLES 2.0 context

GLES 2.0 context — A portable api to access OpenGLES 2.0

Types and Values

Description

Cogl provides portable access to the OpenGLES api through a single library that is able to smooth over inconsistencies between the different vendor drivers for OpenGLES in a single place.

The api is designed to allow Cogl to transparently implement the api on top of other drivers, such as OpenGL, D3D or on Cogl's own drawing api so even if your platform doesn't come with an OpenGLES 2.0 api Cogl may still be able to expose the api to your application.

Since Cogl is a library and not an api specification it is possible to add OpenGLES 2.0 api features to Cogl which can immidiately benefit developers regardless of what platform they are running on.

With this api it's possible to re-use existing OpenGLES 2.0 code within applications that are rendering with the Cogl API and also it's possible for applications that render using OpenGLES 2.0 to incorporate content rendered with Cogl.

Applications can check for OpenGLES 2.0 api support by checking for COGL_FEATURE_ID_GLES2_CONTEXT support with cogl_has_feature().

Functions

COGL_GLES2_CONTEXT_ERROR

#define COGL_GLES2_CONTEXT_ERROR (_cogl_gles2_context_error_quark ())

An error domain for runtime exceptions relating to the cogl_gles2_context api.

Since: 2.0

Stability Level: Unstable


cogl_gles2_context_new ()

CoglGLES2Context *
cogl_gles2_context_new (CoglContext *ctx,
                        CoglError **error);

Allocates a new OpenGLES 2.0 context that can be used to render to CoglOffscreen framebuffers (Rendering to CoglOnscreen framebuffers is not currently supported).

To actually access the OpenGLES 2.0 api itself you need to use cogl_gles2_context_get_vtable(). You should not try to directly link to and use the symbols provided by the a system OpenGLES 2.0 driver.

Once you have allocated an OpenGLES 2.0 context you can make it current using cogl_push_gles2_context(). For those familiar with using the EGL api, this serves a similar purpose to eglMakeCurrent.

Before using this api applications can check for OpenGLES 2.0 api support by checking for COGL_FEATURE_ID_GLES2_CONTEXT support with cogl_has_feature(). This function will return FALSE and return an COGL_GLES2_CONTEXT_ERROR_UNSUPPORTED error if the feature isn't available.

Parameters

ctx

A CoglContext

 

error

A pointer to a CoglError for returning exceptions

 

Returns

A newly allocated CoglGLES2Context or NULL if there was an error and error will be updated in that case.

Since: 2.0

Stability Level: Unstable


cogl_is_gles2_context ()

CoglBool
cogl_is_gles2_context (void *object);

Gets whether the given object references a CoglGLES2Context.

Parameters

object

A CoglObject pointer

 

Returns

TRUE if the object references a CoglGLES2Context and FALSE otherwise.

Since: 2.0

Stability Level: Unstable


cogl_gles2_context_get_vtable ()

const CoglGLES2Vtable *
cogl_gles2_context_get_vtable (CoglGLES2Context *gles2_ctx);

Queries the OpenGLES 2.0 api function pointers that should be used for rendering with the given gles2_ctx .

You should not try to directly link to and use the symbols provided by any system OpenGLES 2.0 driver.

Parameters

gles2_ctx

A CoglGLES2Context allocated with cogl_gles2_context_new()

 

Returns

A pointer to a CoglGLES2Vtable providing pointers to functions for the full OpenGLES 2.0 api.

Since: 2.0

Stability Level: Unstable


cogl_push_gles2_context ()

CoglBool
cogl_push_gles2_context (CoglContext *ctx,
                         CoglGLES2Context *gles2_ctx,
                         CoglFramebuffer *read_buffer,
                         CoglFramebuffer *write_buffer,
                         CoglError **error);

Pushes the given gles2_ctx onto a stack associated with ctx so that the OpenGLES 2.0 api can be used instead of the Cogl rendering apis to read and write to the specified framebuffers.

Usage of the api available through a CoglGLES2Vtable is only allowed between cogl_push_gles2_context() and cogl_pop_gles2_context() calls.

If there is a runtime problem with switching over to the given gles2_ctx then this function will return FALSE and return an error through error .

Parameters

ctx

A CoglContext

 

gles2_ctx

A CoglGLES2Context allocated with cogl_gles2_context_new()

 

read_buffer

A CoglFramebuffer to access to read operations such as glReadPixels. (must be a CoglOffscreen framebuffer currently)

 

write_buffer

A CoglFramebuffer to access for drawing operations such as glDrawArrays. (must be a CoglOffscreen framebuffer currently)

 

error

A pointer to a CoglError for returning exceptions

 

Returns

TRUE if operation was successfull or FALSE otherwise and error will be updated.

Since: 2.0

Stability Level: Unstable


cogl_pop_gles2_context ()

void
cogl_pop_gles2_context (CoglContext *ctx);

Restores the previously active CoglGLES2Context if there were nested calls to cogl_push_gles2_context() or otherwise restores the ability to render with the Cogl api instead of OpenGLES 2.0.

The behaviour is undefined if calls to cogl_pop_gles2_context() are not balenced with the number of corresponding calls to cogl_push_gles2_context().

Parameters

ctx

A CoglContext

 

Since: 2.0

Stability Level: Unstable


cogl_gles2_get_current_vtable ()

CoglGLES2Vtable *
cogl_gles2_get_current_vtable (void);

Returns the OpenGL ES 2.0 api vtable for the currently pushed CoglGLES2Context (last pushed with cogl_push_gles2_context()) or NULL if no CoglGLES2Context has been pushed.

Returns

The CoglGLES2Vtable for the currently pushed CoglGLES2Context or NULL if none has been pushed.

Since: 2.0

Stability Level: Unstable


cogl_gles2_texture_2d_new_from_handle ()

CoglTexture2D *
cogl_gles2_texture_2d_new_from_handle (CoglContext *ctx,
                                       CoglGLES2Context *gles2_ctx,
                                       unsigned int handle,
                                       int width,
                                       int height,
                                       CoglPixelFormat format);

Creates a CoglTexture2D from an OpenGL ES 2.0 texture handle that was created within the given gles2_ctx via glGenTextures(). The texture needs to have been associated with the GL_TEXTURE_2D target.

This interface is only intended for sharing textures to read from. The behaviour is undefined if the texture is modified using the Cogl api.
Applications should only pass this function handles that were created via a CoglGLES2Vtable or via libcogl-gles2 and not pass handles created directly using the system's native libGLESv2 api.

Parameters

ctx

A CoglContext

 

gles2_ctx

A CoglGLES2Context allocated with cogl_gles2_context_new()

 

handle

An OpenGL ES 2.0 texture handle created with glGenTextures()

 

width

Width of the texture to allocate

 

height

Height of the texture to allocate

 

format

The format of the texture

 

Since: 2.0

Stability Level: Unstable


cogl_gles2_texture_get_handle ()

CoglBool
cogl_gles2_texture_get_handle (CoglTexture *texture,
                               unsigned int *handle,
                               unsigned int *target);

Gets an OpenGL ES 2.0 texture handle for a CoglTexture that can then be referenced by a CoglGLES2Context. As well as returning a texture handle the texture's target (such as GL_TEXTURE_2D) is also returned.

If the CoglTexture can not be shared with a CoglGLES2Context then this function will return FALSE.

This api does not affect the lifetime of the CoglTexture and you must take care not to reference the returned handle after the original texture has been freed.

This interface is only intended for sharing textures to read from. The behaviour is undefined if the texture is modified by a GLES2 context.
This function will only return TRUE for low-level CoglTextures such as CoglTexture2D or CoglTexture3D but not for high level meta textures such as CoglTexture2DSliced
The handle returned should not be passed directly to a system OpenGL ES 2.0 library, the handle is only intended to be used via a CoglGLES2Vtable or via libcogl-gles2.

Parameters

texture

A CoglTexture

 

handle

A return location for an OpenGL ES 2.0 texture handle

 

target

A return location for an OpenGL ES 2.0 texture target

 

Returns

TRUE if a handle and target could be returned otherwise FALSE is returned.

Since: 2.0

Stability Level: Unstable

Types and Values

CoglGLES2Context

typedef struct _CoglGLES2Context CoglGLES2Context;

Represents an OpenGLES 2.0 api context used as a sandbox for OpenGLES 2.0 state. This is comparable to an EGLContext for those who have used OpenGLES 2.0 with EGL before.

Since: 1.12

Stability Level: Unstable


struct CoglGLES2Vtable

struct CoglGLES2Vtable {
};

Provides function pointers for the full OpenGLES 2.0 api. The api must be accessed this way and not by directly calling symbols of any system OpenGLES 2.0 api.

Since: 1.12

Stability Level: Unstable


enum CoglGLES2ContextError

Error codes that relate to the cogl_gles2_context api.

Members

COGL_GLES2_CONTEXT_ERROR_UNSUPPORTED

Creating GLES2 contexts isn't supported. Applications should use cogl_has_feature() to check for the COGL_FEATURE_ID_GLES2_CONTEXT.

 

COGL_GLES2_CONTEXT_ERROR_DRIVER

An underlying driver error occured.