diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2021-10-05 10:36:11 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-10-05 10:39:54 +0300 |
commit | 1d49293b80446b89b5b12fa0eeefaf14e5051e48 (patch) | |
tree | 72e007ea9d498576ad9b48050f81f38994aa0d98 /source/blender/draw/intern/draw_view_data.h | |
parent | 08511b1c3de0338314940397083adaba4e9cf492 (diff) |
DRW: Move buffer & temp textures & framebuffer management to DrawManager
This is a necessary step for EEVEE's new arch. This moves more data
to the draw manager. This makes it easier to have the render or draw
engines manage their own data.
This makes more sense and cleans-up what the GPUViewport holds
Also rewrites the Texture pool manager to be in C++.
This also move the DefaultFramebuffer/TextureList and the engine related
data to a new `DRWViewData` struct. This struct manages the per view
(as in stereo view) engine data.
There is a bit of cleanup in the way the draw manager is setup.
We now use a temporary DRWData instead of creating a dummy viewport.
Development: fclem, jbakker
Differential Revision: https://developer.blender.org/D11966
Diffstat (limited to 'source/blender/draw/intern/draw_view_data.h')
-rw-r--r-- | source/blender/draw/intern/draw_view_data.h | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_view_data.h b/source/blender/draw/intern/draw_view_data.h new file mode 100644 index 00000000000..c8176170a61 --- /dev/null +++ b/source/blender/draw/intern/draw_view_data.h @@ -0,0 +1,139 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2021, Blender Foundation. + */ + +/** \file + * \ingroup draw + * + * Engine data + * Structure containing each draw engine instance data. + */ + +#pragma once + +#define GPU_INFO_SIZE 512 /* IMA_MAX_RENDER_TEXT */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct GPUViewport; +struct DrawEngineType; +struct DRWRegisteredDrawEngine; + +/* NOTE these structs are only here for reading the actual lists from the engine. + * The actual length of them is stored in a ViewportEngineData_Info. + * The length of 1 is just here to avoid compiler warning. */ +typedef struct FramebufferList { + struct GPUFrameBuffer *framebuffers[1]; +} FramebufferList; + +typedef struct TextureList { + struct GPUTexture *textures[1]; +} TextureList; + +typedef struct PassList { + struct DRWPass *passes[1]; +} PassList; + +/* Stores custom structs from the engine that have been MEM_(m/c)allocN'ed. */ +typedef struct StorageList { + void *storage[1]; +} StorageList; + +typedef struct ViewportEngineData { + /* Not owning pointer to the draw engine. */ + struct DRWRegisteredDrawEngine *engine_type; + + FramebufferList *fbl; + TextureList *txl; + PassList *psl; + StorageList *stl; + char info[GPU_INFO_SIZE]; + + /* we may want to put this elsewhere */ + struct DRWTextStore *text_draw_cache; + + /* Profiling data */ + double init_time; + double render_time; + double background_time; +} ViewportEngineData; + +typedef struct ViewportEngineData_Info { + int fbl_len; + int txl_len; + int psl_len; + int stl_len; +} ViewportEngineData_Info; + +/* Buffer and textures used by the viewport by default */ +typedef struct DefaultFramebufferList { + struct GPUFrameBuffer *default_fb; + struct GPUFrameBuffer *overlay_fb; + struct GPUFrameBuffer *in_front_fb; + struct GPUFrameBuffer *color_only_fb; + struct GPUFrameBuffer *depth_only_fb; + struct GPUFrameBuffer *overlay_only_fb; +} DefaultFramebufferList; + +typedef struct DefaultTextureList { + struct GPUTexture *color; + struct GPUTexture *color_overlay; + struct GPUTexture *depth; + struct GPUTexture *depth_in_front; +} DefaultTextureList; + +typedef struct DRWViewData DRWViewData; + +DRWViewData *DRW_view_data_create(ListBase *engine_types); +void DRW_view_data_free(DRWViewData *view_data); + +void DRW_view_data_default_lists_from_viewport(DRWViewData *view_data, + struct GPUViewport *viewport); +void DRW_view_data_texture_list_size_validate(DRWViewData *view_data, const int size[2]); +ViewportEngineData *DRW_view_data_engine_data_get_ensure(DRWViewData *view_data, + struct DrawEngineType *engine_type_); +void DRW_view_data_use_engine(DRWViewData *view_data, struct DrawEngineType *engine_type); +void DRW_view_data_reset(DRWViewData *view_data); +void DRW_view_data_free_unused(DRWViewData *view_data); +double *DRW_view_data_cache_time_get(DRWViewData *view_data); +DefaultFramebufferList *DRW_view_data_default_framebuffer_list_get(DRWViewData *view_data); +DefaultTextureList *DRW_view_data_default_texture_list_get(DRWViewData *view_data); + +typedef struct DRWEngineIterator { + int id, end; + ViewportEngineData **engines; +} DRWEngineIterator; + +/* Iterate over used engines of this view_data. */ +void DRW_view_data_enabled_engine_iter_begin(DRWEngineIterator *iterator, DRWViewData *view_data); +ViewportEngineData *DRW_view_data_enabled_engine_iter_step(DRWEngineIterator *iterator); + +#define DRW_ENABLED_ENGINE_ITER(view_data_, engine_, data_) \ + DRWEngineIterator iterator; \ + ViewportEngineData *data_; \ + struct DrawEngineType *engine_; \ + DRW_view_data_enabled_engine_iter_begin(&iterator, view_data_); \ + /* WATCH Comma operator trickery ahead! This tests engine_ == NULL. */ \ + while ((data_ = DRW_view_data_enabled_engine_iter_step(&iterator), \ + engine_ = (data_ != NULL) ? (struct DrawEngineType *)data_->engine_type->draw_engine : \ + NULL)) + +#ifdef __cplusplus +} +#endif |