Draw Manager: cleanup, use doxy categories

Also add DRW_state for accessing current draw state.
This commit is contained in:
2017-04-27 02:04:56 +10:00
parent 7631f4bf6d
commit edd1512741
7 changed files with 153 additions and 57 deletions

View File

@@ -335,7 +335,7 @@ static void CLAY_engine_init(void *vedata)
}
}
if (DRW_viewport_is_fbo()) {
if (DRW_state_is_fbo()) {
const float *viewport_size = DRW_viewport_size_get();
DRWFboTexture tex = {&txl->depth_dup, DRW_BUF_DEPTH_24, 0};
DRW_framebuffer_init(&fbl->dupli_depth,
@@ -358,7 +358,7 @@ static void CLAY_engine_init(void *vedata)
int i;
const float *size = DRW_viewport_size_get();
DRW_get_dfdy_factors(dfdyfacs);
DRW_state_dfdy_factors_get(dfdyfacs);
e_data.ssao_params[0] = ssao_samples;
e_data.ssao_params[1] = size[0] / 64.0;
@@ -607,7 +607,7 @@ static void CLAY_draw_scene(void *vedata)
/* Pass 2 : Duplicate depth */
/* Unless we go for deferred shading we need this to avoid manual depth test and artifacts */
if (DRW_viewport_is_fbo()) {
if (DRW_state_is_fbo()) {
DRW_framebuffer_blit(dfbl->default_fb, fbl->dupli_depth, true);
}

View File

@@ -128,7 +128,7 @@ static void SELECT_engine_init(void *vedata)
}
#ifdef USE_DEPTH
if (DRW_viewport_is_fbo()) {
if (DRW_state_is_fbo()) {
const float *viewport_size = DRW_viewport_size_get();
DRWFboTexture tex = {&txl->depth_dup, DRW_BUF_DEPTH_24, 0};
DRW_framebuffer_init(&fbl->dupli_depth,
@@ -208,7 +208,7 @@ static void SELECT_draw_scene(void *vedata)
/* Pass 2 : Duplicate depth */
/* Unless we go for deferred shading we need this to avoid manual depth test and artifacts */
if (DRW_viewport_is_fbo()) {
if (DRW_state_is_fbo()) {
DRW_framebuffer_blit(dfbl->default_fb, fbl->dupli_depth, true);
}
#endif

View File

@@ -295,9 +295,6 @@ const float *DRW_viewport_size_get(void);
const float *DRW_viewport_screenvecs_get(void);
const float *DRW_viewport_pixelsize_get(void);
bool DRW_viewport_is_persp_get(void);
bool DRW_viewport_is_fbo(void);
bool DRW_viewport_is_select(void);
bool DRW_viewport_cache_is_dirty(void);
struct DefaultFramebufferList *DRW_viewport_framebuffer_list_get(void);
struct DefaultTextureList *DRW_viewport_texture_list_get(void);
@@ -321,8 +318,10 @@ void DRW_state_reset(void);
/* Selection */
void DRW_select_load_id(unsigned int id);
/* Other */
void DRW_get_dfdy_factors(float dfdyfac[2]);
/* Draw State */
void DRW_state_dfdy_factors_get(float dfdyfac[2]);
bool DRW_state_is_fbo(void);
bool DRW_state_is_select(void);
/* Avoid too many lookups while drawing */
typedef struct DRWContextState {

View File

@@ -359,7 +359,7 @@ static void draw_armature_edit(Object *ob)
EditBone *eBone;
bArmature *arm = ob->data;
int index;
const bool is_select = DRW_viewport_is_select();
const bool is_select = DRW_state_is_select();
update_color(NULL);
@@ -421,7 +421,7 @@ static void draw_armature_pose(Object *ob, const float const_color[4])
}
}
bool is_pose_select = (arm->flag & ARM_POSEMODE) && DRW_viewport_is_select();
bool is_pose_select = (arm->flag & ARM_POSEMODE) && DRW_state_is_select();
/* being set below */
arm->layer_used = 0;

View File

@@ -245,7 +245,12 @@ void DRW_select_load_id(unsigned int id)
}
#endif
/* ***************************************** TEXTURES ******************************************/
/* -------------------------------------------------------------------- */
/** \name Textures (DRW_texture)
* \{ */
static void drw_texture_get_format(DRWTextureFormat format, GPUTextureFormat *data_type, int *channels)
{
switch (format) {
@@ -372,8 +377,13 @@ void DRW_texture_free(GPUTexture *tex)
GPU_texture_free(tex);
}
/** \} */
/* ************************************ UNIFORM BUFFER OBJECT **********************************/
/* -------------------------------------------------------------------- */
/** \name Uniform Buffer Object (DRW_uniformbuffer)
* \{ */
GPUUniformBuffer *DRW_uniformbuffer_create(int size, const void *data)
{
@@ -390,7 +400,13 @@ void DRW_uniformbuffer_free(GPUUniformBuffer *ubo)
GPU_uniformbuffer_free(ubo);
}
/* ****************************************** SHADERS ******************************************/
/** \} */
/* -------------------------------------------------------------------- */
/** \name Shaders (DRW_shader)
* \{ */
GPUShader *DRW_shader_create(const char *vert, const char *geom, const char *frag, const char *defines)
{
@@ -461,7 +477,13 @@ void DRW_shader_free(GPUShader *shader)
GPU_shader_free(shader);
}
/* ***************************************** INTERFACE ******************************************/
/** \} */
/* -------------------------------------------------------------------- */
/** \name Interface (DRW_interface)
* \{ */
static DRWInterface *DRW_interface_create(GPUShader *shader)
{
@@ -553,12 +575,13 @@ static void DRW_interface_attrib(DRWShadingGroup *shgroup, const char *name, DRW
BLI_addtail(&shgroup->interface->attribs, attrib);
}
void DRW_get_dfdy_factors(float dfdyfac[2])
{
GPU_get_dfdy_factors(dfdyfac);
}
/** \} */
/* ***************************************** SHADING GROUP ******************************************/
/* -------------------------------------------------------------------- */
/** \name Shading Group (DRW_shgroup)
* \{ */
DRWShadingGroup *DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
{
@@ -874,7 +897,13 @@ static void shgroup_dynamic_batch_from_calls(DRWShadingGroup *shgroup)
}
#endif /* WITH_CLAY_ENGINE */
/* ***************************************** PASSES ******************************************/
/** \} */
/* -------------------------------------------------------------------- */
/** \name Passes (DRW_pass)
* \{ */
DRWPass *DRW_pass_create(const char *name, DRWState state)
{
@@ -897,7 +926,13 @@ void DRW_pass_free(DRWPass *pass)
BLI_freelistN(&pass->shgroups);
}
/* ****************************************** DRAW ******************************************/
/** \} */
/* -------------------------------------------------------------------- */
/** \name Draw (DRW_draw)
* \{ */
#ifdef WITH_CLAY_ENGINE
static void set_state(DRWState flag, const bool reset)
@@ -1164,7 +1199,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup)
GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
break;
case DRW_UNIFORM_BUFFER:
if (!DRW_viewport_is_fbo()) {
if (!DRW_state_is_fbo()) {
break;
}
tex = *((GPUTexture **)uni->value);
@@ -1313,8 +1348,13 @@ void DRW_state_reset(void) {}
#endif /* WITH_CLAY_ENGINE */
/** \} */
/* ****************************************** Settings ******************************************/
/* -------------------------------------------------------------------- */
/** \name Settings
* \{ */
bool DRW_is_object_renderable(Object *ob)
{
@@ -1334,7 +1374,13 @@ bool DRW_is_object_renderable(Object *ob)
return true;
}
/* ****************************************** Framebuffers ******************************************/
/** \} */
/* -------------------------------------------------------------------- */
/** \name Framebuffers (DRW_framebuffer)
* \{ */
static GPUTextureFormat convert_tex_format(int fbo_format, int *channels, bool *is_depth)
{
@@ -1448,7 +1494,13 @@ void DRW_framebuffer_viewport_size(struct GPUFrameBuffer *UNUSED(fb_read), int w
glViewport(0, 0, w, h);
}
/* ****************************************** Viewport ******************************************/
/** \} */
/* -------------------------------------------------------------------- */
/** \name Viewport (DRW_viewport)
* \{ */
static void *DRW_viewport_engine_data_get(void *engine_type)
{
@@ -1549,23 +1601,6 @@ bool DRW_viewport_is_persp_get(void)
return rv3d->is_persp;
}
/**
* When false, drawing doesn't output to a pixel buffer
* eg: Occlusion queries, or when we have setup a context to draw in already.
*/
bool DRW_viewport_is_fbo(void)
{
return (DST.default_framebuffer != NULL);
}
/**
* For when engines need to know if this is drawing for selection or not.
*/
bool DRW_viewport_is_select(void)
{
return (G.f & G_PICKSEL) != 0;
}
DefaultFramebufferList *DRW_viewport_framebuffer_list_get(void)
{
return GPU_viewport_framebuffer_list_get(DST.viewport);
@@ -1576,7 +1611,13 @@ DefaultTextureList *DRW_viewport_texture_list_get(void)
return GPU_viewport_texture_list_get(DST.viewport);
}
/* **************************************** OBJECTS *************************************** */
/** \} */
/* -------------------------------------------------------------------- */
/** \name Objects (DRW_object)
* \{ */
typedef struct ObjectEngineData {
struct ObjectEngineData *next, *prev;
@@ -1627,7 +1668,13 @@ void DRW_lamp_engine_data_free(LampEngineData *led)
GPU_lamp_engine_data_free(led);
}
/* **************************************** RENDERING ************************************** */
/** \} */
/* -------------------------------------------------------------------- */
/** \name Rendering (DRW_engines)
* \{ */
#define TIMER_FALLOFF 0.1f
@@ -1971,6 +2018,12 @@ static void DRW_debug_gpu_stats(void)
draw_stat(&rect, 0, v, pass_name, sizeof(pass_name));
}
/* -------------------------------------------------------------------- */
/** \name Main Draw Loops (DRW_draw)
* \{ */
/* Everything starts here.
* This function takes care of calling all cache and rendering functions
* for each relevant engine / mode engine. */
@@ -2225,7 +2278,43 @@ void DRW_draw_depth_loop(
rv3d->viewport = backup_viewport;
}
/* ****************************************** OTHER ***************************************** */
/** \} */
/* -------------------------------------------------------------------- */
/** \name Draw Manager State (DRW_state)
* \{ */
void DRW_state_dfdy_factors_get(float dfdyfac[2])
{
GPU_get_dfdy_factors(dfdyfac);
}
/**
* When false, drawing doesn't output to a pixel buffer
* eg: Occlusion queries, or when we have setup a context to draw in already.
*/
bool DRW_state_is_fbo(void)
{
return (DST.default_framebuffer != NULL);
}
/**
* For when engines need to know if this is drawing for selection or not.
*/
bool DRW_state_is_select(void)
{
return (G.f & G_PICKSEL) != 0;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Context State (DRW_context_state)
* \{ */
void DRW_context_state_init(const bContext *C, DRWContextState *r_draw_ctx)
{
@@ -2245,7 +2334,13 @@ const DRWContextState *DRW_context_state_get(void)
return &DST.draw_ctx;
}
/* ****************************************** INIT ***************************************** */
/** \} */
/* -------------------------------------------------------------------- */
/** \name Init/Exit (DRW_engines)
* \{ */
void DRW_engine_register(DrawEngineType *draw_engine_type)
{
@@ -2319,3 +2414,5 @@ void DRW_engines_free(void)
BLI_remlink(&R_engines, &DRW_engine_viewport_clay_type);
#endif
}
/** \} */

View File

@@ -220,7 +220,7 @@ static void OBJECT_engine_init(void *vedata)
{&txl->outlines_color_tx, DRW_BUF_RGBA_8, DRW_TEX_FILTER},
};
if (DRW_viewport_is_fbo()) {
if (DRW_state_is_fbo()) {
DRW_framebuffer_init(
&fbl->outlines,
(int)viewport_size[0], (int)viewport_size[1],
@@ -1271,7 +1271,7 @@ static void OBJECT_draw_scene(void *vedata)
DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
float clearcol[4] = {0.0f, 0.0f, 0.0f, 0.0f};
if (DRW_viewport_is_fbo()) {
if (DRW_state_is_fbo()) {
/* Render filled polygon on a separate framebuffer */
DRW_framebuffer_bind(fbl->outlines);
DRW_framebuffer_clear(true, true, false, clearcol, 1.0f);
@@ -1314,7 +1314,7 @@ static void OBJECT_draw_scene(void *vedata)
DRW_draw_pass(psl->non_meshes);
DRW_draw_pass(psl->ob_center);
if (!DRW_viewport_is_select()) {
if (!DRW_state_is_select()) {
DRW_draw_pass(psl->grid);
/* Combine with scene buffer last */

View File

@@ -1189,11 +1189,11 @@ int view3d_opengl_select(
if (IS_VIEWPORT_LEGACY(vc->v3d)) {
ED_view3d_draw_select_loop(vc, scene, sl, v3d, ar, use_obedit_skip, use_nearest);
}
else {
else
#else
{
DRW_draw_select_loop(vc, graph, scene, sl, v3d, ar, use_obedit_skip, use_nearest, &rect);
}
#else
DRW_draw_select_loop(vc, graph, scene, sl, v3d, ar, use_obedit_skip, use_nearest, &rect);
#endif /* WITH_OPENGL_LEGACY */
hits = GPU_select_end();
@@ -1206,11 +1206,11 @@ int view3d_opengl_select(
if (IS_VIEWPORT_LEGACY(vc->v3d)) {
ED_view3d_draw_select_loop(vc, scene, sl, v3d, ar, use_obedit_skip, use_nearest);
}
else {
else
#else
{
DRW_draw_select_loop(vc, graph, scene, sl, v3d, ar, use_obedit_skip, use_nearest, &rect);
}
#else
DRW_draw_select_loop(vc, graph, scene, sl, v3d, ar, use_obedit_skip, use_nearest, &rect);
#endif /* WITH_OPENGL_LEGACY */
GPU_select_end();