Merge remote-tracking branch 'origin/blender-v2.90-release'
This commit is contained in:
commit
56af04d31f
|
@ -217,43 +217,29 @@ static void sync_smoke_volume(Scene *scene, BL::Object &b_ob, Mesh *mesh, float
|
|||
class BlenderVolumeLoader : public VDBImageLoader {
|
||||
public:
|
||||
BlenderVolumeLoader(BL::BlendData &b_data, BL::Volume &b_volume, const string &grid_name)
|
||||
: VDBImageLoader(grid_name), b_data(b_data), b_volume(b_volume), unload(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool load_metadata(ImageMetaData &metadata) override
|
||||
: VDBImageLoader(grid_name), b_volume(b_volume)
|
||||
{
|
||||
b_volume.grids.load(b_data.ptr.data);
|
||||
BL::VolumeGrid b_volume_grid = find_grid();
|
||||
|
||||
if (!b_volume_grid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unload = !b_volume_grid.is_loaded();
|
||||
|
||||
#ifdef WITH_OPENVDB
|
||||
Volume *volume = (Volume *)b_volume.ptr.data;
|
||||
VolumeGrid *volume_grid = (VolumeGrid *)b_volume_grid.ptr.data;
|
||||
grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid);
|
||||
#endif
|
||||
BL::Volume::grids_iterator b_grid_iter;
|
||||
for (b_volume.grids.begin(b_grid_iter); b_grid_iter != b_volume.grids.end(); ++b_grid_iter) {
|
||||
BL::VolumeGrid b_volume_grid(*b_grid_iter);
|
||||
if (b_volume_grid.name() == grid_name) {
|
||||
const bool unload = !b_volume_grid.is_loaded();
|
||||
|
||||
return VDBImageLoader::load_metadata(metadata);
|
||||
}
|
||||
Volume *volume = (Volume *)b_volume.ptr.data;
|
||||
VolumeGrid *volume_grid = (VolumeGrid *)b_volume_grid.ptr.data;
|
||||
grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid);
|
||||
|
||||
bool load_pixels(const ImageMetaData &metadata,
|
||||
void *pixels,
|
||||
const size_t pixel_size,
|
||||
const bool associate_alpha) override
|
||||
{
|
||||
b_volume.grids.load(b_data.ptr.data);
|
||||
BL::VolumeGrid b_volume_grid = find_grid();
|
||||
if (unload) {
|
||||
b_volume_grid.unload();
|
||||
}
|
||||
|
||||
if (!b_volume_grid) {
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return VDBImageLoader::load_pixels(metadata, pixels, pixel_size, associate_alpha);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool equals(const ImageLoader &other) const override
|
||||
|
@ -263,36 +249,7 @@ class BlenderVolumeLoader : public VDBImageLoader {
|
|||
return b_volume == other_loader.b_volume && grid_name == other_loader.grid_name;
|
||||
}
|
||||
|
||||
void cleanup() override
|
||||
{
|
||||
VDBImageLoader::cleanup();
|
||||
|
||||
BL::VolumeGrid b_volume_grid = find_grid();
|
||||
if (b_volume_grid && unload) {
|
||||
b_volume_grid.unload();
|
||||
}
|
||||
}
|
||||
|
||||
/* Find grid with matching name. Grid point not stored in the class since
|
||||
* grids may be unloaded before we load the pixels, for example for motion
|
||||
* blur where we move between frames. */
|
||||
BL::VolumeGrid find_grid()
|
||||
{
|
||||
#ifdef WITH_OPENVDB
|
||||
BL::Volume::grids_iterator b_grid_iter;
|
||||
for (b_volume.grids.begin(b_grid_iter); b_grid_iter != b_volume.grids.end(); ++b_grid_iter) {
|
||||
if (b_grid_iter->name() == grid_name) {
|
||||
return *b_grid_iter;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return BL::VolumeGrid(PointerRNA_NULL);
|
||||
}
|
||||
|
||||
BL::BlendData b_data;
|
||||
BL::Volume b_volume;
|
||||
bool unload;
|
||||
};
|
||||
|
||||
static void sync_volume_object(BL::BlendData &b_data, BL::Object &b_ob, Scene *scene, Mesh *mesh)
|
||||
|
@ -342,7 +299,7 @@ static void sync_volume_object(BL::BlendData &b_data, BL::Object &b_ob, Scene *s
|
|||
ImageParams params;
|
||||
params.frame = b_volume.grids.frame();
|
||||
|
||||
attr->data_voxel() = scene->image_manager->add_image(loader, params);
|
||||
attr->data_voxel() = scene->image_manager->add_image(loader, params, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -362,9 +362,11 @@ ImageHandle ImageManager::add_image(const string &filename,
|
|||
return handle;
|
||||
}
|
||||
|
||||
ImageHandle ImageManager::add_image(ImageLoader *loader, const ImageParams ¶ms)
|
||||
ImageHandle ImageManager::add_image(ImageLoader *loader,
|
||||
const ImageParams ¶ms,
|
||||
const bool builtin)
|
||||
{
|
||||
const int slot = add_image_slot(loader, params, true);
|
||||
const int slot = add_image_slot(loader, params, builtin);
|
||||
|
||||
ImageHandle handle;
|
||||
handle.tile_slots.push_back(slot);
|
||||
|
|
|
@ -169,7 +169,7 @@ class ImageManager {
|
|||
ImageHandle add_image(const string &filename,
|
||||
const ImageParams ¶ms,
|
||||
const vector<int> &tiles);
|
||||
ImageHandle add_image(ImageLoader *loader, const ImageParams ¶ms);
|
||||
ImageHandle add_image(ImageLoader *loader, const ImageParams ¶ms, const bool builtin = true);
|
||||
|
||||
void device_update(Device *device, Scene *scene, Progress &progress);
|
||||
void device_update_slot(Device *device, Scene *scene, int slot, Progress *progress);
|
||||
|
|
|
@ -218,7 +218,9 @@ static struct VolumeFileCache {
|
|||
cache.erase(entry);
|
||||
}
|
||||
else if (entry.num_tree_users == 0) {
|
||||
entry.grid->clear();
|
||||
/* Note we replace the grid rather than clearing, so that if there is
|
||||
* any other shared pointer to the grid it will keep the tree. */
|
||||
entry.grid = entry.grid->copyGridWithNewTree();
|
||||
entry.is_loaded = false;
|
||||
}
|
||||
}
|
||||
|
@ -239,15 +241,14 @@ struct VolumeGrid {
|
|||
VolumeGrid(const VolumeFileCache::Entry &template_entry) : entry(NULL), is_loaded(false)
|
||||
{
|
||||
entry = GLOBAL_CACHE.add_metadata_user(template_entry);
|
||||
vdb = entry->grid;
|
||||
}
|
||||
|
||||
VolumeGrid(const openvdb::GridBase::Ptr &vdb) : vdb(vdb), entry(NULL), is_loaded(true)
|
||||
VolumeGrid(const openvdb::GridBase::Ptr &grid) : entry(NULL), local_grid(grid), is_loaded(true)
|
||||
{
|
||||
}
|
||||
|
||||
VolumeGrid(const VolumeGrid &other)
|
||||
: vdb(other.vdb), entry(other.entry), is_loaded(other.is_loaded)
|
||||
: entry(other.entry), local_grid(other.local_grid), is_loaded(other.is_loaded)
|
||||
{
|
||||
if (entry) {
|
||||
GLOBAL_CACHE.copy_user(*entry, is_loaded);
|
||||
|
@ -330,7 +331,7 @@ struct VolumeGrid {
|
|||
void clear_reference(const char *UNUSED(volume_name))
|
||||
{
|
||||
/* Clear any reference to a grid in the file cache. */
|
||||
vdb = vdb->copyGridWithNewTree();
|
||||
local_grid = grid()->copyGridWithNewTree();
|
||||
if (entry) {
|
||||
GLOBAL_CACHE.remove_user(*entry, is_loaded);
|
||||
entry = NULL;
|
||||
|
@ -344,7 +345,7 @@ struct VolumeGrid {
|
|||
* file cache. Load file grid into memory first if needed. */
|
||||
load(volume_name, filepath);
|
||||
/* TODO: avoid deep copy if we are the only user. */
|
||||
vdb = vdb->deepCopyGrid();
|
||||
local_grid = grid()->deepCopyGrid();
|
||||
if (entry) {
|
||||
GLOBAL_CACHE.remove_user(*entry, is_loaded);
|
||||
entry = NULL;
|
||||
|
@ -356,7 +357,7 @@ struct VolumeGrid {
|
|||
{
|
||||
/* Don't use vdb.getName() since it copies the string, we want a pointer to the
|
||||
* original so it doesn't get freed out of scope. */
|
||||
openvdb::StringMetadata::ConstPtr name_meta = vdb->getMetadata<openvdb::StringMetadata>(
|
||||
openvdb::StringMetadata::ConstPtr name_meta = grid()->getMetadata<openvdb::StringMetadata>(
|
||||
openvdb::GridBase::META_GRID_NAME);
|
||||
return (name_meta) ? name_meta->value().c_str() : "";
|
||||
}
|
||||
|
@ -371,10 +372,22 @@ struct VolumeGrid {
|
|||
}
|
||||
}
|
||||
|
||||
/* OpenVDB grid. */
|
||||
openvdb::GridBase::Ptr vdb;
|
||||
/* File cache entry. */
|
||||
const bool grid_is_loaded() const
|
||||
{
|
||||
return is_loaded;
|
||||
}
|
||||
|
||||
const openvdb::GridBase::Ptr &grid() const
|
||||
{
|
||||
return (entry) ? entry->grid : local_grid;
|
||||
}
|
||||
|
||||
protected:
|
||||
/* File cache entry when grid comes directly from a file and may be shared
|
||||
* with other volume datablocks. */
|
||||
VolumeFileCache::Entry *entry;
|
||||
/* OpenVDB grid if it's not shared through the file cache. */
|
||||
openvdb::GridBase::Ptr local_grid;
|
||||
/* Indicates if the tree has been loaded for this grid. Note that vdb.tree()
|
||||
* may actually be loaded by another user while this is false. But only after
|
||||
* calling load() and is_loaded changes to true is it safe to access. */
|
||||
|
@ -1047,7 +1060,7 @@ void BKE_volume_grid_unload(const Volume *volume, VolumeGrid *grid)
|
|||
bool BKE_volume_grid_is_loaded(const VolumeGrid *grid)
|
||||
{
|
||||
#ifdef WITH_OPENVDB
|
||||
return grid->is_loaded;
|
||||
return grid->grid_is_loaded();
|
||||
#else
|
||||
UNUSED_VARS(grid);
|
||||
return true;
|
||||
|
@ -1069,7 +1082,7 @@ const char *BKE_volume_grid_name(const VolumeGrid *volume_grid)
|
|||
VolumeGridType BKE_volume_grid_type(const VolumeGrid *volume_grid)
|
||||
{
|
||||
#ifdef WITH_OPENVDB
|
||||
const openvdb::GridBase::Ptr &grid = volume_grid->vdb;
|
||||
const openvdb::GridBase::Ptr &grid = volume_grid->grid();
|
||||
|
||||
if (grid->isType<openvdb::FloatGrid>()) {
|
||||
return VOLUME_GRID_FLOAT;
|
||||
|
@ -1138,7 +1151,7 @@ int BKE_volume_grid_channels(const VolumeGrid *grid)
|
|||
void BKE_volume_grid_transform_matrix(const VolumeGrid *volume_grid, float mat[4][4])
|
||||
{
|
||||
#ifdef WITH_OPENVDB
|
||||
const openvdb::GridBase::Ptr &grid = volume_grid->vdb;
|
||||
const openvdb::GridBase::Ptr &grid = volume_grid->grid();
|
||||
const openvdb::math::Transform &transform = grid->transform();
|
||||
|
||||
/* Perspective not supported for now, getAffineMap() will leave out the
|
||||
|
@ -1162,7 +1175,7 @@ bool BKE_volume_grid_bounds(const VolumeGrid *volume_grid, float min[3], float m
|
|||
{
|
||||
#ifdef WITH_OPENVDB
|
||||
/* TODO: we can get this from grid metadata in some cases? */
|
||||
const openvdb::GridBase::Ptr &grid = volume_grid->vdb;
|
||||
const openvdb::GridBase::Ptr &grid = volume_grid->grid();
|
||||
BLI_assert(BKE_volume_grid_is_loaded(volume_grid));
|
||||
|
||||
openvdb::CoordBBox coordbbox;
|
||||
|
@ -1287,14 +1300,14 @@ void BKE_volume_grid_remove(Volume *volume, VolumeGrid *grid)
|
|||
#ifdef WITH_OPENVDB
|
||||
openvdb::GridBase::ConstPtr BKE_volume_grid_openvdb_for_metadata(const VolumeGrid *grid)
|
||||
{
|
||||
return grid->vdb;
|
||||
return grid->grid();
|
||||
}
|
||||
|
||||
openvdb::GridBase::ConstPtr BKE_volume_grid_openvdb_for_read(const Volume *volume,
|
||||
VolumeGrid *grid)
|
||||
{
|
||||
BKE_volume_grid_load(volume, grid);
|
||||
return grid->vdb;
|
||||
return grid->grid();
|
||||
}
|
||||
|
||||
openvdb::GridBase::Ptr BKE_volume_grid_openvdb_for_write(const Volume *volume,
|
||||
|
@ -1310,6 +1323,6 @@ openvdb::GridBase::Ptr BKE_volume_grid_openvdb_for_write(const Volume *volume,
|
|||
grid->duplicate_reference(volume_name, grids.filepath);
|
||||
}
|
||||
|
||||
return grid->vdb;
|
||||
return grid->grid();
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -23,6 +23,7 @@ set(INC
|
|||
../../blentranslation
|
||||
../../bmesh
|
||||
../../depsgraph
|
||||
../../draw
|
||||
../../gpu
|
||||
../../imbuf
|
||||
../../makesdna
|
||||
|
|
|
@ -75,11 +75,10 @@
|
|||
#include "GPU_batch_presets.h"
|
||||
#include "GPU_framebuffer.h"
|
||||
#include "GPU_viewport.h"
|
||||
#include "image_intern.h"
|
||||
|
||||
/* TODO(fclem) remove bad level calls */
|
||||
#include "../draw/DRW_engine.h"
|
||||
#include "wm_draw.h"
|
||||
#include "DRW_engine_types.h"
|
||||
|
||||
#include "image_intern.h"
|
||||
|
||||
/**************************** common state *****************************/
|
||||
|
||||
|
@ -643,17 +642,18 @@ static void image_main_region_draw(const bContext *C, ARegion *region)
|
|||
// View2DScrollers *scrollers;
|
||||
float col[3];
|
||||
|
||||
/* XXX This is in order to draw UI batches with the DRW
|
||||
* old context since we now use it for drawing the entire area. */
|
||||
gpu_batch_presets_reset();
|
||||
GPU_batch_presets_reset();
|
||||
GPUViewport *viewport = WM_draw_region_get_viewport(region);
|
||||
GPUFrameBuffer *framebuffer_default, *framebuffer_overlay;
|
||||
|
||||
GPUViewport *viewport = region->draw_buffer->viewport;
|
||||
DefaultFramebufferList *fbl = GPU_viewport_framebuffer_list_get(viewport);
|
||||
GPU_framebuffer_bind(fbl->default_fb);
|
||||
framebuffer_default = GPU_viewport_framebuffer_default_get(viewport);
|
||||
framebuffer_overlay = GPU_viewport_framebuffer_overlay_get(viewport);
|
||||
|
||||
GPU_framebuffer_bind(framebuffer_default);
|
||||
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
GPU_clear(GPU_COLOR_BIT);
|
||||
|
||||
GPU_framebuffer_bind(fbl->overlay_fb);
|
||||
GPU_framebuffer_bind(framebuffer_overlay);
|
||||
|
||||
/* XXX not supported yet, disabling for now */
|
||||
scene->r.scemode &= ~R_COMP_CROP;
|
||||
|
|
|
@ -50,6 +50,8 @@ bool gpu_batch_presets_unregister(struct GPUBatch *preset_batch);
|
|||
void gpu_batch_presets_reset(void);
|
||||
void gpu_batch_presets_exit(void);
|
||||
|
||||
void GPU_batch_presets_reset(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -41,6 +41,8 @@ extern "C" {
|
|||
|
||||
typedef struct GPUViewport GPUViewport;
|
||||
|
||||
struct GPUFrameBuffer;
|
||||
|
||||
/* Contains memory pools information */
|
||||
typedef struct ViewportMemoryPool {
|
||||
struct BLI_memblock *commands;
|
||||
|
@ -151,6 +153,9 @@ GPUTexture *GPU_viewport_texture_pool_query(
|
|||
bool GPU_viewport_engines_data_validate(GPUViewport *viewport, void **engine_handle_array);
|
||||
void GPU_viewport_cache_release(GPUViewport *viewport);
|
||||
|
||||
struct GPUFrameBuffer *GPU_viewport_framebuffer_default_get(GPUViewport *viewport);
|
||||
struct GPUFrameBuffer *GPU_viewport_framebuffer_overlay_get(GPUViewport *viewport);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -406,4 +406,17 @@ void gpu_batch_presets_exit(void)
|
|||
BLI_mutex_end(&g_presets_3d.mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function only needs to be accessed externally because
|
||||
* we are drawing UI batches with the DRW old context.
|
||||
*
|
||||
* And now we use it for drawing the entire area.
|
||||
*
|
||||
* XXX (Clément) - to cleanup in the upcoming 2.91 refactor.
|
||||
**/
|
||||
void GPU_batch_presets_reset()
|
||||
{
|
||||
gpu_batch_presets_reset();
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -1035,3 +1035,15 @@ void GPU_viewport_free(GPUViewport *viewport)
|
|||
|
||||
MEM_freeN(viewport);
|
||||
}
|
||||
|
||||
GPUFrameBuffer *GPU_viewport_framebuffer_default_get(GPUViewport *viewport)
|
||||
{
|
||||
DefaultFramebufferList *fbl = GPU_viewport_framebuffer_list_get(viewport);
|
||||
return fbl->default_fb;
|
||||
}
|
||||
|
||||
GPUFrameBuffer *GPU_viewport_framebuffer_overlay_get(GPUViewport *viewport)
|
||||
{
|
||||
DefaultFramebufferList *fbl = GPU_viewport_framebuffer_list_get(viewport);
|
||||
return fbl->overlay_fb;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue