forked from bartvdbraak/blender
34f94a02f3
Rendering directly to a resource using OpenGL interop and Hgi doesn't work in Houdini, since it never uses the resulting resource (it does not call `HdRenderBuffer::GetResource`). But since doing that simultaneously disables mapping (`HdRenderBuffer::Map` is not implemented then), nothing was displayed. To fix this, keep track of whether a Hydra viewport does support displaying a Hgi resource directly, by checking whether `HdRenderBuffer::GetResource` is ever called and only enable use of OpenGL interop if that is the case. Differential Revision: https://developer.blender.org/D15090
90 lines
1.9 KiB
C++
90 lines
1.9 KiB
C++
/* SPDX-License-Identifier: Apache-2.0
|
|
* Copyright 2022 NVIDIA Corporation
|
|
* Copyright 2022 Blender Foundation */
|
|
|
|
#pragma once
|
|
|
|
#include "hydra/config.h"
|
|
|
|
#include <pxr/imaging/hd/renderBuffer.h>
|
|
|
|
HDCYCLES_NAMESPACE_OPEN_SCOPE
|
|
|
|
class HdCyclesRenderBuffer final : public PXR_NS::HdRenderBuffer {
|
|
public:
|
|
HdCyclesRenderBuffer(const PXR_NS::SdfPath &bprimId);
|
|
~HdCyclesRenderBuffer() override;
|
|
|
|
void Finalize(PXR_NS::HdRenderParam *renderParam) override;
|
|
|
|
bool Allocate(const PXR_NS::GfVec3i &dimensions,
|
|
PXR_NS::HdFormat format,
|
|
bool multiSampled) override;
|
|
|
|
unsigned int GetWidth() const override
|
|
{
|
|
return _width;
|
|
}
|
|
|
|
unsigned int GetHeight() const override
|
|
{
|
|
return _height;
|
|
}
|
|
|
|
unsigned int GetDepth() const override
|
|
{
|
|
return 1u;
|
|
}
|
|
|
|
PXR_NS::HdFormat GetFormat() const override
|
|
{
|
|
return _format;
|
|
}
|
|
|
|
bool IsMultiSampled() const override
|
|
{
|
|
return false;
|
|
}
|
|
|
|
void *Map() override;
|
|
|
|
void Unmap() override;
|
|
|
|
bool IsMapped() const override;
|
|
|
|
void Resolve() override;
|
|
|
|
bool IsConverged() const override;
|
|
|
|
void SetConverged(bool converged);
|
|
|
|
bool IsResourceUsed() const;
|
|
|
|
PXR_NS::VtValue GetResource(bool multiSampled = false) const override;
|
|
|
|
void SetResource(const PXR_NS::VtValue &resource);
|
|
|
|
void WritePixels(const float *pixels,
|
|
const PXR_NS::GfVec2i &offset,
|
|
const PXR_NS::GfVec2i &dims,
|
|
int channels,
|
|
bool isId = false);
|
|
|
|
private:
|
|
void _Deallocate() override;
|
|
|
|
unsigned int _width = 0u;
|
|
unsigned int _height = 0u;
|
|
PXR_NS::HdFormat _format = PXR_NS::HdFormatInvalid;
|
|
size_t _dataSize = 0;
|
|
|
|
std::vector<uint8_t> _data;
|
|
PXR_NS::VtValue _resource;
|
|
mutable std::atomic_bool _resourceUsed = false;
|
|
|
|
std::atomic_int _mapped = 0;
|
|
std::atomic_bool _converged = false;
|
|
};
|
|
|
|
HDCYCLES_NAMESPACE_CLOSE_SCOPE
|