mirror of
https://github.com/brl/mutter.git
synced 2024-11-30 12:00:44 -05:00
5985eef44c
This glues CoglMaterial in as the fundamental way that Cogl describes how to fill in geometry. It adds cogl_set_source (), which is used to set the material which will be used by all subsequent drawing functions It adds cogl_set_source_texture as a convenience for setting up a default material with a single texture layer, and cogl_set_source_color is now also a convenience for setting up a material with a solid fill. "drawing functions" include, cogl_rectangle, cogl_texture_rectangle, cogl_texture_multiple_rectangles, cogl_texture_polygon (though the cogl_texture_* funcs have been renamed; see below for details), cogl_path_fill/stroke and cogl_vertex_buffer_draw*. cogl_texture_rectangle, cogl_texture_multiple_rectangles and cogl_texture_polygon no longer take a texture handle; instead the current source material is referenced. The functions have also been renamed to: cogl_rectangle_with_texture_coords, cogl_rectangles_with_texture_coords and cogl_polygon respectivly. Most code that previously did: cogl_texture_rectangle (tex_handle, x, y,...); needs to be changed to now do: cogl_set_source_texture (tex_handle); cogl_rectangle_with_texture_coords (x, y,....); In the less likely case where you were blending your source texture with a color like: cogl_set_source_color4ub (r,g,b,a); /* where r,g,b,a isn't just white */ cogl_texture_rectangle (tex_handle, x, y,...); you will need your own material to do that: mat = cogl_material_new (); cogl_material_set_color4ub (r,g,b,a); cogl_material_set_layer (mat, 0, tex_handle)); cogl_set_source_material (mat); Code that uses the texture coordinates, 0, 0, 1, 1 don't need to use cog_rectangle_with_texure_coords since these are the coordinates that cogl_rectangle will use. For cogl_texture_polygon; as well as dropping the texture handle, the n_vertices and vertices arguments were transposed for consistency. So code previously written as: cogl_texture_polygon (tex_handle, 3, verts, TRUE); need to be written as: cogl_set_source_texture (tex_handle); cogl_polygon (verts, 3, TRUE); All of the unit tests have been updated to now use the material API and test-cogl-material has been renamed to test-cogl-multitexture since any textured quad is now technically a test of CoglMaterial but this test specifically creates a material with multiple texture layers. Note: The GLES backend has not been updated yet; that will be done in a following commit.
100 lines
2.8 KiB
C
100 lines
2.8 KiB
C
#ifndef __COGL_MATERIAL_PRIVATE_H
|
|
#define __COGL_MATERIAL_PRIVATE_H
|
|
|
|
#include "cogl-material.h"
|
|
#include "cogl-matrix.h"
|
|
|
|
#include <glib.h>
|
|
|
|
typedef struct _CoglMaterial CoglMaterial;
|
|
typedef struct _CoglMaterialLayer CoglMaterialLayer;
|
|
|
|
/* XXX: I don't think gtk-doc supports having private enums so these aren't
|
|
* bundled in with CoglMaterialLayerFlags */
|
|
typedef enum _CoglMaterialLayerPrivFlags
|
|
{
|
|
/* Ref: CoglMaterialLayerFlags
|
|
COGL_MATERIAL_LAYER_FLAG_HAS_USER_MATRIX = 1L<<0
|
|
*/
|
|
COGL_MATERIAL_LAYER_FLAG_DIRTY = 1L<<1,
|
|
COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE = 1L<<2
|
|
} CoglMaterialLayerPrivFlags;
|
|
|
|
/* For tracking the state of a layer that's been flushed to OpenGL */
|
|
typedef struct _CoglLayerInfo
|
|
{
|
|
CoglHandle handle;
|
|
gulong flags;
|
|
GLenum gl_target;
|
|
GLuint gl_texture;
|
|
gboolean fallback;
|
|
gboolean disabled;
|
|
gboolean layer0_overridden;
|
|
} CoglLayerInfo;
|
|
|
|
struct _CoglMaterialLayer
|
|
{
|
|
guint ref_count;
|
|
guint index; /*!< lowest index is blended first then others
|
|
on top */
|
|
gulong flags;
|
|
CoglHandle texture; /*!< The texture for this layer, or COGL_INVALID_HANDLE
|
|
for an empty layer */
|
|
|
|
/* Determines how the color of individual texture fragments
|
|
* are calculated. */
|
|
CoglMaterialLayerCombineFunc texture_combine_rgb_func;
|
|
CoglMaterialLayerCombineSrc texture_combine_rgb_src[3];
|
|
CoglMaterialLayerCombineOp texture_combine_rgb_op[3];
|
|
|
|
CoglMaterialLayerCombineFunc texture_combine_alpha_func;
|
|
CoglMaterialLayerCombineSrc texture_combine_alpha_src[3];
|
|
CoglMaterialLayerCombineOp texture_combine_alpha_op[3];
|
|
|
|
/* TODO: Support purely GLSL based material layers */
|
|
|
|
CoglMatrix matrix;
|
|
};
|
|
|
|
typedef enum _CoglMaterialFlags
|
|
{
|
|
COGL_MATERIAL_FLAG_ENABLE_BLEND = 1L<<0,
|
|
COGL_MATERIAL_FLAG_SHOWN_SAMPLER_WARNING = 1L<<1,
|
|
COGL_MATERIAL_FLAG_DIRTY = 1L<<2,
|
|
COGL_MATERIAL_FLAG_LAYERS_DIRTY = 1L<<3,
|
|
COGL_MATERIAL_FLAG_DEFAULT_COLOR = 1L<<4,
|
|
COGL_MATERIAL_FLAG_DEFAULT_GL_MATERIAL = 1L<<5,
|
|
COGL_MATERIAL_FLAG_DEFAULT_ALPHA_FUNC = 1L<<6,
|
|
COGL_MATERIAL_FLAG_DEFAULT_BLEND_FUNC = 1L<<7
|
|
} CoglMaterialFlags;
|
|
|
|
struct _CoglMaterial
|
|
{
|
|
guint ref_count;
|
|
|
|
gulong flags;
|
|
|
|
/* If no lighting is enabled; this is the basic material color */
|
|
GLfloat unlit[4];
|
|
|
|
/* Standard OpenGL lighting model attributes */
|
|
GLfloat ambient[4];
|
|
GLfloat diffuse[4];
|
|
GLfloat specular[4];
|
|
GLfloat emission[4];
|
|
GLfloat shininess;
|
|
|
|
/* Determines what fragments are discarded based on their alpha */
|
|
CoglMaterialAlphaFunc alpha_func;
|
|
GLfloat alpha_func_reference;
|
|
|
|
/* Determines how this material is blended with other primitives */
|
|
CoglMaterialBlendFactor blend_src_factor;
|
|
CoglMaterialBlendFactor blend_dst_factor;
|
|
|
|
GList *layers;
|
|
};
|
|
|
|
#endif /* __COGL_MATERIAL_PRIVATE_H */
|
|
|