static void clutter_reflect_texture_paint (ClutterActor *self) { ClutterReflectTexturePrivate *priv; ClutterActor *parent_texture; gint x1, y1, x2, y2; GLenum target_type; priv = CLUTTER_REFLECT_TEXTURE (self)->priv; /* no need to paint stuff if we don't have a texture to reflect */ if (!clutter_clone_texture_get_parent_texture(CLUTTER_CLONE_TEXTURE(self))) return; /* parent texture may have been hidden, there for need to make sure its * realised with resources available. */ parent_texture = CLUTTER_ACTOR (clutter_clone_texture_get_parent_texture(CLUTTER_CLONE_TEXTURE(self))); if (!CLUTTER_ACTOR_IS_REALIZED (parent_texture)) clutter_actor_realize (parent_texture); /* FIXME: figure out nicer way of getting at this info... */ if (clutter_feature_available (CLUTTER_FEATURE_TEXTURE_RECTANGLE) && clutter_texture_is_tiled (CLUTTER_TEXTURE (parent_texture)) == FALSE) { target_type = CGL_TEXTURE_RECTANGLE_ARB; cogl_enable (CGL_ENABLE_TEXTURE_RECT | CGL_ENABLE_BLEND); } else { target_type = CGL_TEXTURE_2D; cogl_enable (CGL_ENABLE_TEXTURE_2D|CGL_ENABLE_BLEND); } cogl_push_matrix (); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub (255, 255, 255, clutter_actor_get_opacity (self)); clutter_actor_get_coords (self, &x1, &y1, &x2, &y2); /* Parent paint translated us into position */ reflect_texture_render_to_gl_quad (CLUTTER_REFLECT_TEXTURE (self), 0, 0, x2 - x1, y2 - y1); cogl_pop_matrix (); }
static void tidy_texture_frame_paint (ClutterActor *self) { TidyTextureFramePrivate *priv; ClutterActor *parent_texture; guint width, height; gint pwidth, pheight, ex, ey; ClutterFixed tx1, ty1, tx2, ty2, tw, th; GLenum target_type; ClutterColor col = { 0xff, 0xff, 0xff, 0xff }; priv = TIDY_TEXTURE_FRAME (self)->priv; /* no need to paint stuff if we don't have a texture to reflect */ if (!clutter_clone_texture_get_parent_texture (CLUTTER_CLONE_TEXTURE(self))) return; /* parent texture may have been hidden, there for need to make sure its * realised with resources available. */ parent_texture = CLUTTER_ACTOR (clutter_clone_texture_get_parent_texture(CLUTTER_CLONE_TEXTURE(self))); if (!CLUTTER_ACTOR_IS_REALIZED (parent_texture)) clutter_actor_realize (parent_texture); if (clutter_texture_is_tiled (CLUTTER_TEXTURE (parent_texture))) { g_warning("tiled textures not yet supported..."); return; } cogl_push_matrix (); #define FX(x) CLUTTER_INT_TO_FIXED(x) clutter_texture_get_base_size (CLUTTER_TEXTURE(parent_texture), &pwidth, &pheight); clutter_actor_get_size (self, &width, &height); tx1 = FX (priv->left); tx2 = FX (pwidth - priv->right); ty1 = FX (priv->top); ty2 = FX (pheight - priv->bottom); tw = FX (pwidth); th = FX (pheight); if (clutter_feature_available (CLUTTER_FEATURE_TEXTURE_RECTANGLE)) { target_type = CGL_TEXTURE_RECTANGLE_ARB; cogl_enable (CGL_ENABLE_TEXTURE_RECT|CGL_ENABLE_BLEND); } else { target_type = CGL_TEXTURE_2D; cogl_enable (CGL_ENABLE_TEXTURE_2D|CGL_ENABLE_BLEND); tw = clutter_util_next_p2 (pwidth); th = clutter_util_next_p2 (pheight); tx1 = tx1/tw; tx2 = tx2/tw; ty1 = ty1/th; ty2 = ty2/th; tw = FX(pwidth)/tw; th = FX(pheight)/th; } col.alpha = clutter_actor_get_opacity (self); cogl_color (&col); clutter_texture_bind_tile (CLUTTER_TEXTURE(parent_texture), 0); ex = width - priv->right; if (ex < 0) ex = priv->right; /* FIXME */ ey = height - priv->bottom; if (ey < 0) ey = priv->bottom; /* FIXME */ /* top left corner */ cogl_texture_quad (0, priv->left, /* FIXME: clip if smaller */ 0, priv->top, 0, 0, tx1, ty1); /* top middle */ cogl_texture_quad (priv->left, ex, 0, priv->top, tx1, 0, tx2, ty1); /* top right */ cogl_texture_quad (ex, width, 0, priv->top, tx2, 0, tw, ty1); /* mid left */ cogl_texture_quad (0, priv->left, priv->top, ey, 0, ty1, tx1, ty2); /* center */ cogl_texture_quad (priv->left, ex, priv->top, ey, tx1, ty1, tx2, ty2); /* mid right */ cogl_texture_quad (ex, width, priv->top, ey, tx2, ty1, tw, ty2); /* bottom left */ cogl_texture_quad (0, priv->left, ey, height, 0, ty2, tx1, th); /* bottom center */ cogl_texture_quad (priv->left, ex, ey, height, tx1, ty2, tx2, th); /* bottom right */ cogl_texture_quad (ex, width, ey, height, tx2, ty2, tw, th); cogl_pop_matrix (); #undef FX }
static gboolean cogl_create_context () { GLubyte default_texture_data[] = { 0xff, 0xff, 0xff, 0x0 }; gulong enable_flags = 0; CoglDrawBufferState *draw_buffer; if (_context != NULL) return FALSE; /* Allocate context memory */ _context = (CoglContext*) g_malloc (sizeof (CoglContext)); /* Init default values */ _context->feature_flags = 0; _context->features_cached = FALSE; _context->enable_flags = 0; _context->color_alpha = 0; _context->enable_backface_culling = FALSE; _context->indirect = gl_is_indirect; _context->default_material = cogl_material_new (); _context->source_material = NULL; _context->default_gl_texture_2d_tex = COGL_INVALID_HANDLE; _context->default_gl_texture_rect_tex = COGL_INVALID_HANDLE; _context->journal = g_array_new (FALSE, FALSE, sizeof (CoglJournalEntry)); _context->logged_vertices = g_array_new (FALSE, FALSE, sizeof (GLfloat)); _context->journal_vbo = 0; _context->journal_vbo_len = 0; _context->current_material = NULL; _context->current_material_flags = 0; memset (&_context->current_material_flush_options, 0, sizeof (CoglMaterialFlushOptions)); _context->current_layers = g_array_new (FALSE, FALSE, sizeof (CoglLayerInfo)); _context->n_texcoord_arrays_enabled = 0; draw_buffer = g_slice_new0 (CoglDrawBufferState); draw_buffer->target = COGL_WINDOW_BUFFER; draw_buffer->offscreen = COGL_INVALID_HANDLE; _context->draw_buffer_stack = g_slist_prepend (NULL, draw_buffer); _context->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode)); _context->last_path = 0; _context->stencil_material = cogl_material_new (); _context->in_begin_gl_block = FALSE; _context->viewport_width = 0; _context->viewport_height = 0; _context->pf_glGenRenderbuffersEXT = NULL; _context->pf_glBindRenderbufferEXT = NULL; _context->pf_glRenderbufferStorageEXT = NULL; _context->pf_glGenFramebuffersEXT = NULL; _context->pf_glBindFramebufferEXT = NULL; _context->pf_glFramebufferTexture2DEXT = NULL; _context->pf_glFramebufferRenderbufferEXT = NULL; _context->pf_glCheckFramebufferStatusEXT = NULL; _context->pf_glDeleteFramebuffersEXT = NULL; _context->pf_glBlitFramebufferEXT = NULL; _context->pf_glRenderbufferStorageMultisampleEXT = NULL; _context->pf_glCreateProgramObjectARB = NULL; _context->pf_glCreateShaderObjectARB = NULL; _context->pf_glShaderSourceARB = NULL; _context->pf_glCompileShaderARB = NULL; _context->pf_glAttachObjectARB = NULL; _context->pf_glLinkProgramARB = NULL; _context->pf_glUseProgramObjectARB = NULL; _context->pf_glGetUniformLocationARB = NULL; _context->pf_glDeleteObjectARB = NULL; _context->pf_glGetInfoLogARB = NULL; _context->pf_glGetObjectParameterivARB = NULL; _context->pf_glUniform1fARB = NULL; _context->pf_glUniform2fARB = NULL; _context->pf_glUniform3fARB = NULL; _context->pf_glUniform4fARB = NULL; _context->pf_glUniform1fvARB = NULL; _context->pf_glUniform2fvARB = NULL; _context->pf_glUniform3fvARB = NULL; _context->pf_glUniform4fvARB = NULL; _context->pf_glUniform1iARB = NULL; _context->pf_glUniform2iARB = NULL; _context->pf_glUniform3iARB = NULL; _context->pf_glUniform4iARB = NULL; _context->pf_glUniform1ivARB = NULL; _context->pf_glUniform2ivARB = NULL; _context->pf_glUniform3ivARB = NULL; _context->pf_glUniform4ivARB = NULL; _context->pf_glUniformMatrix2fvARB = NULL; _context->pf_glUniformMatrix3fvARB = NULL; _context->pf_glUniformMatrix4fvARB = NULL; _context->pf_glDrawRangeElements = NULL; _context->pf_glActiveTexture = NULL; _context->pf_glClientActiveTexture = NULL; _context->pf_glBlendFuncSeparate = NULL; _context->pf_glBlendEquationSeparate = NULL; /* Initialise the clip stack */ _cogl_clip_stack_state_init (); /* Initialise matrix stack */ _cogl_current_matrix_state_init (); /* Create default textures used for fall backs */ _context->default_gl_texture_2d_tex = cogl_texture_new_from_data (1, /* width */ 1, /* height */ COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */ /* internal format */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, 0, /* auto calc row stride */ default_texture_data); _context->default_gl_texture_rect_tex = cogl_texture_new_from_data (1, /* width */ 1, /* height */ COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */ /* internal format */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, 0, /* auto calc row stride */ default_texture_data); cogl_set_source (_context->default_material); _cogl_material_flush_gl_state (_context->source_material, NULL); enable_flags = _cogl_material_get_cogl_enable_flags (_context->source_material); cogl_enable (enable_flags); _context->quad_indices_byte = COGL_INVALID_HANDLE; _context->quad_indices_short = COGL_INVALID_HANDLE; _context->quad_indices_short_len = 0; return TRUE; }
static gboolean cogl_create_context (void) { GLubyte default_texture_data[] = { 0xff, 0xff, 0xff, 0x0 }; unsigned long enable_flags = 0; CoglHandle window_buffer; if (_context != NULL) return FALSE; /* Allocate context memory */ _context = (CoglContext*) g_malloc (sizeof (CoglContext)); /* Init default values */ _context->feature_flags = 0; _context->features_cached = FALSE; /* Initialise the driver specific state */ /* TODO: combine these two into one function */ _cogl_create_context_driver (_context); _cogl_features_init (); _cogl_material_init_default_material (); _context->enable_flags = 0; _context->color_alpha = 0; _context->enable_backface_culling = FALSE; _context->flushed_front_winding = COGL_FRONT_WINDING_COUNTER_CLOCKWISE; _context->indirect = gl_is_indirect; cogl_matrix_init_identity (&_context->identity_matrix); cogl_matrix_init_identity (&_context->y_flip_matrix); cogl_matrix_scale (&_context->y_flip_matrix, 1, -1, 1); _context->flushed_matrix_mode = COGL_MATRIX_MODELVIEW; _context->texture_units = NULL; _context->simple_material = cogl_material_new (); _context->source_material = NULL; _context->default_gl_texture_2d_tex = COGL_INVALID_HANDLE; _context->default_gl_texture_rect_tex = COGL_INVALID_HANDLE; _context->journal = g_array_new (FALSE, FALSE, sizeof (CoglJournalEntry)); _context->logged_vertices = g_array_new (FALSE, FALSE, sizeof (GLfloat)); _context->current_material = NULL; _context->current_material_flags = 0; memset (&_context->current_material_flush_options, 0, sizeof (CoglMaterialFlushOptions)); _context->current_layers = g_array_new (FALSE, FALSE, sizeof (CoglLayerInfo)); _context->n_texcoord_arrays_enabled = 0; _context->framebuffer_stack = _cogl_create_framebuffer_stack (); window_buffer = _cogl_onscreen_new (); cogl_set_framebuffer (window_buffer); /* XXX: the deprecated _cogl_set_draw_buffer API expects to * find the window buffer here... */ _context->window_buffer = window_buffer; _context->dirty_bound_framebuffer = TRUE; _context->dirty_gl_viewport = TRUE; _context->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode)); _context->last_path = 0; _context->stencil_material = cogl_material_new (); _context->in_begin_gl_block = FALSE; _context->quad_indices_byte = COGL_INVALID_HANDLE; _context->quad_indices_short = COGL_INVALID_HANDLE; _context->quad_indices_short_len = 0; _context->texture_download_material = COGL_INVALID_HANDLE; /* Create default textures used for fall backs */ _context->default_gl_texture_2d_tex = cogl_texture_new_from_data (1, /* width */ 1, /* height */ COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */ /* internal format */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, 0, /* auto calc row stride */ default_texture_data); _context->default_gl_texture_rect_tex = cogl_texture_new_from_data (1, /* width */ 1, /* height */ COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */ /* internal format */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, 0, /* auto calc row stride */ default_texture_data); cogl_set_source (_context->simple_material); _cogl_material_flush_gl_state (_context->source_material, NULL); enable_flags = _cogl_material_get_cogl_enable_flags (_context->source_material); cogl_enable (enable_flags); _cogl_flush_face_winding (); _context->atlas = NULL; _context->atlas_texture = COGL_INVALID_HANDLE; _context->current_pbo = NULL; _context->max_texture_units = -1; return TRUE; }