static void uqi_scene_view_real_paint (ClutterActor* base) { UqiSceneView *self; UqiSceneViewPrivate *priv; self = (UqiSceneView*) base; priv = self->priv; CoglColor color = priv->color; cogl_push_matrix (); cogl_translate (priv->translate_x, priv->translate_y, priv->translate_z); cogl_rotate (priv->rx, 1, 0, 0); cogl_rotate (priv->ry, 0, 1, 0); cogl_set_depth_test_enabled (TRUE); if (self->printable != NULL) { GSList *it = NULL; for (it = self->printable->vertex_list; it != NULL; it = it->next) { Vertex3D *v1 = (Vertex3D*)it->data; it = it->next; Vertex3D *v2 = (Vertex3D*)it->data; it = it->next; Vertex3D *v3 = (Vertex3D*)it->data; CoglTextureVertex vertex[3] = { {7*v1->x, 7*v1->y, 7*v1->z, .color = color}, {7*v2->x, 7*v2->y, 7*v2->z, .color = color}, {7*v3->x, 7*v3->y, 7*v3->z, .color = color}, };
static void clutter_deform_effect_paint_target (ClutterOffscreenEffect *effect) { ClutterDeformEffect *self= CLUTTER_DEFORM_EFFECT (effect); ClutterDeformEffectPrivate *priv = self->priv; gboolean is_depth_enabled, is_cull_enabled; CoglHandle material; gint n_tiles; if (priv->is_dirty) { ClutterActor *actor; gfloat width, height; guint opacity; gint i, j; actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect)); opacity = clutter_actor_get_paint_opacity (actor); /* if we don't have a target size, fall back to the actor's * allocation, though wrong it might be */ if (!clutter_offscreen_effect_get_target_size (effect, &width, &height)) clutter_actor_get_size (actor, &width, &height); for (i = 0; i < priv->y_tiles + 1; i++) { for (j = 0; j < priv->x_tiles + 1; j++) { CoglTextureVertex *vertex; vertex = &priv->vertices[(i * (priv->x_tiles + 1)) + j]; vertex->tx = (float) j / priv->x_tiles; vertex->ty = (float) i / priv->y_tiles; vertex->x = width * vertex->tx; vertex->y = height * vertex->ty; vertex->z = 0.0f; cogl_color_init_from_4ub (&vertex->color, 255, 255, 255, opacity); _clutter_deform_effect_deform_vertex (self, width, height, vertex); } } /* XXX in theory, the sub-classes should tell us what they changed * in the texture vertices; we then would be able to avoid resubmitting * the same data, if it did not change. for the time being, we resubmit * everything */ cogl_vertex_buffer_add (priv->vbo, "gl_Vertex", 3, COGL_ATTRIBUTE_TYPE_FLOAT, FALSE, sizeof (CoglTextureVertex), &priv->vertices->x); cogl_vertex_buffer_add (priv->vbo, "gl_MultiTexCoord0", 2, COGL_ATTRIBUTE_TYPE_FLOAT, FALSE, sizeof (CoglTextureVertex), &priv->vertices->tx); cogl_vertex_buffer_add (priv->vbo, "gl_Color", 4, COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE, FALSE, sizeof (CoglTextureVertex), &priv->vertices->color); priv->is_dirty = FALSE; } /* enable depth test, if it's not already enabled */ is_depth_enabled = cogl_get_depth_test_enabled (); if (!is_depth_enabled) cogl_set_depth_test_enabled (TRUE); /* enable backface culling if it's not already enabled and if * we have a back material */ is_cull_enabled = cogl_get_backface_culling_enabled (); if (priv->back_material != COGL_INVALID_HANDLE && !is_cull_enabled) cogl_set_backface_culling_enabled (TRUE); else if (priv->back_material == COGL_INVALID_HANDLE && is_cull_enabled) cogl_set_backface_culling_enabled (FALSE); n_tiles = (priv->x_tiles + 1) * (priv->y_tiles + 1); /* draw the front */ material = clutter_offscreen_effect_get_target (effect); if (material != COGL_INVALID_HANDLE) { cogl_set_source (material); cogl_vertex_buffer_draw_elements (priv->vbo, COGL_VERTICES_MODE_TRIANGLE_STRIP, priv->indices, 0, n_tiles, 0, priv->n_indices); } /* draw the back */ material = priv->back_material; if (material != COGL_INVALID_HANDLE) { cogl_set_source (priv->back_material); cogl_vertex_buffer_draw_elements (priv->vbo, COGL_VERTICES_MODE_TRIANGLE_STRIP, priv->back_indices, 0, n_tiles, 0, priv->n_indices); } /* restore the previous state */ if (!is_depth_enabled) cogl_set_depth_test_enabled (FALSE); if (priv->back_material != COGL_INVALID_HANDLE && !is_cull_enabled) cogl_set_backface_culling_enabled (FALSE); else if (priv->back_material == COGL_INVALID_HANDLE && is_cull_enabled) cogl_set_backface_culling_enabled (TRUE); }
static void paint (TestState *state) { /* Sanity check a few of the different depth test functions * and that depth writing can be disabled... */ { /* Closest */ TestDepthState rect0_state = { 0xff0000ff, /* rgba color */ -10, /* depth */ FALSE, /* depth test enable */ COGL_DEPTH_TEST_FUNCTION_ALWAYS, TRUE, /* depth write enable */ TRUE, /* FB depth write enable */ 0, 1 /* depth range */ }; /* Furthest */ TestDepthState rect1_state = { 0x00ff00ff, /* rgba color */ -70, /* depth */ TRUE, /* depth test enable */ COGL_DEPTH_TEST_FUNCTION_ALWAYS, TRUE, /* depth write enable */ TRUE, /* FB depth write enable */ 0, 1 /* depth range */ }; /* In the middle */ TestDepthState rect2_state = { 0x0000ffff, /* rgba color */ -20, /* depth */ TRUE, /* depth test enable */ COGL_DEPTH_TEST_FUNCTION_NEVER, TRUE, /* depth write enable */ TRUE, /* FB depth write enable */ 0, 1 /* depth range */ }; test_depth (state, 0, 0, /* position */ &rect0_state, &rect1_state, &rect2_state, FALSE, /* legacy mode */ 0x00ff00ff); /* expected */ rect2_state.test_function = COGL_DEPTH_TEST_FUNCTION_ALWAYS; test_depth (state, 1, 0, /* position */ &rect0_state, &rect1_state, &rect2_state, FALSE, /* legacy mode */ 0x0000ffff); /* expected */ rect2_state.test_function = COGL_DEPTH_TEST_FUNCTION_LESS; test_depth (state, 2, 0, /* position */ &rect0_state, &rect1_state, &rect2_state, FALSE, /* legacy mode */ 0x0000ffff); /* expected */ rect2_state.test_function = COGL_DEPTH_TEST_FUNCTION_GREATER; test_depth (state, 3, 0, /* position */ &rect0_state, &rect1_state, &rect2_state, FALSE, /* legacy mode */ 0x00ff00ff); /* expected */ rect0_state.test_enable = TRUE; rect1_state.write_enable = FALSE; test_depth (state, 4, 0, /* position */ &rect0_state, &rect1_state, &rect2_state, FALSE, /* legacy mode */ 0x0000ffff); /* expected */ rect1_state.write_enable = TRUE; rect1_state.fb_write_enable = FALSE; test_depth (state, 4, 0, /* position */ &rect0_state, &rect1_state, &rect2_state, FALSE, /* legacy mode */ 0x0000ffff); /* expected */ /* Re-enable FB depth writing to verify state flush */ rect1_state.write_enable = TRUE; rect1_state.fb_write_enable = TRUE; test_depth (state, 4, 0, /* position */ &rect0_state, &rect1_state, &rect2_state, FALSE, /* legacy mode */ 0x00ff00ff); /* expected */ } /* Check that the depth buffer values can be mapped into different * ranges... */ { /* Closest by depth, furthest by depth range */ TestDepthState rect0_state = { 0xff0000ff, /* rgba color */ -10, /* depth */ TRUE, /* depth test enable */ COGL_DEPTH_TEST_FUNCTION_ALWAYS, TRUE, /* depth write enable */ TRUE, /* FB depth write enable */ 0.5, 1 /* depth range */ }; /* Furthest by depth, nearest by depth range */ TestDepthState rect1_state = { 0x00ff00ff, /* rgba color */ -70, /* depth */ TRUE, /* depth test enable */ COGL_DEPTH_TEST_FUNCTION_GREATER, TRUE, /* depth write enable */ TRUE, /* FB depth write enable */ 0, 0.5 /* depth range */ }; test_depth (state, 0, 1, /* position */ &rect0_state, &rect1_state, NULL, FALSE, /* legacy mode */ 0xff0000ff); /* expected */ } /* Test that the legacy cogl_set_depth_test_enabled() API still * works... */ { /* Nearest */ TestDepthState rect0_state = { 0xff0000ff, /* rgba color */ -10, /* depth */ FALSE, /* depth test enable */ COGL_DEPTH_TEST_FUNCTION_LESS, TRUE, /* depth write enable */ TRUE, /* FB depth write enable */ 0, 1 /* depth range */ }; /* Furthest */ TestDepthState rect1_state = { 0x00ff00ff, /* rgba color */ -70, /* depth */ FALSE, /* depth test enable */ COGL_DEPTH_TEST_FUNCTION_LESS, TRUE, /* depth write enable */ TRUE, /* FB depth write enable */ 0, 1 /* depth range */ }; cogl_set_depth_test_enabled (TRUE); test_depth (state, 0, 2, /* position */ &rect0_state, &rect1_state, NULL, TRUE, /* legacy mode */ 0xff0000ff); /* expected */ cogl_set_depth_test_enabled (FALSE); test_depth (state, 1, 2, /* position */ &rect0_state, &rect1_state, NULL, TRUE, /* legacy mode */ 0x00ff00ff); /* expected */ } }
int main (int argc, char **argv) { gtk_init( &argc, &argv ); g_type_init (); gfx_lib_setup (); g_testtex = cogl_texture_new_from_file ("testtex_sr.bmp", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ANY, NULL); g_xassert (g_testtex != COGL_INVALID_HANDLE); //cogl_ortho (-1.0f, 1.0f, -1.0f, 1.0f, -5.0f, 100.0f); cogl_perspective (45.0f, 1.0f, 0.1f, 100.0f); cogl_set_source_texture (g_testtex); /** * WHY IS THIS NOT ENABLED BY DEFAULT */ cogl_set_depth_test_enabled (TRUE); /** * Enabling this shows polygons actually missing not just culled out? * cogl_set_backface_culling_enabled (TRUE); */ /** * Initialize g_state */ struct NxState state = {0}; g_state = g_new0 (struct NxState, 1); *g_state = state; g_state->dr_n = 1.0f; g_state->dr_f = 100.0f; g_state->vp_w = 100.0f; g_state->vp_h = 100.0f; g_state->vp_x = 0.0f; g_state->vp_y = 0.0f; NxMat z_mat; nx_mat_init_identity (&z_mat); nx_mat_translate (&z_mat, 0.0f, 0.0f, -30.0f); g_state->p_mat = z_mat; g_state->w_mat = z_mat; MaiModel *model; struct aiScene *scene; model = mai_model_new_from_file ("../misc/mtest1.dae", &scene); aiReleaseImport (scene); MaiAnimInstance *mai; g_xassert (model->anims->len > 0); mai = mai_anim_instance_new_from_anim ( g_mai_anim_ptr_array_index (model->anims, 0), model->name_node_map, model->nodes); struct SrNodeGraph *sr_model; sr_node_graph_from_model (model, &sr_model); MaiInfoWin *iw; iw = MAI_INFO_WIN (mai_info_win_new ()); mai_info_win_clear_model (iw); mai_info_win_fill_model_from_node_graph (iw, sr_model); mai_info_win_fill_model_from_model (iw, model); mai_info_win_show (iw); int frame; for (frame=0; frame<600; ++frame) { ALLEGRO_KEYBOARD_STATE aks; gfx_display_clear (); context_switch_allegro (); al_get_keyboard_state (&aks); sr_update_global_ypr (&aks); al_clear_to_color (al_map_rgb (0, 0, 0)); mai_info_win_iteration (iw, FALSE); /** * Allegro drawing origin top left. * Compensate (Want positive x/y go northwest). */ NxMat comp; comp = g_state->w_mat; nx_mat_scale (&comp, -1.0f, 1.0f, -1.0f); struct SrNodeGraph *sr_model_aux; GHashTable *ht; sr_node_graph_copy (&sr_model_aux, sr_model); sr_skeletal_anim_node_graph (mai, sr_model_aux); sr_skeletal_anim_verts (model, mai, sr_model_aux, &ht); GList *model_keys; model_keys = g_hash_table_get_keys (ht); for (GList *k = model_keys; k != NULL; k = k->next) { char *name; GArray *vts_a; MaiNode *mn_a; name = k->data; vts_a = g_hash_table_lookup (ht, name); g_xassert (vts_a); g_array_ref (vts_a); mn_a = g_object_ref (MAI_NODE ( g_hash_table_lookup (model->name_node_map, name))); g_xassert (mn_a); sr_skeletal_draw_node_trans (&comp, sr_model_aux, mn_a, vts_a); g_object_unref (mn_a); g_array_unref (vts_a); } g_list_free (model_keys); g_hash_table_unref (ht); sr_node_graph_free (sr_model_aux); mai->current_frame += mai->current_frame == 29 ? -29 : 1; gfx_display_transfer (); al_rest (0.05f); } return EXIT_SUCCESS; }