libgpcogl - API reference

Shader programs

typedef GLuint gpcogl_prog_id_t;

gpcogl_prog_id_t gpcogl_compile(gpcogl_t *ctx, const char *fragment_shader);

int gpcogl_acompute(gpcogl_t *ctx, gpcogl_prog_id_t pid, gpcogl_array_id_t dst, const char **src_name, gpcogl_array_id_t *src_aid, const char **const_type, const char **const_name, const void **const_val);
int gpcogl_acompute_box(gpcogl_t *ctx, gpcogl_prog_id_t pid, gpcogl_array_id_t dst, GLint x0, GLint y0, GLsizei w, GLsizei h, const char **src_name, gpcogl_array_id_t *src_aid, const char **const_type, const char **const_name, const void **const_val);
int gpcogl_vcompute(gpcogl_t *ctx, gpcogl_prog_id_t pid, gpcogl_array_id_t dst, ...);
int gpcogl_vcompute_box(gpcogl_t *ctx, gpcogl_prog_id_t pid, gpcogl_array_id_t dst, GLint x0, GLint y0, GLsizei w, GLsizei h, ...);

extern const char GPCOGL_C_1F[], GPCOGL_C_2F[], GPCOGL_C_3F[], GPCOGL_C_4F[];
extern const char GPCOGL_C_1U[], GPCOGL_C_2U[], GPCOGL_C_3U[], GPCOGL_C_4U[];
extern const char GPCOGL_C_1I[], GPCOGL_C_2I[], GPCOGL_C_3I[], GPCOGL_C_4I[];

void gpcogl_finish(gpcogl_t *ctx);

Compilation

Each (shader) program compiled is remembered by a gpcogl_prog_id_t (per gpcogl_t context) assigned by the compiler. The compiler is executed using gpcogl_compile(), providing it the target context and the shader source code. Returns the program id or 0 on error.

Computation

For executing programs compiled to peform computations, call gpcogl_*compute*. Output is written to the dst array.

Input is a list of name-array_id pairs, where name must match the name of the input in the shader prorgam. There can be no more input arrays than ctx->array_max_active-2, but at least 14 input arrays must be supported by the hardware.

In the 'a' variant input is passed in the src_name and src_aid C arrays, where src_name is NULL terminated and src_aid contains the corresponding array IDs. If there are no input arrays, both of these arguments can be NULL.

Arguments const_type, const_name, cont_val behave the same, for global constants; const_type is a NULL terminated array, each element is one of GPCOGL_C_*. For each non-NULL type there is a corresponding array element in const_name and const_val. const_name matches one of the constants declared in the shader program and const_val is a float *, uint32_t * or int32_t * array of 1 or more components, matching the number in GPCOGL_C_* used. These constants are made acessible within the shader program using the GPCOGL_CONST_* macros.

The 'v' variant takes a NULL terminated vararg list of mixed array and global constant definitions. An array definition is of form name,array_id pair. A global constant is type,name,val, where type is one of GPCOGL_C_*, name is a (const char *) string and val is a (float *) or (int32_t *) or (uint32_t *) depending on type.

The _box variants operate on a rectangular subset of the output. The target rectangle's first cell affected (top left) is x0;y0, cells being indexed from 0. Target rectangle width and height are w and h, in number-of-cells. If w or h is 0, it is calculated from array width or height so that it spans the whole remaining array in that direction. Thus a 0,0,0,0 means "whole array", while a 0,3,0,2 means "two whole rows of the array starting from row 3".

The GPCOGL_C_* strings are used to identify constant types. Comparison is made by pointer, not by string content so it is important to pass these pointers, not strings built to have the same content.

sync

If for some reason the CPU shall wait for the GPU to finish all computation pushed in the control stream, gpcogl_finish() can be used to locking-wait. This is normally not required: any operation, such as subsequent compute() depending on array output from previous compute() or array download from GPU to CPU will automatically block-wait data to be ready.