forked from bartvdbraak/blender
Draw Manager: edit-mode 3d text drawing
Draw cursor and selection, also support for fast-display.
This commit is contained in:
parent
2b9738b7f8
commit
3a75e84376
@ -39,4 +39,8 @@ struct Batch *BKE_curve_batch_cache_get_overlay_verts(struct Curve *cu);
|
||||
|
||||
struct Batch *BKE_curve_batch_cache_get_triangles_with_normals(struct Curve *cu, struct CurveCache *ob_curve_cache);
|
||||
|
||||
/* OB_FONT */
|
||||
struct Batch *BKE_curve_batch_cache_get_overlay_cursor(struct Curve *cu);
|
||||
struct Batch *BKE_curve_batch_cache_get_overlay_select(struct Curve *cu);
|
||||
|
||||
#endif /* __BKE_CURVE_RENDER_H__ */
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "BKE_curve.h"
|
||||
#include "BKE_curve_render.h"
|
||||
|
||||
#include "BKE_font.h"
|
||||
#include "BKE_displist_render.h"
|
||||
|
||||
#include "GPU_batch.h"
|
||||
@ -152,6 +153,10 @@ typedef struct CurveRenderData {
|
||||
int len;
|
||||
} normal;
|
||||
|
||||
struct {
|
||||
EditFont *edit_font;
|
||||
} text;
|
||||
|
||||
bool hide_handles;
|
||||
bool hide_normals;
|
||||
|
||||
@ -159,7 +164,6 @@ typedef struct CurveRenderData {
|
||||
CurveCache *ob_curve_cache;
|
||||
|
||||
/* borrow from 'Curve' */
|
||||
struct EditNurb *edit_latt;
|
||||
ListBase *nurbs;
|
||||
|
||||
/* edit, index in nurb list */
|
||||
@ -177,6 +181,8 @@ enum {
|
||||
CU_DATATYPE_NORMAL = 1 << 2,
|
||||
/* Geometry */
|
||||
CU_DATATYPE_SURFACE = 1 << 3,
|
||||
/* Text */
|
||||
CU_DATATYPE_TEXT_SELECT = 1 << 4,
|
||||
};
|
||||
|
||||
/*
|
||||
@ -206,8 +212,6 @@ static CurveRenderData *curve_render_data_create(Curve *cu, CurveCache *ob_curve
|
||||
EditNurb *editnurb = cu->editnurb;
|
||||
nurbs = &editnurb->nurbs;
|
||||
|
||||
rdata->edit_latt = editnurb;
|
||||
|
||||
if (types & CU_DATATYPE_OVERLAY) {
|
||||
curve_render_overlay_verts_edges_len_get(
|
||||
nurbs, rdata->hide_handles,
|
||||
@ -227,6 +231,8 @@ static CurveRenderData *curve_render_data_create(Curve *cu, CurveCache *ob_curve
|
||||
|
||||
rdata->nurbs = nurbs;
|
||||
|
||||
rdata->text.edit_font = cu->editfont;
|
||||
|
||||
return rdata;
|
||||
}
|
||||
|
||||
@ -305,6 +311,12 @@ typedef struct CurveBatchCache {
|
||||
Batch *batch;
|
||||
} surface;
|
||||
|
||||
/* 3d text */
|
||||
struct {
|
||||
Batch *select;
|
||||
Batch *cursor;
|
||||
} text;
|
||||
|
||||
/* settings to determine if cache is invalid */
|
||||
bool is_dirty;
|
||||
|
||||
@ -326,16 +338,21 @@ static bool curve_batch_cache_valid(Curve *cu)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cache->is_editmode != (cu->editnurb != NULL)) {
|
||||
if (cache->is_editmode != ((cu->editnurb != NULL) || (cu->editfont != NULL))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cache->is_editmode) {
|
||||
if ((cache->hide_handles != ((cu->drawflag & CU_HIDE_HANDLES) != 0))) {
|
||||
return false;
|
||||
if (cu->editnurb) {
|
||||
if ((cache->hide_handles != ((cu->drawflag & CU_HIDE_HANDLES) != 0))) {
|
||||
return false;
|
||||
}
|
||||
else if ((cache->hide_normals != ((cu->drawflag & CU_HIDE_NORMALS) != 0))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if ((cache->hide_normals != ((cu->drawflag & CU_HIDE_NORMALS) != 0))) {
|
||||
return false;
|
||||
else if (cu->editfont) {
|
||||
/* TODO */
|
||||
}
|
||||
}
|
||||
|
||||
@ -377,7 +394,7 @@ static void curve_batch_cache_init(Curve *cu)
|
||||
}
|
||||
#endif
|
||||
|
||||
cache->is_editmode = cu->editnurb != NULL;
|
||||
cache->is_editmode = (cu->editnurb != NULL) || (cu->editfont != NULL);
|
||||
|
||||
cache->is_dirty = false;
|
||||
}
|
||||
@ -403,8 +420,13 @@ void BKE_curve_batch_selection_dirty(Curve *cu)
|
||||
{
|
||||
CurveBatchCache *cache = cu->batch_cache;
|
||||
if (cache) {
|
||||
/* editnurb */
|
||||
BATCH_DISCARD_ALL_SAFE(cache->overlay.verts);
|
||||
BATCH_DISCARD_ALL_SAFE(cache->overlay.edges);
|
||||
|
||||
/* editfont */
|
||||
BATCH_DISCARD_ALL_SAFE(cache->text.select);
|
||||
BATCH_DISCARD_ALL_SAFE(cache->text.cursor);
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,9 +440,7 @@ void BKE_curve_batch_cache_clear(Curve *cu)
|
||||
BATCH_DISCARD_ALL_SAFE(cache->overlay.verts);
|
||||
BATCH_DISCARD_ALL_SAFE(cache->overlay.edges);
|
||||
|
||||
if (cache->surface.batch) {
|
||||
BATCH_DISCARD_ALL_SAFE(cache->surface.batch);
|
||||
}
|
||||
BATCH_DISCARD_ALL_SAFE(cache->surface.batch);
|
||||
|
||||
if (cache->wire.batch) {
|
||||
BATCH_DISCARD_ALL_SAFE(cache->wire.batch);
|
||||
@ -445,6 +465,10 @@ void BKE_curve_batch_cache_clear(Curve *cu)
|
||||
VERTEXBUFFER_DISCARD_SAFE(cache->normal.edges);
|
||||
ELEMENTLIST_DISCARD_SAFE(cache->normal.elem);
|
||||
}
|
||||
|
||||
/* 3d text */
|
||||
BATCH_DISCARD_ALL_SAFE(cache->text.cursor);
|
||||
BATCH_DISCARD_ALL_SAFE(cache->text.select);
|
||||
}
|
||||
|
||||
void BKE_curve_batch_cache_free(Curve *cu)
|
||||
@ -453,6 +477,11 @@ void BKE_curve_batch_cache_free(Curve *cu)
|
||||
MEM_SAFE_FREE(cu->batch_cache);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
/** \name Private Curve Cache API
|
||||
* \{ */
|
||||
|
||||
/* Batch cache usage. */
|
||||
static VertexBuffer *curve_batch_cache_get_wire_verts(CurveRenderData *rdata, CurveBatchCache *cache)
|
||||
{
|
||||
@ -780,6 +809,118 @@ static Batch *curve_batch_cache_get_pos_and_normals(CurveRenderData *rdata, Curv
|
||||
return cache->surface.batch;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
/** \name Private Object/Font Cache API
|
||||
* \{ */
|
||||
|
||||
|
||||
static Batch *curve_batch_cache_get_overlay_select(CurveRenderData *rdata, CurveBatchCache *cache)
|
||||
{
|
||||
BLI_assert(rdata->types & CU_DATATYPE_TEXT_SELECT);
|
||||
if (cache->text.select == NULL) {
|
||||
EditFont *ef = rdata->text.edit_font;
|
||||
static VertexFormat format = { 0 };
|
||||
static unsigned int pos_id;
|
||||
if (format.attrib_ct == 0) {
|
||||
pos_id = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, KEEP_FLOAT);
|
||||
}
|
||||
|
||||
VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
|
||||
const int vbo_len_capacity = ef->selboxes_len * 6;
|
||||
int vbo_len_used = 0;
|
||||
VertexBuffer_allocate_data(vbo, vbo_len_capacity);
|
||||
|
||||
float box[4][3];
|
||||
|
||||
/* fill in xy below */
|
||||
box[0][2] = box[1][2] = box[2][2] = box[3][2] = 0.001;
|
||||
|
||||
for (int i = 0; i < ef->selboxes_len; i++) {
|
||||
EditFontSelBox *sb = &ef->selboxes[i];
|
||||
|
||||
float selboxw;
|
||||
if (i + 1 != ef->selboxes_len) {
|
||||
if (ef->selboxes[i + 1].y == sb->y)
|
||||
selboxw = ef->selboxes[i + 1].x - sb->x;
|
||||
else
|
||||
selboxw = sb->w;
|
||||
}
|
||||
else {
|
||||
selboxw = sb->w;
|
||||
}
|
||||
|
||||
if (sb->rot == 0.0f) {
|
||||
copy_v2_fl2(box[0], sb->x, sb->y);
|
||||
copy_v2_fl2(box[1], sb->x + selboxw, sb->y);
|
||||
copy_v2_fl2(box[2], sb->x + selboxw, sb->y + sb->h);
|
||||
copy_v2_fl2(box[3], sb->x, sb->y + sb->h);
|
||||
}
|
||||
else {
|
||||
float mat[2][2];
|
||||
|
||||
angle_to_mat2(mat, sb->rot);
|
||||
|
||||
copy_v2_fl2(box[0], sb->x, sb->y);
|
||||
|
||||
copy_v2_fl2(box[1], selboxw, 0.0f);
|
||||
mul_m2v2(mat, box[1]);
|
||||
add_v2_v2(box[1], &sb->x);
|
||||
|
||||
copy_v2_fl2(box[2], selboxw, sb->h);
|
||||
mul_m2v2(mat, box[2]);
|
||||
add_v2_v2(box[2], &sb->x);
|
||||
|
||||
copy_v2_fl2(box[3], 0.0f, sb->h);
|
||||
mul_m2v2(mat, box[3]);
|
||||
add_v2_v2(box[3], &sb->x);
|
||||
}
|
||||
|
||||
VertexBuffer_set_attrib(vbo, pos_id, vbo_len_used++, box[0]);
|
||||
VertexBuffer_set_attrib(vbo, pos_id, vbo_len_used++, box[1]);
|
||||
VertexBuffer_set_attrib(vbo, pos_id, vbo_len_used++, box[2]);
|
||||
|
||||
VertexBuffer_set_attrib(vbo, pos_id, vbo_len_used++, box[0]);
|
||||
VertexBuffer_set_attrib(vbo, pos_id, vbo_len_used++, box[2]);
|
||||
VertexBuffer_set_attrib(vbo, pos_id, vbo_len_used++, box[3]);
|
||||
}
|
||||
BLI_assert(vbo_len_used == vbo_len_capacity);
|
||||
cache->text.select = Batch_create(PRIM_TRIANGLES, vbo, NULL);
|
||||
}
|
||||
return cache->text.select;
|
||||
}
|
||||
|
||||
static Batch *curve_batch_cache_get_overlay_cursor(CurveRenderData *rdata, CurveBatchCache *cache)
|
||||
{
|
||||
BLI_assert(rdata->types & CU_DATATYPE_TEXT_SELECT);
|
||||
if (cache->text.cursor == NULL) {
|
||||
static VertexFormat format = { 0 };
|
||||
static unsigned int pos_id;
|
||||
if (format.attrib_ct == 0) {
|
||||
pos_id = VertexFormat_add_attrib(&format, "pos", COMP_F32, 2, KEEP_FLOAT);
|
||||
}
|
||||
|
||||
VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
|
||||
const int vbo_len_capacity = 4;
|
||||
VertexBuffer_allocate_data(vbo, vbo_len_capacity);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
VertexBuffer_set_attrib(vbo, pos_id, i, rdata->text.edit_font->textcurs[i]);
|
||||
}
|
||||
cache->text.cursor = Batch_create(PRIM_TRIANGLE_FAN, vbo, NULL);
|
||||
}
|
||||
return cache->text.cursor;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
/** \name Public Object/Curve API
|
||||
* \{ */
|
||||
|
||||
Batch *BKE_curve_batch_cache_get_wire_edge(Curve *cu, CurveCache *ob_curve_cache)
|
||||
{
|
||||
CurveBatchCache *cache = curve_batch_cache_get(cu);
|
||||
@ -847,7 +988,7 @@ Batch *BKE_curve_batch_cache_get_overlay_verts(Curve *cu)
|
||||
return cache->overlay.verts;
|
||||
}
|
||||
|
||||
struct Batch *BKE_curve_batch_cache_get_triangles_with_normals(
|
||||
Batch *BKE_curve_batch_cache_get_triangles_with_normals(
|
||||
struct Curve *cu, struct CurveCache *ob_curve_cache)
|
||||
{
|
||||
CurveBatchCache *cache = curve_batch_cache_get(cu);
|
||||
@ -862,3 +1003,41 @@ struct Batch *BKE_curve_batch_cache_get_triangles_with_normals(
|
||||
|
||||
return cache->surface.batch;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
/** \name Public Object/Font API
|
||||
* \{ */
|
||||
|
||||
Batch *BKE_curve_batch_cache_get_overlay_select(Curve *cu)
|
||||
{
|
||||
CurveBatchCache *cache = curve_batch_cache_get(cu);
|
||||
|
||||
if (cache->text.select == NULL) {
|
||||
CurveRenderData *rdata = curve_render_data_create(cu, NULL, CU_DATATYPE_TEXT_SELECT);
|
||||
|
||||
curve_batch_cache_get_overlay_select(rdata, cache);
|
||||
|
||||
curve_render_data_free(rdata);
|
||||
}
|
||||
|
||||
return cache->text.select;
|
||||
}
|
||||
|
||||
Batch *BKE_curve_batch_cache_get_overlay_cursor(Curve *cu)
|
||||
{
|
||||
CurveBatchCache *cache = curve_batch_cache_get(cu);
|
||||
|
||||
if (cache->text.cursor == NULL) {
|
||||
CurveRenderData *rdata = curve_render_data_create(cu, NULL, CU_DATATYPE_TEXT_SELECT);
|
||||
|
||||
curve_batch_cache_get_overlay_cursor(rdata, cache);
|
||||
|
||||
curve_render_data_free(rdata);
|
||||
}
|
||||
|
||||
return cache->text.cursor;
|
||||
}
|
||||
|
||||
/** \} */
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_curve_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
@ -1606,7 +1607,7 @@ Batch *DRW_cache_mesh_verts_get(Object *ob)
|
||||
|
||||
Batch *DRW_cache_curve_edge_wire_get(Object *ob)
|
||||
{
|
||||
BLI_assert(ELEM(ob->type, OB_CURVE, OB_FONT));
|
||||
BLI_assert(ob->type == OB_CURVE);
|
||||
|
||||
struct Curve *cu = ob->data;
|
||||
return BKE_curve_batch_cache_get_wire_edge(cu, ob->curve_cache);
|
||||
@ -1651,14 +1652,38 @@ Batch *DRW_cache_curve_surface_get(Object *ob)
|
||||
/** \name Font
|
||||
* \{ */
|
||||
|
||||
Batch *DRW_cache_text_surface_get(Object *ob)
|
||||
Batch *DRW_cache_text_edge_wire_get(Object *ob)
|
||||
{
|
||||
BLI_assert(ob->type == OB_FONT);
|
||||
|
||||
struct Curve *cu = ob->data;
|
||||
return BKE_curve_batch_cache_get_wire_edge(cu, ob->curve_cache);
|
||||
}
|
||||
|
||||
Batch *DRW_cache_text_surface_get(Object *ob)
|
||||
{
|
||||
BLI_assert(ob->type == OB_FONT);
|
||||
struct Curve *cu = ob->data;
|
||||
if (cu->editfont && (cu->flag & CU_FAST)) {
|
||||
return NULL;
|
||||
}
|
||||
return BKE_curve_batch_cache_get_triangles_with_normals(cu, ob->curve_cache);
|
||||
}
|
||||
|
||||
Batch *DRW_cache_text_cursor_overlay_get(Object *ob)
|
||||
{
|
||||
BLI_assert(ob->type == OB_FONT);
|
||||
struct Curve *cu = ob->data;
|
||||
return BKE_curve_batch_cache_get_overlay_cursor(cu);
|
||||
}
|
||||
|
||||
Batch *DRW_cache_text_select_overlay_get(Object *ob)
|
||||
{
|
||||
BLI_assert(ob->type == OB_FONT);
|
||||
struct Curve *cu = ob->data;
|
||||
return BKE_curve_batch_cache_get_overlay_select(cu);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@ -92,15 +92,20 @@ struct Batch *DRW_cache_mesh_surface_verts_get(struct Object *ob);
|
||||
struct Batch *DRW_cache_mesh_verts_get(struct Object *ob);
|
||||
|
||||
/* Curve */
|
||||
struct Batch *DRW_cache_curve_surface_get(struct Object *ob);
|
||||
struct Batch *DRW_cache_curve_surface_verts_get(struct Object *ob);
|
||||
struct Batch *DRW_cache_curve_edge_wire_get(struct Object *ob);
|
||||
/* edit-mode */
|
||||
struct Batch *DRW_cache_curve_edge_normal_get(struct Object *ob, float normal_size);
|
||||
struct Batch *DRW_cache_curve_edge_overlay_get(struct Object *ob);
|
||||
struct Batch *DRW_cache_curve_vert_overlay_get(struct Object *ob);
|
||||
struct Batch *DRW_cache_curve_surface_get(struct Object *ob);
|
||||
struct Batch *DRW_cache_curve_surface_verts_get(struct Object *ob);
|
||||
|
||||
/* Font */
|
||||
struct Batch *DRW_cache_text_edge_wire_get(struct Object *ob);
|
||||
struct Batch *DRW_cache_text_surface_get(struct Object *ob);
|
||||
/* edit-mode */
|
||||
struct Batch *DRW_cache_text_cursor_overlay_get(struct Object *ob);
|
||||
struct Batch *DRW_cache_text_select_overlay_get(struct Object *ob);
|
||||
|
||||
/* Surface */
|
||||
struct Batch *DRW_cache_surf_surface_get(struct Object *ob);
|
||||
|
@ -61,7 +61,6 @@ typedef struct EDIT_CURVE_PassList {
|
||||
/* Declare all passes here and init them in
|
||||
* EDIT_CURVE_cache_init().
|
||||
* Only contains (DRWPass *) */
|
||||
struct DRWPass *surface_pass;
|
||||
struct DRWPass *wire_pass;
|
||||
struct DRWPass *overlay_edge_pass;
|
||||
struct DRWPass *overlay_vert_pass;
|
||||
@ -107,7 +106,6 @@ static struct {
|
||||
* Add sources to source/blender/draw/modes/shaders
|
||||
* init in EDIT_CURVE_engine_init();
|
||||
* free in EDIT_CURVE_engine_free(); */
|
||||
GPUShader *surface_sh;
|
||||
|
||||
GPUShader *wire_sh;
|
||||
|
||||
@ -120,8 +118,6 @@ typedef struct g_data {
|
||||
/* This keeps the references of the shading groups for
|
||||
* easy access in EDIT_CURVE_cache_populate() */
|
||||
|
||||
DRWShadingGroup *surface_shgrp;
|
||||
|
||||
/* resulting curve as 'wire' for curves (and optionally normals) */
|
||||
DRWShadingGroup *wire_shgrp;
|
||||
|
||||
@ -157,11 +153,6 @@ static void EDIT_CURVE_engine_init(void *vedata)
|
||||
* tex, 2);
|
||||
*/
|
||||
|
||||
|
||||
if (!e_data.surface_sh) {
|
||||
e_data.surface_sh = GPU_shader_get_builtin_shader(GPU_SHADER_SIMPLE_LIGHTING);
|
||||
}
|
||||
|
||||
if (!e_data.wire_sh) {
|
||||
e_data.wire_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
}
|
||||
@ -191,12 +182,6 @@ static void EDIT_CURVE_cache_init(void *vedata)
|
||||
}
|
||||
|
||||
{
|
||||
/* Surface */
|
||||
psl->surface_pass = DRW_pass_create(
|
||||
"Surface",
|
||||
DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
|
||||
stl->g_data->surface_shgrp = DRW_shgroup_create(e_data.surface_sh, psl->surface_pass);
|
||||
|
||||
/* Center-Line (wire) */
|
||||
psl->wire_pass = DRW_pass_create(
|
||||
"Curve Wire",
|
||||
@ -239,14 +224,6 @@ static void EDIT_CURVE_cache_populate(void *vedata, Object *ob)
|
||||
/* Get geometry cache */
|
||||
struct Batch *geom;
|
||||
|
||||
geom = DRW_cache_curve_surface_get(ob);
|
||||
if (geom) {
|
||||
Batch_set_builtin_program(geom, GPU_SHADER_SIMPLE_LIGHTING);
|
||||
Batch_Uniform4f(geom, "color", 1, 1, 1, 1);
|
||||
Batch_Uniform3f(geom, "light", 0, 0, 1);
|
||||
DRW_shgroup_call_add(stl->g_data->surface_shgrp, geom, ob->obmat);
|
||||
}
|
||||
|
||||
geom = DRW_cache_curve_edge_wire_get(ob);
|
||||
DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat);
|
||||
|
||||
@ -299,7 +276,6 @@ static void EDIT_CURVE_draw_scene(void *vedata)
|
||||
*/
|
||||
|
||||
/* ... or just render passes on default framebuffer. */
|
||||
DRW_draw_pass(psl->surface_pass);
|
||||
DRW_draw_pass(psl->wire_pass);
|
||||
DRW_draw_pass(psl->overlay_edge_pass);
|
||||
DRW_draw_pass(psl->overlay_vert_pass);
|
||||
|
@ -26,8 +26,13 @@
|
||||
#include "DRW_engine.h"
|
||||
#include "DRW_render.h"
|
||||
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
#include "BIF_glutil.h"
|
||||
|
||||
/* If builtin shaders are needed */
|
||||
#include "GPU_shader.h"
|
||||
#include "GPU_batch.h"
|
||||
|
||||
#include "draw_common.h"
|
||||
|
||||
@ -50,7 +55,9 @@ typedef struct EDIT_TEXT_PassList {
|
||||
/* Declare all passes here and init them in
|
||||
* EDIT_TEXT_cache_init().
|
||||
* Only contains (DRWPass *) */
|
||||
struct DRWPass *pass;
|
||||
struct DRWPass *wire_pass;
|
||||
struct DRWPass *overlay_select_pass;
|
||||
struct DRWPass *overlay_cursor_pass;
|
||||
} EDIT_TEXT_PassList;
|
||||
|
||||
typedef struct EDIT_TEXT_FramebufferList {
|
||||
@ -93,13 +100,16 @@ static struct {
|
||||
* Add sources to source/blender/draw/modes/shaders
|
||||
* init in EDIT_TEXT_engine_init();
|
||||
* free in EDIT_TEXT_engine_free(); */
|
||||
struct GPUShader *custom_shader;
|
||||
GPUShader *wire_sh;
|
||||
GPUShader *overlay_select_sh;
|
||||
GPUShader *overlay_cursor_sh;
|
||||
} e_data = {NULL}; /* Engine data */
|
||||
|
||||
typedef struct g_data {
|
||||
/* This keeps the references of the shading groups for
|
||||
* easy access in EDIT_TEXT_cache_populate() */
|
||||
DRWShadingGroup *group;
|
||||
/* resulting curve as 'wire' for fast editmode drawing */
|
||||
DRWShadingGroup *wire_shgrp;
|
||||
DRWShadingGroup *overlay_select_shgrp;
|
||||
DRWShadingGroup *overlay_cursor_shgrp;
|
||||
} g_data; /* Transient data */
|
||||
|
||||
/* *********** FUNCTIONS *********** */
|
||||
@ -130,8 +140,16 @@ static void EDIT_TEXT_engine_init(void *vedata)
|
||||
* tex, 2);
|
||||
*/
|
||||
|
||||
if (!e_data.custom_shader) {
|
||||
e_data.custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
if (!e_data.wire_sh) {
|
||||
e_data.wire_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
}
|
||||
|
||||
if (!e_data.overlay_select_sh) {
|
||||
e_data.overlay_select_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
}
|
||||
|
||||
if (!e_data.overlay_cursor_sh) {
|
||||
e_data.overlay_cursor_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,24 +166,22 @@ static void EDIT_TEXT_cache_init(void *vedata)
|
||||
}
|
||||
|
||||
{
|
||||
/* Create a pass */
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE;
|
||||
psl->pass = DRW_pass_create("My Pass", state);
|
||||
/* Text outline (fast drawing!) */
|
||||
psl->wire_pass = DRW_pass_create(
|
||||
"Font Wire",
|
||||
DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE);
|
||||
stl->g_data->wire_shgrp = DRW_shgroup_create(e_data.wire_sh, psl->wire_pass);
|
||||
|
||||
/* Create a shadingGroup using a function in draw_common.c or custom one */
|
||||
/*
|
||||
* stl->g_data->group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire);
|
||||
* -- or --
|
||||
* stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
|
||||
*/
|
||||
stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
|
||||
psl->overlay_select_pass = DRW_pass_create(
|
||||
"Font Select",
|
||||
DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH);
|
||||
stl->g_data->overlay_select_shgrp = DRW_shgroup_create(e_data.overlay_select_sh, psl->overlay_select_pass);
|
||||
|
||||
/* Uniforms need a pointer to it's value so be sure it's accessible at
|
||||
* any given time (i.e. use static vars) */
|
||||
static float color[4] = {1.0f, 0.0f, 0.0f, 1.0};
|
||||
DRW_shgroup_uniform_vec4(stl->g_data->group, "color", color, 1);
|
||||
psl->overlay_cursor_pass = DRW_pass_create(
|
||||
"Font Cursor",
|
||||
DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH);
|
||||
stl->g_data->overlay_cursor_shgrp = DRW_shgroup_create(e_data.overlay_cursor_sh, psl->overlay_cursor_pass);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Add geometry to shadingGroups. Execute for each objects */
|
||||
@ -173,15 +189,38 @@ static void EDIT_TEXT_cache_populate(void *vedata, Object *ob)
|
||||
{
|
||||
EDIT_TEXT_PassList *psl = ((EDIT_TEXT_Data *)vedata)->psl;
|
||||
EDIT_TEXT_StorageList *stl = ((EDIT_TEXT_Data *)vedata)->stl;
|
||||
const struct bContext *C = DRW_get_context();
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Object *obedit = scene->obedit;
|
||||
|
||||
UNUSED_VARS(psl, stl);
|
||||
|
||||
if (ob->type == OB_MESH) {
|
||||
/* Get geometry cache */
|
||||
struct Batch *geom = DRW_cache_mesh_surface_get(ob);
|
||||
if (ob->type == OB_FONT) {
|
||||
if (ob == obedit) {
|
||||
const Curve *cu = ob->data;
|
||||
/* Get geometry cache */
|
||||
struct Batch *geom;
|
||||
|
||||
/* Add geom to a shading group */
|
||||
DRW_shgroup_call_add(stl->g_data->group, geom, ob->obmat);
|
||||
if (cu->flag & CU_FAST) {
|
||||
geom = DRW_cache_text_edge_wire_get(ob);
|
||||
if (geom) {
|
||||
DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* object mode draws */
|
||||
}
|
||||
|
||||
geom = DRW_cache_text_select_overlay_get(ob);
|
||||
if (geom) {
|
||||
DRW_shgroup_call_add(stl->g_data->overlay_select_shgrp, geom, ob->obmat);
|
||||
}
|
||||
|
||||
geom = DRW_cache_text_cursor_overlay_get(ob);
|
||||
if (geom) {
|
||||
DRW_shgroup_call_add(stl->g_data->overlay_cursor_shgrp, geom, ob->obmat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,8 +255,12 @@ static void EDIT_TEXT_draw_scene(void *vedata)
|
||||
* DRW_framebuffer_bind(dfbl->default_fb);
|
||||
*/
|
||||
|
||||
/* ... or just render passes on default framebuffer. */
|
||||
DRW_draw_pass(psl->pass);
|
||||
DRW_draw_pass(psl->wire_pass);
|
||||
|
||||
set_inverted_drawing(1);
|
||||
DRW_draw_pass(psl->overlay_select_pass);
|
||||
DRW_draw_pass(psl->overlay_cursor_pass);
|
||||
set_inverted_drawing(0);
|
||||
|
||||
/* If you changed framebuffer, double check you rebind
|
||||
* the default one with its textures attached before finishing */
|
||||
|
@ -49,6 +49,7 @@
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_curve.h"
|
||||
#include "BKE_curve_render.h"
|
||||
#include "BKE_depsgraph.h"
|
||||
#include "BKE_font.h"
|
||||
#include "BKE_library.h"
|
||||
@ -273,6 +274,8 @@ static void text_update_edited(bContext *C, Object *obedit, int mode)
|
||||
}
|
||||
}
|
||||
|
||||
BKE_curve_batch_selection_dirty(cu);
|
||||
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
|
||||
}
|
||||
|
||||
|
@ -934,7 +934,9 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
|
||||
case OB_MESH:
|
||||
BKE_mesh_batch_selection_dirty(ob->data);
|
||||
break;
|
||||
// case OB_FONT: /* handled by text_update_edited */
|
||||
case OB_CURVE:
|
||||
case OB_SURF:
|
||||
BKE_curve_batch_selection_dirty(ob->data);
|
||||
break;
|
||||
case OB_LATTICE:
|
||||
|
@ -231,8 +231,7 @@ int main(
|
||||
|
||||
/* --- end declarations --- */
|
||||
|
||||
/* ensure we free data on early-exit */
|
||||
struct CreatorAtExitData app_init_data = {NULL};
|
||||
/* ensure we free data on early-exit */ struct CreatorAtExitData app_init_data = {NULL};
|
||||
BKE_blender_atexit_register(callback_main_atexit, &app_init_data);
|
||||
|
||||
#ifdef WIN32
|
||||
|
Loading…
Reference in New Issue
Block a user