Merge branch 'blender2.7'
[blender.git] / source / blender / draw / intern / draw_cache_impl_metaball.c
index 841cb73d9c764070dd81c4eaf7d756ec003e2e98..62e57c9cfc955318be103c2389645cf7916635f1 100644 (file)
@@ -39,7 +39,6 @@
 
 #include "GPU_batch.h"
 
-#include "DRW_render.h"
 
 #include "draw_cache_impl.h"  /* own include */
 
@@ -59,10 +58,7 @@ typedef struct MetaBallBatchCache {
 
        /* Wireframe */
        struct {
-               GPUVertBuf *elem_vbo;
-               GPUTexture *elem_tx;
-               GPUTexture *verts_tx;
-               int tri_count;
+               GPUBatch *batch;
        } face_wire;
 
        /* settings to determine if cache is invalid */
@@ -94,10 +90,7 @@ static void metaball_batch_cache_init(MetaBall *mb)
        cache->shaded_triangles = NULL;
        cache->is_dirty = false;
        cache->pos_nor_in_order = NULL;
-       cache->face_wire.elem_vbo = NULL;
-       cache->face_wire.elem_tx = NULL;
-       cache->face_wire.verts_tx = NULL;
-       cache->face_wire.tri_count = 0;
+       cache->face_wire.batch = NULL;
 }
 
 static MetaBallBatchCache *metaball_batch_cache_get(MetaBall *mb)
@@ -131,10 +124,7 @@ static void metaball_batch_cache_clear(MetaBall *mb)
                return;
        }
 
-       GPU_VERTBUF_DISCARD_SAFE(cache->face_wire.elem_vbo);
-       DRW_TEXTURE_FREE_SAFE(cache->face_wire.elem_tx);
-       DRW_TEXTURE_FREE_SAFE(cache->face_wire.verts_tx);
-
+       GPU_BATCH_DISCARD_SAFE(cache->face_wire.batch);
        GPU_BATCH_DISCARD_SAFE(cache->batch);
        GPU_VERTBUF_DISCARD_SAFE(cache->pos_nor_in_order);
        /* Note: shaded_triangles[0] is already freed by cache->batch */
@@ -152,43 +142,13 @@ static GPUVertBuf *mball_batch_cache_get_pos_and_normals(Object *ob, MetaBallBat
 {
        if (cache->pos_nor_in_order == NULL) {
                ListBase *lb = &ob->runtime.curve_cache->disp;
-               cache->pos_nor_in_order = DRW_displist_vertbuf_calc_pos_with_normals(lb);
+               cache->pos_nor_in_order = MEM_callocN(sizeof(GPUVertBuf), __func__);
+               DRW_displist_vertbuf_create_pos_and_nor(lb, cache->pos_nor_in_order);
        }
        return cache->pos_nor_in_order;
 }
 
-static GPUTexture *mball_batch_cache_get_edges_overlay_texture_buf(Object *ob, MetaBallBatchCache *cache)
-{
-       if (cache->face_wire.elem_tx != NULL) {
-               return cache->face_wire.elem_tx;
-       }
-
-       ListBase *lb = &ob->runtime.curve_cache->disp;
-
-       /* We need a special index buffer. */
-       GPUVertBuf *vbo = cache->face_wire.elem_vbo = DRW_displist_create_edges_overlay_texture_buf(lb);
-
-       /* Upload data early because we need to create the texture for it. */
-       GPU_vertbuf_use(vbo);
-       cache->face_wire.elem_tx = GPU_texture_create_from_vertbuf(vbo);
-       cache->face_wire.tri_count = vbo->vertex_alloc / 3;
-
-       return cache->face_wire.elem_tx;
-}
-
-static GPUTexture *mball_batch_cache_get_vert_pos_and_nor_in_order_buf(Object *ob, MetaBallBatchCache *cache)
-{
-       if (cache->face_wire.verts_tx == NULL) {
-               GPUVertBuf *vbo = mball_batch_cache_get_pos_and_normals(ob, cache);
-               GPU_vertbuf_use(vbo); /* Upload early for buffer texture creation. */
-               cache->face_wire.verts_tx = GPU_texture_create_buffer(GPU_R32F, vbo->vbo_id);
-       }
-
-       return cache->face_wire.verts_tx;
-}
-
 /* -------------------------------------------------------------------- */
-
 /** \name Public Object/MetaBall API
  * \{ */
 
@@ -203,10 +163,12 @@ GPUBatch *DRW_metaball_batch_cache_get_triangles_with_normals(Object *ob)
 
        if (cache->batch == NULL) {
                ListBase *lb = &ob->runtime.curve_cache->disp;
+               GPUIndexBuf *ibo = MEM_callocN(sizeof(GPUIndexBuf), __func__);
+               DRW_displist_indexbuf_create_triangles_in_order(lb, ibo);
                cache->batch = GPU_batch_create_ex(
                        GPU_PRIM_TRIS,
                        mball_batch_cache_get_pos_and_normals(ob, cache),
-                       DRW_displist_indexbuf_calc_triangles_in_order(lb),
+                       ibo,
                        GPU_BATCH_OWNS_INDEX);
        }
 
@@ -232,26 +194,27 @@ GPUBatch **DRW_metaball_batch_cache_get_surface_shaded(Object *ob, MetaBall *mb,
 
 }
 
-void DRW_metaball_batch_cache_get_wireframes_face_texbuf(
-        Object *ob, struct GPUTexture **verts_data, struct GPUTexture **face_indices, int *tri_count)
+GPUBatch *DRW_metaball_batch_cache_get_wireframes_face(Object *ob)
 {
        if (!BKE_mball_is_basis(ob)) {
-               *verts_data = NULL;
-               *face_indices = NULL;
-               *tri_count = 0;
-               return;
+               return NULL;
        }
 
        MetaBall *mb = ob->data;
        MetaBallBatchCache *cache = metaball_batch_cache_get(mb);
 
-       if (cache->face_wire.verts_tx == NULL) {
-               *verts_data = mball_batch_cache_get_vert_pos_and_nor_in_order_buf(ob, cache);
-               *face_indices = mball_batch_cache_get_edges_overlay_texture_buf(ob, cache);
-       }
-       else {
-               *verts_data = cache->face_wire.verts_tx;
-               *face_indices = cache->face_wire.elem_tx;
+       if (cache->face_wire.batch == NULL) {
+               ListBase *lb = &ob->runtime.curve_cache->disp;
+
+               GPUVertBuf *vbo_pos_nor = MEM_callocN(sizeof(GPUVertBuf), __func__);
+               GPUVertBuf *vbo_wireframe_data = MEM_callocN(sizeof(GPUVertBuf), __func__);
+
+               DRW_displist_vertbuf_create_pos_and_nor_and_uv_tess(lb, vbo_pos_nor, NULL);
+               DRW_displist_vertbuf_create_wireframe_data_tess(lb, vbo_wireframe_data);
+
+               cache->face_wire.batch = GPU_batch_create_ex(GPU_PRIM_TRIS, vbo_pos_nor, NULL, GPU_BATCH_OWNS_VBO);
+               GPU_batch_vertbuf_add_ex(cache->face_wire.batch, vbo_wireframe_data, true);
        }
-       *tri_count = cache->face_wire.tri_count;
+
+       return cache->face_wire.batch;
 }