Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2018-12-13 13:51:17 +0300
committerAntonioya <blendergit@gmail.com>2018-12-13 13:51:41 +0300
commit6c39ea27c8c9b91c84ee8b3e870f9c7a3ba8d33b (patch)
tree30c93d0a9377abd9372c36318a2c87f5805a2ced /source/blender/draw
parent715ab529f171234231c06a63d6c0927006b7379d (diff)
GP: Create Framebuffer textures only if needed
Now, if there aren't grease pencil objects, the textures and framebuffers are not created. This unload GPU Memory when not using GP.
Diffstat (limited to 'source/blender/draw')
-rw-r--r--source/blender/draw/engines/gpencil/gpencil_engine.c121
-rw-r--r--source/blender/draw/engines/gpencil/gpencil_engine.h8
2 files changed, 78 insertions, 51 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 8a7d83b0abd..0e998363ec5 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -115,59 +115,66 @@ static void GPENCIL_create_framebuffers(void *vedata)
const int size[2] = { (int)viewport_size[0], (int)viewport_size[1] };
/* create multiframe framebuffer for AA */
- if (stl->storage->multisamples > 0) {
+ if ((stl->storage->framebuffer_flag & GP_FRAMEBUFFER_MULTISAMPLE) &&
+ (stl->storage->multisamples > 0))
+ {
DRW_gpencil_multisample_ensure(vedata, size[0], size[1]);
}
- /* temp textures */
- e_data.temp_depth_tx_a = DRW_texture_pool_query_2D(
- size[0], size[1], GPU_DEPTH_COMPONENT24,
- &draw_engine_gpencil_type);
- e_data.temp_color_tx_a = DRW_texture_pool_query_2D(size[0], size[1], fb_format,
- &draw_engine_gpencil_type);
- GPU_framebuffer_ensure_config(
- &fbl->temp_fb_a, {
- GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_a),
- GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_a)
- });
-
- e_data.temp_depth_tx_b = DRW_texture_pool_query_2D(
- size[0], size[1], GPU_DEPTH_COMPONENT24,
- &draw_engine_gpencil_type);
- e_data.temp_color_tx_b = DRW_texture_pool_query_2D(
- size[0], size[1], fb_format,
- &draw_engine_gpencil_type);
- GPU_framebuffer_ensure_config(
- &fbl->temp_fb_b, {
- GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_b),
- GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_b)
- });
-
- /* used for rim and shadow FX effects */
- e_data.temp_depth_tx_fx = DRW_texture_pool_query_2D(
- size[0], size[1], GPU_DEPTH_COMPONENT24,
- &draw_engine_gpencil_type);
- e_data.temp_color_tx_fx = DRW_texture_pool_query_2D(
- size[0], size[1], fb_format,
- &draw_engine_gpencil_type);
- GPU_framebuffer_ensure_config(
- &fbl->temp_fb_fx, {
- GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_fx),
- GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_fx),
- });
+ /* Framebufers for basic object drawing */
+ if (stl->storage->framebuffer_flag & GP_FRAMEBUFFER_BASIC) {
+ /* temp textures for ping-pong buffers */
+ e_data.temp_depth_tx_a = DRW_texture_pool_query_2D(
+ size[0], size[1], GPU_DEPTH_COMPONENT24,
+ &draw_engine_gpencil_type);
+ e_data.temp_color_tx_a = DRW_texture_pool_query_2D(size[0], size[1], fb_format,
+ &draw_engine_gpencil_type);
+ GPU_framebuffer_ensure_config(
+ &fbl->temp_fb_a, {
+ GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_a),
+ GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_a)
+ });
+
+ e_data.temp_depth_tx_b = DRW_texture_pool_query_2D(
+ size[0], size[1], GPU_DEPTH_COMPONENT24,
+ &draw_engine_gpencil_type);
+ e_data.temp_color_tx_b = DRW_texture_pool_query_2D(
+ size[0], size[1], fb_format,
+ &draw_engine_gpencil_type);
+ GPU_framebuffer_ensure_config(
+ &fbl->temp_fb_b, {
+ GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_b),
+ GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_b)
+ });
+
+ /* used for FX effects and Layer blending */
+ e_data.temp_depth_tx_fx = DRW_texture_pool_query_2D(
+ size[0], size[1], GPU_DEPTH_COMPONENT24,
+ &draw_engine_gpencil_type);
+ e_data.temp_color_tx_fx = DRW_texture_pool_query_2D(
+ size[0], size[1], fb_format,
+ &draw_engine_gpencil_type);
+ GPU_framebuffer_ensure_config(
+ &fbl->temp_fb_fx, {
+ GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_fx),
+ GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_fx),
+ });
+ }
/* background framebuffer to speed up drawing process (always 16 bits) */
- e_data.background_depth_tx = DRW_texture_pool_query_2D(
- size[0], size[1], GPU_DEPTH_COMPONENT24,
- &draw_engine_gpencil_type);
- e_data.background_color_tx = DRW_texture_pool_query_2D(
- size[0], size[1], GPU_RGBA32F,
- &draw_engine_gpencil_type);
- GPU_framebuffer_ensure_config(
- &fbl->background_fb, {
- GPU_ATTACHMENT_TEXTURE(e_data.background_depth_tx),
- GPU_ATTACHMENT_TEXTURE(e_data.background_color_tx)
- });
+ if (stl->storage->framebuffer_flag & GP_FRAMEBUFFER_DRAW) {
+ e_data.background_depth_tx = DRW_texture_pool_query_2D(
+ size[0], size[1], GPU_DEPTH_COMPONENT24,
+ &draw_engine_gpencil_type);
+ e_data.background_color_tx = DRW_texture_pool_query_2D(
+ size[0], size[1], GPU_RGBA32F,
+ &draw_engine_gpencil_type);
+ GPU_framebuffer_ensure_config(
+ &fbl->background_fb, {
+ GPU_ATTACHMENT_TEXTURE(e_data.background_depth_tx),
+ GPU_ATTACHMENT_TEXTURE(e_data.background_color_tx)
+ });
+ }
}
}
@@ -250,9 +257,6 @@ void GPENCIL_engine_init(void *vedata)
stl->storage->multisamples = U.gpencil_multisamples;
- /* create framebuffers */
- GPENCIL_create_framebuffers(vedata);
-
/* create shaders */
GPENCIL_create_shaders();
GPENCIL_create_fx_shaders(&e_data);
@@ -564,6 +568,10 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
if (ob->type == OB_GPENCIL && ob->data) {
bGPdata *gpd = (bGPdata *)ob->data;
+ /* enable multisample and basic framebuffer creation */
+ stl->storage->framebuffer_flag |= GP_FRAMEBUFFER_MULTISAMPLE;
+ stl->storage->framebuffer_flag |= GP_FRAMEBUFFER_BASIC;
+
/* when start/stop animation the cache must be set as dirty to reset all data */
if (stl->storage->reset_cache) {
gpd->flag |= GP_DATA_CACHE_IS_DIRTY;
@@ -622,7 +630,18 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
void GPENCIL_cache_finish(void *vedata)
{
+ GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+
+ /* draw particles */
DRW_gpencil_populate_particles(&e_data, vedata);
+
+ if (stl->g_data->session_flag & (GP_DRW_PAINT_IDLE | GP_DRW_PAINT_FILLING)) {
+ stl->storage->framebuffer_flag |= GP_FRAMEBUFFER_DRAW;
+ }
+
+ /* create framebuffers */
+ GPENCIL_create_framebuffers(vedata);
+
}
/* helper function to sort inverse gpencil objects using qsort */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 4aaf81ea5fd..3c0675c5e8c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -138,6 +138,8 @@ typedef struct GPENCIL_Storage {
int tonemapping;
short multisamples;
+ short framebuffer_flag; /* flag what framebuffer need to create */
+
int blend_mode;
int clamp_layer;
float blend_opacity;
@@ -159,6 +161,12 @@ typedef struct GPENCIL_Storage {
Object *camera; /* camera pointer for render mode */
} GPENCIL_Storage;
+typedef enum eGpencilFramebuffer_Flag {
+ GP_FRAMEBUFFER_MULTISAMPLE = (1 << 0),
+ GP_FRAMEBUFFER_BASIC = (1 << 1),
+ GP_FRAMEBUFFER_DRAW = (1 << 2),
+} eGpencilFramebuffer_Flag;
+
typedef struct GPENCIL_StorageList {
struct GPENCIL_Storage *storage;
struct g_data *g_data;