add usd-21-05-win64_py37
This commit is contained in:
1 parent
41d23e71ba
commit
66bc054336
15675 files changed
+3061008
No files matched your search
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_CAMERA_UTIL_API_H
|
||||
#define PXR_IMAGING_CAMERA_UTIL_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define CAMERAUTIL_API
|
||||
# define CAMERAUTIL_API_TEMPLATE_CLASS(...)
|
||||
# define CAMERAUTIL_API_TEMPLATE_STRUCT(...)
|
||||
# define CAMERAUTIL_LOCAL
|
||||
#else
|
||||
# if defined(CAMERAUTIL_EXPORTS)
|
||||
# define CAMERAUTIL_API ARCH_EXPORT
|
||||
# define CAMERAUTIL_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define CAMERAUTIL_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define CAMERAUTIL_API ARCH_IMPORT
|
||||
# define CAMERAUTIL_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define CAMERAUTIL_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define CAMERAUTIL_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif // PXR_IMAGING_CAMERA_UTIL_API_H
|
||||
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_CAMERA_UTIL_CONFORM_WINDOW_H
|
||||
#define PXR_IMAGING_CAMERA_UTIL_CONFORM_WINDOW_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/cameraUtil/api.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class GfVec2d;
|
||||
class GfVec4d;
|
||||
class GfMatrix4d;
|
||||
class GfRange2d;
|
||||
class GfCamera;
|
||||
class GfFrustum;
|
||||
|
||||
/// \enum CameraUtilConformWindowPolicy
|
||||
///
|
||||
/// Policy of how to conform a window to the given aspect ratio.
|
||||
/// An ASCII-art explanation is given in the corresponding .cpp file.
|
||||
///
|
||||
enum CameraUtilConformWindowPolicy {
|
||||
/// Modify width
|
||||
CameraUtilMatchVertically,
|
||||
/// Modify height
|
||||
CameraUtilMatchHorizontally,
|
||||
/// Increase width or height
|
||||
CameraUtilFit,
|
||||
/// Decrease width or height
|
||||
CameraUtilCrop,
|
||||
/// Leave unchanged (This can result in stretching/shrinking if not pre-fit)
|
||||
CameraUtilDontConform
|
||||
};
|
||||
|
||||
/// Returns a window with aspect ratio \p targetAspect by applying
|
||||
/// \p policy to \p window where \p window is encoded as GfRange2d.
|
||||
CAMERAUTIL_API
|
||||
GfRange2d
|
||||
CameraUtilConformedWindow(
|
||||
const GfRange2d &window,
|
||||
CameraUtilConformWindowPolicy policy, double targetAspect);
|
||||
|
||||
/// Returns a window with aspect ratio \p targetAspect by applying
|
||||
/// \p policy to \p window where \p window is encoded as vector
|
||||
/// (left, right, bottom, top) similarly to RenderMan's RiScreenWindow.
|
||||
CAMERAUTIL_API
|
||||
GfVec4d
|
||||
CameraUtilConformedWindow(
|
||||
const GfVec4d &window,
|
||||
CameraUtilConformWindowPolicy policy, double targetAspect);
|
||||
|
||||
/// Returns a window with aspect ratio \p targetAspect by applying
|
||||
/// \p policy to \p window where \p window is encoded as vector
|
||||
/// (width, height).
|
||||
CAMERAUTIL_API
|
||||
GfVec2d
|
||||
CameraUtilConformedWindow(
|
||||
const GfVec2d &window,
|
||||
CameraUtilConformWindowPolicy policy, double targetAspect);
|
||||
|
||||
/// Conforms the given \p projectionMatrix to have aspect ratio \p targetAspect
|
||||
/// by applying \p policy.
|
||||
///
|
||||
/// Note that this function also supports mirroring about the x- or y-axis of
|
||||
/// the image corresponding to flipping all signs in the second, respectively,
|
||||
/// third column of the projection matrix. In other words, we get the same
|
||||
/// result whether we flip the signs in the matrix and then give it to this
|
||||
/// function or call this function first and flip the signs of the resulting
|
||||
/// matrix.
|
||||
CAMERAUTIL_API
|
||||
GfMatrix4d
|
||||
CameraUtilConformedWindow(
|
||||
const GfMatrix4d &projectionMatrix,
|
||||
CameraUtilConformWindowPolicy policy, double targetAspect);
|
||||
|
||||
/// Conforms the given \p camera to have aspect ratio \p targetAspect
|
||||
/// by applying \p policy.
|
||||
CAMERAUTIL_API
|
||||
void
|
||||
CameraUtilConformWindow(
|
||||
GfCamera *camera,
|
||||
CameraUtilConformWindowPolicy policy, double targetAspect);
|
||||
|
||||
/// Conforms the given \p frustum to have aspect ratio \p targetAspect
|
||||
/// by applying \p policy.
|
||||
CAMERAUTIL_API
|
||||
void
|
||||
CameraUtilConformWindow(
|
||||
GfFrustum *frustum,
|
||||
CameraUtilConformWindowPolicy policy, double targetAspect);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,138 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_CAMERA_UTIL_FRAMING_H
|
||||
#define PXR_IMAGING_CAMERA_UTIL_FRAMING_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/cameraUtil/api.h"
|
||||
|
||||
#include "pxr/imaging/cameraUtil/conformWindow.h"
|
||||
|
||||
#include "pxr/base/gf/rect2i.h"
|
||||
#include "pxr/base/gf/range2f.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class CameraUtilFraming
|
||||
///
|
||||
/// Framing information. That is information determining how the filmback
|
||||
/// plane of a camera maps to the pixels of the rendered image (displayWindow
|
||||
/// together with pixelAspectRatio and window policy) and what pixels of the
|
||||
/// image will be filled by the renderer (dataWindow).
|
||||
///
|
||||
/// The concepts of displayWindow and dataWindow are similar to the ones in
|
||||
/// OpenEXR, including that the x- and y-axis of the coordinate system point
|
||||
/// left and down, respectively.
|
||||
///
|
||||
/// In fact, these windows mean the same here and in OpenEXR if the
|
||||
/// displayWindow has the same aspect ratio (when accounting for the
|
||||
/// pixelAspectRatio) as the filmback plane of the camera has (that is the
|
||||
/// ratio of the horizontalAperture to verticalAperture of, e.g., Usd's Camera
|
||||
/// or GfCamera).
|
||||
///
|
||||
/// In particular, overscan can be achieved by making the dataWindow larger
|
||||
/// than the displayWindow.
|
||||
///
|
||||
/// If the aspect ratios differ, a window policy is applied to the
|
||||
/// displayWindow to determine how the pixels correspond to the
|
||||
/// filmback plane. One such window policy is to take the largest
|
||||
/// rect that fits (centered) into the displayWindow and has the
|
||||
/// camera's aspect ratio. For example, if the displayWindow and dataWindow
|
||||
/// are the same and both have an aspect ratio smaller than the camera, the
|
||||
/// image is created by enlarging the camera frustum slightly in the bottom
|
||||
/// and top direction.
|
||||
///
|
||||
/// When using the AOVs, the render buffer size is determined
|
||||
/// independently from the framing info. However, the dataWindow is
|
||||
/// supposed to be contained in the render buffer rect (in particular,
|
||||
/// the dataWindow cannot contain pixels withs negative coordinates -
|
||||
/// this restriction does not apply if, e.g., hdPrman circumvents AOVs
|
||||
/// and writes directly to EXR). In other words, unlike in OpenEXR,
|
||||
/// the rect of pixels for which we allocate storage can differ from
|
||||
/// the rect the renderer fills with data (dataWindow).
|
||||
///
|
||||
/// For example, an application can set the render buffer size to match
|
||||
/// the widget size but use a dataWindow and displayWindow that only fills
|
||||
/// the render buffer horizontally to have slates at the top and bottom.
|
||||
///
|
||||
class CameraUtilFraming final
|
||||
{
|
||||
public:
|
||||
/// Creates an invalid framing, i.e., with empty display and data
|
||||
/// window.
|
||||
CAMERAUTIL_API
|
||||
CameraUtilFraming();
|
||||
|
||||
/// Creates a framing with given display and data window and pixel
|
||||
/// aspect ratio.
|
||||
///
|
||||
CAMERAUTIL_API
|
||||
CameraUtilFraming(
|
||||
const GfRange2f &displayWindow,
|
||||
const GfRect2i &dataWindow,
|
||||
float pixelAspectRatio = 1.0);
|
||||
|
||||
/// Creates a framing with equal display and data window (and
|
||||
/// assuming square pixels).
|
||||
///
|
||||
CAMERAUTIL_API
|
||||
explicit CameraUtilFraming(
|
||||
const GfRect2i &dataWindow);
|
||||
|
||||
/// Is display and data window non-empty.
|
||||
CAMERAUTIL_API
|
||||
bool IsValid() const;
|
||||
|
||||
CAMERAUTIL_API
|
||||
bool operator==(const CameraUtilFraming& other) const;
|
||||
|
||||
CAMERAUTIL_API
|
||||
bool operator!=(const CameraUtilFraming& other) const;
|
||||
|
||||
/// Given the projectionMatrix computed from a camera, applies
|
||||
/// the framing. To obtain a correct result, a rasterizer needs
|
||||
/// to use the resulting projection matrix and set the viewport
|
||||
/// to the data window.
|
||||
///
|
||||
CAMERAUTIL_API
|
||||
GfMatrix4d ApplyToProjectionMatrix(
|
||||
const GfMatrix4d &projectionMatrix,
|
||||
CameraUtilConformWindowPolicy windowPolicy) const;
|
||||
|
||||
/// The display window. It will be conformed to the camera's
|
||||
/// aspect ratio and then mapped to the filmback plane.
|
||||
GfRange2f displayWindow;
|
||||
|
||||
/// The data window. That is the rect of pixels that the renderer
|
||||
/// will fill.
|
||||
GfRect2i dataWindow;
|
||||
|
||||
/// The ratio of the width to the height of a pixel - same as
|
||||
/// OpenEXR.
|
||||
float pixelAspectRatio;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_CAMERA_UTIL_SCREEN_WINDOW_PARAMETERS_H
|
||||
#define PXR_IMAGING_CAMERA_UTIL_SCREEN_WINDOW_PARAMETERS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/cameraUtil/api.h"
|
||||
#include "pxr/base/gf/camera.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class CameraUtilScreenWindowParameters
|
||||
///
|
||||
/// Given a camera object, compute parameters suitable for setting up
|
||||
/// RenderMan.
|
||||
///
|
||||
class CameraUtilScreenWindowParameters
|
||||
{
|
||||
public:
|
||||
/// Constructs screenwindow parameter. The optional \p fitDirection
|
||||
/// indicates in which direction the screenwindow will have length 2.
|
||||
CAMERAUTIL_API
|
||||
CameraUtilScreenWindowParameters(const GfCamera &camera,
|
||||
GfCamera::FOVDirection fitDirection =
|
||||
GfCamera::FOVHorizontal);
|
||||
|
||||
/// The vector (left, right, bottom, top) defining the rectangle in the
|
||||
/// image plane.
|
||||
/// Give these parameters to RiScreenWindow.
|
||||
const GfVec4d & GetScreenWindow() const { return _screenWindow; }
|
||||
|
||||
/// The field of view. More precisely, the full angle perspective field
|
||||
/// of view (in degrees) between screen space coordinates (-1,0) and
|
||||
/// (1,0).
|
||||
/// Give these parameters to RiProjection as parameter after
|
||||
/// "perspective".
|
||||
double GetFieldOfView() const { return _fieldOfView; }
|
||||
|
||||
/// Returns the inverse of the transform for a camera that is y-Up
|
||||
/// and z-facing (vs the OpenGL camera that is (-z)-facing).
|
||||
/// Write this transform with RiConcatTransform before
|
||||
/// RiWorldBegin.
|
||||
const GfMatrix4d & GetZFacingViewMatrix() const {
|
||||
return _zFacingViewMatrix;
|
||||
}
|
||||
|
||||
private:
|
||||
GfVec4d _screenWindow;
|
||||
double _fieldOfView;
|
||||
GfMatrix4d _zFacingViewMatrix;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_CAMERA_UTIL_SCREEN_WINDOW_PARAMETERS_H
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GARCH_API_H
|
||||
#define PXR_IMAGING_GARCH_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define GARCH_API
|
||||
# define GARCH_API_TEMPLATE_CLASS(...)
|
||||
# define GARCH_API_TEMPLATE_STRUCT(...)
|
||||
# define GARCH_LOCAL
|
||||
#else
|
||||
# if defined(GARCH_EXPORTS)
|
||||
# define GARCH_API ARCH_EXPORT
|
||||
# define GARCH_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define GARCH_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define GARCH_API ARCH_IMPORT
|
||||
# define GARCH_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define GARCH_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define GARCH_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GARCH_GL_H
|
||||
#define PXR_IMAGING_GARCH_GL_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/base/arch/defines.h"
|
||||
|
||||
#include "pxr/imaging/garch/glApi.h"
|
||||
|
||||
#endif // PXR_IMAGING_GARCH_GL_H
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GARCH_GL_DEBUG_WINDOW_H
|
||||
#define PXR_IMAGING_GARCH_GL_DEBUG_WINDOW_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/garch/api.h"
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class Garch_GLPlatformDebugWindow;
|
||||
|
||||
/// \class GarchGLDebugWindow
|
||||
///
|
||||
/// Platform specific minimum GL widget for unit tests.
|
||||
///
|
||||
class GarchGLDebugWindow {
|
||||
public:
|
||||
GARCH_API
|
||||
GarchGLDebugWindow(const char *title, int width, int height);
|
||||
GARCH_API
|
||||
virtual ~GarchGLDebugWindow();
|
||||
|
||||
GARCH_API
|
||||
void Init();
|
||||
GARCH_API
|
||||
void Run();
|
||||
GARCH_API
|
||||
void ExitApp();
|
||||
|
||||
int GetWidth() const { return _width; }
|
||||
int GetHeight() const { return _height; }
|
||||
|
||||
enum Buttons {
|
||||
MyButton1 = 0,
|
||||
MyButton2 = 1,
|
||||
MyButton3 = 2
|
||||
};
|
||||
enum ModifierKeys {
|
||||
NoModifiers = 0,
|
||||
Shift = 1,
|
||||
Alt = 2,
|
||||
Ctrl = 4
|
||||
};
|
||||
|
||||
GARCH_API
|
||||
virtual void OnInitializeGL();
|
||||
GARCH_API
|
||||
virtual void OnUninitializeGL();
|
||||
GARCH_API
|
||||
virtual void OnResize(int w, int h);
|
||||
GARCH_API
|
||||
virtual void OnIdle();
|
||||
GARCH_API
|
||||
virtual void OnPaintGL();
|
||||
GARCH_API
|
||||
virtual void OnKeyRelease(int key);
|
||||
GARCH_API
|
||||
virtual void OnMousePress(int button, int x, int y, int modKeys);
|
||||
GARCH_API
|
||||
virtual void OnMouseRelease(int button, int x, int y, int modKeys);
|
||||
GARCH_API
|
||||
virtual void OnMouseMove(int x, int y, int modKeys);
|
||||
|
||||
private:
|
||||
Garch_GLPlatformDebugWindow *_private;
|
||||
std::string _title;
|
||||
int _width, _height;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_GARCH_GL_DEBUG_WINDOW_H
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GARCH_GL_PLATFORM_CONTEXT_H
|
||||
#define PXR_IMAGING_GARCH_GL_PLATFORM_CONTEXT_H
|
||||
|
||||
/// \file garch/glPlatformContext.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/garch/api.h"
|
||||
#include "pxr/base/arch/defines.h"
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
|
||||
#if defined(ARCH_OS_LINUX)
|
||||
|
||||
#include "pxr/imaging/garch/glPlatformContextGLX.h"
|
||||
|
||||
#elif defined(ARCH_OS_DARWIN)
|
||||
|
||||
#include "pxr/imaging/garch/glPlatformContextDarwin.h"
|
||||
|
||||
#elif defined(ARCH_OS_WINDOWS)
|
||||
|
||||
#include "pxr/imaging/garch/glPlatformContextWindows.h"
|
||||
|
||||
#else
|
||||
|
||||
#error "Unknown platform"
|
||||
|
||||
#endif
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
GARCH_API GarchGLPlatformContextState GarchGetNullGLPlatformContextState();
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<PXR_NS::GarchGLPlatformContextState>
|
||||
{
|
||||
inline size_t operator()(const PXR_NS::GarchGLPlatformContextState& x) const
|
||||
{
|
||||
return x.GetHash();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // PXR_IMAGING_GARCH_GL_PLATFORM_CONTEXT_H
|
||||
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GARCH_GL_PLATFORM_CONTEXT_WINDOWS_H
|
||||
#define PXR_IMAGING_GARCH_GL_PLATFORM_CONTEXT_WINDOWS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/garch/api.h"
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class GarchWGLContextState {
|
||||
public:
|
||||
/// Construct with the current state.
|
||||
GARCH_API
|
||||
GarchWGLContextState();
|
||||
|
||||
enum class NullState { nullstate };
|
||||
|
||||
/// Construct with the null state.
|
||||
GARCH_API
|
||||
GarchWGLContextState(NullState);
|
||||
|
||||
/// Compare for equality.
|
||||
GARCH_API
|
||||
bool operator==(const GarchWGLContextState& rhs) const;
|
||||
|
||||
/// Returns a hash value for the state.
|
||||
GARCH_API
|
||||
size_t GetHash() const;
|
||||
|
||||
/// Returns \c true if the context state is valid.
|
||||
GARCH_API
|
||||
bool IsValid() const;
|
||||
|
||||
/// Make the context current.
|
||||
GARCH_API
|
||||
void MakeCurrent();
|
||||
|
||||
/// Make no context current.
|
||||
GARCH_API
|
||||
static void DoneCurrent();
|
||||
|
||||
private:
|
||||
class _Detail;
|
||||
std::shared_ptr<_Detail> _detail;
|
||||
};
|
||||
|
||||
// Hide the platform specific type name behind a common name.
|
||||
typedef GarchWGLContextState GarchGLPlatformContextState;
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_GARCH_GL_PLATFORM_CONTEXT_WINDOWS_H
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GARCH_GL_PLATFORM_DEBUG_CONTEXT_H
|
||||
#define PXR_IMAGING_GARCH_GL_PLATFORM_DEBUG_CONTEXT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/garch/api.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class GarchGLPlatformDebugContextPrivate;
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(GarchGLPlatformDebugContext);
|
||||
|
||||
/// \class GarchGLPlatformDebugContext
|
||||
///
|
||||
/// Platform specific context (e.g. X11/GLX) which supports debug output.
|
||||
///
|
||||
class GarchGLPlatformDebugContext : public TfRefBase, public TfWeakBase {
|
||||
public:
|
||||
|
||||
static GarchGLPlatformDebugContextRefPtr
|
||||
New(int majorVersion, int minorVersion, bool coreProfile,
|
||||
bool directRenderering) {
|
||||
return TfCreateRefPtr(
|
||||
new GarchGLPlatformDebugContext(
|
||||
majorVersion, minorVersion, coreProfile, directRenderering));
|
||||
}
|
||||
|
||||
virtual ~GarchGLPlatformDebugContext();
|
||||
|
||||
GARCH_API
|
||||
static bool IsEnabledDebugOutput();
|
||||
|
||||
GARCH_API
|
||||
static bool IsEnabledCoreProfile();
|
||||
|
||||
GARCH_API
|
||||
void makeCurrent();
|
||||
|
||||
GARCH_API
|
||||
void *chooseMacVisual();
|
||||
|
||||
public:
|
||||
std::unique_ptr<GarchGLPlatformDebugContextPrivate> _private;
|
||||
bool _coreProfile;
|
||||
|
||||
protected:
|
||||
GARCH_API
|
||||
GarchGLPlatformDebugContext(int majorVersion,
|
||||
int minorVersion,
|
||||
bool coreProfile,
|
||||
bool directRenderering);
|
||||
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_GARCH_GL_PLATFORM_DEBUG_CONTEXT_H
|
||||
@@ -0,0 +1,290 @@
|
||||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included
|
||||
** in all copies or substantial portions of the Materials.
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||
# define KHRONOS_STATIC 1
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(KHRONOS_STATIC)
|
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */
|
||||
# define KHRONOS_APICALL
|
||||
#elif defined(_WIN32)
|
||||
# define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined (__SYMBIAN32__)
|
||||
# define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
# define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(KHRONOS_STATIC)
|
||||
/* Win32 but not WinCE */
|
||||
# define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
# define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined (__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__VMS ) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef _WIN64
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_API_H
|
||||
#define PXR_IMAGING_GLF_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define GLF_API
|
||||
# define GLF_API_TEMPLATE_CLASS(...)
|
||||
# define GLF_API_TEMPLATE_STRUCT(...)
|
||||
# define GLF_LOCAL
|
||||
#else
|
||||
# if defined(GLF_EXPORTS)
|
||||
# define GLF_API ARCH_EXPORT
|
||||
# define GLF_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define GLF_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define GLF_API ARCH_IMPORT
|
||||
# define GLF_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define GLF_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define GLF_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif // PXR_IMAGING_GLF_API_H
|
||||
@@ -0,0 +1,139 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_BINDING_MAP_H
|
||||
#define PXR_IMAGING_GLF_BINDING_MAP_H
|
||||
|
||||
/// \file glf/bindingMap.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/imaging/garch/glApi.h"
|
||||
#include "pxr/base/tf/refBase.h"
|
||||
#include "pxr/base/tf/stringUtils.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class GlfBindingMap : public TfRefBase, public TfWeakBase {
|
||||
public:
|
||||
typedef TfHashMap<TfToken, int, TfToken::HashFunctor> BindingMap;
|
||||
|
||||
GlfBindingMap()
|
||||
: _samplerBindingBaseIndex(0)
|
||||
, _uniformBindingBaseIndex(0)
|
||||
{ }
|
||||
|
||||
GLF_API
|
||||
int GetSamplerUnit(std::string const &name);
|
||||
GLF_API
|
||||
int GetSamplerUnit(TfToken const & name);
|
||||
|
||||
// If GetAttributeIndex is called with an unknown
|
||||
// attribute token they return -1
|
||||
GLF_API
|
||||
int GetAttributeIndex(std::string const & name);
|
||||
GLF_API
|
||||
int GetAttributeIndex(TfToken const & name);
|
||||
|
||||
GLF_API
|
||||
int GetUniformBinding(std::string const & name);
|
||||
GLF_API
|
||||
int GetUniformBinding(TfToken const & name);
|
||||
|
||||
GLF_API
|
||||
bool HasUniformBinding(std::string const & name) const;
|
||||
GLF_API
|
||||
bool HasUniformBinding(TfToken const & name) const;
|
||||
|
||||
int GetNumSamplerBindings() const {
|
||||
return (int)_samplerBindings.size();
|
||||
}
|
||||
|
||||
void ClearAttribBindings() {
|
||||
_attribBindings.clear();
|
||||
}
|
||||
|
||||
/// \name Sampler and UBO Bindings
|
||||
///
|
||||
/// Sampler units and uniform block bindings are reset and will be
|
||||
/// assigned sequentially starting from the specified baseIndex.
|
||||
/// This allows other subsystems to claim sampler units and uniform
|
||||
/// block bindings before additional indices are assigned by this
|
||||
/// binding map.
|
||||
///
|
||||
/// @{
|
||||
|
||||
void ResetSamplerBindings(int baseIndex) {
|
||||
_samplerBindings.clear();
|
||||
_samplerBindingBaseIndex = baseIndex;
|
||||
}
|
||||
|
||||
void ResetUniformBindings(int baseIndex) {
|
||||
_uniformBindings.clear();
|
||||
_uniformBindingBaseIndex = baseIndex;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
void AddAttribBinding(TfToken const &name, int location) {
|
||||
_attribBindings[name] = location;
|
||||
}
|
||||
|
||||
BindingMap const &GetAttributeBindings() const {
|
||||
return _attribBindings;
|
||||
}
|
||||
|
||||
GLF_API
|
||||
void AssignSamplerUnitsToProgram(GLuint program);
|
||||
|
||||
GLF_API
|
||||
void AssignUniformBindingsToProgram(GLuint program);
|
||||
|
||||
GLF_API
|
||||
void AddCustomBindings(GLuint program);
|
||||
|
||||
GLF_API
|
||||
void Debug() const;
|
||||
|
||||
private:
|
||||
void _AddActiveAttributeBindings(GLuint program);
|
||||
void _AddActiveUniformBindings(GLuint program);
|
||||
void _AddActiveUniformBlockBindings(GLuint program);
|
||||
|
||||
BindingMap _attribBindings;
|
||||
BindingMap _samplerBindings;
|
||||
BindingMap _uniformBindings;
|
||||
|
||||
int _samplerBindingBaseIndex;
|
||||
int _uniformBindingBaseIndex;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_GLF_BINDING_MAP_H
|
||||
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_CONTEXT_CAPS_H
|
||||
#define PXR_IMAGING_GLF_CONTEXT_CAPS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/base/tf/singleton.h"
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class GlfContextCaps
|
||||
///
|
||||
/// This class is intended to be a cache of the capabilites
|
||||
/// (resource limits and features) of the underlying
|
||||
/// GL context.
|
||||
///
|
||||
/// It serves two purposes. Firstly to reduce driver
|
||||
/// transition overhead of querying these values.
|
||||
/// Secondly to provide access to these values from other
|
||||
/// threads that don't have the context bound.
|
||||
///
|
||||
/// In the event of failure (InitInstance() wasn't called
|
||||
/// or an issue accessing the GL context), a reasonable
|
||||
/// set of defaults, based on GL minimums, is provided.
|
||||
///
|
||||
///
|
||||
/// TO DO (bug #124971):
|
||||
/// - LoadCaps() should be called whenever the context
|
||||
/// changes.
|
||||
/// - Provide a mechanism where other Hd systems can
|
||||
/// subscribe to when the caps changes, so they can
|
||||
/// update and invalidate.
|
||||
///
|
||||
class GlfContextCaps
|
||||
{
|
||||
public:
|
||||
|
||||
/// InitInstance queries the GL context for its capabilities.
|
||||
/// It should be called by the application before using systems
|
||||
/// that depend on the caps, such as Hydra. A good example would be
|
||||
/// to pair the call to initialize after a call to initialize GL
|
||||
GLF_API
|
||||
static void InitInstance();
|
||||
|
||||
/// GetInstance() returns the filled capabilities structure.
|
||||
/// This function will not populate the caps and will issue a
|
||||
/// coding error if it hasn't been filled.
|
||||
GLF_API
|
||||
static const GlfContextCaps &GetInstance();
|
||||
|
||||
|
||||
|
||||
// GL version
|
||||
int glVersion; // 400 (4.0), 410 (4.1), ...
|
||||
|
||||
// Whether or not we are running with core profile
|
||||
bool coreProfile;
|
||||
|
||||
// Max constants
|
||||
int maxArrayTextureLayers;
|
||||
int maxUniformBlockSize;
|
||||
int maxShaderStorageBlockSize;
|
||||
int maxTextureBufferSize;
|
||||
int uniformBufferOffsetAlignment;
|
||||
|
||||
// GL extensions (ordered by version)
|
||||
bool arrayTexturesEnabled; // EXT_texture_array (3.0)
|
||||
bool shaderStorageBufferEnabled; // ARB_shader_storage_buffer_object (4.3)
|
||||
bool bufferStorageEnabled; // ARB_buffer_storage (4.4)
|
||||
bool directStateAccessEnabled; // ARB_direct_state_access (4.5)
|
||||
bool multiDrawIndirectEnabled; // ARB_multi_draw_indirect (4.5)
|
||||
|
||||
bool bindlessTextureEnabled; // ARB_bindless_texture
|
||||
bool bindlessBufferEnabled; // NV_shader_buffer_load
|
||||
|
||||
// GLSL version and extensions
|
||||
int glslVersion; // 400, 410, ...
|
||||
bool explicitUniformLocation; // ARB_explicit_uniform_location (4.3)
|
||||
bool shadingLanguage420pack; // ARB_shading_language_420pack (4.2)
|
||||
bool shaderDrawParametersEnabled; // ARB_shader_draw_parameters (4.5)
|
||||
|
||||
// workarounds for driver issues
|
||||
bool copyBufferEnabled;
|
||||
|
||||
bool floatingPointBuffersEnabled;
|
||||
|
||||
private:
|
||||
void _LoadCaps();
|
||||
GlfContextCaps();
|
||||
~GlfContextCaps() = default;
|
||||
|
||||
// Disallow copies
|
||||
GlfContextCaps(const GlfContextCaps&) = delete;
|
||||
GlfContextCaps& operator=(const GlfContextCaps&) = delete;
|
||||
|
||||
friend class TfSingleton<GlfContextCaps>;
|
||||
};
|
||||
|
||||
GLF_API_TEMPLATE_CLASS(TfSingleton<GlfContextCaps>);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_GLF_CONTEXT_CAPS_H
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_DIAGNOSTIC_H
|
||||
#define PXR_IMAGING_GLF_DIAGNOSTIC_H
|
||||
|
||||
/// \file glf/diagnostic.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/imaging/garch/glApi.h"
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// Posts diagnostic errors for all GL errors in the current context.
|
||||
/// This macro tags the diagnostic errors with the name of the calling
|
||||
/// function.
|
||||
#define GLF_POST_PENDING_GL_ERRORS() \
|
||||
GlfPostPendingGLErrors(__ARCH_PRETTY_FUNCTION__)
|
||||
|
||||
/// Posts diagnostic errors for all GL errors in the current context.
|
||||
GLF_API
|
||||
void GlfPostPendingGLErrors(std::string const & where = std::string());
|
||||
|
||||
/// Registers GlfDefaultDebugOutputMessageCallback as the
|
||||
/// debug message callback for the current GL context.
|
||||
GLF_API
|
||||
void GlfRegisterDefaultDebugOutputMessageCallback();
|
||||
|
||||
/// A GL debug output message callback method which posts diagnostic
|
||||
/// errors for messages of type DEBUG_TYPE_ERROR and diagnostic warnings
|
||||
/// for other message types.
|
||||
GLF_API
|
||||
void GlfDefaultDebugOutputMessageCallback(
|
||||
GLenum source, GLenum type, GLuint id, GLenum severity,
|
||||
GLsizei length, char const * message, GLvoid const * userParam);
|
||||
|
||||
/// Returns a string representation of debug output enum values.
|
||||
GLF_API
|
||||
char const * GlfDebugEnumToString(GLenum debugEnum);
|
||||
|
||||
/// Emit a GlfDebugGroup tracing the current function.
|
||||
#define GLF_GROUP_FUNCTION() \
|
||||
GlfDebugGroup __glf_group_function(__ARCH_PRETTY_FUNCTION__)
|
||||
|
||||
/// Emit a GlfDebugGroup tracing the current scope with the given string.
|
||||
#define GLF_GROUP_SCOPE(str) \
|
||||
GlfDebugGroup __glf_group_scope(str)
|
||||
|
||||
/// \class GlfDebugGroup
|
||||
///
|
||||
/// Represents a GL debug group in Glf
|
||||
///
|
||||
/// The debug group conditionally adds debug objects to the GL stream
|
||||
/// based on the value to the environment variable GLF_ENABLE_DIAGNOSTIC_TRACE.
|
||||
/// If set to 1 (true) the debug objects will be pushed and popped in
|
||||
/// the command stream as long as the GL implementation and version supports it.
|
||||
///
|
||||
class GlfDebugGroup {
|
||||
public:
|
||||
/// Pushes a new debug group onto the GL api debug trace stack
|
||||
GLF_API
|
||||
GlfDebugGroup(char const *message);
|
||||
|
||||
/// Pops a debug group off the GL api debug trace stack
|
||||
GLF_API
|
||||
~GlfDebugGroup();
|
||||
|
||||
GlfDebugGroup() = delete;
|
||||
GlfDebugGroup(GlfDebugGroup const&) = delete;
|
||||
GlfDebugGroup& operator =(GlfDebugGroup const&) = delete;
|
||||
};
|
||||
|
||||
/// Label a buffer object to improve tracing in the debug output.
|
||||
GLF_API
|
||||
void GlfDebugLabelBuffer(GLuint id, char const *label);
|
||||
|
||||
/// Label a shader object to improve tracing in the debug output.
|
||||
GLF_API
|
||||
void GlfDebugLabelShader(GLuint id, char const *label);
|
||||
|
||||
/// Label a program object to improve tracing in the debug output.
|
||||
GLF_API
|
||||
void GlfDebugLabelProgram(GLuint id, char const *label);
|
||||
|
||||
/// \class GlfGLQueryObject
|
||||
///
|
||||
/// Represents a GL query object in Glf
|
||||
///
|
||||
class GlfGLQueryObject {
|
||||
public:
|
||||
GLF_API
|
||||
GlfGLQueryObject();
|
||||
GLF_API
|
||||
~GlfGLQueryObject();
|
||||
|
||||
/// Begin query for the given \p target
|
||||
/// target has to be one of
|
||||
/// GL_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED,
|
||||
/// GL_ANY_SAMPLES_PASSED_CONSERVATIVE, GL_PRIMITIVES_GENERATED
|
||||
/// GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
|
||||
/// GL_TIME_ELAPSED, GL_TIMESTAMP
|
||||
GLF_API
|
||||
void Begin(GLenum target);
|
||||
|
||||
/// equivalent to Begin(GL_SAMPLES_PASSED).
|
||||
/// The number of samples that pass the depth test for all drawing
|
||||
/// commands within the scope of the query will be returned.
|
||||
GLF_API
|
||||
void BeginSamplesPassed();
|
||||
|
||||
/// equivalent to Begin(GL_PRIMITIVES_GENERATED).
|
||||
/// The number of primitives sent to the rasterizer by the scoped
|
||||
/// drawing command will be returned.
|
||||
GLF_API
|
||||
void BeginPrimitivesGenerated();
|
||||
|
||||
/// equivalent to Begin(GL_TIME_ELAPSED).
|
||||
/// The time that it takes for the GPU to execute all of the scoped commands
|
||||
/// will be returned in nanoseconds.
|
||||
GLF_API
|
||||
void BeginTimeElapsed();
|
||||
|
||||
/// End query
|
||||
GLF_API
|
||||
void End();
|
||||
|
||||
/// Return the query result (synchronous)
|
||||
/// stalls CPU until the result becomes available.
|
||||
GLF_API
|
||||
int64_t GetResult();
|
||||
|
||||
/// Return the query result (asynchronous)
|
||||
/// returns 0 if the result hasn't been available.
|
||||
GLF_API
|
||||
int64_t GetResultNoWait();
|
||||
|
||||
GlfGLQueryObject(GlfGLQueryObject const&) = delete;
|
||||
GlfGLQueryObject& operator =(GlfGLQueryObject const&) = delete;
|
||||
private:
|
||||
GLuint _id;
|
||||
GLenum _target;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,305 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_DRAW_TARGET_H
|
||||
#define PXR_IMAGING_GLF_DRAW_TARGET_H
|
||||
|
||||
/// \file glf/drawTarget.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/imaging/glf/texture.h"
|
||||
#include "pxr/imaging/garch/glApi.h"
|
||||
|
||||
#include "pxr/base/gf/vec2i.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/refBase.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(GlfDrawTarget);
|
||||
typedef std::shared_ptr<class GlfGLContext> GlfGLContextSharedPtr;
|
||||
|
||||
/// \class GlfDrawTarget
|
||||
///
|
||||
/// A class representing a GL render target with mutliple image attachments.
|
||||
///
|
||||
/// A DrawTarget is essentially a custom render pass into which several
|
||||
/// arbitrary variables can be output into. These can later be used as
|
||||
/// texture samplers by GLSL shaders.
|
||||
///
|
||||
/// The DrawTarget maintains a map of named attachments that correspond
|
||||
/// to GL_TEXTURE_2D mages. By default, DrawTargets also create a depth
|
||||
/// component that is used both as a depth buffer during the draw pass,
|
||||
/// and can later be accessed as a regular GL_TEXTURE_2D data. Stencils
|
||||
/// are also available (by setting the format to GL_DEPTH_STENCIL and
|
||||
/// the internalFormat to GL_DEPTH24_STENCIL8)
|
||||
///
|
||||
class GlfDrawTarget : public TfRefBase, public TfWeakBase {
|
||||
public:
|
||||
typedef GlfDrawTarget This;
|
||||
|
||||
public:
|
||||
|
||||
/// Returns a new instance.
|
||||
GLF_API
|
||||
static GlfDrawTargetRefPtr New( GfVec2i const & size,
|
||||
bool requestMSAA = false );
|
||||
|
||||
/// Returns a new instance.
|
||||
/// GL framebuffers cannot be shared across contexts, but texture
|
||||
/// attachments can. In order to reflect this, GlfDrawTargets hold
|
||||
/// onto their maps of attachments through a RefPtr that can be shared
|
||||
/// by multiple GlfDrawTargets, one for each of the active GL contexts
|
||||
/// (ex. one for each active QT viewer).
|
||||
/// This constructor creates a new framebuffer, but populates its map of
|
||||
/// attachments by sharing the RefPtr of the source GlfDrawTarget.
|
||||
GLF_API
|
||||
static GlfDrawTargetRefPtr New( GlfDrawTargetPtr const & drawtarget );
|
||||
|
||||
class Attachment : public GlfTexture {
|
||||
public:
|
||||
typedef TfDeclarePtrs<class Attachment>::RefPtr AttachmentRefPtr;
|
||||
|
||||
GLF_API
|
||||
static AttachmentRefPtr New(int glIndex, GLenum format, GLenum type,
|
||||
GLenum internalFormat, GfVec2i size,
|
||||
unsigned int numSamples);
|
||||
|
||||
GLF_API
|
||||
~Attachment() override;
|
||||
|
||||
/// Returns the GL texture index (can be used as any regular GL texture)
|
||||
GLuint GetGlTextureName() override;
|
||||
|
||||
/// Returns the GL texture index multisampled of this attachment
|
||||
GLuint GetGlTextureMSName() const { return _textureNameMS; }
|
||||
|
||||
/// Returns the GL format of the texture (GL_RGB, GL_DEPTH_COMPONENT...)
|
||||
GLenum GetFormat() const { return _format; }
|
||||
|
||||
/// Returns the GL type of the texture (GL_BYTE, GL_INT, GL_FLOAT...)
|
||||
GLenum GetType() const { return _type; }
|
||||
|
||||
/// Returns the GL internalFormat of the texture
|
||||
GLenum GetInternalFormat() const { return _internalFormat; }
|
||||
|
||||
/// Returns the GL attachment point index in the framebuffer.
|
||||
int GetAttach() const { return _glIndex; }
|
||||
|
||||
/// Resize the attachment recreating the texture
|
||||
GLF_API
|
||||
void ResizeTexture(const GfVec2i &size);
|
||||
|
||||
// GlfTexture overrides
|
||||
GLF_API
|
||||
BindingVector GetBindings(TfToken const & identifier,
|
||||
GLuint samplerName) override;
|
||||
GLF_API
|
||||
VtDictionary GetTextureInfo(bool forceLoad) override;
|
||||
|
||||
/// Updates the contents signature for the underlying texture
|
||||
/// to allow downstream consumers to know that the texture image
|
||||
/// data may have changed.
|
||||
GLF_API
|
||||
void TouchContents();
|
||||
|
||||
private:
|
||||
Attachment(int glIndex, GLenum format, GLenum type,
|
||||
GLenum internalFormat, GfVec2i size,
|
||||
unsigned int numSamples);
|
||||
|
||||
void _GenTexture();
|
||||
void _DeleteTexture();
|
||||
|
||||
GLuint _textureName;
|
||||
GLuint _textureNameMS;
|
||||
|
||||
GLenum _format,
|
||||
_type,
|
||||
_internalFormat;
|
||||
|
||||
int _glIndex;
|
||||
|
||||
GfVec2i _size;
|
||||
|
||||
unsigned int _numSamples;
|
||||
};
|
||||
|
||||
typedef TfDeclarePtrs<class Attachment>::RefPtr AttachmentRefPtr;
|
||||
|
||||
typedef std::map<std::string, AttachmentRefPtr> AttachmentsMap;
|
||||
|
||||
/// Add an attachment to the DrawTarget.
|
||||
GLF_API
|
||||
void AddAttachment( std::string const & name,
|
||||
GLenum format, GLenum type, GLenum internalFormat );
|
||||
|
||||
/// Removes the named attachment from the DrawTarget.
|
||||
GLF_API
|
||||
void DeleteAttachment( std::string const & name );
|
||||
|
||||
/// Clears all the attachments for this DrawTarget.
|
||||
GLF_API
|
||||
void ClearAttachments();
|
||||
|
||||
/// Copies the list of attachments from DrawTarget.
|
||||
GLF_API
|
||||
void CloneAttachments( GlfDrawTargetPtr const & drawtarget );
|
||||
|
||||
/// Returns the list of Attachments for this DrawTarget.
|
||||
GLF_API
|
||||
AttachmentsMap const & GetAttachments() const;
|
||||
|
||||
/// Returns the attachment with a given name or TfNullPtr;
|
||||
GLF_API
|
||||
AttachmentRefPtr GetAttachment(std::string const & name);
|
||||
|
||||
/// Write the Attachment buffer to an image file (debugging).
|
||||
GLF_API
|
||||
bool WriteToFile(std::string const & name,
|
||||
std::string const & filename,
|
||||
GfMatrix4d const & viewMatrix = GfMatrix4d(1),
|
||||
GfMatrix4d const & projectionMatrix = GfMatrix4d(1));
|
||||
|
||||
/// Resize the DrawTarget.
|
||||
GLF_API
|
||||
void SetSize( GfVec2i );
|
||||
|
||||
/// Returns the size of the DrawTarget.
|
||||
GfVec2i const & GetSize() const { return _size; }
|
||||
|
||||
/// Returns if the draw target uses msaa
|
||||
bool HasMSAA() const { return (_numSamples > 1); }
|
||||
|
||||
/// Returns the framebuffer object Id.
|
||||
GLF_API
|
||||
GLuint GetFramebufferId() const;
|
||||
|
||||
/// Returns the id of the framebuffer object with MSAA buffers.
|
||||
GLF_API
|
||||
GLuint GetFramebufferMSId() const;
|
||||
|
||||
/// Binds the framebuffer.
|
||||
GLF_API
|
||||
void Bind();
|
||||
|
||||
/// Unbinds the framebuffer.
|
||||
GLF_API
|
||||
void Unbind();
|
||||
|
||||
/// Returns whether the framebuffer is currently bound.
|
||||
GLF_API
|
||||
bool IsBound() const;
|
||||
|
||||
/// Resolve the MSAA framebuffer to a regular framebuffer. If there
|
||||
/// is no MSAA enabled, this function does nothing.
|
||||
GLF_API
|
||||
void Resolve();
|
||||
|
||||
/// Resolve several MSAA framebuffers at once. If any framebuffers don't
|
||||
/// have MSAA enabled, nothing happens to them.
|
||||
GLF_API
|
||||
static void Resolve(const std::vector<GlfDrawTarget*>& drawTargets);
|
||||
|
||||
/// Updates the contents signature for attached textures
|
||||
/// to allow downstream consumers to know that the texture image
|
||||
/// data may have changed.
|
||||
GLF_API
|
||||
void TouchContents();
|
||||
|
||||
/// Returns whether the enclosed framebuffer object is complete.
|
||||
/// If \a reason is non-NULL, and this framebuffer is not valid,
|
||||
/// sets \a reason to the reason why not.
|
||||
GLF_API
|
||||
bool IsValid(std::string * reason = NULL);
|
||||
|
||||
protected:
|
||||
|
||||
/// Weak/Ref-based container for the the map of texture attachments.
|
||||
/// Multiple GlfDrawTargets can jointly share their attachment textures :
|
||||
/// this construction allows the use of a RefPtr on the map of attachments.
|
||||
class AttachmentsContainer : public TfRefBase, public TfWeakBase {
|
||||
public:
|
||||
AttachmentsMap attachments;
|
||||
};
|
||||
|
||||
GLF_API
|
||||
GlfDrawTarget( GfVec2i const & size, bool requestMSAA );
|
||||
|
||||
GLF_API
|
||||
GlfDrawTarget( GlfDrawTargetPtr const & drawtarget );
|
||||
|
||||
GLF_API
|
||||
virtual ~GlfDrawTarget();
|
||||
|
||||
private:
|
||||
void _GenFrameBuffer();
|
||||
|
||||
void _BindAttachment( GlfDrawTarget::AttachmentRefPtr const & a );
|
||||
|
||||
GLuint _AllocAttachment( GLenum format, GLenum type );
|
||||
|
||||
AttachmentsMap & _GetAttachments() const;
|
||||
|
||||
void _DeleteAttachments( );
|
||||
|
||||
void _AllocDepth( );
|
||||
|
||||
bool _Validate(std::string * reason = NULL);
|
||||
|
||||
void _SaveBindingState();
|
||||
|
||||
void _RestoreBindingState();
|
||||
|
||||
void _Resolve();
|
||||
|
||||
GLuint _framebuffer;
|
||||
GLuint _framebufferMS;
|
||||
|
||||
GLuint _unbindRestoreReadFB,
|
||||
_unbindRestoreDrawFB;
|
||||
|
||||
int _bindDepth;
|
||||
|
||||
GfVec2i _size;
|
||||
|
||||
unsigned int _numSamples;
|
||||
|
||||
TfRefPtr<AttachmentsContainer> _attachmentsPtr;
|
||||
GlfGLContextSharedPtr _owningContext;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // GLF_DRAW_TARGET_H
|
||||
@@ -0,0 +1,360 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_GL_CONTEXT_H
|
||||
#define PXR_IMAGING_GLF_GL_CONTEXT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/base/arch/threads.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
typedef std::shared_ptr<class GlfGLContext> GlfGLContextSharedPtr;
|
||||
|
||||
/// \class GlfGLContext
|
||||
///
|
||||
/// Provides window system independent access to GL contexts.
|
||||
///
|
||||
/// All OpenGL operation occurs within a current GL Context. The GL
|
||||
/// contexts used by an application are allocated and managed by the window
|
||||
/// system interface layer, i.e. Qt, GLUT, GLX, etc.
|
||||
///
|
||||
/// This class provides a way for lower-level OpenGL framework code to
|
||||
/// get useful information about the GL contexts in use by the application.
|
||||
///
|
||||
/// This mechanism depends on the application code registering callbacks to
|
||||
/// provide access to its GL contexts.
|
||||
///
|
||||
class GlfGLContext
|
||||
{
|
||||
public:
|
||||
GLF_API
|
||||
virtual ~GlfGLContext();
|
||||
|
||||
// Disallow copies
|
||||
GlfGLContext(const GlfGLContext&) = delete;
|
||||
GlfGLContext& operator=(const GlfGLContext&) = delete;
|
||||
|
||||
/// Returns an instance for the current GL context.
|
||||
GLF_API
|
||||
static GlfGLContextSharedPtr GetCurrentGLContext();
|
||||
|
||||
/// Returns an instance for the shared GL context.
|
||||
GLF_API
|
||||
static GlfGLContextSharedPtr GetSharedGLContext();
|
||||
|
||||
/// Makes \p context current if valid, otherwise makes no context current.
|
||||
GLF_API
|
||||
static void MakeCurrent(const GlfGLContextSharedPtr& context);
|
||||
|
||||
/// Returns \c true if \a context1 and \a context2 are sharing.
|
||||
GLF_API
|
||||
static bool AreSharing(GlfGLContextSharedPtr const & context1,
|
||||
GlfGLContextSharedPtr const & context2);
|
||||
|
||||
/// Returns whether this interface has been initialized.
|
||||
GLF_API
|
||||
static bool IsInitialized();
|
||||
|
||||
/// Returns \c true if this context is current.
|
||||
GLF_API
|
||||
bool IsCurrent() const;
|
||||
|
||||
private:
|
||||
/// Makes this context current.
|
||||
///
|
||||
/// If the context is not valid this does nothing.
|
||||
void MakeCurrent();
|
||||
|
||||
public:
|
||||
/// Makes no context current.
|
||||
GLF_API
|
||||
static void DoneCurrent();
|
||||
|
||||
/// Returns \c true if this context is sharing with \a otherContext.
|
||||
GLF_API
|
||||
bool IsSharing(GlfGLContextSharedPtr const & otherContext);
|
||||
|
||||
/// Returns \c true if this context is valid.
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
/// Creates a new GlfContext that shares GL resources with this context.
|
||||
/// The purpose of this function is to be able to create a new GL context
|
||||
/// on a second thread that shares with the context on the main-thread.
|
||||
/// If the GlfContext implementation does not support sharing contexts
|
||||
/// null is returned. Example usage:
|
||||
/// Main-thread:
|
||||
/// RegisterGLContextCallbacks();
|
||||
/// GlfGLContext::MakeCurrent(...);
|
||||
/// Second-thread:
|
||||
/// s = GetCurrentGLContext();
|
||||
/// c = s->CreateSharingContext();
|
||||
virtual GlfGLContextSharedPtr CreateSharingContext() {return nullptr;}
|
||||
|
||||
protected:
|
||||
GLF_API
|
||||
GlfGLContext();
|
||||
|
||||
/// Makes this context current.
|
||||
virtual void _MakeCurrent() = 0;
|
||||
|
||||
/// Returns \c true if this context is sharing with \a rhs.
|
||||
virtual bool _IsSharing(const GlfGLContextSharedPtr& rhs) const = 0;
|
||||
|
||||
/// Returns \c true if this context is equal to \p rhs.
|
||||
virtual bool _IsEqual(const GlfGLContextSharedPtr& rhs) const = 0;
|
||||
};
|
||||
|
||||
/// \class GlfGLContextScopeHolder
|
||||
///
|
||||
/// Helper class to make a GL context current.
|
||||
///
|
||||
/// It is often useful to wrap a dynamic GL resource with a class interface.
|
||||
///
|
||||
/// In addition to providing API to make it more convenient to use the
|
||||
/// underlying GL resource, the lifetime of the underlying resource can
|
||||
/// be tied to the lifetime of a wrapper object instance, e.g. allocate
|
||||
/// the GL resource during construction, delete the GL resource during
|
||||
/// destruction.
|
||||
///
|
||||
/// While the construction and use of these kinds of wrapper objects is
|
||||
/// usually pretty safe and straightforward, it can be more difficult to
|
||||
/// manage destruction. Specifically, it can be hard to guarantee that
|
||||
/// a suitable GL context is current at the time that a wrapper object
|
||||
/// instance is destroyed. If a suitable context is not current, then
|
||||
/// it will not be possible to delete the underlying resource, which
|
||||
/// may cause the resource to remain allocated, which will then result
|
||||
/// in a resource leak.
|
||||
///
|
||||
/// Typically, these GL resources are allocated from contexts which are
|
||||
/// sharing the GL resources. In which case it is sufficient for any one
|
||||
/// one of the sharing contexts to be current in order to be able to safely
|
||||
/// delete the GL resource from the destructor of a wrapper object.
|
||||
///
|
||||
/// GlfGLContext and GlfGLContextScopeHolder can help.
|
||||
///
|
||||
/// When GlfGLContext has been initialized, i.e. when suitable context
|
||||
/// callbacks have been registered, we can use GlfGLContext to make
|
||||
/// a GL context current.
|
||||
///
|
||||
/// GlfGLContextScopeHolder does this automatically for the duration
|
||||
/// of a code block.
|
||||
///
|
||||
/// The underlying calls to make GL contexts current can be moderately
|
||||
/// expensive. So, this mechanism should be used carefully.
|
||||
///
|
||||
class GlfGLContextScopeHolder
|
||||
{
|
||||
public:
|
||||
/// Make the given context current and restore the current context
|
||||
/// when this object is destroyed.
|
||||
GLF_API
|
||||
explicit GlfGLContextScopeHolder(const GlfGLContextSharedPtr& newContext);
|
||||
|
||||
GLF_API
|
||||
~GlfGLContextScopeHolder();
|
||||
|
||||
GlfGLContextScopeHolder(const GlfGLContextScopeHolder&) = delete;
|
||||
GlfGLContextScopeHolder& operator=(const GlfGLContextScopeHolder) = delete;
|
||||
|
||||
protected:
|
||||
GLF_API
|
||||
void _MakeNewContextCurrent();
|
||||
GLF_API
|
||||
void _RestoreOldContext();
|
||||
|
||||
private:
|
||||
GlfGLContextSharedPtr _newContext;
|
||||
GlfGLContextSharedPtr _oldContext;
|
||||
};
|
||||
|
||||
/// \class GlfSharedGLContextScopeHolder
|
||||
///
|
||||
/// Helper class to make the shared GL context current.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// \code
|
||||
/// class MyTexture {
|
||||
/// public:
|
||||
/// MyTexture() : _textureId(0) {
|
||||
/// // allocate from the shared context pool.
|
||||
/// GlfSharedGLContextScopeHolder sharedContextScopeHolder;
|
||||
/// glGenTextures(1, &_textureId);
|
||||
/// }
|
||||
///
|
||||
/// ~MyTexture() {
|
||||
/// // delete from the shared context pool.
|
||||
/// GlfSharedGLContextScopeHolder sharedContextScopeHolder;
|
||||
/// glDeleteTextures(1, &_texureId);
|
||||
/// _textureId = 0;
|
||||
/// }
|
||||
///
|
||||
/// // The caller is responsible for making sure that a suitable
|
||||
/// // GL context is current before calling other methods.
|
||||
///
|
||||
/// void Bind() {
|
||||
/// glBindTexture(GL_TEXTURE_2D, _textureId);
|
||||
/// }
|
||||
///
|
||||
/// void Unbind() {
|
||||
/// glBindTexture(GL_TEXTURE_2D, 0);
|
||||
/// }
|
||||
///
|
||||
/// ...
|
||||
///
|
||||
/// private:
|
||||
/// GLuint _textureId;
|
||||
///
|
||||
/// };
|
||||
/// \endcode
|
||||
///
|
||||
class GlfSharedGLContextScopeHolder final : private GlfGLContextScopeHolder
|
||||
{
|
||||
public:
|
||||
GlfSharedGLContextScopeHolder() :
|
||||
GlfGLContextScopeHolder(_GetSharedContext())
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
private:
|
||||
static GlfGLContextSharedPtr _GetSharedContext()
|
||||
{
|
||||
if (GlfGLContext::IsInitialized() && ArchIsMainThread()) {
|
||||
return GlfGLContext::GetSharedGLContext();
|
||||
}
|
||||
return GlfGLContextSharedPtr();
|
||||
}
|
||||
};
|
||||
|
||||
#define API_GLF_HAS_ANY_GL_CONTEXT_SCOPE_HOLDER 1
|
||||
|
||||
/// \class GlfAnyGLContextScopeHolder
|
||||
///
|
||||
/// Helper class to make the shared GL context current if there is no
|
||||
/// valid current context.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// \code
|
||||
/// class MyTexture {
|
||||
/// public:
|
||||
/// MyTexture() : _textureId(0) {
|
||||
/// // Ensure we have valid GL context to allocate
|
||||
/// GlfAnyGLContextScopeHolder anyContextScopeHolder;
|
||||
/// glGenTextures(1, &_textureId);
|
||||
/// }
|
||||
///
|
||||
/// ~MyTexture() {
|
||||
/// // Ensure we have valid GL context to delete
|
||||
/// GlfAnyGLContextScopeHolder anyContextScopeHolder;
|
||||
/// glDeleteTextures(1, &_texureId);
|
||||
/// _textureId = 0;
|
||||
/// }
|
||||
///
|
||||
/// // The caller is responsible for making sure that a suitable
|
||||
/// // GL context is current before calling other methods.
|
||||
///
|
||||
/// void Bind() {
|
||||
/// glBindTexture(GL_TEXTURE_2D, _textureId);
|
||||
/// }
|
||||
///
|
||||
/// void Unbind() {
|
||||
/// glBindTexture(GL_TEXTURE_2D, 0);
|
||||
/// }
|
||||
///
|
||||
/// ...
|
||||
///
|
||||
/// private:
|
||||
/// GLuint _textureId;
|
||||
///
|
||||
/// };
|
||||
/// \endcode
|
||||
///
|
||||
class GlfAnyGLContextScopeHolder final : private GlfGLContextScopeHolder
|
||||
{
|
||||
public:
|
||||
GlfAnyGLContextScopeHolder() :
|
||||
GlfGLContextScopeHolder(_GetAnyContext())
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
private:
|
||||
static GlfGLContextSharedPtr _GetAnyContext()
|
||||
{
|
||||
if (GlfGLContext::IsInitialized() && ArchIsMainThread()) {
|
||||
GlfGLContextSharedPtr const current =
|
||||
GlfGLContext::GetCurrentGLContext();
|
||||
if (!(current && current->IsValid())) {
|
||||
return GlfGLContext::GetSharedGLContext();
|
||||
}
|
||||
}
|
||||
return GlfGLContextSharedPtr();
|
||||
}
|
||||
};
|
||||
|
||||
/// \class GlfGLContextRegistrationInterface
|
||||
///
|
||||
/// Interface for registering a GlfGLContext system.
|
||||
///
|
||||
/// If you subclass GlfGLContext you should subclass this type and
|
||||
/// instantiate an instance on the heap. It will be cleaned up
|
||||
/// automatically.
|
||||
class GlfGLContextRegistrationInterface
|
||||
{
|
||||
public:
|
||||
GLF_API
|
||||
virtual ~GlfGLContextRegistrationInterface();
|
||||
|
||||
// Disallow copies
|
||||
GlfGLContextRegistrationInterface(
|
||||
const GlfGLContextRegistrationInterface&) = delete;
|
||||
GlfGLContextRegistrationInterface& operator=(
|
||||
const GlfGLContextRegistrationInterface&) = delete;
|
||||
|
||||
/// If this GLContext system supports a shared context this should
|
||||
/// return it. This will be called at most once.
|
||||
virtual GlfGLContextSharedPtr GetShared() = 0;
|
||||
|
||||
/// Whatever your GLContext system thinks is the current GL context
|
||||
/// may not really be the current context if another system has since
|
||||
/// changed the context. This method should return what it thinks is
|
||||
/// the current context. If it thinks there is no current context it
|
||||
/// should return \c NULL.
|
||||
virtual GlfGLContextSharedPtr GetCurrent() = 0;
|
||||
|
||||
protected:
|
||||
GLF_API
|
||||
GlfGLContextRegistrationInterface();
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_GL_RAW_CONTEXT_H
|
||||
#define PXR_IMAGING_GLF_GL_RAW_CONTEXT_H
|
||||
|
||||
/// \file glf/glRawContext.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/imaging/glf/glContext.h"
|
||||
#include "pxr/imaging/garch/glPlatformContext.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
typedef std::shared_ptr<class GlfGLRawContext> GlfGLRawContextSharedPtr;
|
||||
|
||||
class GlfGLRawContext : public GlfGLContext {
|
||||
public:
|
||||
/// Returns a new object with the current context.
|
||||
GLF_API
|
||||
static GlfGLRawContextSharedPtr New();
|
||||
|
||||
/// Returns a new object with the given state.
|
||||
GLF_API
|
||||
static GlfGLRawContextSharedPtr New(const GarchGLPlatformContextState&);
|
||||
|
||||
GLF_API
|
||||
virtual ~GlfGLRawContext();
|
||||
|
||||
/// Returns the held state.
|
||||
const GarchGLPlatformContextState& GetState() const { return _state; }
|
||||
|
||||
// GlfGLContext overrides
|
||||
GLF_API
|
||||
virtual bool IsValid() const;
|
||||
|
||||
protected:
|
||||
// GlfGLContext overrides
|
||||
GLF_API
|
||||
virtual void _MakeCurrent();
|
||||
GLF_API
|
||||
virtual bool _IsSharing(const GlfGLContextSharedPtr& rhs) const;
|
||||
GLF_API
|
||||
virtual bool _IsEqual(const GlfGLContextSharedPtr& rhs) const;
|
||||
|
||||
private:
|
||||
GlfGLRawContext(const GarchGLPlatformContextState&);
|
||||
|
||||
private:
|
||||
GarchGLPlatformContextState _state;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_GLF_GL_RAW_CONTEXT_H
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_INFO_H
|
||||
#define PXR_IMAGING_GLF_INFO_H
|
||||
|
||||
/// \file glf/info.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// Tests for GL extension support.
|
||||
///
|
||||
/// Returns \c true if each extension name listed in \a extensions
|
||||
/// is supported by the current GL context.
|
||||
GLF_API
|
||||
bool GlfHasExtensions(std::string const & extensions);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,240 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_SIMPLE_LIGHT_H
|
||||
#define PXR_IMAGING_GLF_SIMPLE_LIGHT_H
|
||||
|
||||
/// \file glf/simpleLight.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/vec3f.h"
|
||||
#include "pxr/base/gf/vec4f.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/assetPath.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class GlfSimpleLight final {
|
||||
public:
|
||||
GLF_API
|
||||
GlfSimpleLight(GfVec4f const & position = GfVec4f(0.0, 0.0, 0.0, 1.0));
|
||||
GLF_API
|
||||
~GlfSimpleLight();
|
||||
|
||||
GLF_API
|
||||
GfMatrix4d const & GetTransform() const;
|
||||
GLF_API
|
||||
void SetTransform(GfMatrix4d const & mat);
|
||||
|
||||
GLF_API
|
||||
GfVec4f const & GetAmbient() const;
|
||||
GLF_API
|
||||
void SetAmbient(GfVec4f const & ambient);
|
||||
|
||||
GLF_API
|
||||
GfVec4f const & GetDiffuse() const;
|
||||
GLF_API
|
||||
void SetDiffuse(GfVec4f const & diffuse);
|
||||
|
||||
GLF_API
|
||||
GfVec4f const & GetSpecular() const;
|
||||
GLF_API
|
||||
void SetSpecular(GfVec4f const & specular);
|
||||
|
||||
GLF_API
|
||||
GfVec4f const & GetPosition() const;
|
||||
GLF_API
|
||||
void SetPosition(GfVec4f const & position);
|
||||
|
||||
GLF_API
|
||||
GfVec3f const & GetSpotDirection() const;
|
||||
GLF_API
|
||||
void SetSpotDirection(GfVec3f const & spotDirection);
|
||||
|
||||
GLF_API
|
||||
float const & GetSpotCutoff() const;
|
||||
GLF_API
|
||||
void SetSpotCutoff(float const & spotCutoff);
|
||||
|
||||
GLF_API
|
||||
float const & GetSpotFalloff() const;
|
||||
GLF_API
|
||||
void SetSpotFalloff(float const & spotFalloff);
|
||||
|
||||
GLF_API
|
||||
GfVec3f const & GetAttenuation() const;
|
||||
GLF_API
|
||||
void SetAttenuation(GfVec3f const & attenuation);
|
||||
|
||||
GLF_API
|
||||
std::vector<GfMatrix4d> const & GetShadowMatrices() const;
|
||||
GLF_API
|
||||
void SetShadowMatrices(std::vector<GfMatrix4d> const &matrix);
|
||||
|
||||
GLF_API
|
||||
int GetShadowResolution() const;
|
||||
GLF_API
|
||||
void SetShadowResolution(int resolution);
|
||||
|
||||
GLF_API
|
||||
float GetShadowBias() const;
|
||||
GLF_API
|
||||
void SetShadowBias(float bias);
|
||||
|
||||
GLF_API
|
||||
float GetShadowBlur() const;
|
||||
GLF_API
|
||||
void SetShadowBlur(float blur);
|
||||
|
||||
GLF_API
|
||||
int GetShadowIndexStart() const;
|
||||
GLF_API
|
||||
void SetShadowIndexStart(int shadowStart);
|
||||
|
||||
GLF_API
|
||||
int GetShadowIndexEnd() const;
|
||||
GLF_API
|
||||
void SetShadowIndexEnd(int shadowEnd);
|
||||
|
||||
GLF_API
|
||||
bool HasShadow() const;
|
||||
GLF_API
|
||||
void SetHasShadow(bool hasShadow);
|
||||
|
||||
GLF_API
|
||||
bool HasIntensity() const;
|
||||
GLF_API
|
||||
void SetHasIntensity(bool hasIntensity);
|
||||
|
||||
GLF_API
|
||||
bool IsCameraSpaceLight() const;
|
||||
GLF_API
|
||||
|
||||
void SetIsCameraSpaceLight(bool isCameraSpaceLight);
|
||||
GLF_API
|
||||
SdfPath const & GetID() const;
|
||||
GLF_API
|
||||
void SetID(SdfPath const & id);
|
||||
|
||||
GLF_API
|
||||
bool IsDomeLight() const;
|
||||
GLF_API
|
||||
void SetIsDomeLight(bool isDomeLight);
|
||||
|
||||
/// The path to the (unprocessed) environment map texture.
|
||||
///
|
||||
/// All textures actually used by the dome light (irradiance, prefilter,
|
||||
/// brdf) are derived from this texture in a pre-calculation step.
|
||||
GLF_API
|
||||
const SdfAssetPath &GetDomeLightTextureFile() const;
|
||||
GLF_API
|
||||
void SetDomeLightTextureFile(const SdfAssetPath &);
|
||||
|
||||
|
||||
/// \name Post Surface Lighting
|
||||
///
|
||||
/// Post surface lighting is evaluated after other surface illumination
|
||||
/// and can be used to implement lighting effects beyond those that
|
||||
/// correspond to basic positional lighting, e.g. range base fog, etc.
|
||||
///
|
||||
/// @{
|
||||
|
||||
GLF_API
|
||||
TfToken const & GetPostSurfaceIdentifier() const;
|
||||
GLF_API
|
||||
std::string const & GetPostSurfaceShaderSource() const;
|
||||
GLF_API
|
||||
VtUCharArray const & GetPostSurfaceShaderParams() const;
|
||||
|
||||
GLF_API
|
||||
void SetPostSurfaceParams(TfToken const & identifier,
|
||||
std::string const & shaderSource,
|
||||
VtUCharArray const & shaderParams);
|
||||
|
||||
/// @}
|
||||
|
||||
GLF_API
|
||||
bool operator ==(GlfSimpleLight const &other) const;
|
||||
GLF_API
|
||||
bool operator !=(GlfSimpleLight const &other) const;
|
||||
|
||||
private:
|
||||
GLF_API
|
||||
friend std::ostream & operator <<(std::ostream &out,
|
||||
const GlfSimpleLight& v);
|
||||
GfVec4f _ambient;
|
||||
GfVec4f _diffuse;
|
||||
GfVec4f _specular;
|
||||
GfVec4f _position;
|
||||
GfVec3f _spotDirection;
|
||||
float _spotCutoff;
|
||||
float _spotFalloff;
|
||||
GfVec3f _attenuation;
|
||||
bool _isCameraSpaceLight;
|
||||
bool _hasIntensity;
|
||||
|
||||
bool _hasShadow;
|
||||
int _shadowResolution;
|
||||
float _shadowBias;
|
||||
float _shadowBlur;
|
||||
int _shadowIndexStart;
|
||||
int _shadowIndexEnd;
|
||||
|
||||
GfMatrix4d _transform;
|
||||
std::vector<GfMatrix4d> _shadowMatrices;
|
||||
|
||||
// domeLight specific parameters
|
||||
bool _isDomeLight;
|
||||
// path to texture for dome light.
|
||||
SdfAssetPath _domeLightTextureFile;
|
||||
|
||||
TfToken _postSurfaceIdentifier;
|
||||
std::string _postSurfaceShaderSource;
|
||||
VtUCharArray _postSurfaceShaderParams;
|
||||
|
||||
SdfPath _id;
|
||||
};
|
||||
|
||||
// VtValue requirements
|
||||
GLF_API
|
||||
std::ostream& operator<<(std::ostream& out, const GlfSimpleLight& v);
|
||||
|
||||
typedef std::vector<class GlfSimpleLight> GlfSimpleLightVector;
|
||||
|
||||
// VtValue requirements
|
||||
GLF_API
|
||||
std::ostream& operator<<(std::ostream& out, const GlfSimpleLightVector& pv);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,180 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_SIMPLE_LIGHTING_CONTEXT_H
|
||||
#define PXR_IMAGING_GLF_SIMPLE_LIGHTING_CONTEXT_H
|
||||
|
||||
/// \file glf/simpleLightingContext.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/imaging/glf/simpleLight.h"
|
||||
#include "pxr/imaging/glf/simpleMaterial.h"
|
||||
#include "pxr/imaging/glf/simpleShadowArray.h"
|
||||
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/vec4f.h"
|
||||
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/refBase.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(GlfBindingMap);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(GlfUniformBlock);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleLightingContext);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleShadowArray);
|
||||
|
||||
class GlfSimpleLightingContext : public TfRefBase, public TfWeakBase {
|
||||
public:
|
||||
typedef GlfSimpleLightingContext This;
|
||||
|
||||
GLF_API
|
||||
static GlfSimpleLightingContextRefPtr New();
|
||||
|
||||
GLF_API
|
||||
void SetLights(GlfSimpleLightVector const & lights);
|
||||
GLF_API
|
||||
GlfSimpleLightVector const & GetLights() const;
|
||||
|
||||
// returns the effective number of lights taken into account
|
||||
// in composable/compatible shader constraints
|
||||
GLF_API
|
||||
int GetNumLightsUsed() const;
|
||||
|
||||
// returns the number of shadow maps needed, by summing shadow maps
|
||||
// allocated to each light.
|
||||
GLF_API
|
||||
int ComputeNumShadowsUsed() const;
|
||||
|
||||
GLF_API
|
||||
void SetShadows(GlfSimpleShadowArrayRefPtr const & shadows);
|
||||
GLF_API
|
||||
GlfSimpleShadowArrayRefPtr const & GetShadows() const;
|
||||
|
||||
GLF_API
|
||||
void SetMaterial(GlfSimpleMaterial const & material);
|
||||
GLF_API
|
||||
GlfSimpleMaterial const & GetMaterial() const;
|
||||
|
||||
GLF_API
|
||||
void SetSceneAmbient(GfVec4f const & sceneAmbient);
|
||||
GLF_API
|
||||
GfVec4f const & GetSceneAmbient() const;
|
||||
|
||||
GLF_API
|
||||
void SetCamera(GfMatrix4d const &worldToViewMatrix,
|
||||
GfMatrix4d const &projectionMatrix);
|
||||
|
||||
GLF_API
|
||||
void SetUseLighting(bool val);
|
||||
GLF_API
|
||||
bool GetUseLighting() const;
|
||||
|
||||
// returns true if any light has shadow enabled.
|
||||
GLF_API
|
||||
bool GetUseShadows() const;
|
||||
|
||||
GLF_API
|
||||
void SetUseColorMaterialDiffuse(bool val);
|
||||
GLF_API
|
||||
bool GetUseColorMaterialDiffuse() const;
|
||||
|
||||
GLF_API
|
||||
void InitUniformBlockBindings(GlfBindingMapPtr const &bindingMap) const;
|
||||
GLF_API
|
||||
void InitSamplerUnitBindings(GlfBindingMapPtr const &bindingMap) const;
|
||||
|
||||
GLF_API
|
||||
void BindUniformBlocks(GlfBindingMapPtr const &bindingMap);
|
||||
GLF_API
|
||||
void BindSamplers(GlfBindingMapPtr const &bindingMap);
|
||||
|
||||
GLF_API
|
||||
void UnbindSamplers(GlfBindingMapPtr const &bindingMap);
|
||||
|
||||
GLF_API
|
||||
void SetStateFromOpenGL();
|
||||
|
||||
/// \name Post Surface Lighting
|
||||
///
|
||||
/// This context can provide additional shader source, currently
|
||||
/// used to implement post surface lighting, along with a hash
|
||||
/// to help de-duplicate use by client shader programs.
|
||||
///
|
||||
/// @{
|
||||
|
||||
GLF_API
|
||||
size_t ComputeShaderSourceHash();
|
||||
|
||||
GLF_API
|
||||
std::string const & ComputeShaderSource(TfToken const &shaderStageKey);
|
||||
|
||||
/// @}
|
||||
|
||||
protected:
|
||||
GLF_API
|
||||
GlfSimpleLightingContext();
|
||||
GLF_API
|
||||
~GlfSimpleLightingContext();
|
||||
|
||||
void _ComputePostSurfaceShaderState();
|
||||
void _BindPostSurfaceShaderParams(GlfBindingMapPtr const &bindingMap);
|
||||
|
||||
private:
|
||||
GlfSimpleLightVector _lights;
|
||||
GlfSimpleShadowArrayRefPtr _shadows;
|
||||
|
||||
GfMatrix4d _worldToViewMatrix;
|
||||
GfMatrix4d _projectionMatrix;
|
||||
|
||||
GlfSimpleMaterial _material;
|
||||
GfVec4f _sceneAmbient;
|
||||
|
||||
bool _useLighting;
|
||||
bool _useShadows;
|
||||
bool _useColorMaterialDiffuse;
|
||||
|
||||
GlfUniformBlockRefPtr _lightingUniformBlock;
|
||||
GlfUniformBlockRefPtr _shadowUniformBlock;
|
||||
GlfUniformBlockRefPtr _materialUniformBlock;
|
||||
GlfUniformBlockRefPtr _bindlessShadowlUniformBlock;
|
||||
|
||||
class _PostSurfaceShaderState;
|
||||
std::unique_ptr<_PostSurfaceShaderState> _postSurfaceShaderState;
|
||||
|
||||
bool _lightingUniformBlockValid;
|
||||
bool _shadowUniformBlockValid;
|
||||
bool _materialUniformBlockValid;
|
||||
bool _postSurfaceShaderStateValid;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_SIMPLE_MATERIAL_H
|
||||
#define PXR_IMAGING_GLF_SIMPLE_MATERIAL_H
|
||||
|
||||
/// \file glf/simpleMaterial.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/base/gf/vec4f.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class GlfSimpleMaterial final {
|
||||
public:
|
||||
GLF_API
|
||||
GlfSimpleMaterial();
|
||||
GLF_API
|
||||
~GlfSimpleMaterial();
|
||||
|
||||
GLF_API
|
||||
GfVec4f const & GetAmbient() const;
|
||||
GLF_API
|
||||
void SetAmbient(GfVec4f const & ambient);
|
||||
|
||||
GLF_API
|
||||
GfVec4f const & GetDiffuse() const;
|
||||
GLF_API
|
||||
void SetDiffuse(GfVec4f const & diffuse);
|
||||
|
||||
GLF_API
|
||||
GfVec4f const & GetSpecular() const;
|
||||
GLF_API
|
||||
void SetSpecular(GfVec4f const & specular);
|
||||
|
||||
GLF_API
|
||||
GfVec4f const & GetEmission() const;
|
||||
GLF_API
|
||||
void SetEmission(GfVec4f const & specular);
|
||||
|
||||
GLF_API
|
||||
double GetShininess() const;
|
||||
GLF_API
|
||||
void SetShininess(double specular);
|
||||
|
||||
GLF_API
|
||||
bool operator ==(GlfSimpleMaterial const & other) const;
|
||||
GLF_API
|
||||
bool operator !=(GlfSimpleMaterial const & other) const;
|
||||
|
||||
private:
|
||||
GfVec4f _ambient;
|
||||
GfVec4f _diffuse;
|
||||
GfVec4f _specular;
|
||||
GfVec4f _emission;
|
||||
double _shininess;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,179 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_SIMPLE_SHADOW_ARRAY_H
|
||||
#define PXR_IMAGING_GLF_SIMPLE_SHADOW_ARRAY_H
|
||||
|
||||
/// \file glf/simpleShadowArray.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/refPtr.h"
|
||||
#include "pxr/base/tf/weakPtr.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/vec2i.h"
|
||||
#include "pxr/base/gf/vec4d.h"
|
||||
#include "pxr/imaging/garch/glApi.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class GlfSimpleShadowArray : public TfRefBase,
|
||||
public TfWeakBase
|
||||
{
|
||||
public:
|
||||
GLF_API
|
||||
GlfSimpleShadowArray();
|
||||
GLF_API
|
||||
~GlfSimpleShadowArray() override;
|
||||
|
||||
// Disallow copies
|
||||
GlfSimpleShadowArray(const GlfSimpleShadowArray&) = delete;
|
||||
GlfSimpleShadowArray& operator=(const GlfSimpleShadowArray&) = delete;
|
||||
|
||||
// Driven by the env var GLF_ENABLE_BINDLESS_SHADOW_TEXTURE, this returns
|
||||
// whether bindless shadow maps are enabled, which in turn dictates the API
|
||||
// to use. See below.
|
||||
GLF_API static
|
||||
bool GetBindlessShadowMapsEnabled();
|
||||
|
||||
/// Bindful API:
|
||||
|
||||
// Set the 2D size of the shadow map texture array.
|
||||
GLF_API
|
||||
void SetSize(GfVec2i const & size);
|
||||
|
||||
// Set the depth of the shadow map texture array, which corresponds to the
|
||||
// number of shadow maps necessary. Each shadow casting light uses one
|
||||
// shadow map.
|
||||
GLF_API
|
||||
void SetNumLayers(size_t numLayers);
|
||||
|
||||
// Returns the GL texture id of the texture array.
|
||||
GLF_API
|
||||
GLuint GetShadowMapTexture() const;
|
||||
|
||||
// Returns the GL sampler id of the sampler object used to read the raw
|
||||
// depth values.
|
||||
GLF_API
|
||||
GLuint GetShadowMapDepthSampler() const;
|
||||
|
||||
// Returns the GL sampler id of the sampler object used for depth comparison
|
||||
GLF_API
|
||||
GLuint GetShadowMapCompareSampler() const;
|
||||
|
||||
/// Bindless API:
|
||||
|
||||
// Set the resolutions of all the shadow maps necessary. The number of
|
||||
// resolutions corresponds to the number of shadow map textures necessary,
|
||||
// which is currently one per shadow casting light.
|
||||
GLF_API
|
||||
void SetShadowMapResolutions(std::vector<GfVec2i> const& resolutions);
|
||||
|
||||
// Returns a vector of the 64bit bindless handles corresponding to the
|
||||
// bindless shadow map textures.
|
||||
GLF_API
|
||||
std::vector<uint64_t> const& GetBindlessShadowMapHandles() const;
|
||||
|
||||
/// Common API (for shadow map generation)
|
||||
|
||||
// Returns the number of shadow map generation passes required, which is
|
||||
// currently one per shadow map (corresponding to a shadow casting light).
|
||||
GLF_API
|
||||
size_t GetNumShadowMapPasses() const;
|
||||
|
||||
// Returns the shadow map resolution for a given pass. For bindful shadows,
|
||||
// this returns a single size for all passes, while for bindless, it returns
|
||||
// the resolution of the corresponding shadow map,
|
||||
GLF_API
|
||||
GfVec2i GetShadowMapSize(size_t pass) const;
|
||||
|
||||
// Get/Set the view (world to shadow camera) transform to use for a given
|
||||
// shadow map generation pass.
|
||||
GLF_API
|
||||
GfMatrix4d GetViewMatrix(size_t index) const;
|
||||
GLF_API
|
||||
void SetViewMatrix(size_t index, GfMatrix4d const & matrix);
|
||||
|
||||
// Get/Set the projection transform to use for a given shadow map generation
|
||||
// pass.
|
||||
GLF_API
|
||||
GfMatrix4d GetProjectionMatrix(size_t index) const;
|
||||
GLF_API
|
||||
void SetProjectionMatrix(size_t index, GfMatrix4d const & matrix);
|
||||
|
||||
GLF_API
|
||||
GfMatrix4d GetWorldToShadowMatrix(size_t index) const;
|
||||
|
||||
// Bind necessary resources for a given shadow map generation pass.
|
||||
GLF_API
|
||||
void BeginCapture(size_t index, bool clear);
|
||||
|
||||
// Unbind necssary resources after a shadow map gneration pass.
|
||||
GLF_API
|
||||
void EndCapture(size_t index);
|
||||
|
||||
private:
|
||||
void _AllocResources();
|
||||
void _AllocBindfulTextures();
|
||||
void _AllocBindlessTextures();
|
||||
void _FreeResources();
|
||||
void _FreeBindfulTextures();
|
||||
void _FreeBindlessTextures();
|
||||
bool _ShadowMapExists() const;
|
||||
void _BindFramebuffer(size_t index);
|
||||
void _UnbindFramebuffer();
|
||||
|
||||
private:
|
||||
// bindful state
|
||||
GfVec2i _size;
|
||||
size_t _numLayers;
|
||||
GLuint _bindfulTexture;
|
||||
GLuint _shadowDepthSampler;
|
||||
|
||||
// bindless state
|
||||
std::vector<GfVec2i> _resolutions;
|
||||
std::vector<GLuint> _bindlessTextures;
|
||||
std::vector<uint64_t> _bindlessTextureHandles;
|
||||
|
||||
// common state
|
||||
std::vector<GfMatrix4d> _viewMatrix;
|
||||
std::vector<GfMatrix4d> _projectionMatrix;
|
||||
|
||||
GLuint _framebuffer;
|
||||
|
||||
GLuint _shadowCompareSampler;
|
||||
|
||||
GLuint _unbindRestoreDrawFramebuffer;
|
||||
GLuint _unbindRestoreReadFramebuffer;
|
||||
|
||||
GLint _unbindRestoreViewport[4];
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,176 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_TEXTURE_H
|
||||
#define PXR_IMAGING_GLF_TEXTURE_H
|
||||
|
||||
/// \file glf/texture.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/imaging/hio/image.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/refPtr.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
#include "pxr/base/tf/weakPtr.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
|
||||
#include "pxr/imaging/garch/glApi.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
#define GLF_TEXTURE_TOKENS \
|
||||
(texels) \
|
||||
(layout)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(GlfTextureTokens, GLF_API, GLF_TEXTURE_TOKENS);
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(GlfTexture);
|
||||
|
||||
/// \class GlfTexture
|
||||
///
|
||||
/// Represents a texture object in Glf.
|
||||
///
|
||||
/// A texture is typically defined by reading texture image data from an image
|
||||
/// file but a texture might also represent an attachment of a draw target.
|
||||
///
|
||||
class GlfTexture : public TfRefBase, public TfWeakBase
|
||||
{
|
||||
public:
|
||||
/// \class Binding
|
||||
///
|
||||
/// A texture has one or more bindings which describe how the different
|
||||
/// aspects of the texture should be bound in order to allow shader
|
||||
/// access. Most textures will have a single binding for the role
|
||||
/// "texels", but some textures might need multiple bindings, e.g. a
|
||||
/// ptexTexture will have an additional binding for the role "layout".
|
||||
///
|
||||
struct Binding {
|
||||
Binding(TfToken name, TfToken role, GLenum target,
|
||||
GLuint textureId, GLuint samplerId)
|
||||
: name(name)
|
||||
, role(role)
|
||||
, target(target)
|
||||
, textureId(textureId)
|
||||
, samplerId(samplerId) { }
|
||||
|
||||
TfToken name;
|
||||
TfToken role;
|
||||
GLenum target;
|
||||
GLuint textureId;
|
||||
GLuint samplerId;
|
||||
};
|
||||
typedef std::vector<Binding> BindingVector;
|
||||
|
||||
GLF_API
|
||||
virtual ~GlfTexture() = 0;
|
||||
|
||||
// Disallow copies
|
||||
GlfTexture(const GlfTexture&) = delete;
|
||||
GlfTexture& operator=(const GlfTexture&) = delete;
|
||||
|
||||
/// Returns the bindings to use this texture for the shader resource
|
||||
/// named \a identifier. If \a samplerId is specified, the bindings
|
||||
/// returned will use this samplerId for resources which can be sampled.
|
||||
virtual BindingVector GetBindings(TfToken const & identifier,
|
||||
GLuint samplerId = 0) = 0;
|
||||
|
||||
/// Returns the OpenGl texture name for the texture.
|
||||
virtual GLuint GetGlTextureName() = 0;
|
||||
|
||||
/// Amount of memory used to store the texture
|
||||
GLF_API
|
||||
size_t GetMemoryUsed() const;
|
||||
|
||||
/// Amount of memory the user wishes to allocate to the texture
|
||||
GLF_API
|
||||
size_t GetMemoryRequested() const;
|
||||
|
||||
/// Specify the amount of memory the user wishes to allocate to the texture
|
||||
GLF_API
|
||||
void SetMemoryRequested(size_t targetMemory);
|
||||
|
||||
virtual VtDictionary GetTextureInfo(bool forceLoad) = 0;
|
||||
|
||||
GLF_API
|
||||
virtual bool IsMinFilterSupported(GLenum filter);
|
||||
|
||||
GLF_API
|
||||
virtual bool IsMagFilterSupported(GLenum filter);
|
||||
|
||||
/// static reporting function
|
||||
GLF_API
|
||||
static size_t GetTextureMemoryAllocated();
|
||||
|
||||
/// Returns an identifier that can be used to determine when the
|
||||
/// contents of this texture (i.e. its image data) has changed.
|
||||
///
|
||||
/// The contents of most textures will be immutable for the lifetime
|
||||
/// of the texture. However, the contents of the texture attachments
|
||||
/// of a draw target change when the draw target is updated.
|
||||
GLF_API
|
||||
size_t GetContentsID() const;
|
||||
|
||||
GLF_API
|
||||
HioImage::ImageOriginLocation GetOriginLocation() const;
|
||||
|
||||
GLF_API
|
||||
bool IsOriginLowerLeft() const;
|
||||
|
||||
protected:
|
||||
GLF_API
|
||||
GlfTexture();
|
||||
|
||||
GLF_API
|
||||
GlfTexture(HioImage::ImageOriginLocation originLocation);
|
||||
|
||||
GLF_API
|
||||
void _SetMemoryUsed(size_t size);
|
||||
|
||||
GLF_API
|
||||
virtual void _OnMemoryRequestedDirty();
|
||||
|
||||
GLF_API
|
||||
void _UpdateContentsID();
|
||||
|
||||
private:
|
||||
size_t _memoryUsed;
|
||||
size_t _memoryRequested;
|
||||
size_t _contentsID;
|
||||
HioImage::ImageOriginLocation _originLocation;
|
||||
};
|
||||
|
||||
class GlfTextureFactoryBase : public TfType::FactoryBase {
|
||||
public:
|
||||
virtual GlfTextureRefPtr New(const TfToken& texturePath,
|
||||
HioImage::ImageOriginLocation originLocation) const = 0;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_GLF_TEXTURE_H
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_UNIFORM_BLOCK_H
|
||||
#define PXR_IMAGING_GLF_UNIFORM_BLOCK_H
|
||||
|
||||
/// \file glf/uniformBlock.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/imaging/garch/glApi.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/refBase.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(GlfUniformBlock);
|
||||
TF_DECLARE_WEAK_PTRS(GlfBindingMap);
|
||||
|
||||
/// \class GlfUniformBlock
|
||||
///
|
||||
/// Manages a GL uniform buffer object.
|
||||
///
|
||||
class GlfUniformBlock : public TfRefBase, public TfWeakBase {
|
||||
public:
|
||||
|
||||
/// Returns a new instance.
|
||||
GLF_API
|
||||
static GlfUniformBlockRefPtr New(char const *label = nullptr);
|
||||
|
||||
GLF_API
|
||||
virtual ~GlfUniformBlock();
|
||||
|
||||
/// Binds the uniform buffer using a bindingMap and identifier.
|
||||
GLF_API
|
||||
void Bind(GlfBindingMapPtr const & bindingMap,
|
||||
std::string const & identifier);
|
||||
|
||||
/// Updates the content of the uniform buffer. If the size
|
||||
/// is different, the buffer will be reallocated.
|
||||
GLF_API
|
||||
void Update(const void *data, int size);
|
||||
|
||||
protected:
|
||||
GLF_API
|
||||
GlfUniformBlock(char const *label);
|
||||
|
||||
private:
|
||||
GLuint _buffer;
|
||||
int _size;
|
||||
std::string _debugLabel;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_GLF_UTILS_H
|
||||
#define PXR_IMAGING_GLF_UTILS_H
|
||||
|
||||
/// \file glf/utils.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/glf/api.h"
|
||||
#include "pxr/imaging/garch/glApi.h"
|
||||
#include "pxr/imaging/hio/types.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Number of elements.
|
||||
///
|
||||
/// Returns the number of elements (channels) in a given GL enum format.
|
||||
///
|
||||
/// Supported formats are : GL_DEPTH_COMPONENT, GL_COLOR_INDEX, GL_ALPHA,
|
||||
/// GL_RED, GL_LUMINANCE, GL_RG, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA
|
||||
GLF_API
|
||||
int GlfGetNumElements(GLenum format);
|
||||
|
||||
/// Byte size of a GL type.
|
||||
///
|
||||
/// Returns the size in bytes of a given GL type.
|
||||
///
|
||||
/// Supported types are : GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT,
|
||||
/// GL_SHORT, GL_FLOAT, GL_DOUBLE
|
||||
GLF_API
|
||||
int GlfGetElementSize(GLenum type);
|
||||
|
||||
/// HioFormat
|
||||
///
|
||||
/// Returns the HioFormat for the given GL format and GL type
|
||||
///
|
||||
/// Supported formats are : GL_DEPTH_COMPONENT, GL_COLOR_INDEX, GL_ALPHA,
|
||||
/// GL_RED, GL_LUMINANCE, GL_RG, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA
|
||||
///
|
||||
/// Supported types are : GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT,
|
||||
/// GL_SHORT, GL_FLOAT, GL_DOUBLE
|
||||
GLF_API
|
||||
HioFormat GlfGetHioFormat(GLenum glFormat, GLenum glType, bool isSRGB);
|
||||
|
||||
|
||||
/// Checks the valitidy of a GL framebuffer
|
||||
///
|
||||
/// True if the currently bound GL framebuffer is valid and can be bound
|
||||
/// or returns the cause of the problem
|
||||
GLF_API
|
||||
bool GlfCheckGLFrameBufferStatus(GLuint target, std::string * reason);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,186 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_AOV_H
|
||||
#define PXR_IMAGING_HD_AOV_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/gf/vec3i.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
typedef TfHashMap<TfToken, VtValue, TfToken::HashFunctor> HdAovSettingsMap;
|
||||
|
||||
/// \class HdAovDescriptor
|
||||
///
|
||||
/// A bundle of state describing an AOV ("Arbitrary Output Variable") display
|
||||
/// channel. Note that in hydra API, this data is split between
|
||||
/// HdRenderPassAovBinding and HdRenderBufferDescriptor. This class is
|
||||
/// provided for use in higher level application-facing API.
|
||||
struct HdAovDescriptor
|
||||
{
|
||||
HdAovDescriptor()
|
||||
: format(HdFormatInvalid), multiSampled(false)
|
||||
, clearValue(), aovSettings() {}
|
||||
HdAovDescriptor(HdFormat f, bool ms, VtValue const& c)
|
||||
: format(f), multiSampled(ms), clearValue(c), aovSettings() {}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Render buffer parameters
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
/// The AOV output format. See also HdRenderBufferDescriptor#format.
|
||||
HdFormat format;
|
||||
|
||||
/// Whether the render buffer should be multisampled.
|
||||
/// See also HdRenderBufferDescriptor#multiSampled.
|
||||
bool multiSampled;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Renderpass binding parameters.
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
/// The clear value to apply to the render buffer before rendering.
|
||||
/// The type of "clearValue" should match the provided format.
|
||||
/// If clearValue is empty, no clear will be performed.
|
||||
/// See also HdRenderPassAovBinding#clearValue.
|
||||
VtValue clearValue;
|
||||
|
||||
/// Extra settings for AOV rendering, such as pixel filtering options.
|
||||
/// See also HdRenderPassAovBinding#aovSettings.
|
||||
HdAovSettingsMap aovSettings;
|
||||
};
|
||||
typedef std::vector<HdAovDescriptor> HdAovDescriptorList;
|
||||
|
||||
/// \struct HdRenderBufferDescriptor
|
||||
///
|
||||
/// Describes the allocation structure of a render buffer bprim.
|
||||
struct HdRenderBufferDescriptor {
|
||||
/// The width, height, and depth of the allocated render buffer.
|
||||
GfVec3i dimensions;
|
||||
|
||||
/// The data format of the render buffer. See also HdAovDescriptor#format.
|
||||
HdFormat format;
|
||||
|
||||
/// Whether the render buffer should be multisampled. See also
|
||||
/// HdAovDescriptor#multiSampled.
|
||||
bool multiSampled;
|
||||
|
||||
bool operator==(HdRenderBufferDescriptor const& rhs) const {
|
||||
return dimensions == rhs.dimensions &&
|
||||
format == rhs.format && multiSampled == rhs.multiSampled;
|
||||
}
|
||||
bool operator!=(HdRenderBufferDescriptor const& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
/// \class HdRenderPassAovBinding
|
||||
///
|
||||
/// A renderpass AOV represents a binding of some output of the
|
||||
/// rendering process to an output buffer.
|
||||
|
||||
class HdRenderBuffer;
|
||||
|
||||
struct HdRenderPassAovBinding {
|
||||
|
||||
HdRenderPassAovBinding()
|
||||
: renderBuffer(nullptr) {}
|
||||
|
||||
/// The identifier of the renderer output to be consumed. This should take
|
||||
/// a value from HdAovTokens.
|
||||
/// XXX: Depth aov bindings are identified by the "depth" suffix.
|
||||
/// See HdAovHasDepthSemantic().
|
||||
TfToken aovName;
|
||||
|
||||
/// The render buffer to be bound to the above terminal output.
|
||||
///
|
||||
/// From the app or scene, this can be specified as either a pointer or
|
||||
/// a path to a renderbuffer in the render index. If both are specified,
|
||||
/// the pointer is used preferentially.
|
||||
///
|
||||
/// Note: hydra never takes ownership of the renderBuffer, but assumes it
|
||||
/// will be alive until the end of the renderpass, or whenever the buffer
|
||||
/// is marked converged, whichever is later.
|
||||
HdRenderBuffer* renderBuffer;
|
||||
|
||||
/// The render buffer to be bound to the above terminal output.
|
||||
SdfPath renderBufferId;
|
||||
|
||||
/// The clear value to apply to the bound render buffer, before rendering.
|
||||
/// The type of "clearValue" should match the type of the bound buffer.
|
||||
/// If clearValue is empty, it indicates no clear should be performed.
|
||||
/// See also HdAovDescriptor#clearValue.
|
||||
VtValue clearValue;
|
||||
|
||||
/// Extra settings for AOV rendering, such as pixel filtering options.
|
||||
/// See also HdAovDescriptor#aovSettings.
|
||||
HdAovSettingsMap aovSettings;
|
||||
};
|
||||
|
||||
typedef std::vector<HdRenderPassAovBinding> HdRenderPassAovBindingVector;
|
||||
|
||||
// VtValue requirements for HdRenderPassAovBinding
|
||||
HD_API
|
||||
std::ostream& operator<<(std::ostream& out,
|
||||
const HdRenderPassAovBinding& desc);
|
||||
HD_API
|
||||
bool operator==(const HdRenderPassAovBinding& lhs,
|
||||
const HdRenderPassAovBinding& rhs);
|
||||
HD_API
|
||||
bool operator!=(const HdRenderPassAovBinding& lhs,
|
||||
const HdRenderPassAovBinding& rhs);
|
||||
|
||||
HD_API
|
||||
size_t hash_value(const HdRenderPassAovBinding &b);
|
||||
|
||||
/// Returns true if the aov is used as a depth binding based on its name.
|
||||
HD_API
|
||||
bool HdAovHasDepthSemantic(TfToken const& aovName);
|
||||
|
||||
/// \class HdParsedAovToken
|
||||
///
|
||||
/// Represents an AOV token which has been parsed to extract the prefix
|
||||
/// (in the case of "primvars:"/"lpe:"/etc.).
|
||||
struct HdParsedAovToken {
|
||||
HD_API
|
||||
HdParsedAovToken();
|
||||
HD_API
|
||||
HdParsedAovToken(TfToken const& aovName);
|
||||
|
||||
TfToken name;
|
||||
bool isPrimvar : 1;
|
||||
bool isLpe : 1;
|
||||
bool isShader : 1;
|
||||
};
|
||||
typedef std::vector<HdParsedAovToken> HdParsedAovTokenVector;
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_AOV_H
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_API_H
|
||||
#define PXR_IMAGING_HD_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define HD_API
|
||||
# define HD_API_TEMPLATE_CLASS(...)
|
||||
# define HD_API_TEMPLATE_STRUCT(...)
|
||||
# define HD_LOCAL
|
||||
#else
|
||||
# if defined(HD_EXPORTS)
|
||||
# define HD_API ARCH_EXPORT
|
||||
# define HD_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define HD_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define HD_API ARCH_IMPORT
|
||||
# define HD_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define HD_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define HD_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif // PXR_IMAGING_HD_API_H
|
||||
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BASIS_CURVES_H
|
||||
#define PXR_IMAGING_HD_BASIS_CURVES_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/rprim.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
#define HD_BASISCURVES_REPR_DESC_TOKENS \
|
||||
(surfaceShader) \
|
||||
(hullColor) \
|
||||
(pointColor)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdBasisCurvesReprDescTokens, HD_API,
|
||||
HD_BASISCURVES_REPR_DESC_TOKENS);
|
||||
|
||||
/// \class HdBasisCurvesReprDesc
|
||||
///
|
||||
/// Descriptor to configure a drawItem for a repr.
|
||||
///
|
||||
struct HdBasisCurvesReprDesc {
|
||||
HdBasisCurvesReprDesc(
|
||||
HdBasisCurvesGeomStyle geomStyle = HdBasisCurvesGeomStyleInvalid,
|
||||
TfToken shadingTerminal = HdBasisCurvesReprDescTokens->surfaceShader)
|
||||
: geomStyle(geomStyle),
|
||||
shadingTerminal(shadingTerminal)
|
||||
{}
|
||||
|
||||
bool IsEmpty() const {
|
||||
return geomStyle == HdBasisCurvesGeomStyleInvalid;
|
||||
}
|
||||
|
||||
HdBasisCurvesGeomStyle geomStyle;
|
||||
/// Specifies how the fragment color should be computed from primvar;
|
||||
/// this can be used to render heatmap highlighting etc.
|
||||
TfToken shadingTerminal;
|
||||
};
|
||||
|
||||
/// Hydra Schema for a collection of curves using a particular basis.
|
||||
///
|
||||
class HdBasisCurves : public HdRprim {
|
||||
public:
|
||||
HD_API
|
||||
virtual ~HdBasisCurves();
|
||||
|
||||
///
|
||||
/// Topology
|
||||
///
|
||||
inline HdBasisCurvesTopology GetBasisCurvesTopology(HdSceneDelegate* delegate) const;
|
||||
inline HdDisplayStyle GetDisplayStyle(HdSceneDelegate* delegate) const;
|
||||
|
||||
HD_API
|
||||
TfTokenVector const & GetBuiltinPrimvarNames() const override;
|
||||
|
||||
/// Configure geometric style of drawItems for \p reprName
|
||||
HD_API
|
||||
static void ConfigureRepr(TfToken const &reprName,
|
||||
HdBasisCurvesReprDesc desc);
|
||||
|
||||
/// Returns whether refinement is always on or not.
|
||||
HD_API
|
||||
static bool IsEnabledForceRefinedCurves();
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
HdBasisCurves(SdfPath const& id);
|
||||
|
||||
typedef _ReprDescConfigs<HdBasisCurvesReprDesc> _BasisCurvesReprConfig;
|
||||
|
||||
HD_API
|
||||
static _BasisCurvesReprConfig::DescArray
|
||||
_GetReprDesc(TfToken const &reprName);
|
||||
|
||||
private:
|
||||
// Class can not be default constructed or copied.
|
||||
HdBasisCurves() = delete;
|
||||
HdBasisCurves(const HdBasisCurves &) = delete;
|
||||
HdBasisCurves &operator =(const HdBasisCurves &) = delete;
|
||||
|
||||
static _BasisCurvesReprConfig _reprDescConfig;
|
||||
};
|
||||
|
||||
inline HdBasisCurvesTopology
|
||||
HdBasisCurves::GetBasisCurvesTopology(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetBasisCurvesTopology(GetId());
|
||||
}
|
||||
|
||||
inline HdDisplayStyle
|
||||
HdBasisCurves::GetDisplayStyle(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetDisplayStyle(GetId());
|
||||
}
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BASIS_CURVES_H
|
||||
@@ -0,0 +1,175 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BASIS_CURVES_TOPOLOGY_H
|
||||
#define PXR_IMAGING_HD_BASIS_CURVES_TOPOLOGY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/topology.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdBasisCurvesTopology
|
||||
///
|
||||
/// Topology data for basisCurves.
|
||||
///
|
||||
/// HdBasisCurvesTopology holds the raw input topology data for basisCurves
|
||||
///
|
||||
/// The Type, Basis and Wrap mode combined describe the curve and it's
|
||||
/// segments.
|
||||
///
|
||||
/// If Type == linear, the curve is a bunch of line segments and basis is
|
||||
/// ignored.
|
||||
///
|
||||
/// The wrap mode defines how the curve segments are specified:
|
||||
///
|
||||
/// If Wrap == segmented, this is equivalent to GL_LINES and curve vertex
|
||||
/// counts is 2 * number of segments (multiple entries in curve vertex
|
||||
/// array is optional).
|
||||
///
|
||||
/// If Wrap == nonperiodic, this is equivalent to GL_LINE_STRIP and curve
|
||||
/// counts is an array where each entry is the number of vertices in that
|
||||
/// line segment. The first and last vertex in the segment are not joined.
|
||||
///
|
||||
/// If Wrap == periodic, this is equivalent to GL_LINE_LOOP and curve counts
|
||||
/// is an array where each entry is the number of vertices in that line
|
||||
/// segment. An additional line is place between the first and last vertex
|
||||
/// in each segment.
|
||||
///
|
||||
/// If Type == cubic, the type of curve is specified by basis:
|
||||
/// The Basis can be bezier, bspline or catmullRom.
|
||||
///
|
||||
/// Wrap can be either periodic or nonperiodic (segmented is unsupported).
|
||||
///
|
||||
/// For each type of line, the generated vertex indices can pass through an
|
||||
/// optional index buffer to map the generated indices to actual indices in
|
||||
/// the vertex buffer.
|
||||
///
|
||||
class HdBasisCurvesTopology : public HdTopology {
|
||||
public:
|
||||
|
||||
HD_API
|
||||
HdBasisCurvesTopology();
|
||||
HD_API
|
||||
HdBasisCurvesTopology(const HdBasisCurvesTopology &src);
|
||||
|
||||
HD_API
|
||||
HdBasisCurvesTopology(const TfToken &curveType,
|
||||
const TfToken &curveBasis,
|
||||
const TfToken &curveWrap,
|
||||
const VtIntArray &curveVertexCounts,
|
||||
const VtIntArray &curveIndices);
|
||||
HD_API
|
||||
virtual ~HdBasisCurvesTopology();
|
||||
|
||||
///
|
||||
/// \name Topological invisibility
|
||||
/// @{
|
||||
///
|
||||
HD_API
|
||||
void SetInvisiblePoints(VtIntArray const &invisiblePoints) {
|
||||
_invisiblePoints = invisiblePoints;
|
||||
}
|
||||
|
||||
HD_API
|
||||
VtIntArray const & GetInvisiblePoints() const {
|
||||
return _invisiblePoints;
|
||||
}
|
||||
|
||||
HD_API
|
||||
void SetInvisibleCurves(VtIntArray const &invisibleCurves) {
|
||||
_invisibleCurves = invisibleCurves;
|
||||
}
|
||||
|
||||
HD_API
|
||||
VtIntArray const & GetInvisibleCurves() const {
|
||||
return _invisibleCurves;
|
||||
}
|
||||
/// @}
|
||||
|
||||
/// Returns segment vertex counts.
|
||||
VtIntArray const &GetCurveVertexCounts() const {
|
||||
return _curveVertexCounts;
|
||||
}
|
||||
|
||||
/// Returns indices.
|
||||
VtIntArray const &GetCurveIndices() const {
|
||||
return _curveIndices;
|
||||
}
|
||||
|
||||
/// Returns the number of curves
|
||||
size_t GetNumCurves() const {
|
||||
return _curveVertexCounts.size();
|
||||
}
|
||||
|
||||
/// See class documentation for valid combination of values
|
||||
TfToken GetCurveType() const { return _curveType; }
|
||||
TfToken GetCurveBasis() const { return _curveBasis; }
|
||||
TfToken GetCurveWrap() const { return _curveWrap; }
|
||||
|
||||
/// Does the topology use an index buffer
|
||||
bool HasIndices() const { return !_curveIndices.empty(); }
|
||||
|
||||
/// Returns the hash value of this topology to be used for instancing.
|
||||
HD_API
|
||||
virtual ID ComputeHash() const;
|
||||
|
||||
/// Equality check between two basisCurves topologies.
|
||||
HD_API
|
||||
bool operator==(HdBasisCurvesTopology const &other) const;
|
||||
HD_API
|
||||
bool operator!=(HdBasisCurvesTopology const &other) const;
|
||||
|
||||
/// Figure out how many vertices / control points this topology references
|
||||
HD_API
|
||||
size_t CalculateNeededNumberOfControlPoints() const;
|
||||
|
||||
/// Figure out how many control points with varying data this topology needs
|
||||
HD_API
|
||||
size_t CalculateNeededNumberOfVaryingControlPoints() const;
|
||||
|
||||
private:
|
||||
TfToken _curveType;
|
||||
TfToken _curveBasis;
|
||||
TfToken _curveWrap;
|
||||
VtIntArray _curveVertexCounts;
|
||||
VtIntArray _curveIndices;
|
||||
VtIntArray _invisiblePoints;
|
||||
VtIntArray _invisibleCurves;
|
||||
};
|
||||
|
||||
HD_API
|
||||
std::ostream& operator << (std::ostream &out, HdBasisCurvesTopology const &topo);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BASIS_CURVES_TOPOLOGY_H
|
||||
@@ -0,0 +1,303 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BINDING_H
|
||||
#define PXR_IMAGING_HD_BINDING_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/imaging/hd/bufferResource.h"
|
||||
#include "pxr/imaging/hd/bufferArrayRange.h"
|
||||
|
||||
#include "pxr/base/tf/hash.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
typedef std::vector<class HdBinding> HdBindingVector;
|
||||
typedef std::vector<class HdBindingRequest> HdBindingRequestVector;
|
||||
|
||||
/// \class HdBinding
|
||||
///
|
||||
/// Bindings are used for buffers or textures, it simple associates a binding
|
||||
/// type with a binding location.
|
||||
///
|
||||
class HdBinding {
|
||||
public:
|
||||
enum Type { // primvar, drawing coordinate and dispatch buffer bindings
|
||||
// also shader fallback values
|
||||
UNKNOWN,
|
||||
DISPATCH, // GL_DRAW_INDIRECT_BUFFER
|
||||
DRAW_INDEX, // per-drawcall. not instanced
|
||||
DRAW_INDEX_INSTANCE, // per-drawcall. attribdivisor=on
|
||||
DRAW_INDEX_INSTANCE_ARRAY, // per-drawcall. attribdivisor=on, array
|
||||
VERTEX_ATTR, // vertex-attribute
|
||||
INDEX_ATTR, // GL_ELEMENT_ARRAY_BUFFER
|
||||
SSBO, //
|
||||
BINDLESS_SSBO_RANGE, //
|
||||
UBO, //
|
||||
BINDLESS_UNIFORM, //
|
||||
UNIFORM, //
|
||||
UNIFORM_ARRAY, //
|
||||
|
||||
// shader parameter bindings
|
||||
FALLBACK, // fallback value
|
||||
TEXTURE_2D, // non-bindless uv texture
|
||||
TEXTURE_FIELD, // non-bindless field texture
|
||||
// creates accessor that samples uvw
|
||||
// texture after transforming coordinates
|
||||
// by a sampling transform
|
||||
TEXTURE_UDIM_ARRAY, // non-bindless udim texture array
|
||||
TEXTURE_UDIM_LAYOUT, // non-bindless udim layout
|
||||
TEXTURE_PTEX_TEXEL, // non-bindless ptex texels
|
||||
TEXTURE_PTEX_LAYOUT, // non-bindless ptex layout
|
||||
BINDLESS_TEXTURE_2D, // bindless uv texture
|
||||
BINDLESS_TEXTURE_FIELD, // bindless field texture
|
||||
// (see above)
|
||||
BINDLESS_TEXTURE_UDIM_ARRAY, // bindless uv texture array
|
||||
BINDLESS_TEXTURE_UDIM_LAYOUT, // bindless udim layout
|
||||
BINDLESS_TEXTURE_PTEX_TEXEL, // bindless ptex texels
|
||||
BINDLESS_TEXTURE_PTEX_LAYOUT, // bindless ptex layout
|
||||
PRIMVAR_REDIRECT, // primvar redirection
|
||||
FIELD_REDIRECT, // accesses a field texture by name and
|
||||
// uses fallbackValue if no accessor for
|
||||
// the texture exists.
|
||||
TRANSFORM_2D // transform2d
|
||||
};
|
||||
enum Location {
|
||||
// NOT_EXIST is a special value of location for a uniform
|
||||
// which is assigned but optimized out after linking program.
|
||||
NOT_EXIST = 0xffff
|
||||
};
|
||||
HdBinding() : _typeAndLocation(-1) { }
|
||||
HdBinding(Type type, int location, int textureUnit=0) {
|
||||
Set(type, location, textureUnit);
|
||||
}
|
||||
void Set(Type type, int location, int textureUnit) {
|
||||
_typeAndLocation = (textureUnit << 24)|(location << 8)|(int)(type);
|
||||
}
|
||||
bool IsValid() const { return _typeAndLocation >= 0; }
|
||||
Type GetType() const { return (Type)(_typeAndLocation & 0xff); }
|
||||
int GetLocation() const { return (_typeAndLocation >> 8) & 0xffff; }
|
||||
int GetTextureUnit() const { return (_typeAndLocation >> 24) & 0xff; }
|
||||
int GetValue() const { return _typeAndLocation; }
|
||||
bool operator < (HdBinding const &b) const {
|
||||
return (_typeAndLocation < b._typeAndLocation);
|
||||
}
|
||||
private:
|
||||
int _typeAndLocation;
|
||||
};
|
||||
|
||||
/// BindingRequest allows externally allocated buffers to be bound at render
|
||||
/// time. The different modes of binding discussed below allow the caller a
|
||||
/// range of opt-in binding behaviors, from simply reserving a binding location
|
||||
/// so it can be managed from client code, to fully generating buffer accessor
|
||||
/// code at compile time (i.e. when using a BufferArrayRange or BufferResource).
|
||||
///
|
||||
/// This is a "request" because the caller makes a request before bindings are
|
||||
/// resolved. All requests are consulted and fulfilled during binding
|
||||
/// resolution.
|
||||
class HdBindingRequest {
|
||||
public:
|
||||
|
||||
HdBindingRequest() = default;
|
||||
|
||||
/// A data binding, not backed by neither BufferArrayRange nor
|
||||
/// BufferResource. This binding request simply
|
||||
/// generates named metadata (#define HD_HAS_foo 1, #define HD_foo_Binding)
|
||||
HdBindingRequest(HdBinding::Type bindingType, TfToken const& name)
|
||||
: _bindingType(bindingType)
|
||||
, _dataType(HdTypeInvalid)
|
||||
, _name(name)
|
||||
, _resource(nullptr)
|
||||
, _bar(nullptr)
|
||||
, _isInterleaved(false)
|
||||
{}
|
||||
|
||||
/// A data binding, not backed by neither BufferArrayRange nor
|
||||
/// BufferResource.
|
||||
HdBindingRequest(HdBinding::Type bindingType, TfToken const& name,
|
||||
HdType dataType)
|
||||
: _bindingType(bindingType)
|
||||
, _dataType(dataType)
|
||||
, _name(name)
|
||||
, _resource(nullptr)
|
||||
, _bar(nullptr)
|
||||
, _isInterleaved(false)
|
||||
{}
|
||||
|
||||
/// A buffer resource binding. Binds a given buffer resource to a specified
|
||||
/// name. The data type is set from the resource.
|
||||
HdBindingRequest(HdBinding::Type bindingType, TfToken const& name,
|
||||
HdBufferResourceSharedPtr const& resource)
|
||||
: _bindingType(bindingType)
|
||||
, _dataType(resource->GetTupleType().type)
|
||||
, _name(name)
|
||||
, _resource(resource)
|
||||
, _bar(nullptr)
|
||||
, _isInterleaved(false)
|
||||
{}
|
||||
|
||||
/// A named struct binding. From an interleaved BufferArray, an array of
|
||||
/// structs will be generated, consuming a single binding point. Note that
|
||||
/// all resources in the buffer array must have the same underlying
|
||||
/// identifier, hence must be interleaved and bindable as a single resource.
|
||||
/// Data types can be derived from each HdBufferResource of bar.
|
||||
HdBindingRequest(HdBinding::Type type, TfToken const& name,
|
||||
HdBufferArrayRangeSharedPtr bar,
|
||||
bool interleave)
|
||||
: _bindingType(type)
|
||||
, _dataType(HdTypeInvalid)
|
||||
, _name(name)
|
||||
, _resource(nullptr)
|
||||
, _bar(bar)
|
||||
, _isInterleaved(interleave)
|
||||
{}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Discriminators
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Resource bingings have a single associated Hydra resource, but no buffer
|
||||
/// array.
|
||||
bool IsResource() const {
|
||||
return bool(_resource);
|
||||
}
|
||||
|
||||
/// A buffer array binding has several buffers bundled together and each
|
||||
/// buffer will be bound individually and exposed as independent arrays in
|
||||
/// the shader.
|
||||
bool IsBufferArray() const {
|
||||
return _bar && !_isInterleaved;
|
||||
}
|
||||
|
||||
/// Like BufferArray binding requests, struct bindings have several buffers,
|
||||
/// however they must be allocated into a single resource and interleaved.
|
||||
/// This type of binding request is exposed in the shader an array of
|
||||
/// structs.
|
||||
bool IsInterleavedBufferArray() const {
|
||||
return _bar && _isInterleaved;
|
||||
}
|
||||
|
||||
/// This binding is typelss. CodeGen only allocate location and
|
||||
/// skip emitting declarations and accessors.
|
||||
bool IsTypeless() const {
|
||||
return (!_bar) && (!_resource) && (_dataType == HdTypeInvalid);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Accessors
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the name of the binding point, if any; buffer arrays and structs
|
||||
/// need not be named.
|
||||
TfToken const& GetName() const {
|
||||
return _name;
|
||||
}
|
||||
/// Returns the HdBinding type of this request.
|
||||
HdBinding::Type GetBindingType() const {
|
||||
return _bindingType;
|
||||
}
|
||||
/// Returns the single resource associated with this binding request or
|
||||
/// null when IsResource() returns false.
|
||||
HdBufferResourceSharedPtr const& GetResource() const {
|
||||
return _resource;
|
||||
}
|
||||
/// Returns the resource or buffer array range offset, defaults to zero.
|
||||
int GetByteOffset() const {
|
||||
// buffer resource binding
|
||||
if (_resource) return _resource->GetOffset();
|
||||
|
||||
// named struct binding (interleaved) - the resource name doesn't matter
|
||||
// since a single binding point is used.
|
||||
if (_bar) return _bar->GetByteOffset(TfToken());
|
||||
return 0;
|
||||
}
|
||||
/// Returns the buffer array range associated with this binding request or
|
||||
/// null when IsBufferArrqay() returns false.
|
||||
HdBufferArrayRangeSharedPtr const& GetBar() const {
|
||||
return _bar;
|
||||
}
|
||||
|
||||
/// Return the data type of this request
|
||||
HdType GetDataType() const {
|
||||
return _dataType;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Comparison
|
||||
// ---------------------------------------------------------------------- //
|
||||
HD_API
|
||||
bool operator==(HdBindingRequest const &other) const;
|
||||
|
||||
HD_API
|
||||
bool operator!=(HdBindingRequest const &other) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Hash
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the hash corresponding to this buffer request.
|
||||
///
|
||||
/// Note that this hash captures the structural state of the request, not
|
||||
/// the contents. For example, buffer array versions/reallocations will not
|
||||
/// affect hash, but changing the BAR pointer will.
|
||||
HD_API
|
||||
size_t ComputeHash() const;
|
||||
|
||||
// TfHash support.
|
||||
template <class HashState>
|
||||
friend void TfHashAppend(HashState &h, HdBindingRequest const &br) {
|
||||
h.Append(br._name,
|
||||
br._bindingType,
|
||||
br._dataType,
|
||||
br._isInterleaved);
|
||||
}
|
||||
|
||||
private:
|
||||
// This class unfortunately represents several concepts packed into a single
|
||||
// class. Ideally, we would break this out as one class per concept,
|
||||
// however that would also require virtual dispatch, which is overkill for
|
||||
// the current use cases.
|
||||
|
||||
// Named binding request
|
||||
HdBinding::Type _bindingType;
|
||||
HdType _dataType;
|
||||
TfToken _name;
|
||||
|
||||
// Resource binding request
|
||||
HdBufferResourceSharedPtr _resource;
|
||||
|
||||
// Struct binding request
|
||||
HdBufferArrayRangeSharedPtr _bar;
|
||||
bool _isInterleaved;
|
||||
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BINDING_H
|
||||
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BPRIM_H
|
||||
#define PXR_IMAGING_HD_BPRIM_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
class HdRenderParam;
|
||||
|
||||
/// \class HdBprim
|
||||
///
|
||||
/// Bprim (buffer prim) is a base class of managing a blob of data that is
|
||||
/// used to communicate between the scene delegate and render.
|
||||
///
|
||||
/// Like other prim types (Rprim and Sprim), the Bprim communicates with the
|
||||
/// scene delegate got get buffer properties (e.g. the size of the buffer) as
|
||||
/// well as the contents of the buffer.
|
||||
///
|
||||
/// Changes to the properties and contents are change tracked and updates
|
||||
/// are cached in the renderer. The Render Delegate may choose to transform
|
||||
/// the data into a renderer specific form on download.
|
||||
///
|
||||
/// BPrims are sync'ed first and thus, Bprims should not be
|
||||
/// Dependent on the state of any other prim.
|
||||
///
|
||||
/// The most typical use of a Bprim would be a Texture.
|
||||
class HdBprim {
|
||||
public:
|
||||
HD_API
|
||||
HdBprim(SdfPath const & id);
|
||||
HD_API
|
||||
virtual ~HdBprim();
|
||||
|
||||
/// Returns the identifier by which this buffer is known. This
|
||||
/// identifier is a common associative key used by the SceneDelegate,
|
||||
/// RenderIndex, and for binding to the buffer
|
||||
SdfPath const& GetId() const { return _id; }
|
||||
|
||||
/// Synchronizes state from the delegate to this object.
|
||||
/// @param[in, out] dirtyBits: On input specifies which state is
|
||||
/// is dirty and can be pulled from the scene
|
||||
/// delegate.
|
||||
/// On output specifies which bits are still
|
||||
/// dirty and were not cleaned by the sync.
|
||||
///
|
||||
virtual void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) = 0;
|
||||
|
||||
/// Finalizes object resources. This function might not delete resources,
|
||||
/// but it should deal with resource ownership so that the sprim is
|
||||
/// deletable.
|
||||
HD_API
|
||||
virtual void Finalize(HdRenderParam *renderParam);
|
||||
|
||||
/// Returns the minimal set of dirty bits to place in the
|
||||
/// change tracker for use in the first sync of this prim.
|
||||
/// Typically this would be all dirty bits.
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const = 0;
|
||||
|
||||
private:
|
||||
SdfPath _id;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BPRIM_H
|
||||
@@ -0,0 +1,207 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_ARRAY_H
|
||||
#define PXR_IMAGING_HD_BUFFER_ARRAY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/bufferResource.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdBufferArrayRange;
|
||||
|
||||
using HdBufferArraySharedPtr = std::shared_ptr<class HdBufferArray>;
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<HdBufferArrayRange>;
|
||||
using HdBufferArrayRangePtr = std::weak_ptr<HdBufferArrayRange>;
|
||||
|
||||
/// \union HdBufferArrayUsageHint
|
||||
///
|
||||
/// The union provides a set of flags that provide hints to the memory
|
||||
/// management system about the properties of a Buffer Array Range (BAR),
|
||||
/// so it can efficiently organize that memory. For example,
|
||||
/// the memory manager should probably not aggregate BARs with different
|
||||
/// usage hints.
|
||||
///
|
||||
/// The union provides two members:
|
||||
/// - value: The combined set of flags
|
||||
/// - bits: Access to individual flag bits
|
||||
///
|
||||
/// The flag bits are:
|
||||
/// - immutable: The BAR will not be modified once created and populated.
|
||||
/// - sizeVarying: The number of elements in the BAR changes with time.
|
||||
///
|
||||
/// Some flag bits may not make sense in combination
|
||||
/// (i.e. mutually exclusive to each other). For example, it is logically
|
||||
/// impossible to be both immutable (i.e. not changing) and sizeVarying
|
||||
/// (changing). However, these logically impossible combinations are
|
||||
/// not enforced and remain valid potential values.
|
||||
///
|
||||
union HdBufferArrayUsageHint {
|
||||
struct _Bits {
|
||||
uint32_t immutable : 1;
|
||||
uint32_t sizeVarying : 1;
|
||||
uint32_t pad : 30;
|
||||
} bits;
|
||||
uint32_t value;
|
||||
|
||||
HdBufferArrayUsageHint() : value(0) {}
|
||||
};
|
||||
|
||||
|
||||
/// \class HdBufferArray
|
||||
///
|
||||
/// Similar to a VAO, this object is a bundle of coherent buffers. This object
|
||||
/// can be shared across multiple HdRprims, in the context of buffer
|
||||
/// aggregation.
|
||||
///
|
||||
class HdBufferArray : public std::enable_shared_from_this<HdBufferArray>
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
HdBufferArray(TfToken const &role,
|
||||
TfToken const garbageCollectionPerfToken,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
HD_API
|
||||
virtual ~HdBufferArray();
|
||||
|
||||
/// Returns the role of the GPU data in this bufferArray.
|
||||
TfToken const& GetRole() const {return _role;}
|
||||
|
||||
/// Returns the version of this buffer array.
|
||||
/// Used to determine when to rebuild outdated indirect dispatch buffers
|
||||
size_t GetVersion() const {
|
||||
return _version;
|
||||
}
|
||||
|
||||
/// Increments the version of this buffer array.
|
||||
HD_API
|
||||
void IncrementVersion();
|
||||
|
||||
/// Attempts to assign a range to this buffer array.
|
||||
/// Multiple threads could be trying to assign to this buffer at the same time.
|
||||
/// Returns true is the range is assigned to this buffer otherwise
|
||||
/// returns false if the buffer doesn't have space to assign the range.
|
||||
HD_API
|
||||
bool TryAssignRange(HdBufferArrayRangeSharedPtr &range);
|
||||
|
||||
/// Performs compaction if necessary and returns true if it becomes empty.
|
||||
virtual bool GarbageCollect() = 0;
|
||||
|
||||
/// Performs reallocation. After reallocation, the buffer will contain
|
||||
/// the specified \a ranges. If these ranges are currently held by a
|
||||
/// different buffer array instance, then their data will be copied
|
||||
/// from the specified \a curRangeOwner.
|
||||
virtual void Reallocate(
|
||||
std::vector<HdBufferArrayRangeSharedPtr> const &ranges,
|
||||
HdBufferArraySharedPtr const &curRangeOwner) = 0;
|
||||
|
||||
/// Returns the maximum number of elements capacity.
|
||||
HD_API
|
||||
virtual size_t GetMaxNumElements() const;
|
||||
|
||||
/// Debug output
|
||||
virtual void DebugDump(std::ostream &out) const = 0;
|
||||
|
||||
/// How many ranges are attached to the buffer array.
|
||||
size_t GetRangeCount() const { return _rangeCount; }
|
||||
|
||||
/// Get the attached range at the specified index.
|
||||
HD_API
|
||||
HdBufferArrayRangePtr GetRange(size_t idx) const;
|
||||
|
||||
/// Remove any ranges from the range list that have been deallocated
|
||||
/// Returns number of ranges after clean-up
|
||||
HD_API
|
||||
void RemoveUnusedRanges();
|
||||
|
||||
/// Returns true if Reallocate() needs to be called on this buffer array.
|
||||
bool NeedsReallocation() const {
|
||||
return _needsReallocation;
|
||||
}
|
||||
|
||||
/// Returns true if this buffer array is marked as immutable.
|
||||
bool IsImmutable() const {
|
||||
return _usageHint.bits.immutable;
|
||||
}
|
||||
|
||||
/// Returns the usage hints for this buffer array.
|
||||
HdBufferArrayUsageHint GetUsageHint() const {
|
||||
return _usageHint;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Dirty bit to set when the ranges attached to the buffer
|
||||
/// changes. If set Reallocate() should be called to clean it.
|
||||
bool _needsReallocation;
|
||||
|
||||
/// Limits the number of ranges that can be
|
||||
/// allocated to this buffer to max.
|
||||
void _SetMaxNumRanges(size_t max) { _maxNumRanges = max; }
|
||||
|
||||
/// Swap the rangelist with \p ranges
|
||||
HD_API
|
||||
void _SetRangeList(std::vector<HdBufferArrayRangeSharedPtr> const &ranges);
|
||||
|
||||
private:
|
||||
|
||||
// Do not allow copies.
|
||||
HdBufferArray(const HdBufferArray &) = delete;
|
||||
HdBufferArray &operator=(const HdBufferArray &) = delete;
|
||||
|
||||
|
||||
typedef std::vector<HdBufferArrayRangePtr> _RangeList;
|
||||
|
||||
// Vector of ranges associated with this buffer
|
||||
// We add values to the list in a multi-threaded fashion
|
||||
// but can later remove them in _RemoveUnusedRanges
|
||||
// than add more.
|
||||
//
|
||||
_RangeList _rangeList;
|
||||
std::atomic_size_t _rangeCount; // how many ranges are valid in list
|
||||
std::mutex _rangeListLock;
|
||||
|
||||
const TfToken _role;
|
||||
const TfToken _garbageCollectionPerfToken;
|
||||
|
||||
size_t _version;
|
||||
|
||||
size_t _maxNumRanges;
|
||||
HdBufferArrayUsageHint _usageHint;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_BUFFER_ARRAY_H
|
||||
@@ -0,0 +1,169 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_ARRAY_RANGE_H
|
||||
#define PXR_IMAGING_HD_BUFFER_ARRAY_RANGE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include "pxr/imaging/hd/bufferArray.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdBufferSpecVector = std::vector<struct HdBufferSpec>;
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
|
||||
using HdBufferSourceSharedPtr = std::shared_ptr<class HdBufferSource>;
|
||||
|
||||
/// \class HdBufferArrayRange
|
||||
///
|
||||
/// Interface class for representing range (subset) locator of HdBufferArray.
|
||||
///
|
||||
/// Each memory management strategy defines a specialized range class which is
|
||||
/// inherited of this interface so that client (drawItem) can be agnostic about
|
||||
/// the implementation detail of aggregation.
|
||||
///
|
||||
class HdBufferArrayRange
|
||||
{
|
||||
public:
|
||||
|
||||
HD_API
|
||||
HdBufferArrayRange();
|
||||
|
||||
/// Destructor (do nothing).
|
||||
/// The specialized range class may want to do something for garbage
|
||||
/// collection in its destructor. However, be careful not do any
|
||||
/// substantial work here (obviously including any kind of GL calls),
|
||||
/// since the destructor gets called frequently on various contexts.
|
||||
HD_API
|
||||
virtual ~HdBufferArrayRange();
|
||||
|
||||
/// Returns true if this range is valid
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
/// Returns true is the range has been assigned to a buffer
|
||||
virtual bool IsAssigned() const = 0;
|
||||
|
||||
/// Returns true if this range is marked as immutable.
|
||||
virtual bool IsImmutable() const = 0;
|
||||
|
||||
/// Resize memory area for this range. Returns true if it causes container
|
||||
/// buffer reallocation.
|
||||
virtual bool Resize(int numElements) = 0;
|
||||
|
||||
/// Copy source data into buffer
|
||||
virtual void CopyData(HdBufferSourceSharedPtr const &bufferSource) = 0;
|
||||
|
||||
/// Read back the buffer content
|
||||
virtual VtValue ReadData(TfToken const &name) const = 0;
|
||||
|
||||
/// Returns the offset at which this range begins in the underlying buffer
|
||||
/// array in terms of elements.
|
||||
virtual int GetElementOffset() const = 0;
|
||||
|
||||
/// Returns the byte offset at which this range begins in the underlying
|
||||
/// buffer array for the given resource.
|
||||
virtual int GetByteOffset(TfToken const& resourceName) const = 0;
|
||||
|
||||
/// Returns the number of elements
|
||||
virtual size_t GetNumElements() const = 0;
|
||||
|
||||
/// Returns the version of the buffer array.
|
||||
virtual size_t GetVersion() const = 0;
|
||||
|
||||
/// Increment the version of the buffer array. mostly used for notifying
|
||||
/// drawbatches to be rebuilt to remove expired BufferArrayRange.
|
||||
virtual void IncrementVersion() = 0;
|
||||
|
||||
/// Returns the max number of elements
|
||||
virtual size_t GetMaxNumElements() const = 0;
|
||||
|
||||
/// Gets the usage hint on the underlying buffer array
|
||||
virtual HdBufferArrayUsageHint GetUsageHint() const = 0;
|
||||
|
||||
/// Sets the buffer array associated with this buffer;
|
||||
virtual void SetBufferArray(HdBufferArray *bufferArray) = 0;
|
||||
|
||||
/// Debug output
|
||||
virtual void DebugDump(std::ostream &out) const = 0;
|
||||
|
||||
/// Returns true if the underlying buffer array is aggregated to other's
|
||||
bool IsAggregatedWith(HdBufferArrayRangeSharedPtr const &other) const {
|
||||
return (other && (_GetAggregation() == other->_GetAggregation()));
|
||||
}
|
||||
|
||||
/// Gets the bufferSpecs for all resources.
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *bufferSpecs) const = 0;
|
||||
|
||||
protected:
|
||||
/// Returns the aggregation container to be used in IsAggregatedWith()
|
||||
virtual const void *_GetAggregation() const = 0;
|
||||
|
||||
// Don't allow copies
|
||||
HdBufferArrayRange(const HdBufferArrayRange &) = delete;
|
||||
HdBufferArrayRange &operator=(const HdBufferArrayRange &) = delete;
|
||||
|
||||
};
|
||||
|
||||
HD_API
|
||||
std::ostream &operator <<(std::ostream &out,
|
||||
const HdBufferArrayRange &self);
|
||||
|
||||
/// \class HdBufferArrayRangeContainer
|
||||
///
|
||||
/// A resizable container of HdBufferArrayRanges.
|
||||
///
|
||||
class HdBufferArrayRangeContainer
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
HdBufferArrayRangeContainer(int size) : _ranges(size) { }
|
||||
|
||||
/// Set \p range into the container at \p index.
|
||||
/// If the size of container is smaller than index, resize it.
|
||||
HD_API
|
||||
void Set(int index, HdBufferArrayRangeSharedPtr const &range);
|
||||
|
||||
/// Returns the bar at \p index. returns null if either the index
|
||||
/// is out of range or not yet set.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &Get(int index) const;
|
||||
|
||||
/// Resize the buffer array range container to size \p size.
|
||||
/// Used to explicitly resize or shrink the container.
|
||||
HD_API
|
||||
void Resize(int size);
|
||||
|
||||
private:
|
||||
std::vector<HdBufferArrayRangeSharedPtr> _ranges;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BUFFER_ARRAY_RANGE_H
|
||||
@@ -0,0 +1,161 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_ARRAY_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_BUFFER_ARRAY_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
|
||||
#include "pxr/imaging/hd/bufferArrayRange.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
#include "pxr/imaging/hd/strategyBase.h"
|
||||
|
||||
#include "pxr/imaging/hf/perfLog.h"
|
||||
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <tbb/concurrent_unordered_map.h>
|
||||
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdBufferArraySharedPtr = std::shared_ptr<class HdBufferArray>;
|
||||
|
||||
/// \class HdBufferArrayRegistry
|
||||
///
|
||||
/// Manages the pool of buffer arrays.
|
||||
///
|
||||
class HdBufferArrayRegistry
|
||||
{
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdBufferArrayRegistry");
|
||||
|
||||
HD_API
|
||||
HdBufferArrayRegistry();
|
||||
~HdBufferArrayRegistry() = default;
|
||||
|
||||
/// Allocate new buffer array range using strategy
|
||||
/// Thread-Safe
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr AllocateRange(
|
||||
HdAggregationStrategy *strategy,
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// Triggers reallocation on all buffers managed by the registry.
|
||||
HD_API
|
||||
void ReallocateAll(HdAggregationStrategy *strategy);
|
||||
|
||||
/// Frees up buffers that no longer contain any allocated ranges.
|
||||
HD_API
|
||||
void GarbageCollect();
|
||||
|
||||
/// Generate a report on resources consumed by the managed
|
||||
/// buffer array. The returned size is an esitmate of the
|
||||
/// gpu memory consumed by the buffers
|
||||
HD_API
|
||||
size_t GetResourceAllocation(HdAggregationStrategy *strategy,
|
||||
VtDictionary &result) const;
|
||||
|
||||
/// Debug dump
|
||||
HD_API
|
||||
friend std::ostream &operator <<(std::ostream &out,
|
||||
const HdBufferArrayRegistry& self);
|
||||
|
||||
private:
|
||||
|
||||
HdBufferArrayRegistry(const HdBufferArrayRegistry &) = delete;
|
||||
HdBufferArrayRegistry &operator=(const HdBufferArrayRegistry &) = delete;
|
||||
|
||||
typedef std::list<HdBufferArraySharedPtr> _HdBufferArraySharedPtrList;
|
||||
|
||||
/// \struct _Entry
|
||||
///
|
||||
/// Entry in the buffer array cache. The list is the buffer arrays which
|
||||
/// all have the same format. There is as a lock for modifications to the
|
||||
/// entry and a condition used to determine if the entry has been
|
||||
/// construction.
|
||||
///
|
||||
/// A constructed entry always has at least 1 buffer array in its list.
|
||||
///
|
||||
struct _Entry
|
||||
{
|
||||
_HdBufferArraySharedPtrList bufferArrays;
|
||||
std::mutex lock;
|
||||
std::condition_variable emptyCondition;
|
||||
|
||||
// Default / Copy constructors needed for std::make_pair.
|
||||
// as the version of TBB doesn't have emplace() yet.
|
||||
_Entry() {}
|
||||
_Entry(const _Entry &other) { TF_VERIFY(bufferArrays.empty()); }
|
||||
};
|
||||
|
||||
|
||||
/// Predicate class for determine if an entry
|
||||
/// has been consturcted (determined by there
|
||||
/// being at least 1 entry in the buffer array list.
|
||||
class _EntryIsNotEmpty
|
||||
{
|
||||
public:
|
||||
_EntryIsNotEmpty(const _Entry &entry) : _entry(entry) {}
|
||||
|
||||
bool operator()() {
|
||||
return (!(_entry.bufferArrays.empty()));
|
||||
}
|
||||
|
||||
private:
|
||||
const _Entry &_entry;
|
||||
};
|
||||
|
||||
typedef tbb::concurrent_unordered_map< HdAggregationStrategy::AggregationId, _Entry> _BufferArrayIndex;
|
||||
|
||||
_BufferArrayIndex _entries;
|
||||
|
||||
/// Concurrently adds a new buffer to an entry in the cache.
|
||||
/// If expectedTail differs from the buffer at the end of the
|
||||
/// entries list after locking, then this function fails and
|
||||
/// does not add a new buffer (because another thread beat it
|
||||
/// to it).
|
||||
/// strategy is the factory class used to create the BufferArray.
|
||||
/// role and bufferSpecs are parameters to the BufferArray creation.
|
||||
void _InsertNewBufferArray(_Entry &entry,
|
||||
const HdBufferArraySharedPtr &expectedTail,
|
||||
HdAggregationStrategy *strategy,
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BUFFER_ARRAY_REGISTRY_H
|
||||
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_RESOURCE_H
|
||||
#define PXR_IMAGING_HD_BUFFER_RESOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/resource.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdBufferResource;
|
||||
|
||||
using HdBufferResourceSharedPtr = std::shared_ptr<HdBufferResource>;
|
||||
using HdBufferResourceNamedList = std::vector<
|
||||
std::pair<TfToken, HdBufferResourceSharedPtr> >;
|
||||
|
||||
/// \class HdBufferResource
|
||||
///
|
||||
/// A specific type of HdResource (GPU resource) representing a buffer object.
|
||||
///
|
||||
class HdBufferResource : public HdResource {
|
||||
public:
|
||||
HD_API
|
||||
HdBufferResource(TfToken const &role,
|
||||
HdTupleType tupleType,
|
||||
int offset,
|
||||
int stride);
|
||||
HD_API
|
||||
~HdBufferResource();
|
||||
|
||||
/// Data type and count
|
||||
HdTupleType GetTupleType() const { return _tupleType; }
|
||||
|
||||
/// Returns the interleaved offset (in bytes) of this data.
|
||||
int GetOffset() const {return _offset;}
|
||||
|
||||
/// Returns the stride (in bytes) of underlying buffer.
|
||||
int GetStride() const {return _stride;}
|
||||
|
||||
protected:
|
||||
HdTupleType _tupleType;
|
||||
int _offset;
|
||||
int _stride;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_BUFFER_RESOURCE_H
|
||||
@@ -0,0 +1,257 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_SOURCE_H
|
||||
#define PXR_IMAGING_HD_BUFFER_SOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdBufferSource;
|
||||
using HdBufferSourceSharedPtr = std::shared_ptr<HdBufferSource>;
|
||||
using HdBufferSourceConstSharedPtr = std::shared_ptr<HdBufferSource const>;
|
||||
using HdBufferSourceSharedPtrVector = std::vector<HdBufferSourceSharedPtr>;
|
||||
using HdBufferSourceWeakPtr = std::weak_ptr<HdBufferSource>;
|
||||
|
||||
/// \class HdBufferSource
|
||||
///
|
||||
/// A transient buffer of data that has not yet been committed.
|
||||
///
|
||||
/// HdBufferSource is an abstract interface class, to be registered to the
|
||||
/// resource registry with the buffer array range that specifies the
|
||||
/// destination resource.
|
||||
///
|
||||
class HdBufferSource
|
||||
{
|
||||
public:
|
||||
HdBufferSource() : _state(UNRESOLVED) { }
|
||||
|
||||
HD_API
|
||||
virtual ~HdBufferSource();
|
||||
|
||||
/// Return the name of this buffer source.
|
||||
virtual TfToken const &GetName() const = 0;
|
||||
|
||||
/// Add the buffer spec for this buffer source into given bufferspec vector.
|
||||
/// note: buffer specs has to be determined before the source resolution.
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const = 0;
|
||||
|
||||
/// Computes and returns a hash value for the underlying data.
|
||||
HD_API
|
||||
virtual size_t ComputeHash() const;
|
||||
|
||||
/// Prepare the access of GetData(). This process may include some
|
||||
/// computations (e.g. cpu smooth normals).
|
||||
/// Note: Resolve may be called in parallel from multiple threads
|
||||
/// across buffer sources, so be careful if it uses static/shared
|
||||
/// states among objects.
|
||||
/// Returns true if it resolved. If the buffer source has to wait
|
||||
/// some results of other buffer sources, or the buffer source is
|
||||
/// being resolved by other threads, it returns false.
|
||||
virtual bool Resolve() = 0;
|
||||
|
||||
/// Following interfaces will be called after Resolve.
|
||||
|
||||
/// Returns the raw pointer to the underlying data.
|
||||
virtual void const* GetData() const = 0;
|
||||
|
||||
/// Returns the data type and count (array size) for this buffer source.
|
||||
virtual HdTupleType GetTupleType() const = 0;
|
||||
|
||||
/// Returns the number of elements (e.g. VtVec3dArray().GetLength()) from
|
||||
/// the source array.
|
||||
virtual size_t GetNumElements() const = 0;
|
||||
|
||||
/// Returns true it this computation has already been resolved.
|
||||
bool IsResolved() const {
|
||||
return _state >= RESOLVED;
|
||||
}
|
||||
|
||||
/// Returns true if an error occurred during resolve.
|
||||
bool HasResolveError() const {
|
||||
return _state == RESOLVE_ERROR;
|
||||
}
|
||||
|
||||
/// \name Chained Buffers
|
||||
/// Buffer sources may be daisy-chained together.
|
||||
///
|
||||
/// Pre-chained buffer sources typically represent sources that
|
||||
/// are inputs to computed buffer sources (e.g. coarse vertex
|
||||
/// privmar data needing to be quadrangulated or refined) and
|
||||
/// will be scheduled to be resolved along with their owning
|
||||
/// buffer sources.
|
||||
///
|
||||
/// Post-chained buffer sources typically represent additional
|
||||
/// results produced by a computation (e.g. primitive param data
|
||||
/// computed along with index buffer data) and will be scheduled
|
||||
/// to be committed along with their owning buffer sources.
|
||||
/// @{
|
||||
|
||||
/// Returns true if this buffer has a pre-chained buffer.
|
||||
HD_API
|
||||
virtual bool HasPreChainedBuffer() const;
|
||||
|
||||
/// Returns the pre-chained buffer.
|
||||
HD_API
|
||||
virtual HdBufferSourceSharedPtr GetPreChainedBuffer() const;
|
||||
|
||||
/// Returns true if this buffer has any chained buffer(s)
|
||||
HD_API
|
||||
virtual bool HasChainedBuffer() const;
|
||||
|
||||
/// Returns the vector of chained buffers.
|
||||
HD_API
|
||||
virtual HdBufferSourceSharedPtrVector GetChainedBuffers() const;
|
||||
|
||||
/// @}
|
||||
|
||||
/// Checks the validity of the source buffer.
|
||||
/// The function should be called to determine if
|
||||
/// AddBufferSpec() and Resolve() would return valid
|
||||
/// results.
|
||||
HD_API
|
||||
bool IsValid() const;
|
||||
|
||||
protected:
|
||||
/// Marks this buffer source as resolved. It has to be called
|
||||
/// at the end of Resolve on concrete implementations.
|
||||
void _SetResolved() {
|
||||
TF_VERIFY(_state == BEING_RESOLVED);
|
||||
_state = RESOLVED;
|
||||
}
|
||||
|
||||
/// Called during Resolve() to indicate an unrecoverable failure occurred
|
||||
/// and the results of the computation can not be used.
|
||||
/// Further calls to Resolve() will not lead to success.
|
||||
///
|
||||
/// This is different from Resolve() returning false, which indicates
|
||||
/// that additional calls to Resolve() will eventually lead to success.
|
||||
///
|
||||
/// This is also later in the pipeline than IsValid, which checks
|
||||
/// that the buffer is setup such that Resolve() can be successful.
|
||||
void _SetResolveError() {
|
||||
TF_VERIFY(_state == BEING_RESOLVED);
|
||||
_state = RESOLVE_ERROR;
|
||||
}
|
||||
|
||||
/// Non-blocking lock acquisition.
|
||||
/// If no one else is resolving this buffer source, returns true.
|
||||
/// In that case the caller needs to call _SetResolved at the end
|
||||
/// of computation.
|
||||
/// It returns false if anyone else has already acquired lock.
|
||||
bool _TryLock() {
|
||||
State oldState = UNRESOLVED;
|
||||
return _state.compare_exchange_strong(oldState, BEING_RESOLVED);
|
||||
}
|
||||
|
||||
/// Checks the validity of the source buffer.
|
||||
/// This function is called by IsValid() to do the real checking.
|
||||
///
|
||||
/// Should only be implemented in classes at leafs of the class hierarchy
|
||||
/// (Please place common validation code in a new non-virtual method)
|
||||
///
|
||||
/// This code should return false:
|
||||
/// - If the buffer would produce an invalid BufferSpec
|
||||
/// - If a required dependent buffer is invalid
|
||||
/// For example, return false when:
|
||||
/// The data type is invalid, causing an invalid BufferSpec.
|
||||
///
|
||||
/// The resolve step requires a 'source' buffer and that buffer is invalid.
|
||||
///
|
||||
/// If returning false, the buffer will not be registered with the resource
|
||||
/// registry. AddBufferSpec and Resolve will not be called
|
||||
virtual bool _CheckValid() const = 0;
|
||||
|
||||
private:
|
||||
// Don't allow copies
|
||||
HdBufferSource(const HdBufferSource &) = delete;
|
||||
HdBufferSource &operator=(const HdBufferSource &) = delete;
|
||||
|
||||
enum State { UNRESOLVED=0, BEING_RESOLVED, RESOLVED, RESOLVE_ERROR};
|
||||
std::atomic<State> _state;
|
||||
};
|
||||
|
||||
/// A abstract base class for cpu computation followed by buffer
|
||||
/// transfer to the GPU.
|
||||
///
|
||||
/// concrete class needs to implement
|
||||
/// virtual void GetBufferSpecs(HdBufferSpecVector *specs) const;
|
||||
/// virtual void Resolve();
|
||||
/// and set the result via _SetResult().
|
||||
///
|
||||
class HdComputedBufferSource : public HdBufferSource {
|
||||
public:
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
HD_API
|
||||
virtual size_t ComputeHash() const override;
|
||||
HD_API
|
||||
virtual void const* GetData() const override;
|
||||
HD_API
|
||||
virtual HdTupleType GetTupleType() const override;
|
||||
HD_API
|
||||
virtual size_t GetNumElements() const override;
|
||||
|
||||
protected:
|
||||
void _SetResult(HdBufferSourceSharedPtr const &result) {
|
||||
_result = result;
|
||||
}
|
||||
|
||||
private:
|
||||
HdBufferSourceSharedPtr _result;
|
||||
};
|
||||
|
||||
/// A abstract base class for pure cpu computation.
|
||||
/// the result won't be scheduled for GPU transfer.
|
||||
///
|
||||
class HdNullBufferSource : public HdBufferSource {
|
||||
public:
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
HD_API
|
||||
virtual void const* GetData() const override;
|
||||
HD_API
|
||||
virtual size_t ComputeHash() const override;
|
||||
HD_API
|
||||
virtual size_t GetNumElements() const override;
|
||||
HD_API
|
||||
virtual HdTupleType GetTupleType() const override;
|
||||
HD_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_BUFFER_SOURCE_H
|
||||
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_SPEC_H
|
||||
#define PXR_IMAGING_HD_BUFFER_SPEC_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/base/tf/stl.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
typedef std::vector<struct HdBufferSpec> HdBufferSpecVector;
|
||||
|
||||
/// \class HdBufferSpec
|
||||
///
|
||||
/// Describes each named resource of buffer array.
|
||||
/// This specifies the buffer's value type as HdTupleType,
|
||||
/// which specifies the value type, number of components, and
|
||||
/// number of array entries (which may be 1).
|
||||
///
|
||||
/// for example:
|
||||
/// HdBufferSpecVector
|
||||
/// 0: name = points, tupleType = {HdTypeFloatVec3, 1}
|
||||
/// 1: name = normals, tupleType = {HdTypeFloatVec3, 1}
|
||||
/// 2: name = colors, tupleType = {HdTypeFloatVec3, 1}
|
||||
///
|
||||
struct HdBufferSpec final {
|
||||
/// Constructor.
|
||||
HdBufferSpec(TfToken const &name, HdTupleType tupleType) :
|
||||
name(name), tupleType(tupleType) {}
|
||||
|
||||
/// Util function for adding buffer specs of sources into bufferspecs.
|
||||
template<typename T>
|
||||
static void GetBufferSpecs(T const &sources,
|
||||
HdBufferSpecVector *bufferSpecs) {
|
||||
for (auto const &src : sources) {
|
||||
if (src->IsValid()) {
|
||||
src->GetBufferSpecs(bufferSpecs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if \p subset is a subset of \p superset.
|
||||
/// An empty set is considered a valid subset of the superset.
|
||||
HD_API
|
||||
static bool IsSubset(HdBufferSpecVector const &subset,
|
||||
HdBufferSpecVector const &superset);
|
||||
|
||||
/// Returns union set of \p spec1 and \p spec2.
|
||||
/// Duplicated entries are uniquified.
|
||||
HD_API
|
||||
static HdBufferSpecVector ComputeUnion(HdBufferSpecVector const &spec1,
|
||||
HdBufferSpecVector const &spec2);
|
||||
|
||||
/// Returns difference set of \p spec1 and \p spec2, i.e., entries in spec1
|
||||
/// that are not in spec2.
|
||||
HD_API
|
||||
static HdBufferSpecVector ComputeDifference(HdBufferSpecVector const &spec1,
|
||||
HdBufferSpecVector const &spec2);
|
||||
|
||||
/// Debug output.
|
||||
HD_API
|
||||
static void Dump(HdBufferSpecVector const &specs);
|
||||
|
||||
/// Return a size_t hash for this spec.
|
||||
HD_API
|
||||
size_t Hash() const;
|
||||
|
||||
/// Functor to use for unorderd sets, maps.
|
||||
struct HashFunctor {
|
||||
size_t operator()(HdBufferSpec const& spec) const {
|
||||
return spec.Hash();
|
||||
}
|
||||
};
|
||||
|
||||
/// Equality checks.
|
||||
bool operator == (HdBufferSpec const &other) const {
|
||||
return name == other.name && tupleType == other.tupleType;
|
||||
}
|
||||
bool operator != (HdBufferSpec const &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
/// Ordering.
|
||||
bool operator < (HdBufferSpec const &other) const {
|
||||
return name < other.name || (name == other.name &&
|
||||
tupleType < other.tupleType);
|
||||
}
|
||||
|
||||
TfToken name;
|
||||
HdTupleType tupleType;
|
||||
};
|
||||
|
||||
// Support TfHash.
|
||||
template <class HashState>
|
||||
void
|
||||
TfHashAppend(HashState &h, HdBufferSpec const &bs)
|
||||
{
|
||||
h.Append(bs.name, bs.tupleType);
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BUFFER_SPEC_H
|
||||
@@ -0,0 +1,263 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_CAMERA_H
|
||||
#define PXR_IMAGING_HD_CAMERA_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
|
||||
#include "pxr/imaging/cameraUtil/conformWindow.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/range1f.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Camera state that can be requested from the scene delegate via
|
||||
/// GetCameraParamValue(id, token). The parameters below mimic the
|
||||
/// USD camera schema and GfCamera (with the exception of window
|
||||
/// policy). All spatial units are in world units though and
|
||||
/// projection is HdCamera::Projection rather than a token.
|
||||
#define HD_CAMERA_TOKENS \
|
||||
/* frustum */ \
|
||||
(projection) \
|
||||
(horizontalAperture) \
|
||||
(verticalAperture) \
|
||||
(horizontalApertureOffset) \
|
||||
(verticalApertureOffset) \
|
||||
(focalLength) \
|
||||
(clippingRange) \
|
||||
(clipPlanes) \
|
||||
\
|
||||
/* depth of field */ \
|
||||
(fStop) \
|
||||
(focusDistance) \
|
||||
\
|
||||
/* shutter/lighting */ \
|
||||
(shutterOpen) \
|
||||
(shutterClose) \
|
||||
(exposure) \
|
||||
\
|
||||
/* how to match window with different aspect */ \
|
||||
(windowPolicy) \
|
||||
\
|
||||
/* OpenGL-style matrices, deprecated */ \
|
||||
(worldToViewMatrix) \
|
||||
(projectionMatrix)
|
||||
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdCameraTokens, HD_API, HD_CAMERA_TOKENS);
|
||||
|
||||
/// \class HdCamera
|
||||
///
|
||||
/// Hydra schema for a camera that pulls the params (see above) during
|
||||
/// Sync.
|
||||
/// Backends that use additional camera parameters can inherit from HdCamera and
|
||||
/// pull on them.
|
||||
///
|
||||
class HdCamera : public HdSprim
|
||||
{
|
||||
public:
|
||||
using ClipPlanesVector = std::vector<GfVec4d>;
|
||||
|
||||
HD_API
|
||||
HdCamera(SdfPath const & id);
|
||||
HD_API
|
||||
~HdCamera() override;
|
||||
|
||||
// change tracking for HdCamera
|
||||
enum DirtyBits : HdDirtyBits
|
||||
{
|
||||
Clean = 0,
|
||||
DirtyTransform = 1 << 0,
|
||||
DirtyViewMatrix = DirtyTransform, // deprecated
|
||||
DirtyProjMatrix = 1 << 1, // deprecated
|
||||
DirtyWindowPolicy = 1 << 2,
|
||||
DirtyClipPlanes = 1 << 3,
|
||||
DirtyParams = 1 << 4,
|
||||
AllDirty = (DirtyTransform
|
||||
|DirtyProjMatrix
|
||||
|DirtyWindowPolicy
|
||||
|DirtyClipPlanes
|
||||
|DirtyParams)
|
||||
};
|
||||
|
||||
enum Projection {
|
||||
Perspective = 0,
|
||||
Orthographic
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Sprim API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Synchronizes state from the delegate to this object.
|
||||
HD_API
|
||||
void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
|
||||
/// Returns the minimal set of dirty bits to place in the
|
||||
/// change tracker for use in the first sync of this prim.
|
||||
/// Typically this would be all dirty bits.
|
||||
HD_API
|
||||
HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Camera parameters accessor API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns camera transform
|
||||
GfMatrix4d const& GetTransform() const {
|
||||
return _transform;
|
||||
}
|
||||
|
||||
/// Returns whether camera is orthographic and perspective
|
||||
Projection GetProjection() const {
|
||||
return _projection;
|
||||
}
|
||||
|
||||
/// Returns horizontal aperture in world units.
|
||||
float GetHorizontalAperture() const {
|
||||
return _horizontalAperture;
|
||||
}
|
||||
|
||||
/// Returns vertical aperture in world units.
|
||||
float GetVerticalAperture() const {
|
||||
return _verticalAperture;
|
||||
}
|
||||
|
||||
/// Returns horizontal aperture offset in world units.
|
||||
float GetHorizontalApertureOffset() const {
|
||||
return _horizontalApertureOffset;
|
||||
}
|
||||
|
||||
/// Returns vertical aperture offset in world units.
|
||||
float GetVerticalApertureOffset() const {
|
||||
return _verticalApertureOffset;
|
||||
}
|
||||
|
||||
/// Returns focal length in world units.
|
||||
float GetFocalLength() const {
|
||||
return _focalLength;
|
||||
}
|
||||
|
||||
/// Returns near and far plane in world units
|
||||
GfRange1f const &GetClippingRange() const {
|
||||
return _clippingRange;
|
||||
}
|
||||
|
||||
/// Returns any additional clipping planes defined in camera space.
|
||||
std::vector<GfVec4d> const& GetClipPlanes() const {
|
||||
return _clipPlanes;
|
||||
}
|
||||
|
||||
/// Returns fstop of camera
|
||||
float GetFStop() const {
|
||||
return _fStop;
|
||||
}
|
||||
|
||||
/// Returns focus distance in world units.
|
||||
float GetFocusDistance() const {
|
||||
return _focusDistance;
|
||||
}
|
||||
|
||||
double GetShutterOpen() const {
|
||||
return _shutterOpen;
|
||||
}
|
||||
|
||||
double GetShutterClose() const {
|
||||
return _shutterClose;
|
||||
}
|
||||
|
||||
float GetExposure() const {
|
||||
return _exposure;
|
||||
}
|
||||
|
||||
/// Returns the window policy of the camera. If no opinion is authored, we
|
||||
/// default to "CameraUtilFit"
|
||||
CameraUtilConformWindowPolicy const& GetWindowPolicy() const {
|
||||
return _windowPolicy;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Legacy camera parameters accessor API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the matrix transformation from world to camera space.
|
||||
/// \deprecated Use GetTransform instead
|
||||
HD_API
|
||||
GfMatrix4d GetViewMatrix() const;
|
||||
|
||||
/// Returns the matrix transformation from camera to world space.
|
||||
/// \deprecated Use GetTransform and invert instead
|
||||
HD_API
|
||||
GfMatrix4d GetViewInverseMatrix() const;
|
||||
|
||||
/// Returns the projection matrix for the camera.
|
||||
/// \deprecated Compute from above physically based attributes
|
||||
HD_API
|
||||
GfMatrix4d GetProjectionMatrix() const;
|
||||
|
||||
protected:
|
||||
// frustum
|
||||
GfMatrix4d _transform;
|
||||
Projection _projection;
|
||||
float _horizontalAperture;
|
||||
float _verticalAperture;
|
||||
float _horizontalApertureOffset;
|
||||
float _verticalApertureOffset;
|
||||
float _focalLength;
|
||||
GfRange1f _clippingRange;
|
||||
std::vector<GfVec4d> _clipPlanes;
|
||||
|
||||
// focus
|
||||
float _fStop;
|
||||
float _focusDistance;
|
||||
|
||||
// shutter/lighting
|
||||
double _shutterOpen;
|
||||
double _shutterClose;
|
||||
float _exposure;
|
||||
|
||||
// Camera's opinion how it display in a window with
|
||||
// a different aspect ratio
|
||||
CameraUtilConformWindowPolicy _windowPolicy;
|
||||
|
||||
// OpenGL-style matrices
|
||||
GfMatrix4d _worldToViewMatrix;
|
||||
GfMatrix4d _worldToViewInverseMatrix;
|
||||
GfMatrix4d _projectionMatrix;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_CAMERA_H
|
||||
@@ -0,0 +1,624 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_CHANGE_TRACKER_H
|
||||
#define PXR_IMAGING_HD_CHANGE_TRACKER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/rprimCollection.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
|
||||
#include <tbb/concurrent_hash_map.h>
|
||||
#include <atomic>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class HdChangeTracker
|
||||
///
|
||||
/// Tracks changes from the HdSceneDelegate, providing invalidation cues to the
|
||||
/// render engine.
|
||||
///
|
||||
/// Changes flagged here are accumulated until the next time resource associated
|
||||
/// with the change is required, at which point the resource is updated and the
|
||||
/// flag is cleared.
|
||||
///
|
||||
class HdChangeTracker
|
||||
{
|
||||
public:
|
||||
|
||||
// Common dirty bits for Rprims
|
||||
// XXX: Move this to HdRprim
|
||||
enum RprimDirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
InitRepr = 1 << 0,
|
||||
Varying = 1 << 1,
|
||||
AllDirty = ~Varying,
|
||||
DirtyPrimID = 1 << 2,
|
||||
DirtyExtent = 1 << 3,
|
||||
DirtyDisplayStyle = 1 << 4,
|
||||
DirtyPoints = 1 << 5,
|
||||
DirtyPrimvar = 1 << 6,
|
||||
DirtyMaterialId = 1 << 7,
|
||||
DirtyTopology = 1 << 8,
|
||||
DirtyTransform = 1 << 9,
|
||||
DirtyVisibility = 1 << 10,
|
||||
DirtyNormals = 1 << 11,
|
||||
DirtyDoubleSided = 1 << 12,
|
||||
DirtyCullStyle = 1 << 13,
|
||||
DirtySubdivTags = 1 << 14,
|
||||
DirtyWidths = 1 << 15,
|
||||
DirtyInstancer = 1 << 16,
|
||||
DirtyInstanceIndex = 1 << 17,
|
||||
DirtyRepr = 1 << 18,
|
||||
DirtyRenderTag = 1 << 19,
|
||||
DirtyComputationPrimvarDesc = 1 << 20,
|
||||
DirtyCategories = 1 << 21,
|
||||
DirtyVolumeField = 1 << 22,
|
||||
AllSceneDirtyBits = ((1<<23) - 1),
|
||||
|
||||
NewRepr = 1 << 23,
|
||||
|
||||
CustomBitsBegin = 1 << 24,
|
||||
CustomBitsEnd = 1 << 30,
|
||||
};
|
||||
|
||||
// InstancerDirtybits are a subset of rprim dirty bits right now:
|
||||
// DirtyPrimvar, DirtyTransform, DirtyInstanceIndex, DirtyInstancer.
|
||||
|
||||
// Dirty bits for Tasks
|
||||
// XXX: Move this to HdTask
|
||||
enum TaskDirtyBits : HdDirtyBits {
|
||||
//Varying = 1 << 0,
|
||||
DirtyType = 1 << 1,
|
||||
DirtyParams = 1 << 2,
|
||||
DirtyCollection = 1 << 3,
|
||||
DirtyRenderTags = 1 << 4,
|
||||
};
|
||||
|
||||
HD_API
|
||||
HdChangeTracker();
|
||||
HD_API
|
||||
virtual ~HdChangeTracker();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Rprim Object Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Start tracking Rprim with the given \p id.
|
||||
HD_API
|
||||
void RprimInserted(SdfPath const& id, HdDirtyBits initialDirtyState);
|
||||
|
||||
/// Stop tracking Rprim with the given \p id.
|
||||
HD_API
|
||||
void RprimRemoved(SdfPath const& id);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Rprim State Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the dirty bits for the rprim with \p id.
|
||||
HD_API
|
||||
HdDirtyBits GetRprimDirtyBits(SdfPath const& id) const;
|
||||
|
||||
/// Flag the Rprim with the given \p id as being dirty. Multiple calls with
|
||||
/// different dirty bits accumulate.
|
||||
HD_API
|
||||
void MarkRprimDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
|
||||
|
||||
/// Clear the dirty flags for an HdRprim. if inSync is true, set OutOfSync
|
||||
/// flag to notify dirtyList will discover the prim to sync the residual
|
||||
/// data for new repr.
|
||||
HD_API
|
||||
void MarkRprimClean(SdfPath const& id, HdDirtyBits newBits=Clean);
|
||||
|
||||
/// Mark the primvar for the rprim with \p id as being dirty.
|
||||
HD_API
|
||||
void MarkPrimvarDirty(SdfPath const& id, TfToken const& name);
|
||||
|
||||
/// Flag all the Rprim with the given \p id as being dirty. Multiple calls
|
||||
/// with different dirty bits accumulate.
|
||||
/// Doesn't touch varying state.
|
||||
HD_API
|
||||
void MarkAllRprimsDirty(HdDirtyBits bits);
|
||||
|
||||
/// Clear Varying bit of all prims.
|
||||
///
|
||||
/// The idea is that from frame to frame (update iteration), the set of
|
||||
/// dirty rprims and their dirty bits do not change; that is, the same
|
||||
/// rprims get dirtied with the same dirty bits.. The change tracker can
|
||||
/// leverage this and build stable sets of dirty lists and reduce the
|
||||
/// overall cost of an update iteration.
|
||||
HD_API
|
||||
void ResetVaryingState();
|
||||
|
||||
/// Reset the varying state on one Rprim
|
||||
/// This is done for Rprims, where we choose not to clean them
|
||||
/// (due to state like invisibility).
|
||||
HD_API
|
||||
void ResetRprimVaryingState(SdfPath const& id);
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns true if the rprim identified by \p id has any dirty flags set.
|
||||
HD_API
|
||||
bool IsRprimDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty extent.
|
||||
HD_API
|
||||
bool IsExtentDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty display style.
|
||||
HD_API
|
||||
bool IsDisplayStyleDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id with primvar \p name is
|
||||
/// dirty.
|
||||
HD_API
|
||||
bool IsPrimvarDirty(SdfPath const& id, TfToken const& name);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has any dirty primvars.
|
||||
HD_API
|
||||
bool IsAnyPrimvarDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty topology.
|
||||
HD_API
|
||||
bool IsTopologyDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has dirty doubleSided state.
|
||||
HD_API
|
||||
bool IsDoubleSidedDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has dirty cullstyle.
|
||||
HD_API
|
||||
bool IsCullStyleDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty subdiv tags.
|
||||
HD_API
|
||||
bool IsSubdivTagsDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty transform.
|
||||
HD_API
|
||||
bool IsTransformDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has dirty visibility.
|
||||
HD_API
|
||||
bool IsVisibilityDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty primID.
|
||||
HD_API
|
||||
bool IsPrimIdDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has any flags set other than the varying flag.
|
||||
static bool IsDirty(HdDirtyBits dirtyBits) {
|
||||
return (dirtyBits & AllDirty) != 0;
|
||||
}
|
||||
|
||||
/// Returns true if the dirtyBits has no flags set except the varying flag.
|
||||
static bool IsClean(HdDirtyBits dirtyBits) {
|
||||
return (dirtyBits & AllDirty) == 0;
|
||||
}
|
||||
|
||||
/// Returns true if the dirtyBits has no flags set except the varying flag.
|
||||
static bool IsVarying(HdDirtyBits dirtyBits) {
|
||||
return (dirtyBits & Varying) != 0;
|
||||
}
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty extent. id is for perflog.
|
||||
HD_API
|
||||
static bool IsExtentDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty display style. id is for perflog.
|
||||
HD_API
|
||||
static bool IsDisplayStyleDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty subdiv tags. id is for perflog.
|
||||
HD_API
|
||||
static bool IsSubdivTagsDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty primvar \p name.
|
||||
/// id is for perflog.
|
||||
HD_API
|
||||
static bool IsPrimvarDirty(HdDirtyBits dirtyBits, SdfPath const& id,
|
||||
TfToken const& name);
|
||||
|
||||
/// Returns true if the dirtyBits has any dirty primvars.
|
||||
/// id is for perflog.
|
||||
HD_API
|
||||
static bool IsAnyPrimvarDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty topology. id is for perflog.
|
||||
HD_API
|
||||
static bool IsTopologyDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has dirty doubleSided state. id is for perflog.
|
||||
HD_API
|
||||
static bool IsDoubleSidedDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has dirty cullstyle. id is for perflog.
|
||||
HD_API
|
||||
static bool IsCullStyleDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty transform. id is for perflog.
|
||||
HD_API
|
||||
static bool IsTransformDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has dirty visibility. id is for perflog.
|
||||
HD_API
|
||||
static bool IsVisibilityDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty primID. id is for perflog.
|
||||
HD_API
|
||||
static bool IsPrimIdDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty instancer. id is for perflog.
|
||||
HD_API
|
||||
static bool IsInstancerDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty instance index. id is for perflog.
|
||||
HD_API
|
||||
static bool IsInstanceIndexDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
HD_API
|
||||
static bool IsReprDirty(HdDirtyBits dirtyBits, SdfPath const &id);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Set the primvar dirty flag to \p dirtyBits.
|
||||
HD_API
|
||||
static void MarkPrimvarDirty(HdDirtyBits *dirtyBits, TfToken const &name);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Task Object Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Start tracking Task with the given \p id.
|
||||
HD_API
|
||||
void TaskInserted(SdfPath const& id, HdDirtyBits initialDirtyState);
|
||||
|
||||
/// Stop tracking Task with the given \p id.
|
||||
HD_API
|
||||
void TaskRemoved(SdfPath const& id);
|
||||
|
||||
/// Set the dirty flags to \p bits.
|
||||
HD_API
|
||||
void MarkTaskDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
|
||||
|
||||
/// Get the dirty bits for Task with the given \p id.
|
||||
HD_API
|
||||
HdDirtyBits GetTaskDirtyBits(SdfPath const& id);
|
||||
|
||||
/// Set the dirty flags to \p newBits.
|
||||
HD_API
|
||||
void MarkTaskClean(SdfPath const& id, HdDirtyBits newBits=Clean);
|
||||
|
||||
/// Called to flag when the set of active render tags have changed.
|
||||
/// This can either be because either the Task's opinion (which
|
||||
/// resolves both view and render pass opinions) and a Prims opinion.
|
||||
///
|
||||
/// Calling this means that any cached prim gathers that filter by render
|
||||
/// tag need to invalidated.
|
||||
HD_API
|
||||
void MarkRenderTagsDirty();
|
||||
|
||||
/// Retrieve the current version number of the render tag set
|
||||
HD_API
|
||||
unsigned GetRenderTagVersion() const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Instancer State Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Start tracking Instancer with the given \p id.
|
||||
HD_API
|
||||
void InstancerInserted(SdfPath const& id, HdDirtyBits initialDirtyState);
|
||||
|
||||
/// Stop tracking Instancer with the given \p id.
|
||||
HD_API
|
||||
void InstancerRemoved(SdfPath const& id);
|
||||
|
||||
/// Returns the dirty bits for the instancer with \p id.
|
||||
HD_API
|
||||
HdDirtyBits GetInstancerDirtyBits(SdfPath const& id);
|
||||
|
||||
/// Flag the Instancer with the given \p id as being dirty. Multiple calls
|
||||
/// with different dirty bits accumulate.
|
||||
HD_API
|
||||
void MarkInstancerDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
|
||||
|
||||
/// Clean the specified dirty bits for the instancer with \p id.
|
||||
HD_API
|
||||
void MarkInstancerClean(SdfPath const& id, HdDirtyBits newBits=Clean);
|
||||
|
||||
/// Insert a dependency between \p rprimId and parent instancer
|
||||
/// \p instancerId. Changes to the latter mark the former with
|
||||
/// DirtyInstancer.
|
||||
HD_API
|
||||
void AddInstancerRprimDependency(SdfPath const& instancerId,
|
||||
SdfPath const& rprimId);
|
||||
|
||||
/// Remove a dependency between \p rprimId and parent instancer
|
||||
/// \p instancerId.
|
||||
HD_API
|
||||
void RemoveInstancerRprimDependency(SdfPath const& instancerId,
|
||||
SdfPath const& rprimId);
|
||||
|
||||
/// Insert a dependency between \p instancerId and parent instancer
|
||||
/// \p parentInstancerId. Changes to the latter mark the former with
|
||||
/// DirtyInstancer.
|
||||
HD_API
|
||||
void AddInstancerInstancerDependency(SdfPath const& parentInstancerId,
|
||||
SdfPath const& instancerId);
|
||||
|
||||
/// Remove a dependency between \p instancerId and parent instancer
|
||||
/// \p parentInstancerId.
|
||||
HD_API
|
||||
void RemoveInstancerInstancerDependency(SdfPath const& parentInstancerId,
|
||||
SdfPath const& instancerId);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Sprim (scene state prim: camera, light, ...) state Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Start tracking sprim with the given \p id.
|
||||
HD_API
|
||||
void SprimInserted(SdfPath const& id, HdDirtyBits initialDirtyState);
|
||||
|
||||
/// Stop tracking sprim with the given \p id.
|
||||
HD_API
|
||||
void SprimRemoved(SdfPath const& id);
|
||||
|
||||
/// Get the dirty bits for sprim with the given \p id.
|
||||
HD_API
|
||||
HdDirtyBits GetSprimDirtyBits(SdfPath const& id);
|
||||
|
||||
/// Set the dirty flags to \p bits.
|
||||
HD_API
|
||||
void MarkSprimDirty(SdfPath const& id, HdDirtyBits bits);
|
||||
|
||||
/// Set the dirty flags to \p newBits.
|
||||
HD_API
|
||||
void MarkSprimClean(SdfPath const& id, HdDirtyBits newBits=Clean);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Bprim (buffer prim: texture, buffer, ...) state Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Start tracking bprim with the given \p id.
|
||||
HD_API
|
||||
void BprimInserted(SdfPath const& id, HdDirtyBits initialDirtyState);
|
||||
|
||||
/// Stop tracking bprim with the given \p id.
|
||||
HD_API
|
||||
void BprimRemoved(SdfPath const& id);
|
||||
|
||||
/// Get the dirty bits for bprim with the given \p id.
|
||||
HD_API
|
||||
HdDirtyBits GetBprimDirtyBits(SdfPath const& id);
|
||||
|
||||
/// Set the dirty flags to \p bits.
|
||||
HD_API
|
||||
void MarkBprimDirty(SdfPath const& id, HdDirtyBits bits);
|
||||
|
||||
/// Set the dirty flags to \p newBits.
|
||||
HD_API
|
||||
void MarkBprimClean(SdfPath const& id, HdDirtyBits newBits=Clean);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name RprimCollection Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Adds a named collection for tracking.
|
||||
HD_API
|
||||
void AddCollection(TfToken const& collectionName);
|
||||
|
||||
/// Marks a named collection as being dirty, this bumps the version of the
|
||||
/// collection.
|
||||
HD_API
|
||||
void MarkCollectionDirty(TfToken const& collectionName);
|
||||
|
||||
/// Returns the current version of the named collection.
|
||||
HD_API
|
||||
unsigned GetCollectionVersion(TfToken const& collectionName) const;
|
||||
|
||||
/// Returns the number of changes to visibility. This is intended to be used
|
||||
/// to detect when visibility has changed for *any* Rprim.
|
||||
HD_API
|
||||
unsigned GetVisibilityChangeCount() const;
|
||||
|
||||
/// Returns the current version of varying state. This is used to refresh
|
||||
/// cached DirtyLists
|
||||
unsigned GetVaryingStateVersion() const {
|
||||
return _varyingStateVersion;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Render Index Versioning
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the current version of the Render Index's RPrim set.
|
||||
/// This version number changes when Rprims are inserted or removed
|
||||
/// from the render index. Invalidating any cached gather operations.
|
||||
unsigned GetRprimIndexVersion() const {
|
||||
return _rprimIndexVersion;
|
||||
}
|
||||
|
||||
/// Returns the current version of the Render Index's SPrim set.
|
||||
/// This version number changes when Sprims are inserted or removed
|
||||
/// from the render index. Invalidating any cached gather operations.
|
||||
unsigned GetSprimIndexVersion() const {
|
||||
return _sprimIndexVersion;
|
||||
}
|
||||
|
||||
/// Returns the current version of the Render Index's BPrim set.
|
||||
/// This version number changes when Bprims are inserted or removed
|
||||
/// from the render index. Invalidating any cached gather operations.
|
||||
unsigned GetBprimIndexVersion() const {
|
||||
return _bprimIndexVersion;
|
||||
}
|
||||
|
||||
/// Returns the current version of the Render Index's Instancer set.
|
||||
/// This version number changes when Instancers are inserted or removed
|
||||
/// from the render index. Invalidating any cached gather operations.
|
||||
unsigned GetInstancerIndexVersion() const {
|
||||
return _instancerIndexVersion;
|
||||
}
|
||||
|
||||
|
||||
/// Returns the current version of the scene state.
|
||||
/// This version number changes whenever any prims are inserted, removed
|
||||
/// or marked dirty.
|
||||
/// The use case is to detect that nothing has changed, so the Sync
|
||||
/// phase can be avoided.
|
||||
unsigned GetSceneStateVersion() const {
|
||||
return _sceneStateVersion;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name General state tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Adds a named state for tracking.
|
||||
HD_API
|
||||
void AddState(TfToken const& name);
|
||||
|
||||
/// Marks a named state as being dirty., this bumps the version of the
|
||||
/// state.
|
||||
HD_API
|
||||
void MarkStateDirty(TfToken const& name);
|
||||
|
||||
/// Returns the current version of the named state.
|
||||
HD_API
|
||||
unsigned GetStateVersion(TfToken const &name) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Debug
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
HD_API
|
||||
static std::string StringifyDirtyBits(HdDirtyBits dirtyBits);
|
||||
|
||||
HD_API
|
||||
static void DumpDirtyBits(HdDirtyBits dirtyBits);
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
|
||||
// Don't allow copies
|
||||
HdChangeTracker(const HdChangeTracker &) = delete;
|
||||
HdChangeTracker &operator=(const HdChangeTracker &) = delete;
|
||||
|
||||
|
||||
static void _LogCacheAccess(TfToken const& cacheName,
|
||||
SdfPath const& id, bool hit);
|
||||
|
||||
typedef TfHashMap<SdfPath, HdDirtyBits, SdfPath::Hash> _IDStateMap;
|
||||
typedef TfHashMap<TfToken, int, TfToken::HashFunctor> _CollectionStateMap;
|
||||
typedef TfHashMap<TfToken, unsigned, TfToken::HashFunctor> _GeneralStateMap;
|
||||
|
||||
struct _PathHashCompare {
|
||||
static bool equal(const SdfPath& a, const SdfPath& b)
|
||||
{ return a == b; }
|
||||
|
||||
static size_t hash(const SdfPath& path)
|
||||
{ return hash_value(path); }
|
||||
};
|
||||
typedef tbb::concurrent_hash_map<SdfPath, SdfPathSet, _PathHashCompare>
|
||||
_DependencyMap;
|
||||
|
||||
// Core dirty state.
|
||||
_IDStateMap _rprimState;
|
||||
_IDStateMap _instancerState;
|
||||
_IDStateMap _taskState;
|
||||
_IDStateMap _sprimState;
|
||||
_IDStateMap _bprimState;
|
||||
_GeneralStateMap _generalState;
|
||||
|
||||
// Collection versions / state.
|
||||
_CollectionStateMap _collectionState;
|
||||
|
||||
// Provides reverse-association between instancers and the child
|
||||
// instancers/rprims that use them.
|
||||
_DependencyMap _instancerRprimDependencies;
|
||||
_DependencyMap _instancerInstancerDependencies;
|
||||
|
||||
// Dependency map helpers
|
||||
void _AddDependency(_DependencyMap &depMap,
|
||||
SdfPath const& parent, SdfPath const& child);
|
||||
void _RemoveDependency(_DependencyMap &depMap,
|
||||
SdfPath const& parent, SdfPath const& child);
|
||||
|
||||
// Typically the Rprims that get marked dirty per update iteration end up
|
||||
// being a stable set of objects; to leverage this fact, we require the
|
||||
// delegate notify the change tracker when that state changes, which bumps
|
||||
// the varyingStateVersion, which triggers downstream invalidation.
|
||||
unsigned _varyingStateVersion;
|
||||
|
||||
// Tracks changes (insertions/removals) of prims in the render index.
|
||||
// This is used to indicating that cached gather operations need to be
|
||||
// re-evaluated, such as dirty lists or batch building.
|
||||
unsigned _rprimIndexVersion;
|
||||
unsigned _sprimIndexVersion;
|
||||
unsigned _bprimIndexVersion;
|
||||
unsigned _instancerIndexVersion;
|
||||
|
||||
// The following tracks any changes of state. As a result it is very broad.
|
||||
// The use case to detect, when no changes have been made, as to
|
||||
// avoid the need to sync or reset progressive renderers.
|
||||
unsigned _sceneStateVersion;
|
||||
|
||||
// Used to detect that visibility changed somewhere in the render index.
|
||||
unsigned _visChangeCount;
|
||||
|
||||
// Used to detect changes to the set of active render tags
|
||||
unsigned _renderTagVersion;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_CHANGE_TRACKER_H
|
||||
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
#ifndef PXR_IMAGING_HD_COMP_EXT_COMP_INPUT_SOURCE_H
|
||||
#define PXR_IMAGING_HD_COMP_EXT_COMP_INPUT_SOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/extCompInputSource.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdExtCompCpuComputation;
|
||||
|
||||
using HdExtCompCpuComputationSharedPtr =
|
||||
std::shared_ptr<HdExtCompCpuComputation>;
|
||||
|
||||
///
|
||||
/// An Hd Buffer Source Computation that is used to bind an ExtComputation input
|
||||
/// to a specific output of another ExtComputation.
|
||||
///
|
||||
class Hd_CompExtCompInputSource final : public Hd_ExtCompInputSource {
|
||||
public:
|
||||
/// Constructs the computation, binding inputName to sourceOutputName
|
||||
/// on buffer source representation of the source computation.
|
||||
HD_API
|
||||
Hd_CompExtCompInputSource(const TfToken &inputName,
|
||||
const HdExtCompCpuComputationSharedPtr &source,
|
||||
const TfToken &sourceOutputName);
|
||||
|
||||
HD_API
|
||||
virtual ~Hd_CompExtCompInputSource() = default;
|
||||
|
||||
/// Returns true once the source computation has been resolved.
|
||||
HD_API
|
||||
virtual bool Resolve() override;
|
||||
|
||||
/// Obtains the value of the output from the source computation.
|
||||
HD_API
|
||||
virtual const VtValue &GetValue() const override;
|
||||
|
||||
protected:
|
||||
/// Returns true if the binding is successful.
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
HdExtCompCpuComputationSharedPtr _source;
|
||||
size_t _sourceOutputIdx;
|
||||
|
||||
Hd_CompExtCompInputSource() = delete;
|
||||
Hd_CompExtCompInputSource(const Hd_CompExtCompInputSource &) = delete;
|
||||
Hd_CompExtCompInputSource &operator = (const Hd_CompExtCompInputSource &)
|
||||
= delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_COMP_EXT_COMP_INPUT_SOURCE_H
|
||||
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_COMPUTATION_H
|
||||
#define PXR_IMAGING_HD_COMPUTATION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
|
||||
|
||||
using HdComputationSharedPtr = std::shared_ptr<class HdComputation>;
|
||||
using HdComputationSharedPtrVector = std::vector<HdComputationSharedPtr>;
|
||||
|
||||
/// \class HdComputation
|
||||
///
|
||||
/// An interface class for GPU computation.
|
||||
///
|
||||
/// GPU computation fills the result into range, which has to be allocated
|
||||
/// using buffer specs determined by GetBufferSpecs, and registered as a pair
|
||||
/// of computation and range.
|
||||
///
|
||||
class HdComputation
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
virtual ~HdComputation();
|
||||
|
||||
/// Execute computation.
|
||||
virtual void Execute(
|
||||
HdBufferArrayRangeSharedPtr const &range,
|
||||
HdResourceRegistry *resourceRegistry) = 0;
|
||||
|
||||
/// Returns the size of its destination buffer (located by range argument
|
||||
/// of Execute()). This function will be called after all HdBufferSources
|
||||
/// have been resolved and commited, so it can use the result of those
|
||||
/// buffer source results.
|
||||
/// Returning 0 means it doesn't need to resize.
|
||||
virtual int GetNumOutputElements() const = 0;
|
||||
|
||||
/// Add the buffer spec for this computation into given bufferspec vector.
|
||||
/// Caller has to allocate the destination buffer with respect to the
|
||||
/// BufferSpecs, and passes the range when registering the computation.
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const = 0;
|
||||
|
||||
/// This function is needed as HdComputation shares a templatized interface
|
||||
/// with HdBufferSource.
|
||||
///
|
||||
/// It is a check to see if the GetBufferSpecs would produce a valid result.
|
||||
bool IsValid() { return true; }
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_COMPUTATION_H
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// Copyright 2019 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_COORD_SYS_H
|
||||
#define PXR_IMAGING_HD_COORD_SYS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
|
||||
/// \class HdCoordSys
|
||||
///
|
||||
/// HdCoordSys representes a coordinate system as a Hydra state prim.
|
||||
///
|
||||
/// Coordinate systems may be referred to by name from a shader network.
|
||||
/// Following the convention in UsdShadeCoordSysAPI, we use the Hydra
|
||||
/// id to establish the name, where the id is a namespaced property
|
||||
/// path of the form <tt><.../prim.coordSys:NAME></tt>. GetName()
|
||||
/// will retrieve the name.
|
||||
///
|
||||
/// Each rprim may have a set of bound coordinate systems, which
|
||||
/// may be retrieved via the <tt>HdTokens->coordSysBindings</tt> key.
|
||||
/// The returned value is of type HdIdVectorSharedPtr, a reference-
|
||||
/// counted pointer to a vector of ids of coordinate systems.
|
||||
/// The intention of this design is to make it efficient for scene
|
||||
/// delegates to communicate to renderer delegates the common
|
||||
/// mappings of bound coordinate systems across groups of rprims.
|
||||
///
|
||||
/// The transform value of an HdCoordSys is the matrix representation
|
||||
/// of the transform from its local space to world space. In other
|
||||
/// words, it has the same interpretation as the transform for rprims.
|
||||
///
|
||||
class HdCoordSys : public HdSprim {
|
||||
public:
|
||||
HD_API
|
||||
HdCoordSys(SdfPath const & id);
|
||||
HD_API
|
||||
virtual ~HdCoordSys();
|
||||
|
||||
// Change tracking for HdCoordSys
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyTransform = 1 << 0,
|
||||
AllDirty = DirtyTransform
|
||||
};
|
||||
|
||||
/// Returns the name bound to this coordinate system.
|
||||
///
|
||||
/// There may be multiple coordinate systems with the same
|
||||
/// name, but they must associate with disjoint sets of rprims.
|
||||
TfToken GetName() const { return _name; }
|
||||
|
||||
private:
|
||||
TfToken _name;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_COORD_SYS_H
|
||||
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DEBUG_CODES_H
|
||||
#define PXR_IMAGING_HD_DEBUG_CODES_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/tf/debug.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
TF_DEBUG_CODES(
|
||||
HD_BPRIM_ADDED,
|
||||
HD_BPRIM_REMOVED,
|
||||
HD_BUFFER_ARRAY_INFO,
|
||||
HD_BUFFER_ARRAY_RANGE_CLEANED,
|
||||
HD_CACHE_HITS,
|
||||
HD_CACHE_MISSES,
|
||||
HD_COUNTER_CHANGED,
|
||||
HD_DIRTY_ALL_COLLECTIONS,
|
||||
HD_DIRTY_LIST,
|
||||
HD_DISABLE_MULTITHREADED_RPRIM_SYNC,
|
||||
HD_DRAWITEMS_CULLED,
|
||||
HD_ENGINE_PHASE_INFO,
|
||||
HD_EXT_COMPUTATION_ADDED,
|
||||
HD_EXT_COMPUTATION_REMOVED,
|
||||
HD_EXT_COMPUTATION_UPDATED,
|
||||
HD_EXT_COMPUTATION_EXECUTION,
|
||||
HD_FREEZE_CULL_FRUSTUM,
|
||||
HD_INSTANCER_ADDED,
|
||||
HD_INSTANCER_CLEANED,
|
||||
HD_INSTANCER_REMOVED,
|
||||
HD_INSTANCER_UPDATED,
|
||||
HD_MDI,
|
||||
HD_RENDER_SETTINGS,
|
||||
HD_RPRIM_ADDED,
|
||||
HD_RPRIM_CLEANED,
|
||||
HD_RPRIM_REMOVED,
|
||||
HD_RPRIM_UPDATED,
|
||||
HD_SAFE_MODE,
|
||||
HD_SELECTION_UPDATE,
|
||||
HD_SHARED_EXT_COMPUTATION_DATA,
|
||||
HD_SPRIM_ADDED,
|
||||
HD_SPRIM_REMOVED,
|
||||
HD_TASK_ADDED,
|
||||
HD_TASK_REMOVED,
|
||||
HD_VARYING_STATE
|
||||
);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_DEBUG_CODES_H
|
||||
@@ -0,0 +1,138 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DIRTY_LIST_H
|
||||
#define PXR_IMAGING_HD_DIRTY_LIST_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/rprimCollection.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRenderIndex;
|
||||
|
||||
using HdDirtyListSharedPtr = std::shared_ptr<class HdDirtyList>;
|
||||
|
||||
/// \class HdDirtyList
|
||||
///
|
||||
/// Used for faster iteration of dirty rprims, filtered by mask.
|
||||
///
|
||||
/// GetDirtyRprims implicitly refresh and cache the list if needed.
|
||||
/// The returning prims list will be used for sync.
|
||||
///
|
||||
/// DirtyList construction can expensive. We have 3 layer
|
||||
/// versioning to make it efficient.
|
||||
///
|
||||
/// 1. Nothing changed since last time (super fast),
|
||||
/// no prims need to be synced.
|
||||
/// DirtyList returns empty vector GetDirtyRprims.
|
||||
/// This can be detected by HdChangeTracker::GetSceneStateVersion.
|
||||
/// It's incremented when any change made on any prim.
|
||||
///
|
||||
/// 2. Constantly updating Prims in a stable set (fast)
|
||||
/// when munging or playing back, the same set of prims are being updated,
|
||||
/// while the remaining prims (could be huge -- for example a large set)
|
||||
/// are static.
|
||||
/// Those animating prims can be distinguished by the Varying bit. The Varying
|
||||
/// bit is set on a prim when any dirty bit is set, and stays even after clean
|
||||
/// the dirty bit until HdChangeTracker::ResetVaryingState clears out.
|
||||
///
|
||||
/// DirtyList caches those prims in a list at the first time (described in 3.),
|
||||
/// and returns the list for the subsequent queries. Since that list is
|
||||
/// conservatively picked by the Varying bit instead of the actual DirtyBits
|
||||
/// needed for various reprs, consumer of DirtyList needs to check the
|
||||
/// dirtybits again (this is a common pattern in HdRprim, HdMesh and other).
|
||||
///
|
||||
/// 3. Varying state changed (medium cost)
|
||||
/// when a exisitng prim newly starts updating (start munging), or when
|
||||
/// a majority of the dirtylist stop updating, we need to reconstruct
|
||||
/// the dirtylist. HdChangeTracker::GetVaryingStateVersion() tells the
|
||||
/// right timing to refresh, by comparing the cached version number in
|
||||
/// the dirtylist.
|
||||
///
|
||||
/// To construct a dirtylist, the Varying bit is checked instead of other
|
||||
/// dirtybits, since effective dirtybits may differ over prims, by prim
|
||||
/// type (mesh vs curve) or by per-prim repr style (flat vs smooth)
|
||||
///
|
||||
/// example: [x]=Varying [x*]=Dirty,Varying
|
||||
///
|
||||
/// say in change tracker:
|
||||
/// A B C D E [F*] [G] [H*] [I*] [J] [K] L M N ...
|
||||
/// then the dirtylist will be:
|
||||
/// F*, G, H*, I*, J, K
|
||||
///
|
||||
/// Note that G, J and K are not dirty, but it exists in the dirtylist.
|
||||
/// This optimization gives the maximum efficiency when all of Varying
|
||||
/// prims are being updated.
|
||||
///
|
||||
/// 4. Initial creation, filter changes (most expensive)
|
||||
/// If we fail to early out all the above condition, such as when we add
|
||||
/// new prims or switch the render tag set, all prims should be
|
||||
/// passed down to HdRenderIndex::Sync, except ones we know that are
|
||||
/// completely clean. Although it requires to sweep all prims in the
|
||||
/// render index, this traversal has already been optimized
|
||||
/// using the Gather utility.
|
||||
///
|
||||
class HdDirtyList {
|
||||
public:
|
||||
HD_API
|
||||
HdDirtyList(HdRprimCollection const& collection,
|
||||
HdRenderIndex &index);
|
||||
HD_API
|
||||
~HdDirtyList();
|
||||
|
||||
/// Returns a reference of dirty ids.
|
||||
/// If the change tracker hasn't changed any state since the last time
|
||||
/// GetDirtyRprims gets called, it simply returns an empty list.
|
||||
/// Otherwise depending on what changed, it will return a list of
|
||||
/// prims to be synced.
|
||||
/// Therefore, it is expected that GetDirtyRprims is called only once
|
||||
/// per render index sync.
|
||||
HD_API
|
||||
SdfPathVector const& GetDirtyRprims();
|
||||
|
||||
/// Update the tracking state for this HdDirtyList with the new collection,
|
||||
/// if the update cannot be applied, return false.
|
||||
HD_API
|
||||
bool ApplyEdit(HdRprimCollection const& newCollection);
|
||||
|
||||
private:
|
||||
HdRprimCollection _collection;
|
||||
SdfPathVector _dirtyIds;
|
||||
HdRenderIndex &_renderIndex;
|
||||
|
||||
unsigned int _sceneStateVersion;
|
||||
unsigned int _rprimIndexVersion;
|
||||
unsigned int _renderTagVersion;
|
||||
unsigned int _varyingStateVersion;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_DIRTY_LIST_H
|
||||
@@ -0,0 +1,254 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DRAW_ITEM_H
|
||||
#define PXR_IMAGING_HD_DRAW_ITEM_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
#include "pxr/imaging/hd/drawingCoord.h"
|
||||
#include "pxr/imaging/hd/rprimSharedData.h"
|
||||
|
||||
#include "pxr/imaging/hf/perfLog.h"
|
||||
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/bbox3d.h"
|
||||
#include "pxr/base/gf/vec2i.h"
|
||||
#include "pxr/base/gf/vec4f.h"
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdDrawItem
|
||||
///
|
||||
/// A draw item is a light-weight representation of an HdRprim's resources and
|
||||
/// material to be used for rendering. The visual representation (HdRepr) of an
|
||||
/// HdRprim might require multiple draw items.
|
||||
///
|
||||
/// HdDrawItem(s) are created by the HdRprim (HdMesh, HdBasisCurve, ..) for each
|
||||
/// HdRepr. The relevant compositional hierarchy is:
|
||||
///
|
||||
/// HdRprim
|
||||
/// |
|
||||
/// +--HdRepr(s)
|
||||
/// |
|
||||
/// +--HdDrawItem(s)
|
||||
///
|
||||
/// HdDrawItem(s) are consumed by HdRenderPass for its HdRprimCollection via
|
||||
/// HdRenderIndex::GetDrawItems.
|
||||
///
|
||||
/// \note
|
||||
/// Rendering backends may choose to specialize this class.
|
||||
///
|
||||
class HdDrawItem {
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdDrawItem");
|
||||
|
||||
HD_API
|
||||
HdDrawItem(HdRprimSharedData const *sharedData);
|
||||
HD_API
|
||||
virtual ~HdDrawItem();
|
||||
|
||||
HD_API
|
||||
SdfPath const &GetRprimID() const { return _sharedData->rprimID; }
|
||||
|
||||
HD_API
|
||||
GfBBox3d const & GetBounds() const { return _sharedData->bounds; }
|
||||
|
||||
HD_API
|
||||
GfRange3d const& GetExtent() const {
|
||||
return _sharedData->bounds.GetRange();
|
||||
}
|
||||
|
||||
HD_API
|
||||
GfMatrix4d const& GetMatrix() const {
|
||||
return _sharedData->bounds.GetMatrix();
|
||||
}
|
||||
|
||||
/// Returns a BufferRange of constant-Primvar.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetConstantPrimvarRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetConstantPrimvarIndex());
|
||||
}
|
||||
|
||||
/// Returns the number of nested levels of instance primvars.
|
||||
HD_API
|
||||
int GetInstancePrimvarNumLevels() const {
|
||||
TF_VERIFY(_sharedData->instancerLevels != -1);
|
||||
return _sharedData->instancerLevels;
|
||||
}
|
||||
|
||||
/// Returns a BufferRange of instance-Primvars at \p level
|
||||
/// the level is assigned to nested instancers in a bottom-up manner.
|
||||
///
|
||||
/// example: (numLevels = 2)
|
||||
///
|
||||
/// instancerA (level = 1)
|
||||
/// |
|
||||
/// +-- instancerB (level = 0)
|
||||
/// |
|
||||
/// +-- mesh_prototype
|
||||
///
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetInstancePrimvarRange(int level) const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetInstancePrimvarIndex(level));
|
||||
}
|
||||
|
||||
/// Returns a BufferRange of instance-index indirection.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetInstanceIndexRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetInstanceIndexIndex());
|
||||
}
|
||||
|
||||
/// Returns a BufferRange of element-Primvars.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetElementPrimvarRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetElementPrimvarIndex());
|
||||
}
|
||||
|
||||
/// Returns a BufferArrayRange of topology.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetTopologyRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetTopologyIndex());
|
||||
}
|
||||
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetTopologyVisibilityRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetTopologyVisibilityIndex());
|
||||
}
|
||||
|
||||
/// Returns a BufferArrayRange of vertex-primvars.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetVertexPrimvarRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetVertexPrimvarIndex());
|
||||
}
|
||||
|
||||
/// Returns a BufferArrayRange of varying primvars.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetVaryingPrimvarRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetVaryingPrimvarIndex());
|
||||
}
|
||||
|
||||
|
||||
/// Returns a BufferArrayRange of face-varying primvars.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetFaceVaryingPrimvarRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetFaceVaryingPrimvarIndex());
|
||||
}
|
||||
|
||||
HD_API
|
||||
HdDrawingCoord *GetDrawingCoord() {
|
||||
return &_drawingCoord;
|
||||
}
|
||||
|
||||
/// Returns the authored visibility, expressed by the delegate.
|
||||
HD_API
|
||||
bool GetVisible() const { return _sharedData->visible; }
|
||||
|
||||
HD_API
|
||||
TfToken const& GetMaterialTag() const {
|
||||
return _sharedData->materialTag;
|
||||
}
|
||||
|
||||
/// Returns true if the drawItem has instancer.
|
||||
HD_API
|
||||
bool HasInstancer() const {
|
||||
TF_VERIFY(_sharedData->instancerLevels != -1);
|
||||
return (_sharedData->instancerLevels > 0);
|
||||
}
|
||||
|
||||
/// Returns the hash of the versions of underlying buffers. When the
|
||||
/// hash changes, it means the drawing coord might have been reassigned,
|
||||
/// so any drawing coord caching buffer (e.g. indirect dispatch buffer)
|
||||
/// has to be rebuilt at the moment.
|
||||
/// Note that this value is a hash, not sequential.
|
||||
HD_API
|
||||
size_t GetBufferArraysHash() const;
|
||||
|
||||
/// Returns the hash of the element offsets of the underlying BARs.
|
||||
/// When the hash changes, it means that any drawing coord caching
|
||||
/// buffer (e.g. the indirect dispatch buffer) has to be rebuilt.
|
||||
/// Note that this value is a hash, not sequential.
|
||||
HD_API
|
||||
size_t GetElementOffsetsHash() const;
|
||||
|
||||
/// Tests the intersection with the view projection matrix.
|
||||
/// Returns true if this drawItem is in the frustum.
|
||||
///
|
||||
/// XXX: Currently if this drawitem uses HW instancing, always returns true.
|
||||
HD_API
|
||||
bool IntersectsViewVolume(GfMatrix4d const &viewProjMatrix) const;
|
||||
|
||||
HD_API
|
||||
friend std::ostream &operator <<(std::ostream &out,
|
||||
const HdDrawItem& self);
|
||||
|
||||
protected:
|
||||
// TfHash support.
|
||||
template <class HashState>
|
||||
friend void TfHashAppend(HashState &h, HdDrawItem const &di);
|
||||
|
||||
/// Returns the shared data
|
||||
HD_API
|
||||
HdRprimSharedData const *_GetSharedData() const {
|
||||
return _sharedData;
|
||||
}
|
||||
|
||||
/// Allows derived classes to return a hash of the versions of buffers
|
||||
/// they manage.
|
||||
/// Called by GetBufferArraysHash.
|
||||
HD_API
|
||||
virtual size_t _GetBufferArraysHash() const;
|
||||
|
||||
/// Allows derived classes to return a hash of the element offsets of
|
||||
/// the underlying BARs they manage.
|
||||
/// Called by GetBufferArraysHash.
|
||||
HD_API
|
||||
virtual size_t _GetElementOffsetsHash() const;
|
||||
|
||||
private:
|
||||
// configuration of how to bundle the drawing coordinate for this draw item
|
||||
// out of BARs in sharedData
|
||||
HdDrawingCoord _drawingCoord;
|
||||
|
||||
// pointer to shared data across reprs, owned by rprim:
|
||||
// bufferArrayRanges, bounds, visibility
|
||||
HdRprimSharedData const *_sharedData;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_DRAW_ITEM_H
|
||||
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DRAWING_COORD_H
|
||||
#define PXR_IMAGING_HD_DRAWING_COORD_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
#include <stdint.h>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdDrawingCoord
|
||||
///
|
||||
/// A tiny set of integers, which provides an indirection mapping from the
|
||||
/// conceptual space of an HdRprim's resources (topological, primvar &
|
||||
/// instancing) to the index within HdBufferArrayRangeContainer, where the
|
||||
/// resource is stored.
|
||||
///
|
||||
/// Each HdDrawItem contains a HdDrawingCoord, with the relevant compositional
|
||||
/// hierarchy being:
|
||||
///
|
||||
/// HdRprim
|
||||
/// |
|
||||
/// +--HdRepr(s)
|
||||
/// | |
|
||||
/// | +--HdDrawItem(s)----------.
|
||||
/// | | |
|
||||
/// | +--HdDrawingCoord |
|
||||
/// | | (mapping provided by HdDrawingCoord)
|
||||
/// +--HdRprimSharedData |
|
||||
/// | |
|
||||
/// +--HdBARContainer <--------+
|
||||
///
|
||||
///
|
||||
/// Having this indirection provides a recipe for how to configure
|
||||
/// a drawing coordinate, which is a bundle of HdBufferArrayRanges, while
|
||||
/// they are shared or not shared across different representations
|
||||
/// constructed on the same prim.
|
||||
///
|
||||
/// HullRepr --------- Rprim --------- RefinedRepr
|
||||
/// | | |
|
||||
/// DrawItem | DrawItem
|
||||
/// | | |
|
||||
/// DrawingCoord Container DrawingCoord
|
||||
/// constant -------> [ 0 ] <------ constant
|
||||
/// vertex -------> [ 1 ]
|
||||
/// topology -------> [ 2 ]
|
||||
/// [ 3 ]
|
||||
/// [ 4 ]
|
||||
/// [ 5 ]
|
||||
/// [ 6 ]
|
||||
/// [ 7 ]
|
||||
/// [ 8 ] <------ vertex (refined)
|
||||
/// [ 9 ] <------ topology (refined)
|
||||
/// ...
|
||||
/// instance level=0 ---> [ k ]
|
||||
/// instance level=1 ---> [k+1]
|
||||
/// instance level=2 ---> [k+2]
|
||||
///
|
||||
class HdDrawingCoord {
|
||||
public:
|
||||
static const int CustomSlotsBegin = 8;
|
||||
static const int DefaultNumSlots = 3; /* Constant, Vertex, Topology */
|
||||
static const int Unassigned = -1;
|
||||
|
||||
HdDrawingCoord() :
|
||||
// default slots:
|
||||
_constantPrimvar(0),
|
||||
_vertexPrimvar(1),
|
||||
_topology(2),
|
||||
_elementPrimvar(3),
|
||||
_instanceIndex(4),
|
||||
_faceVaryingPrimvar(5),
|
||||
_topologyVisibility(6),
|
||||
_varyingPrimvar(7),
|
||||
_instancePrimvar(Unassigned) {
|
||||
}
|
||||
|
||||
int GetConstantPrimvarIndex() const { return _constantPrimvar; }
|
||||
void SetConstantPrimvarIndex(int slot) { _constantPrimvar = slot; }
|
||||
int GetVertexPrimvarIndex() const { return _vertexPrimvar; }
|
||||
void SetVertexPrimvarIndex(int slot) { _vertexPrimvar = slot; }
|
||||
int GetTopologyIndex() const { return _topology; }
|
||||
void SetTopologyIndex(int slot) { _topology = slot; }
|
||||
int GetElementPrimvarIndex() const { return _elementPrimvar; }
|
||||
void SetElementPrimvarIndex(int slot) { _elementPrimvar = slot; }
|
||||
int GetInstanceIndexIndex() const { return _instanceIndex; }
|
||||
void SetInstanceIndexIndex(int slot) { _instanceIndex = slot; }
|
||||
int GetFaceVaryingPrimvarIndex() const { return _faceVaryingPrimvar; }
|
||||
void SetFaceVaryingPrimvarIndex(int slot) { _faceVaryingPrimvar = slot; }
|
||||
int GetTopologyVisibilityIndex() const { return _topologyVisibility; }
|
||||
void SetTopologyVisibilityIndex(int slot) { _topologyVisibility = slot; }
|
||||
int GetVaryingPrimvarIndex() const { return _varyingPrimvar; }
|
||||
void SetVaryingPrimvarIndex(int slot) { _varyingPrimvar = slot; }
|
||||
|
||||
// instance primvars take up a range of slots.
|
||||
void SetInstancePrimvarBaseIndex(int slot) { _instancePrimvar = slot; }
|
||||
int GetInstancePrimvarIndex(int level) const {
|
||||
TF_VERIFY(_instancePrimvar != Unassigned);
|
||||
return _instancePrimvar + level;
|
||||
}
|
||||
|
||||
private:
|
||||
int8_t _constantPrimvar;
|
||||
int8_t _vertexPrimvar;
|
||||
int8_t _topology;
|
||||
int8_t _elementPrimvar;
|
||||
int8_t _instanceIndex;
|
||||
int8_t _faceVaryingPrimvar;
|
||||
int8_t _topologyVisibility;
|
||||
int8_t _varyingPrimvar;
|
||||
int8_t _instancePrimvar;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_DRAWING_COORD_H
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DRIVER_H
|
||||
#define PXR_IMAGING_HD_DRIVER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// HdDriver represents a device object, commonly a render device, that is owned
|
||||
/// by the application and passed to HdRenderIndex. The RenderIndex passes it to
|
||||
/// the render delegate and rendering tasks.
|
||||
/// The application manages the lifetime (destruction) of HdDriver and must
|
||||
/// ensure it remains valid while Hydra is running.
|
||||
class HdDriver {
|
||||
public:
|
||||
TfToken name;
|
||||
VtValue driver;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_ENGINE_H
|
||||
#define PXR_IMAGING_HD_ENGINE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
|
||||
#include "pxr/imaging/hd/task.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRenderIndex;
|
||||
class HdRenderDelegate;
|
||||
class HdResourceRegistry;
|
||||
|
||||
using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
|
||||
using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
|
||||
|
||||
/// \class HdEngine
|
||||
///
|
||||
/// The application-facing entry point top-level entry point for accessing Hydra.
|
||||
/// Typically the application would only create one of these.
|
||||
class HdEngine {
|
||||
public:
|
||||
HD_API
|
||||
HdEngine();
|
||||
HD_API
|
||||
virtual ~HdEngine();
|
||||
|
||||
/// \name Task Context
|
||||
///
|
||||
/// External interface to set data/state in the task context passed to
|
||||
/// each task in the render graph
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Adds or updates the value associated with the token.
|
||||
/// Only one is supported for each token.
|
||||
HD_API
|
||||
void SetTaskContextData(const TfToken &id, const VtValue &data);
|
||||
|
||||
/// If found, will return the value from the task context data associated
|
||||
/// with the token. Returns false if the data could not be found.
|
||||
HD_API
|
||||
bool GetTaskContextData(const TfToken &id, VtValue *data) const;
|
||||
|
||||
/// Removes the specified token.
|
||||
HD_API
|
||||
void RemoveTaskContextData(const TfToken &id);
|
||||
|
||||
/// Removes all keys.
|
||||
HD_API
|
||||
void ClearTaskContextData();
|
||||
|
||||
/// @}
|
||||
|
||||
/// Execute tasks.
|
||||
HD_API
|
||||
void Execute(HdRenderIndex *index,
|
||||
HdTaskSharedPtrVector *tasks);
|
||||
|
||||
|
||||
private:
|
||||
/// Context containing token-value pairs, that is passed to each
|
||||
/// task in the render graph. The task-context can be pre-populated
|
||||
/// and managed externally, so the state is persistent between runs of the
|
||||
/// render graph.
|
||||
HdTaskContext _taskContext;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_ENGINE_H
|
||||
@@ -0,0 +1,247 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_ENUMS_H
|
||||
#define PXR_IMAGING_HD_ENUMS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \enum HdCompareFunction
|
||||
///
|
||||
/// Abstraction of the Graphics compare functions.
|
||||
///
|
||||
enum HdCompareFunction
|
||||
{
|
||||
HdCmpFuncNever,
|
||||
HdCmpFuncLess,
|
||||
HdCmpFuncEqual,
|
||||
HdCmpFuncLEqual,
|
||||
HdCmpFuncGreater,
|
||||
HdCmpFuncNotEqual,
|
||||
HdCmpFuncGEqual,
|
||||
HdCmpFuncAlways,
|
||||
|
||||
HdCmpFuncLast
|
||||
};
|
||||
|
||||
/// \enum HdStencilOp
|
||||
///
|
||||
/// Abstraction of the Graphics stencil test operations.
|
||||
///
|
||||
enum HdStencilOp
|
||||
{
|
||||
HdStencilOpKeep,
|
||||
HdStencilOpZero,
|
||||
HdStencilOpReplace,
|
||||
HdStencilOpIncrement,
|
||||
HdStencilOpIncrementWrap,
|
||||
HdStencilOpDecrement,
|
||||
HdStencilOpDecrementWrap,
|
||||
HdStencilOpInvert,
|
||||
|
||||
HdStencilOpLast
|
||||
};
|
||||
|
||||
/// \enum HdBlendOp
|
||||
///
|
||||
/// Abstraction of the Graphics blend operations.
|
||||
///
|
||||
enum HdBlendOp
|
||||
{
|
||||
HdBlendOpAdd,
|
||||
HdBlendOpSubtract,
|
||||
HdBlendOpReverseSubtract,
|
||||
HdBlendOpMin,
|
||||
HdBlendOpMax,
|
||||
|
||||
HdBlendOpLast
|
||||
};
|
||||
|
||||
/// \enum HdBlendFactor
|
||||
///
|
||||
/// Abstraction of the Graphics blend factors.
|
||||
///
|
||||
enum HdBlendFactor
|
||||
{
|
||||
HdBlendFactorZero,
|
||||
HdBlendFactorOne,
|
||||
HdBlendFactorSrcColor,
|
||||
HdBlendFactorOneMinusSrcColor,
|
||||
HdBlendFactorDstColor,
|
||||
HdBlendFactorOneMinusDstColor,
|
||||
HdBlendFactorSrcAlpha,
|
||||
HdBlendFactorOneMinusSrcAlpha,
|
||||
HdBlendFactorDstAlpha,
|
||||
HdBlendFactorOneMinusDstAlpha,
|
||||
HdBlendFactorConstantColor,
|
||||
HdBlendFactorOneMinusConstantColor,
|
||||
HdBlendFactorConstantAlpha,
|
||||
HdBlendFactorOneMinusConstantAlpha,
|
||||
HdBlendFactorSrcAlphaSaturate,
|
||||
HdBlendFactorSrc1Color,
|
||||
HdBlendFactorOneMinusSrc1Color,
|
||||
HdBlendFactorSrc1Alpha,
|
||||
HdBlendFactorOneMinusSrc1Alpha,
|
||||
|
||||
HdBlendFactorLast
|
||||
};
|
||||
|
||||
/// \enum HdCullStyle
|
||||
///
|
||||
/// Face culling options.
|
||||
///
|
||||
/// DontCare indicates this prim doesn't determine what should be culled.
|
||||
/// Any other CullStyle opinion will override this (such as from the viewer).
|
||||
///
|
||||
/// BackUnlessDoubleSided and FrontUnlessDoubleSided will only cull back or
|
||||
/// front faces if prim isn't marked as doubleSided.
|
||||
///
|
||||
enum HdCullStyle
|
||||
{
|
||||
HdCullStyleDontCare,
|
||||
HdCullStyleNothing,
|
||||
HdCullStyleBack,
|
||||
HdCullStyleFront,
|
||||
HdCullStyleBackUnlessDoubleSided,
|
||||
HdCullStyleFrontUnlessDoubleSided
|
||||
};
|
||||
|
||||
/// Returns the opposite of the given cullstyle; backface culling becomes
|
||||
/// frontface and vice versa.
|
||||
HD_API
|
||||
HdCullStyle HdInvertCullStyle(HdCullStyle cs);
|
||||
|
||||
enum HdPolygonMode
|
||||
{
|
||||
HdPolygonModeFill,
|
||||
HdPolygonModeLine
|
||||
};
|
||||
|
||||
/// \enum HdMeshGeomStyle
|
||||
///
|
||||
/// Hydra native geom styles.
|
||||
///
|
||||
enum HdMeshGeomStyle {
|
||||
HdMeshGeomStyleInvalid,
|
||||
HdMeshGeomStyleSurf,
|
||||
HdMeshGeomStyleEdgeOnly,
|
||||
HdMeshGeomStyleEdgeOnSurf,
|
||||
HdMeshGeomStyleHull,
|
||||
HdMeshGeomStyleHullEdgeOnly,
|
||||
HdMeshGeomStyleHullEdgeOnSurf,
|
||||
HdMeshGeomStylePoints
|
||||
};
|
||||
|
||||
enum HdBasisCurvesGeomStyle {
|
||||
HdBasisCurvesGeomStyleInvalid,
|
||||
HdBasisCurvesGeomStyleWire,
|
||||
HdBasisCurvesGeomStylePatch,
|
||||
HdBasisCurvesGeomStylePoints
|
||||
};
|
||||
|
||||
enum HdPointsGeomStyle {
|
||||
HdPointsGeomStyleInvalid,
|
||||
HdPointsGeomStylePoints
|
||||
};
|
||||
|
||||
///
|
||||
/// \enum HdInterpolation
|
||||
///
|
||||
/// Enumerates Hydra's primvar interpolation modes.
|
||||
///
|
||||
/// Constant: One value remains constant over the entire surface primitive.
|
||||
///
|
||||
/// Uniform: One value remains constant for each uv patch segment of the
|
||||
/// surface primitive.
|
||||
///
|
||||
/// Varying: Four values are interpolated over each uv patch segment of
|
||||
/// the surface. Bilinear interpolation is used for interpolation
|
||||
/// between the four values.
|
||||
///
|
||||
/// Vertex: Values are interpolated between each vertex in the surface
|
||||
/// primitive. The basis function of the surface is used for
|
||||
/// interpolation between vertices.
|
||||
///
|
||||
/// Facevarying: For polygons and subdivision surfaces, four values are
|
||||
/// interpolated over each face of the mesh. Bilinear interpolation
|
||||
/// is used for interpolation between the four values.
|
||||
///
|
||||
/// Instance: One value remains constant across each instance.
|
||||
///
|
||||
enum HdInterpolation
|
||||
{
|
||||
HdInterpolationConstant = 0,
|
||||
HdInterpolationUniform,
|
||||
HdInterpolationVarying,
|
||||
HdInterpolationVertex,
|
||||
HdInterpolationFaceVarying,
|
||||
HdInterpolationInstance,
|
||||
|
||||
HdInterpolationCount
|
||||
};
|
||||
|
||||
///
|
||||
/// \enum HdTextureType
|
||||
/// Enumerates Hydra's supported texture types.
|
||||
///
|
||||
/// Uv: Sample the uv coordinates and accesses a single 2d texture.
|
||||
///
|
||||
/// Field: Transform coordinates by matrix before accessing a single 3d
|
||||
/// texture.
|
||||
///
|
||||
/// Ptex: Use the ptex connectivity information to sample a ptex texture.
|
||||
///
|
||||
/// Udim: Remap the uv coordinates into udim coordinates using a maximum
|
||||
/// tile width of 10 and sample all the udim tiles found in the
|
||||
/// file system.
|
||||
///
|
||||
enum class HdTextureType
|
||||
{
|
||||
Uv,
|
||||
Field,
|
||||
Ptex,
|
||||
Udim
|
||||
};
|
||||
|
||||
/// \enum HdDepthPriority
|
||||
/// Sets the priorities for a depth based operation
|
||||
///
|
||||
/// <ul>
|
||||
/// <li>HdDepthPriorityNearest Prioritize objects nearest to the camera</li>
|
||||
/// <li>HdDepthPriorityFarthest Prioritize objects farthest from the camera</li>
|
||||
/// </ul>
|
||||
///
|
||||
enum HdDepthPriority
|
||||
{
|
||||
HdDepthPriorityNearest = 0,
|
||||
HdDepthPriorityFarthest,
|
||||
|
||||
HdDepthPriorityCount
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ENUMS_H
|
||||
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMP_CPU_COMPUTATION_H
|
||||
#define PXR_IMAGING_HD_EXT_COMP_CPU_COMPUTATION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/extCompInputSource.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
class HdExtComputation;
|
||||
class HdExtCompCpuComputation;
|
||||
|
||||
using HdExtCompCpuComputationSharedPtr =
|
||||
std::shared_ptr<HdExtCompCpuComputation>;
|
||||
|
||||
///
|
||||
/// A Buffer Source that represents a CPU implementation of a ExtComputation.
|
||||
///
|
||||
/// The computation implements the basic: input->processing->output model
|
||||
/// where the inputs are other buffer sources and processing happens during
|
||||
/// resolve.
|
||||
///
|
||||
/// As a computation may have many outputs, the outputs from the CPU
|
||||
/// Computation can not be directly associated with a BAR. Instead
|
||||
/// other buffer source computation bind the output to sources that can
|
||||
/// be used in a BAR.
|
||||
///
|
||||
/// Outputs to a computation are in SOA form, so a computation may have
|
||||
/// many outputs, but each output has the same number of elements in it.
|
||||
class HdExtCompCpuComputation final : public HdNullBufferSource {
|
||||
public:
|
||||
static const size_t INVALID_OUTPUT_INDEX;
|
||||
|
||||
/// Constructs a new Cpu ExtComputation source.
|
||||
/// inputs provides a list of buffer sources that this computation
|
||||
/// requires.
|
||||
/// outputs is a list of outputs by names that the computation produces.
|
||||
///
|
||||
/// Num elements specifies the number of elements in the output.
|
||||
///
|
||||
/// sceneDelegate and id are used to callback to the scene delegate
|
||||
/// in order to invoke computation processing.
|
||||
HdExtCompCpuComputation(const SdfPath &id,
|
||||
const Hd_ExtCompInputSourceSharedPtrVector &inputs,
|
||||
const TfTokenVector &outputs,
|
||||
int numElements,
|
||||
HdSceneDelegate *sceneDelegate);
|
||||
|
||||
/// Create a CPU computation implementing the given abstract computation.
|
||||
/// The scene delegate identifies which delegate to pull scene inputs from.
|
||||
HD_API
|
||||
static HdExtCompCpuComputationSharedPtr
|
||||
CreateComputation(HdSceneDelegate *sceneDelegate,
|
||||
const HdExtComputation &computation,
|
||||
HdBufferSourceSharedPtrVector *computationSources);
|
||||
|
||||
HD_API
|
||||
virtual ~HdExtCompCpuComputation() = default;
|
||||
|
||||
/// Returns the id for this computation as a token.
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
|
||||
/// Ask the scene delegate to run the computation and captures the output
|
||||
/// signals.
|
||||
HD_API
|
||||
virtual bool Resolve() override;
|
||||
|
||||
HD_API
|
||||
virtual size_t GetNumElements() const override;
|
||||
|
||||
|
||||
/// Converts a output name token into an index.
|
||||
HD_API
|
||||
size_t GetOutputIndex(const TfToken &outputName) const;
|
||||
|
||||
/// Returns the value of the specified output
|
||||
/// (after the computations been Resolved).
|
||||
HD_API
|
||||
const VtValue &GetOutputByIndex(size_t index) const;
|
||||
|
||||
protected:
|
||||
/// Returns if the computation is specified correctly.
|
||||
HD_API
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
SdfPath _id;
|
||||
Hd_ExtCompInputSourceSharedPtrVector _inputs;
|
||||
TfTokenVector _outputs;
|
||||
size_t _numElements;
|
||||
HdSceneDelegate *_sceneDelegate;
|
||||
|
||||
std::vector<VtValue> _outputValues;
|
||||
|
||||
HdExtCompCpuComputation() = delete;
|
||||
HdExtCompCpuComputation(const HdExtCompCpuComputation &) = delete;
|
||||
HdExtCompCpuComputation &operator = (const HdExtCompCpuComputation &)
|
||||
= delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMP_CPU_COMPUTATION_H
|
||||
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMP_INPUT_SOURCE_H
|
||||
#define PXR_IMAGING_HD_EXT_COMP_INPUT_SOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class VtValue;
|
||||
|
||||
///
|
||||
/// Abstract base class for a Buffer Source that represents a binding to an
|
||||
/// input to an ExtComputation.
|
||||
///
|
||||
///
|
||||
class Hd_ExtCompInputSource : public HdNullBufferSource {
|
||||
public:
|
||||
/// Constructs the input binding with the name inputName
|
||||
HD_API
|
||||
Hd_ExtCompInputSource(const TfToken &inputName);
|
||||
|
||||
HD_API
|
||||
virtual ~Hd_ExtCompInputSource() = default;
|
||||
|
||||
/// Returns the name of the input.
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const final;
|
||||
|
||||
/// Returns the value associated with the input.
|
||||
HD_API
|
||||
virtual const VtValue &GetValue() const = 0;
|
||||
|
||||
private:
|
||||
TfToken _inputName;
|
||||
|
||||
Hd_ExtCompInputSource() = delete;
|
||||
Hd_ExtCompInputSource(const Hd_ExtCompInputSource &) = delete;
|
||||
Hd_ExtCompInputSource &operator = (const Hd_ExtCompInputSource &) = delete;
|
||||
};
|
||||
|
||||
using Hd_ExtCompInputSourceSharedPtr =
|
||||
std::shared_ptr<Hd_ExtCompInputSource>;
|
||||
using Hd_ExtCompInputSourceSharedPtrVector =
|
||||
std::vector<Hd_ExtCompInputSourceSharedPtr>;
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMP_INPUT_SOURCE_H
|
||||
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMP_PRIMVAR_BUFFER_SOURCE_H
|
||||
#define PXR_IMAGING_HD_EXT_COMP_PRIMVAR_BUFFER_SOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdExtCompCpuComputation;
|
||||
|
||||
using HdExtCompCpuComputationSharedPtr =
|
||||
std::shared_ptr<HdExtCompCpuComputation>;
|
||||
|
||||
/// Hd Buffer Source that binds a primvar to a Ext Computation output.
|
||||
/// This buffer source is compatible with being bound to a Bar.
|
||||
class HdExtCompPrimvarBufferSource final : public HdBufferSource {
|
||||
public:
|
||||
|
||||
/// Constructs a new primvar buffer source called primvarName and
|
||||
/// binds it to the output called sourceOutputName from the
|
||||
/// computation identified by source.
|
||||
///
|
||||
/// Default value provides type information for the primvar and may
|
||||
/// be used in the event of an error.
|
||||
HD_API
|
||||
HdExtCompPrimvarBufferSource(const TfToken &primvarName,
|
||||
const HdExtCompCpuComputationSharedPtr &source,
|
||||
const TfToken &sourceOutputName,
|
||||
const HdTupleType &valueType);
|
||||
|
||||
HD_API
|
||||
virtual ~HdExtCompPrimvarBufferSource() = default;
|
||||
|
||||
/// Returns the name of the primvar.
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
|
||||
/// Adds this Primvar's buffer description to the buffer spec vector.
|
||||
HD_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
|
||||
/// Computes and returns a hash value for the underlying data.
|
||||
HD_API
|
||||
virtual size_t ComputeHash() const override;
|
||||
|
||||
/// Extracts the primvar from the source computation.
|
||||
HD_API
|
||||
virtual bool Resolve() override;
|
||||
|
||||
/// Returns a raw pointer to the primvar data.
|
||||
HD_API
|
||||
virtual void const *GetData() const override;
|
||||
|
||||
/// Returns the tuple data format of the primvar data.
|
||||
HD_API
|
||||
virtual HdTupleType GetTupleType() const override;
|
||||
|
||||
/// Returns a count of the number of elements.
|
||||
HD_API
|
||||
virtual size_t GetNumElements() const override;
|
||||
|
||||
protected:
|
||||
/// Returns true if the binding to the source computation was successful.
|
||||
HD_API
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
// TfHash support.
|
||||
template <class HashState>
|
||||
friend void TfHashAppend(HashState &h,
|
||||
HdExtCompPrimvarBufferSource const &);
|
||||
|
||||
TfToken _primvarName;
|
||||
HdExtCompCpuComputationSharedPtr _source;
|
||||
size_t _sourceOutputIdx;
|
||||
HdTupleType _tupleType;
|
||||
void const *_rawDataPtr;
|
||||
|
||||
HdExtCompPrimvarBufferSource() = delete;
|
||||
HdExtCompPrimvarBufferSource(const HdExtCompPrimvarBufferSource &)
|
||||
= delete;
|
||||
HdExtCompPrimvarBufferSource &operator = (
|
||||
const HdExtCompPrimvarBufferSource &)
|
||||
= delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMP_PRIMVAR_BUFFER_SOURCE_H
|
||||
@@ -0,0 +1,162 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/sceneDelegate.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// Hydra Representation of a Client defined computation.
|
||||
///
|
||||
/// A computation provides a way to procedurally generate a primvar.
|
||||
///
|
||||
/// It represents a basic Input -> Processing -> Output model.
|
||||
///
|
||||
/// Primarily inputs are provided by the scene delegate via the Get()
|
||||
/// mechanism.
|
||||
///
|
||||
/// Computations can also be chained together, such that the output from
|
||||
/// one computation can be an input to another.
|
||||
///
|
||||
/// The results of a computation is designed to be in SOA form (structure or
|
||||
/// array), where each output is a member of the "structure" producing several
|
||||
/// parallel arrays. While the type of the elements of the array is defined
|
||||
/// by the output member, the number of elements in each array is the same
|
||||
/// across all outputs.
|
||||
///
|
||||
/// ExtComputations use a pull model, so processing is only triggered if
|
||||
/// a downstream computation or prim pulls on one the computations outputs.
|
||||
///
|
||||
class HdExtComputation : public HdSprim {
|
||||
public:
|
||||
/// Construct a new ExtComputation identified by id.
|
||||
HD_API
|
||||
HdExtComputation(SdfPath const &id);
|
||||
|
||||
HD_API
|
||||
virtual ~HdExtComputation() = default;
|
||||
|
||||
///
|
||||
/// Change tracking
|
||||
///
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyInputDesc = 1 << 0, ///< The list of inputs or input
|
||||
/// bindings changed
|
||||
DirtyOutputDesc = 1 << 1, ///< The list of outputs changed
|
||||
DirtyElementCount = 1 << 2, ///< The number of elements in the
|
||||
/// output arrays changed
|
||||
DirtySceneInput = 1 << 3, ///< A scene input changed value
|
||||
DirtyCompInput = 1 << 4, ///< A computation input changed value
|
||||
DirtyKernel = 1 << 5, ///< The compute kernel binding changed
|
||||
|
||||
DirtyDispatchCount = 1 << 6, ///< The number of kernel
|
||||
/// invocations to execute changed
|
||||
|
||||
AllDirty = (DirtyInputDesc
|
||||
|DirtyOutputDesc
|
||||
|DirtyElementCount
|
||||
|DirtySceneInput
|
||||
|DirtyCompInput
|
||||
|DirtyKernel
|
||||
|DirtyDispatchCount)
|
||||
};
|
||||
|
||||
HD_API
|
||||
virtual void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
HD_API
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
HD_API
|
||||
size_t GetDispatchCount() const;
|
||||
|
||||
HD_API
|
||||
size_t GetElementCount() const { return _elementCount; }
|
||||
|
||||
HD_API
|
||||
TfTokenVector const & GetSceneInputNames() const {
|
||||
return _sceneInputNames;
|
||||
}
|
||||
|
||||
HD_API
|
||||
TfTokenVector GetOutputNames() const;
|
||||
|
||||
HD_API
|
||||
HdExtComputationInputDescriptorVector const &
|
||||
GetComputationInputs() const {
|
||||
return _computationInputs;
|
||||
}
|
||||
|
||||
HD_API
|
||||
HdExtComputationOutputDescriptorVector const &
|
||||
GetComputationOutputs() const {
|
||||
return _computationOutputs;
|
||||
}
|
||||
|
||||
HD_API
|
||||
const std::string& GetGpuKernelSource() const { return _gpuKernelSource; }
|
||||
|
||||
HD_API
|
||||
bool IsInputAggregation() const;
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
void
|
||||
_Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
HD_API
|
||||
static bool _IsEnabledSharedExtComputationData();
|
||||
|
||||
private:
|
||||
size_t _dispatchCount;
|
||||
size_t _elementCount;
|
||||
TfTokenVector _sceneInputNames;
|
||||
HdExtComputationInputDescriptorVector _computationInputs;
|
||||
HdExtComputationOutputDescriptorVector _computationOutputs;
|
||||
std::string _gpuKernelSource;
|
||||
|
||||
// No default construction or copying
|
||||
HdExtComputation() = delete;
|
||||
HdExtComputation(const HdExtComputation &) = delete;
|
||||
HdExtComputation &operator =(const HdExtComputation &) = delete;
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMPUTATION_H
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_CONTEXT_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_CONTEXT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// Interface class that defines the execution environment for the client
|
||||
/// to run a computation.
|
||||
///
|
||||
class HdExtComputationContext {
|
||||
public:
|
||||
HdExtComputationContext() = default;
|
||||
virtual ~HdExtComputationContext();
|
||||
|
||||
///
|
||||
/// Obtains the value of an named input to the computation.
|
||||
///
|
||||
/// The code will issue a coding error and return a empty array
|
||||
/// if the input is missing or of a different type.
|
||||
///
|
||||
virtual const VtValue &GetInputValue(const TfToken &name) const = 0;
|
||||
|
||||
///
|
||||
/// Obtains the value of an named input to the computation.
|
||||
///
|
||||
/// If the input isn't present or of a different type
|
||||
/// nullptr will be returned.
|
||||
///
|
||||
virtual const VtValue *GetOptionalInputValuePtr(
|
||||
const TfToken &name) const = 0;
|
||||
|
||||
///
|
||||
/// Set the value of the specified output.
|
||||
///
|
||||
virtual void SetOutputValue(const TfToken &name, const VtValue &output) = 0;
|
||||
|
||||
///
|
||||
/// Called to indicate an error occurred while executing a computation
|
||||
/// so that its output are invalid.
|
||||
///
|
||||
virtual void RaiseComputationError() = 0;
|
||||
|
||||
private:
|
||||
HdExtComputationContext(const HdExtComputationContext &) = delete;
|
||||
HdExtComputationContext &operator = (const HdExtComputationContext &)
|
||||
= delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMPUTATION_CONTEXT_H
|
||||
@@ -0,0 +1,280 @@
|
||||
//
|
||||
// Copyright 2019 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_UTILS_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_UTILS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/extComputation.h"
|
||||
#include "pxr/imaging/hd/sceneDelegate.h"
|
||||
|
||||
#include "pxr/base/tf/span.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdExtComputationConstPtr = HdExtComputation const *;
|
||||
using HdExtComputationConstPtrVector = std::vector<HdExtComputationConstPtr>;
|
||||
|
||||
// This class contains utility methods to allow any Hydra backend to execute
|
||||
// CPU computations via the Hydra ExtComputation framework.
|
||||
//
|
||||
// Note:
|
||||
// The computation execution happens during Rprim sync. This precludes the
|
||||
// use of computations shared by multiple Rprims, since the chain of
|
||||
// computations for a computation primvar is executed for each Rprim.
|
||||
class HdExtComputationUtils {
|
||||
public:
|
||||
using ValueStore =
|
||||
std::unordered_map<TfToken, VtValue, TfToken::HashFunctor>;
|
||||
|
||||
// Returns a map containing the (token, value) pairs for each "computation
|
||||
// primvar".
|
||||
// The participating computations are ordered based on their dependency
|
||||
// and then, the CPU kernel is executed for each computation.
|
||||
HD_API
|
||||
static ValueStore
|
||||
GetComputedPrimvarValues(
|
||||
HdExtComputationPrimvarDescriptorVector const& compPrimvars,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
|
||||
template <unsigned int CAPACITY>
|
||||
using SampledValueStore =
|
||||
std::unordered_map<TfToken, HdTimeSampleArray<VtValue, CAPACITY>,
|
||||
TfToken::HashFunctor>;
|
||||
|
||||
/// Returns a map containing the (token, samples) pairs for each
|
||||
/// computation primvar, with up to \a maxSampleCount samples.
|
||||
/// The participating computations are ordered based on their dependency
|
||||
/// and then, the CPU kernel is executed for each computation.
|
||||
template <unsigned int CAPACITY>
|
||||
static void
|
||||
SampleComputedPrimvarValues(
|
||||
HdExtComputationPrimvarDescriptorVector const& compPrimvars,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
size_t maxSampleCount,
|
||||
SampledValueStore<CAPACITY> *computedPrimvarValueStore);
|
||||
|
||||
// Helper methods (these are public for testing purposes)
|
||||
using ComputationDependencyMap =
|
||||
std::unordered_map<HdExtComputation const *,
|
||||
HdExtComputationConstPtrVector>;
|
||||
// Returns true if an ordering of the computations wherein any dependencies
|
||||
// of a given computation come before it is possible, and fills
|
||||
// sortedComps with the ordering.
|
||||
// Returns false otherwise.
|
||||
// The directed graph of a computation (vertex) and its dependencies (edges)
|
||||
// is represented via the ComputationDependencyMap.
|
||||
HD_API
|
||||
static bool
|
||||
DependencySort(ComputationDependencyMap cdm,
|
||||
HdExtComputationConstPtrVector* sortedComps);
|
||||
|
||||
HD_API
|
||||
static void
|
||||
PrintDependencyMap(ComputationDependencyMap const& cdm);
|
||||
|
||||
private:
|
||||
HD_API
|
||||
static ComputationDependencyMap
|
||||
_GenerateDependencyMap(
|
||||
HdExtComputationPrimvarDescriptorVector const& compPrimvars,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
|
||||
template <unsigned int CAPACITY>
|
||||
static void
|
||||
_ExecuteSampledComputations(
|
||||
HdExtComputationConstPtrVector computations,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
size_t maxSampleCount,
|
||||
SampledValueStore<CAPACITY>* valueStore);
|
||||
|
||||
// Limits the list of the computation input time samples to the specified
|
||||
// maximum number of (unique) samples.
|
||||
HD_API
|
||||
static void
|
||||
_LimitTimeSamples(size_t maxSampleCount, std::vector<double>* times);
|
||||
|
||||
// Internal method to invoke the computation with the specified input
|
||||
// values, storing the output values in the provided buffer. The value
|
||||
// arrays correspond to GetSceneInputNames(), GetComputationInputs(), and
|
||||
// GetComputationOutputs() from the HdExtComputation, respectively, and are
|
||||
// required to have the same lengths.
|
||||
HD_API
|
||||
static bool
|
||||
_InvokeComputation(
|
||||
HdSceneDelegate& sceneDelegate,
|
||||
HdExtComputation const& computation,
|
||||
TfSpan<const VtValue> sceneInputValues,
|
||||
TfSpan<const VtValue> compInputValues,
|
||||
TfSpan<VtValue> compOutputValues);
|
||||
};
|
||||
|
||||
template <unsigned int CAPACITY>
|
||||
/*static*/ void
|
||||
HdExtComputationUtils::SampleComputedPrimvarValues(
|
||||
HdExtComputationPrimvarDescriptorVector const& compPrimvars,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
size_t maxSampleCount,
|
||||
SampledValueStore<CAPACITY> *computedPrimvarValueStore
|
||||
)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
|
||||
// Directed graph representation of the participating computations
|
||||
ComputationDependencyMap cdm =
|
||||
_GenerateDependencyMap(compPrimvars, sceneDelegate);
|
||||
|
||||
// Topological ordering of the computations
|
||||
HdExtComputationConstPtrVector sortedComputations;
|
||||
bool success = DependencySort(cdm, &sortedComputations);
|
||||
if (!success) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Execution
|
||||
SampledValueStore<CAPACITY> valueStore;
|
||||
_ExecuteSampledComputations<CAPACITY>(sortedComputations, sceneDelegate,
|
||||
maxSampleCount, &valueStore);
|
||||
|
||||
// Output extraction
|
||||
for (auto const& pv : compPrimvars) {
|
||||
TfToken const& compOutputName = pv.sourceComputationOutputName;
|
||||
(*computedPrimvarValueStore)[pv.name] = valueStore[compOutputName];
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned int CAPACITY>
|
||||
/*static*/ void
|
||||
HdExtComputationUtils::_ExecuteSampledComputations(
|
||||
HdExtComputationConstPtrVector computations,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
size_t maxSampleCount,
|
||||
SampledValueStore<CAPACITY> *valueStore
|
||||
)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
|
||||
for (auto const& comp : computations) {
|
||||
SdfPath const& compId = comp->GetId();
|
||||
|
||||
TfTokenVector const& sceneInputNames = comp->GetSceneInputNames();
|
||||
HdExtComputationInputDescriptorVector const& compInputs =
|
||||
comp->GetComputationInputs();
|
||||
HdExtComputationOutputDescriptorVector const& compOutputs =
|
||||
comp->GetComputationOutputs();
|
||||
|
||||
// Add all the scene inputs to the value store
|
||||
std::vector<double> times;
|
||||
for (TfToken const& input : sceneInputNames) {
|
||||
auto &samples = (*valueStore)[input];
|
||||
sceneDelegate->SampleExtComputationInput(compId, input, &samples);
|
||||
|
||||
for (size_t i = 0; i < samples.count; ++i)
|
||||
times.push_back(samples.times[i]);
|
||||
}
|
||||
|
||||
if (comp->IsInputAggregation()) {
|
||||
// An aggregator computation produces no output, and thus
|
||||
// doesn't need to be executed.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Also find all the time samples from the computed inputs.
|
||||
for (auto const& computedInput : compInputs) {
|
||||
auto const& samples =
|
||||
valueStore->at(computedInput.sourceComputationOutputName);
|
||||
for (size_t i = 0; i < samples.count; ++i) {
|
||||
times.push_back(samples.times[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the time samples to evaluate the computation at.
|
||||
_LimitTimeSamples(maxSampleCount, ×);
|
||||
|
||||
// Allocate enough space for the evaluated outputs.
|
||||
for (const TfToken &name : comp->GetOutputNames())
|
||||
{
|
||||
auto &output_samples = (*valueStore)[name];
|
||||
output_samples.Resize(times.size());
|
||||
output_samples.count = 0;
|
||||
}
|
||||
|
||||
TfSmallVector<VtValue, CAPACITY> sceneInputValues;
|
||||
sceneInputValues.reserve(sceneInputNames.size());
|
||||
|
||||
TfSmallVector<VtValue, CAPACITY> compInputValues;
|
||||
compInputValues.reserve(compInputs.size());
|
||||
|
||||
TfSmallVector<VtValue, CAPACITY> compOutputValues;
|
||||
|
||||
// Evaluate the computation for each time sample.
|
||||
for (double t : times) {
|
||||
|
||||
// Retrieve all the inputs (scene, computed) from the value store,
|
||||
// resampled to the required time.
|
||||
sceneInputValues.clear();
|
||||
for (auto const& sceneInput : comp->GetSceneInputNames()) {
|
||||
auto const& samples = valueStore->at(sceneInput);
|
||||
sceneInputValues.push_back(samples.Resample(t));
|
||||
}
|
||||
|
||||
compInputValues.clear();
|
||||
for (auto const& computedInput : compInputs) {
|
||||
auto const& samples =
|
||||
valueStore->at(computedInput.sourceComputationOutputName);
|
||||
compInputValues.push_back(samples.Resample(t));
|
||||
}
|
||||
|
||||
compOutputValues.resize(compOutputs.size());
|
||||
if (!_InvokeComputation(*sceneDelegate, *comp,
|
||||
TfMakeSpan(sceneInputValues),
|
||||
TfMakeSpan(compInputValues),
|
||||
TfMakeSpan(compOutputValues))) {
|
||||
// We could bail here, or choose to execute other computations.
|
||||
// Choose the latter.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add outputs to the value store (subsequent computations may need
|
||||
// them as computation inputs)
|
||||
for (size_t i = 0; i < compOutputValues.size(); ++i) {
|
||||
auto &output_samples = (*valueStore)[compOutputs[i].name];
|
||||
|
||||
output_samples.times[output_samples.count] = t;
|
||||
output_samples.values[output_samples.count] =
|
||||
std::move(compOutputValues[i]);
|
||||
++output_samples.count;
|
||||
}
|
||||
}
|
||||
|
||||
} // for each computation
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMPUTATION_UTILS_H
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_FIELD_H
|
||||
#define PXR_IMAGING_HD_FIELD_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bprim.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
#define HD_FIELD_TOKENS \
|
||||
(filePath)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdFieldTokens, HD_API, HD_FIELD_TOKENS);
|
||||
|
||||
class HdSceneDelegate;
|
||||
typedef std::vector<class HdField const *> HdFieldPtrConstVector;
|
||||
|
||||
/// \class HdField
|
||||
///
|
||||
/// Hydra schema for a USD field primitive. Acts like a texture, combined
|
||||
/// with other fields to make up a renderable volume.
|
||||
///
|
||||
class HdField : public HdBprim {
|
||||
public:
|
||||
HD_API
|
||||
HdField(SdfPath const & id);
|
||||
HD_API
|
||||
virtual ~HdField();
|
||||
|
||||
// Change tracking for HdField
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyTransform = 1 << 0,
|
||||
DirtyParams = 1 << 1,
|
||||
AllDirty = (DirtyTransform
|
||||
|DirtyParams)
|
||||
};
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_FIELD_H
|
||||
@@ -0,0 +1,109 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_FLAT_NORMALS_H
|
||||
#define PXR_IMAGING_HD_FLAT_NORMALS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/computation.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/base/gf/vec3d.h"
|
||||
#include "pxr/base/gf/vec3f.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdMeshTopology;
|
||||
|
||||
/// \class Hd_FlatNormals
|
||||
///
|
||||
/// Hd_FlatNormals encapsulates mesh flat normals information.
|
||||
/// It uses passed-in face index data and points data to compute
|
||||
/// flat per-face normals. It does this by breaking each face into
|
||||
/// a triangle fan centered at vertex 0, and averaging triangle normals.
|
||||
///
|
||||
class Hd_FlatNormals final {
|
||||
public:
|
||||
/// Computes the flat normals result using the supplied face coord
|
||||
/// information and points data. Returns an array of the same size and
|
||||
/// type as the source points, with optional packing.
|
||||
HD_API
|
||||
static VtArray<GfVec3f> ComputeFlatNormals(
|
||||
HdMeshTopology const * topology,
|
||||
GfVec3f const * pointsPtr);
|
||||
HD_API
|
||||
static VtArray<GfVec3d> ComputeFlatNormals(
|
||||
HdMeshTopology const * topology,
|
||||
GfVec3d const * pointsPtr);
|
||||
HD_API
|
||||
static VtArray<HdVec4f_2_10_10_10_REV> ComputeFlatNormalsPacked(
|
||||
HdMeshTopology const * topology,
|
||||
GfVec3f const * pointsPtr);
|
||||
HD_API
|
||||
static VtArray<HdVec4f_2_10_10_10_REV> ComputeFlatNormalsPacked(
|
||||
HdMeshTopology const * topology,
|
||||
GfVec3d const * pointsPtr);
|
||||
|
||||
private:
|
||||
Hd_FlatNormals() = delete;
|
||||
~Hd_FlatNormals() = delete;
|
||||
};
|
||||
|
||||
/// \class Hd_FlatNormalsComputation
|
||||
///
|
||||
/// Flat normal computation CPU.
|
||||
///
|
||||
class Hd_FlatNormalsComputation : public HdComputedBufferSource {
|
||||
public:
|
||||
HD_API
|
||||
Hd_FlatNormalsComputation(HdMeshTopology const *topology,
|
||||
HdBufferSourceSharedPtr const &points,
|
||||
TfToken const &dstName,
|
||||
bool packed);
|
||||
|
||||
/// overrides
|
||||
HD_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
HD_API
|
||||
virtual bool Resolve() override;
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
HdMeshTopology const *_topology;
|
||||
HdBufferSourceSharedPtr const _points;
|
||||
TfToken _dstName;
|
||||
bool _packed;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_FLAT_NORMALS_H
|
||||
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_GEOM_SUBSET_H
|
||||
#define PXR_IMAGING_HD_GEOM_SUBSET_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdGeomSubset
|
||||
///
|
||||
/// Describes a subset of a piece of geometry as a set of indices.
|
||||
///
|
||||
struct HdGeomSubset {
|
||||
enum Type {
|
||||
/// A subset of faces
|
||||
TypeFaceSet,
|
||||
|
||||
// For now, there is only one type, but this may grow in the future
|
||||
// to accomodate edges, points, etc.
|
||||
};
|
||||
|
||||
/// The type of elements this geometry subset includes.
|
||||
Type type;
|
||||
/// The path used to identify this subset in the scene.
|
||||
SdfPath id;
|
||||
/// The path used to identify this material bound to the subset.
|
||||
SdfPath materialId;
|
||||
/// The list of element indices contained in the subset.
|
||||
VtIntArray indices;
|
||||
};
|
||||
|
||||
/// A group of geometry subsets.
|
||||
typedef std::vector<HdGeomSubset> HdGeomSubsets;
|
||||
|
||||
HD_API
|
||||
bool operator==(const HdGeomSubset& lhs, const HdGeomSubset& rhs);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_GEOM_SUBSET_H
|
||||
@@ -0,0 +1,287 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_INSTANCE_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_INSTANCE_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
#include "pxr/imaging/hf/perfLog.h"
|
||||
|
||||
#include <tbb/concurrent_unordered_map.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class HdInstance
|
||||
///
|
||||
/// This class is used as an interface to a shared instance in
|
||||
/// HdInstanceRegistry.
|
||||
///
|
||||
/// KeyType is a hashable index type and VALUE is shared_ptr. In most use
|
||||
/// cases, the client computes a hash key which represents large bulky data
|
||||
/// (like topology, primvars) and registers it into HdInstanceRegistry. If the
|
||||
/// key has already been registered, the registry returns HdInstance and the
|
||||
/// client can use GetValue() without setting/computing actual bulky data. If
|
||||
/// it doesn't exist, IsFirstInstance() returns true for the first instance
|
||||
/// and the client needs to populate an appropriate data VALUE into the
|
||||
/// instance by SetValue().
|
||||
///
|
||||
/// In order to support concurrent access to HdInstanceRegistry, this
|
||||
/// class holds a lock to a mutex in HdInstanceRegistry. This lock will
|
||||
/// be held until the instance of this interface class is destroyed.
|
||||
///
|
||||
template <typename VALUE>
|
||||
class HdInstance {
|
||||
public:
|
||||
typedef uint64_t KeyType;
|
||||
typedef VALUE ValueType;
|
||||
|
||||
typedef KeyType ID;
|
||||
|
||||
struct ValueHolder {
|
||||
ValueHolder(ValueType const & value = ValueType())
|
||||
: value(value)
|
||||
, recycleCounter(0)
|
||||
{ }
|
||||
void ResetRecycleCounter() {
|
||||
recycleCounter = 0;
|
||||
}
|
||||
|
||||
ValueType value;
|
||||
int recycleCounter;
|
||||
};
|
||||
typedef tbb::concurrent_unordered_map<KeyType, ValueHolder> Dictionary;
|
||||
|
||||
typedef std::mutex RegistryMutex;
|
||||
typedef std::unique_lock<RegistryMutex> RegistryLock;
|
||||
|
||||
HdInstance() = delete;
|
||||
|
||||
/// Construct an instance holding a registry lock, representing a value
|
||||
/// held in a registry container.
|
||||
explicit HdInstance(KeyType const &key,
|
||||
ValueType const &value,
|
||||
RegistryLock &®istryLock,
|
||||
Dictionary *container)
|
||||
: _key(key)
|
||||
, _value(value)
|
||||
, _registryLock(std::move(registryLock))
|
||||
, _container(container)
|
||||
, _isFirstInstance(!bool(_value))
|
||||
{ }
|
||||
|
||||
/// Construct an instance with no lock or registry container. This
|
||||
/// is used to present a consistent interface to clients in cases
|
||||
/// where shared resource registration is disabled.
|
||||
explicit HdInstance(KeyType const &key)
|
||||
: _key(key)
|
||||
, _value(ValueType())
|
||||
, _registryLock()
|
||||
, _container(nullptr)
|
||||
, _isFirstInstance(!bool(_value))
|
||||
{ }
|
||||
|
||||
/// Returns the key
|
||||
KeyType const &GetKey() const { return _key; }
|
||||
|
||||
/// Returns the value
|
||||
ValueType const &GetValue() const { return _value; }
|
||||
|
||||
/// Update the value in dictionary indexed by the key.
|
||||
void SetValue(ValueType const &value) {
|
||||
if (_container) (*_container)[_key] = ValueHolder(value);
|
||||
_value = value;
|
||||
}
|
||||
|
||||
/// Returns true if the value has not been initialized.
|
||||
bool IsFirstInstance() const {
|
||||
return _isFirstInstance;
|
||||
}
|
||||
|
||||
private:
|
||||
KeyType _key;
|
||||
ValueType _value;
|
||||
RegistryLock _registryLock;
|
||||
Dictionary *_container;
|
||||
bool _isFirstInstance;
|
||||
};
|
||||
|
||||
/// \class HdInstanceRegistry
|
||||
///
|
||||
/// HdInstanceRegistry is a dictionary container of HdInstance.
|
||||
/// This class is almost just a dictionary from key to value.
|
||||
/// For cleaning unused entries, it provides GarbageCollect() API.
|
||||
/// It sweeps all entries in the dictionary and erase unreferenced entries.
|
||||
/// When HdInstance::ValueType is shared_ptr, it is regarded as unreferenced
|
||||
/// if the shared_ptr is unique (use_count==1). Note that Key is not
|
||||
/// involved to determine the lifetime of entries.
|
||||
///
|
||||
template <typename VALUE>
|
||||
class HdInstanceRegistry {
|
||||
public:
|
||||
typedef HdInstance<VALUE> InstanceType;
|
||||
|
||||
HdInstanceRegistry() = default;
|
||||
|
||||
/// Copy constructor. Need as HdInstanceRegistry is placed in a map
|
||||
/// and mutex is not copy constructable, so can't use default
|
||||
HdInstanceRegistry(const HdInstanceRegistry &other)
|
||||
: _dictionary(other._dictionary)
|
||||
, _registryMutex() // mutex is not copied
|
||||
{ }
|
||||
|
||||
/// Returns a shared instance for given key.
|
||||
InstanceType GetInstance(
|
||||
typename InstanceType::KeyType const &key);
|
||||
|
||||
/// Returns a shared instance for a given key
|
||||
/// only if the key exists in the dictionary.
|
||||
InstanceType FindInstance(
|
||||
typename InstanceType::KeyType const &key, bool *found);
|
||||
|
||||
/// Removes unreferenced entries and returns the count
|
||||
/// of remaining entries. When recycleCount is greater than zero,
|
||||
/// unreferenced entries will not be removed until GarbageCollect() is
|
||||
/// called that many more times, i.e. allowing unreferenced entries to
|
||||
/// be recycled if they are needed again.
|
||||
size_t GarbageCollect(int recycleCount = 0);
|
||||
|
||||
/// Returns a const iterator being/end of dictionary. Mainly used for
|
||||
/// resource auditing.
|
||||
typedef typename InstanceType::Dictionary::const_iterator const_iterator;
|
||||
const_iterator begin() const { return _dictionary.begin(); }
|
||||
const_iterator end() const { return _dictionary.end(); }
|
||||
|
||||
size_t size() const { return _dictionary.size(); }
|
||||
|
||||
void Invalidate();
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
static bool _IsUnique(std::shared_ptr<T> const &value) {
|
||||
return value.unique();
|
||||
}
|
||||
|
||||
typename InstanceType::Dictionary _dictionary;
|
||||
typename InstanceType::RegistryMutex _registryMutex;
|
||||
|
||||
HdInstanceRegistry &operator =(HdInstanceRegistry &) = delete;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// instance registry impl
|
||||
|
||||
template <typename VALUE>
|
||||
HdInstance<VALUE>
|
||||
HdInstanceRegistry<VALUE>::GetInstance(
|
||||
typename HdInstance<VALUE>::KeyType const &key)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
HF_MALLOC_TAG_FUNCTION();
|
||||
|
||||
// Grab Registry lock
|
||||
// (and don't release it in this function, return it instead)
|
||||
typename InstanceType::RegistryLock lock(_registryMutex);
|
||||
|
||||
typename InstanceType::Dictionary::iterator it = _dictionary.find(key);
|
||||
if (it == _dictionary.end()) {
|
||||
// not found. create new one
|
||||
it = _dictionary.insert(
|
||||
std::make_pair(key, typename InstanceType::ValueHolder())).first;
|
||||
}
|
||||
|
||||
it->second.ResetRecycleCounter();
|
||||
return InstanceType(key, it->second.value, std::move(lock), &_dictionary);
|
||||
}
|
||||
|
||||
template <typename VALUE>
|
||||
HdInstance<VALUE>
|
||||
HdInstanceRegistry<VALUE>::FindInstance(
|
||||
typename HdInstance<VALUE>::KeyType const &key, bool *found)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
HF_MALLOC_TAG_FUNCTION();
|
||||
|
||||
// Grab Registry lock
|
||||
// (and don't release it in this function, return it instead)
|
||||
typename InstanceType::RegistryLock lock(_registryMutex);
|
||||
|
||||
typename InstanceType::Dictionary::iterator it = _dictionary.find(key);
|
||||
if (it == _dictionary.end()) {
|
||||
*found = false;
|
||||
return InstanceType(key, VALUE(), std::move(lock), nullptr);
|
||||
} else {
|
||||
*found = true;
|
||||
it->second.ResetRecycleCounter();
|
||||
return InstanceType(key, it->second.value,std::move(lock),&_dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VALUE>
|
||||
size_t
|
||||
HdInstanceRegistry<VALUE>::GarbageCollect(int recycleCount)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
HF_MALLOC_TAG_FUNCTION();
|
||||
|
||||
// Skip garbage collection entirely when then the recycleCount is < 0
|
||||
if (recycleCount < 0) {
|
||||
return _dictionary.size();
|
||||
}
|
||||
|
||||
size_t inUseCount = 0;
|
||||
for (typename InstanceType::Dictionary::iterator it = _dictionary.begin();
|
||||
it != _dictionary.end();) {
|
||||
|
||||
// erase instance which isn't referred from anyone
|
||||
bool isUnique = _IsUnique(it->second.value);
|
||||
if (isUnique && (++it->second.recycleCounter > recycleCount)) {
|
||||
it = _dictionary.unsafe_erase(it);
|
||||
} else {
|
||||
++it;
|
||||
++inUseCount;
|
||||
}
|
||||
}
|
||||
return inUseCount;
|
||||
}
|
||||
|
||||
template <typename VALUE>
|
||||
void
|
||||
HdInstanceRegistry<VALUE>::Invalidate()
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
HF_MALLOC_TAG_FUNCTION();
|
||||
|
||||
_dictionary.clear();
|
||||
}
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_INSTANCE_REGISTRY_H
|
||||
@@ -0,0 +1,182 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_INSTANCER_H
|
||||
#define PXR_IMAGING_HD_INSTANCER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
class HdRenderIndex;
|
||||
class HdRprim;
|
||||
class HdRenderParam;
|
||||
|
||||
/// \class HdInstancer
|
||||
///
|
||||
/// This class exists to facilitate point cloud style instancing. Instancers,
|
||||
/// conceptually, are instructions to draw N objects; for each object, store
|
||||
/// which Rprim you're drawing and what instance-specific primvars you're
|
||||
/// binding.
|
||||
///
|
||||
/// "/InstancerA": prototypes = ["/sphere", "/cube", "/sphere"];
|
||||
/// translate = [ <0,0,0>, <1,0,0>, <0,1,0>]
|
||||
///
|
||||
/// Hydra stores this in reverse: Rprims store which instancer is drawing them,
|
||||
/// and the instancer stores which indices in that array of N objects are the
|
||||
/// given Rprim.
|
||||
///
|
||||
/// "/sphere": instancerId = "/InstancerA"
|
||||
/// "/cube": instancerId = "/InstancerA"
|
||||
/// Instancer A: indices("/sphere") = [0, 2]
|
||||
/// indices("/cube") = [1]
|
||||
/// translate = [<0,0,0>, <1,0,0>, <0,1,0>]
|
||||
///
|
||||
/// Instancing is implemented by the prototype drawing itself multiple times,
|
||||
/// and looking up per-instance data each time based on "indices": so
|
||||
/// "/sphere" would draw itself once with translate=<0,0,0> and once with
|
||||
/// translate=<0,1,0>.
|
||||
///
|
||||
/// To make things more exciting, instancers can be nested.
|
||||
///
|
||||
/// "/cube": instancerId = "/InstancerA"
|
||||
/// "/InstancerA": instancerId = "/InstancerB"
|
||||
/// indices("/cube") = [0, 1]
|
||||
/// translate = [<0,0,0>, <1,0,0>]
|
||||
/// "/InstancerB": indices("/InstancerA") = [0, 1]
|
||||
/// translate = [<0,0,0>, <0,1,0>]
|
||||
///
|
||||
/// In this case, "/cube" draws itself four times, for each of the
|
||||
/// index tuples <0,0>, <0,1>, <1,0>, <1,1> where the first index is
|
||||
/// the index in instancerA, and the second index is in instancerB.
|
||||
///
|
||||
/// If the same primvar (e.g. "translate") shows up at multiple levels of
|
||||
/// nesting, it's resolved as follows:
|
||||
///
|
||||
/// Transforms
|
||||
/// ----------
|
||||
///
|
||||
/// Instance primvars "translate", "rotate", "scale", and "instanceTransform"
|
||||
/// are used to compute the final transform of an instance. "translate"
|
||||
/// and "scale" are interpreted as vec3: position, and axis-aligned scale
|
||||
/// respectively. "rotate" is interpreted as a vec4 quaternion, and
|
||||
/// "instanceTransform" is a 4x4 matrix. In the transform computation,
|
||||
/// everything is converted to a 4x4 matrix.
|
||||
///
|
||||
/// There are additional transforms: "instancerTransform" comes from
|
||||
/// HdSceneDelegate::GetInstancerTransform(instancer, proto), and represents
|
||||
/// the constant transform between the instancer and the prototype. It
|
||||
/// varies with each level of nesting, but not across instances.
|
||||
///
|
||||
/// "transform" is the proto Rprim's local transform.
|
||||
///
|
||||
/// The final instance transform for instance "index" is computed as:
|
||||
///
|
||||
/// nested_transform(level) = instancerTransform(level) *
|
||||
/// translate(level, index) *
|
||||
/// rotate(level, index) *
|
||||
/// scale(level, index) *
|
||||
/// instanceTransform(level, index);
|
||||
/// output_transform = product(i : nested-levels - 1 -> 0) {
|
||||
/// nested_transform(i)
|
||||
/// } * transform;
|
||||
///
|
||||
/// Any transforms not provided by the scene delegate are set to identity.
|
||||
///
|
||||
/// Class responsibilities
|
||||
/// ======================
|
||||
///
|
||||
/// HdInstancer's primary role is to track the "indices" arrays for each
|
||||
/// proto used by an instancer, and any provided primvar arrays. The
|
||||
/// implementation is in the renderer-specific instancers, like HdStInstancer.
|
||||
///
|
||||
/// All data access (aside from local caches) is routed to the HdSceneDelegate.
|
||||
///
|
||||
|
||||
class HdInstancer {
|
||||
public:
|
||||
/// Constructor.
|
||||
HD_API
|
||||
HdInstancer(HdSceneDelegate* delegate, SdfPath const& id);
|
||||
|
||||
HD_API
|
||||
virtual ~HdInstancer();
|
||||
|
||||
/// Returns the identifier.
|
||||
SdfPath const& GetId() const { return _id; }
|
||||
|
||||
/// Returns the parent instancer identifier.
|
||||
SdfPath const& GetParentId() const { return _parentId; }
|
||||
|
||||
HdSceneDelegate* GetDelegate() const { return _delegate; }
|
||||
|
||||
HD_API
|
||||
static int GetInstancerNumLevels(HdRenderIndex& index,
|
||||
HdRprim const& rprim);
|
||||
|
||||
HD_API
|
||||
static TfTokenVector const & GetBuiltinPrimvarNames();
|
||||
|
||||
HD_API
|
||||
virtual void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
HD_API
|
||||
virtual void Finalize(HdRenderParam *renderParam);
|
||||
|
||||
HD_API
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const;
|
||||
|
||||
HD_API
|
||||
static void _SyncInstancerAndParents(
|
||||
HdRenderIndex &renderIndex,
|
||||
SdfPath const& instancerId);
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
void _UpdateInstancer(HdSceneDelegate *delegate,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
private:
|
||||
HdSceneDelegate* _delegate;
|
||||
SdfPath _id;
|
||||
SdfPath _parentId;
|
||||
|
||||
// XXX: This mutex exists for _SyncInstancerAndParents, which will go
|
||||
// away when the render index calls sync on instancers.
|
||||
std::mutex _instanceLock;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_INSTANCER_H
|
||||
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_LIGHT_H
|
||||
#define PXR_IMAGING_HD_LIGHT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
#define HD_LIGHT_TOKENS \
|
||||
(angle) \
|
||||
(color) \
|
||||
(colorTemperature) \
|
||||
(enableColorTemperature) \
|
||||
(exposure) \
|
||||
(height) \
|
||||
(intensity) \
|
||||
(radius) \
|
||||
(length) \
|
||||
((textureFile, "texture:file")) \
|
||||
((textureFormat, "texture:format")) \
|
||||
(width) \
|
||||
(diffuse) \
|
||||
(specular) \
|
||||
(normalize) \
|
||||
((shapingFocus, "shaping:focus")) \
|
||||
((shapingFocusTint, "shaping:focusTint")) \
|
||||
((shapingConeAngle, "shaping:cone:angle")) \
|
||||
((shapingConeSoftness, "shaping:cone:softness")) \
|
||||
((shapingIesFile, "shaping:ies:file")) \
|
||||
((shapingIesAngleScale, "shaping:ies:angleScale")) \
|
||||
((shapingIesNormalize, "shaping:ies:normalize")) \
|
||||
((shadowEnable, "shadow:enable")) \
|
||||
((shadowColor, "shadow:color")) \
|
||||
((shadowDistance, "shadow:distance")) \
|
||||
((shadowFalloff, "shadow:falloff")) \
|
||||
((shadowFalloffGamma, "shadow:falloffGamma")) \
|
||||
\
|
||||
(params) \
|
||||
(shadowCollection) \
|
||||
(shadowParams)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdLightTokens, HD_API, HD_LIGHT_TOKENS);
|
||||
|
||||
class HdSceneDelegate;
|
||||
typedef std::vector<class HdLight const *> HdLightPtrConstVector;
|
||||
|
||||
/// \class HdLight
|
||||
///
|
||||
/// A light model, used in conjunction with HdRenderPass.
|
||||
///
|
||||
class HdLight : public HdSprim {
|
||||
public:
|
||||
HD_API
|
||||
HdLight(SdfPath const & id);
|
||||
HD_API
|
||||
virtual ~HdLight();
|
||||
|
||||
// Change tracking for HdLight
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyTransform = 1 << 0,
|
||||
DirtyParams = 1 << 1,
|
||||
DirtyShadowParams = 1 << 2,
|
||||
DirtyCollection = 1 << 3,
|
||||
DirtyResource = 1 << 4,
|
||||
AllDirty = (DirtyTransform
|
||||
|DirtyParams
|
||||
|DirtyShadowParams
|
||||
|DirtyCollection
|
||||
|DirtyResource)
|
||||
};
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_LIGHT_H
|
||||
@@ -0,0 +1,216 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_MATERIAL_H
|
||||
#define PXR_IMAGING_HD_MATERIAL_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
#include "pxr/imaging/hd/sceneDelegate.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// Hydra Schema for a material object.
|
||||
///
|
||||
class HdMaterial : public HdSprim {
|
||||
public:
|
||||
// change tracking for HdMaterial prim
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
// XXX: Got to skip varying and force sync bits for now
|
||||
DirtyParams = 1 << 2,
|
||||
DirtyResource = 1 << 3,
|
||||
AllDirty = (DirtyParams | DirtyResource)
|
||||
};
|
||||
|
||||
HD_API
|
||||
virtual ~HdMaterial();
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
HdMaterial(SdfPath const& id);
|
||||
|
||||
private:
|
||||
// Class can not be default constructed or copied.
|
||||
HdMaterial() = delete;
|
||||
HdMaterial(const HdMaterial &) = delete;
|
||||
HdMaterial &operator =(const HdMaterial &) = delete;
|
||||
};
|
||||
|
||||
|
||||
/// \struct HdMaterialRelationship
|
||||
///
|
||||
/// Describes a connection between two nodes in a material.
|
||||
///
|
||||
/// A brief discussion of terminology follows:
|
||||
///
|
||||
/// * Shading nodes have inputs and outputs.
|
||||
/// * Shading nodes consume input values and produce output values.
|
||||
/// * Connections also have inputs and outputs.
|
||||
/// * Connections consume a value from the (\em inputId, \em inputName)
|
||||
/// and pass that value to the (\em outputId, \em outputName).
|
||||
///
|
||||
/// Note that a connection's input is considered an output on the
|
||||
/// upstream shading node, and the connection's output is an input
|
||||
/// on the downstream shading node.
|
||||
///
|
||||
/// A guideline to remember this terminology is that inputs
|
||||
/// are always upstream of outputs in the dataflow.
|
||||
///
|
||||
struct HdMaterialRelationship {
|
||||
SdfPath inputId;
|
||||
TfToken inputName;
|
||||
SdfPath outputId;
|
||||
TfToken outputName;
|
||||
};
|
||||
|
||||
// VtValue requirements
|
||||
HD_API
|
||||
bool operator==(const HdMaterialRelationship& lhs,
|
||||
const HdMaterialRelationship& rhs);
|
||||
|
||||
|
||||
/// \struct HdMaterialNode
|
||||
///
|
||||
/// Describes a material node which is made of a path, an identifier and
|
||||
/// a list of parameters.
|
||||
struct HdMaterialNode {
|
||||
SdfPath path;
|
||||
TfToken identifier;
|
||||
std::map<TfToken, VtValue> parameters;
|
||||
};
|
||||
|
||||
// VtValue requirements
|
||||
HD_API
|
||||
bool operator==(const HdMaterialNode& lhs, const HdMaterialNode& rhs);
|
||||
|
||||
|
||||
/// \struct HdMaterialNetwork
|
||||
///
|
||||
/// Describes a material network composed of nodes, primvars, and relationships
|
||||
/// between the nodes and terminals of those nodes.
|
||||
struct HdMaterialNetwork {
|
||||
std::vector<HdMaterialRelationship> relationships;
|
||||
std::vector<HdMaterialNode> nodes;
|
||||
TfTokenVector primvars;
|
||||
};
|
||||
|
||||
/// \struct HdMaterialNetworkMap
|
||||
///
|
||||
/// Describes a map from network type to network.
|
||||
struct HdMaterialNetworkMap {
|
||||
std::map<TfToken, HdMaterialNetwork> map;
|
||||
std::vector<SdfPath> terminals;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HdMaterialNetwork2
|
||||
///
|
||||
/// This struct replaces the previously used MatfiltNetwork and
|
||||
/// HdSt_MaterialNetwork.
|
||||
/// In the furuture this HdMaterialNetwork2 will replace the current
|
||||
/// HdMaterialNetwork defined above.
|
||||
///
|
||||
|
||||
/// \struct HdMaterialConnection2
|
||||
///
|
||||
/// Describes a single connection to an upsream node and output port
|
||||
/// Replacement for HdRelationship.
|
||||
struct HdMaterialConnection2 {
|
||||
SdfPath upstreamNode;
|
||||
TfToken upstreamOutputName;
|
||||
|
||||
bool operator==(const HdMaterialConnection2 & rhs) const {
|
||||
return upstreamNode == rhs.upstreamNode
|
||||
&& upstreamOutputName == rhs.upstreamOutputName;
|
||||
}
|
||||
};
|
||||
|
||||
/// \struct HdMaterialNode2
|
||||
///
|
||||
/// Describes an instance of a node within a network
|
||||
/// A node contains a (shader) type identifier, parameter values, and
|
||||
/// connections to upstream nodes. A single input (mapped by TfToken) may have
|
||||
/// multiple upstream connections to describe connected array elements.
|
||||
struct HdMaterialNode2 {
|
||||
TfToken nodeTypeId;
|
||||
std::map<TfToken, VtValue> parameters;
|
||||
std::map<TfToken, std::vector<HdMaterialConnection2>> inputConnections;
|
||||
|
||||
bool operator==(const HdMaterialNode2 & rhs) const {
|
||||
return nodeTypeId == rhs.nodeTypeId
|
||||
&& parameters == rhs.parameters
|
||||
&& inputConnections == rhs.inputConnections;
|
||||
}
|
||||
};
|
||||
|
||||
/// \struct HdMaterialNetwork2
|
||||
///
|
||||
/// Container of nodes and top-level terminal connections. This is the mutable
|
||||
/// representation of a shading network sent to filtering functions by a
|
||||
/// MatfiltFilterChain.
|
||||
struct HdMaterialNetwork2 {
|
||||
std::map<SdfPath, HdMaterialNode2> nodes;
|
||||
std::map<TfToken, HdMaterialConnection2> terminals;
|
||||
TfTokenVector primvars;
|
||||
|
||||
bool operator==(const HdMaterialNetwork2 & rhs) const {
|
||||
return nodes == rhs.nodes
|
||||
&& terminals == rhs.terminals
|
||||
&& primvars == rhs.primvars;
|
||||
}
|
||||
};
|
||||
|
||||
/// Converts a HdMaterialNetworkMap to a HdMaterialNetwork2
|
||||
HD_API
|
||||
void HdMaterialNetwork2ConvertFromHdMaterialNetworkMap(
|
||||
const HdMaterialNetworkMap & hdNetworkMap,
|
||||
HdMaterialNetwork2 *result,
|
||||
bool *isVolume = nullptr);
|
||||
|
||||
|
||||
// VtValue requirements
|
||||
HD_API
|
||||
std::ostream& operator<<(std::ostream& out, const HdMaterialNetwork& pv);
|
||||
HD_API
|
||||
bool operator==(const HdMaterialNetwork& lhs, const HdMaterialNetwork& rhs);
|
||||
HD_API
|
||||
bool operator!=(const HdMaterialNetwork& lhs, const HdMaterialNetwork& rhs);
|
||||
|
||||
HD_API
|
||||
std::ostream& operator<<(std::ostream& out,
|
||||
const HdMaterialNetworkMap& pv);
|
||||
HD_API
|
||||
bool operator==(const HdMaterialNetworkMap& lhs,
|
||||
const HdMaterialNetworkMap& rhs);
|
||||
HD_API
|
||||
bool operator!=(const HdMaterialNetworkMap& lhs,
|
||||
const HdMaterialNetworkMap& rhs);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_MATERIAL_H
|
||||
@@ -0,0 +1,224 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_MESH_H
|
||||
#define PXR_IMAGING_HD_MESH_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/meshTopology.h"
|
||||
#include "pxr/imaging/hd/rprim.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
#include "pxr/imaging/pxOsd/subdivTags.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
#define HD_MESH_REPR_DESC_TOKENS \
|
||||
(surfaceShader) \
|
||||
(surfaceShaderUnlit) \
|
||||
(surfaceShaderSheer) \
|
||||
(surfaceShaderOutline) \
|
||||
(constantColor) \
|
||||
(hullColor) \
|
||||
(pointColor)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMeshReprDescTokens, HD_API,
|
||||
HD_MESH_REPR_DESC_TOKENS);
|
||||
|
||||
/// \class HdMeshReprDesc
|
||||
///
|
||||
/// Descriptor to configure the drawItem(s) for a repr
|
||||
///
|
||||
struct HdMeshReprDesc {
|
||||
HdMeshReprDesc(HdMeshGeomStyle geomStyle = HdMeshGeomStyleInvalid,
|
||||
HdCullStyle cullStyle = HdCullStyleDontCare,
|
||||
TfToken shadingTerminal = HdMeshReprDescTokens->surfaceShader,
|
||||
bool flatShadingEnabled = true,
|
||||
bool blendWireframeColor = true,
|
||||
bool doubleSided = false,
|
||||
float lineWidth = 0,
|
||||
bool useCustomDisplacement = true,
|
||||
bool enableScalarOverride = true)
|
||||
: geomStyle(geomStyle)
|
||||
, cullStyle(cullStyle)
|
||||
, shadingTerminal(shadingTerminal)
|
||||
, flatShadingEnabled(flatShadingEnabled)
|
||||
, blendWireframeColor(blendWireframeColor)
|
||||
, doubleSided(doubleSided)
|
||||
, lineWidth(lineWidth)
|
||||
, useCustomDisplacement(useCustomDisplacement)
|
||||
, enableScalarOverride(enableScalarOverride)
|
||||
{}
|
||||
|
||||
bool IsEmpty() const {
|
||||
return geomStyle == HdMeshGeomStyleInvalid;
|
||||
}
|
||||
|
||||
/// The rendering style: draw refined/unrefined, edge, points, etc.
|
||||
HdMeshGeomStyle geomStyle;
|
||||
/// The culling style: draw front faces, back faces, etc.
|
||||
HdCullStyle cullStyle;
|
||||
/// Specifies how the fragment color should be computed from surfaceShader;
|
||||
/// this can be used to render a mesh lit, unlit, unshaded, etc.
|
||||
TfToken shadingTerminal;
|
||||
/// Does this mesh want flat shading?
|
||||
bool flatShadingEnabled;
|
||||
/// Should the wireframe color be blended into the color primvar?
|
||||
bool blendWireframeColor;
|
||||
/// Should this mesh be treated as double-sided? The resolved value is
|
||||
/// (prim.doubleSided || repr.doubleSided).
|
||||
bool doubleSided;
|
||||
/// How big (in pixels) should line drawing be?
|
||||
float lineWidth;
|
||||
/// Should this mesh use displacementShader() to displace points?
|
||||
bool useCustomDisplacement;
|
||||
/// Should scalar override be allowed on this drawItem.
|
||||
/// scalar override allows for visualization of a single float value
|
||||
/// across a prim.
|
||||
bool enableScalarOverride;
|
||||
};
|
||||
|
||||
/// Hydra Schema for a subdivision surface or poly-mesh object.
|
||||
///
|
||||
class HdMesh : public HdRprim {
|
||||
public:
|
||||
HD_API
|
||||
virtual ~HdMesh();
|
||||
|
||||
///
|
||||
/// Render State
|
||||
///
|
||||
inline bool IsDoubleSided(HdSceneDelegate* delegate) const;
|
||||
inline HdCullStyle GetCullStyle(HdSceneDelegate* delegate) const;
|
||||
inline VtValue GetShadingStyle(HdSceneDelegate* delegate) const;
|
||||
|
||||
///
|
||||
/// Topological accessors via the scene delegate
|
||||
///
|
||||
inline HdMeshTopology GetMeshTopology(HdSceneDelegate* delegate) const;
|
||||
inline HdDisplayStyle GetDisplayStyle(HdSceneDelegate* delegate) const;
|
||||
inline PxOsdSubdivTags GetSubdivTags(HdSceneDelegate* delegate) const;
|
||||
|
||||
/// Topology getter
|
||||
virtual HdMeshTopologySharedPtr GetTopology() const;
|
||||
|
||||
///
|
||||
/// Primvars Accessors
|
||||
///
|
||||
inline VtValue GetPoints(HdSceneDelegate* delegate) const;
|
||||
inline VtValue GetNormals(HdSceneDelegate* delegate) const;
|
||||
|
||||
HD_API
|
||||
TfTokenVector const & GetBuiltinPrimvarNames() const override;
|
||||
|
||||
/// Configure the geometric style of the mesh for a given representation.
|
||||
/// We currently allow up to 2 descriptors for a representation.
|
||||
/// Example of when this may be useful:
|
||||
/// Drawing the outline in addition to the surface for a mesh.
|
||||
HD_API
|
||||
static void ConfigureRepr(TfToken const &reprName,
|
||||
HdMeshReprDesc desc1,
|
||||
HdMeshReprDesc desc2=HdMeshReprDesc());
|
||||
|
||||
protected:
|
||||
/// Constructor. instancerId, if specified, is the instancer which uses
|
||||
/// this mesh as a prototype.
|
||||
HD_API
|
||||
HdMesh(SdfPath const& id);
|
||||
|
||||
// We allow up to 2 repr descs per repr for meshes (see ConfigureRepr above)
|
||||
typedef _ReprDescConfigs<HdMeshReprDesc, 2> _MeshReprConfig;
|
||||
|
||||
HD_API
|
||||
static _MeshReprConfig::DescArray _GetReprDesc(TfToken const &reprName);
|
||||
|
||||
private:
|
||||
|
||||
// Class can not be default constructed or copied.
|
||||
HdMesh() = delete;
|
||||
HdMesh(const HdMesh &) = delete;
|
||||
HdMesh &operator =(const HdMesh &) = delete;
|
||||
|
||||
static _MeshReprConfig _reprDescConfig;
|
||||
};
|
||||
|
||||
inline bool
|
||||
HdMesh::IsDoubleSided(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetDoubleSided(GetId());
|
||||
}
|
||||
|
||||
inline HdCullStyle
|
||||
HdMesh::GetCullStyle(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetCullStyle(GetId());
|
||||
}
|
||||
|
||||
inline VtValue
|
||||
HdMesh::GetShadingStyle(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetShadingStyle(GetId());
|
||||
}
|
||||
|
||||
inline HdMeshTopology
|
||||
HdMesh::GetMeshTopology(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetMeshTopology(GetId());
|
||||
}
|
||||
|
||||
inline HdDisplayStyle
|
||||
HdMesh::GetDisplayStyle(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetDisplayStyle(GetId());
|
||||
}
|
||||
|
||||
inline PxOsdSubdivTags
|
||||
HdMesh::GetSubdivTags(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetSubdivTags(GetId());
|
||||
}
|
||||
|
||||
inline HdMeshTopologySharedPtr
|
||||
HdMesh::GetTopology() const
|
||||
{
|
||||
return HdMeshTopologySharedPtr();
|
||||
}
|
||||
|
||||
inline VtValue
|
||||
HdMesh::GetPoints(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return GetPrimvar(delegate, HdTokens->points);
|
||||
}
|
||||
|
||||
inline VtValue
|
||||
HdMesh::GetNormals(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return GetPrimvar(delegate, HdTokens->normals);
|
||||
}
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_MESH_H
|
||||
@@ -0,0 +1,227 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_MESH_TOPOLOGY_H
|
||||
#define PXR_IMAGING_HD_MESH_TOPOLOGY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/geomSubset.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/topology.h"
|
||||
|
||||
#include "pxr/imaging/pxOsd/meshTopology.h"
|
||||
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdMeshTopologySharedPtr = std::shared_ptr<class HdMeshTopology>;
|
||||
|
||||
/// \class HdMeshTopology
|
||||
///
|
||||
/// Topology data for meshes.
|
||||
///
|
||||
/// HdMeshTopology holds the raw input topology data for a mesh and is capable
|
||||
/// of computing derivative topological data (such as indices or subdivision
|
||||
/// stencil tables and patch tables).
|
||||
///
|
||||
class HdMeshTopology : public HdTopology {
|
||||
public:
|
||||
HD_API
|
||||
HdMeshTopology();
|
||||
HD_API
|
||||
HdMeshTopology(const HdMeshTopology &, int refineLevel=0);
|
||||
HD_API
|
||||
HdMeshTopology(const PxOsdMeshTopology &, int refineLevel=0);
|
||||
HD_API
|
||||
HdMeshTopology(const TfToken &scheme,
|
||||
const TfToken &orientation,
|
||||
const VtIntArray &faceVertexCounts,
|
||||
const VtIntArray &faceVertexIndices,
|
||||
int refineLevel = 0);
|
||||
HD_API
|
||||
HdMeshTopology(const TfToken &scheme,
|
||||
const TfToken &orientation,
|
||||
const VtIntArray &faceVertexCounts,
|
||||
const VtIntArray &faceVertexIndices,
|
||||
const VtIntArray &holeIndices,
|
||||
int refineLevel = 0);
|
||||
HD_API
|
||||
virtual ~HdMeshTopology();
|
||||
|
||||
HD_API
|
||||
HdMeshTopology &operator =(const HdMeshTopology ©);
|
||||
|
||||
/// Returns whether adaptive subdivision is enabled or not.
|
||||
HD_API
|
||||
static bool IsEnabledAdaptive();
|
||||
|
||||
PxOsdMeshTopology const & GetPxOsdMeshTopology() const {
|
||||
return _topology;
|
||||
}
|
||||
|
||||
/// Returns the num faces
|
||||
HD_API
|
||||
int GetNumFaces() const;
|
||||
|
||||
/// Returns the num facevarying primvars
|
||||
HD_API
|
||||
int GetNumFaceVaryings() const;
|
||||
|
||||
/// Returns the num points of the topology vert indices array
|
||||
HD_API
|
||||
int GetNumPoints() const;
|
||||
|
||||
/// Returns the num points by looking vert indices array
|
||||
HD_API
|
||||
static int ComputeNumPoints(VtIntArray const &verts);
|
||||
|
||||
/// Returns the subdivision scheme
|
||||
TfToken const GetScheme() const {
|
||||
return _topology.GetScheme();
|
||||
}
|
||||
|
||||
/// Returns the refinement level
|
||||
int GetRefineLevel() const {
|
||||
return _refineLevel;
|
||||
}
|
||||
|
||||
/// Returns face vertex counts.
|
||||
VtIntArray const &GetFaceVertexCounts() const {
|
||||
return _topology.GetFaceVertexCounts();
|
||||
}
|
||||
|
||||
/// Returns face vertex indics.
|
||||
VtIntArray const &GetFaceVertexIndices() const {
|
||||
return _topology.GetFaceVertexIndices();
|
||||
}
|
||||
|
||||
/// Returns orientation.
|
||||
TfToken const &GetOrientation() const {
|
||||
return _topology.GetOrientation();
|
||||
}
|
||||
|
||||
/// Returns the hash value of this topology to be used for instancing.
|
||||
HD_API
|
||||
virtual ID ComputeHash() const;
|
||||
|
||||
/// Equality check between two mesh topologies.
|
||||
HD_API
|
||||
bool operator==(HdMeshTopology const &other) const;
|
||||
|
||||
///
|
||||
/// \name Hole
|
||||
/// @{
|
||||
|
||||
/// Sets hole face indices. faceIndices needs to be sorted in
|
||||
/// ascending order.
|
||||
void SetHoleIndices(VtIntArray const &holeIndices) {
|
||||
_topology = _topology.WithHoleIndices(holeIndices);
|
||||
}
|
||||
|
||||
/// Returns the hole face indices.
|
||||
VtIntArray const &GetHoleIndices() const {
|
||||
return _topology.GetHoleIndices();
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
///
|
||||
/// \name Subdivision
|
||||
/// @{
|
||||
|
||||
/// Sets subdivision tags.
|
||||
void SetSubdivTags(PxOsdSubdivTags const &subdivTags) {
|
||||
_topology = _topology.WithSubdivTags(subdivTags);
|
||||
}
|
||||
|
||||
/// Returns subdivision tags
|
||||
PxOsdSubdivTags const&GetSubdivTags() const {
|
||||
return _topology.GetSubdivTags();
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
///
|
||||
/// \name Geometry subsets
|
||||
/// @{
|
||||
|
||||
/// Sets geometry subsets
|
||||
HD_API
|
||||
void SetGeomSubsets(HdGeomSubsets const &geomSubsets) {
|
||||
_geomSubsets = geomSubsets;
|
||||
}
|
||||
|
||||
/// Returns geometry subsets
|
||||
HD_API
|
||||
HdGeomSubsets const &GetGeomSubsets() const {
|
||||
return _geomSubsets;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
///
|
||||
/// \name Topological invisibility
|
||||
/// @{
|
||||
///
|
||||
HD_API
|
||||
void SetInvisiblePoints(VtIntArray const &invisiblePoints) {
|
||||
_invisiblePoints = invisiblePoints;
|
||||
}
|
||||
|
||||
HD_API
|
||||
VtIntArray const & GetInvisiblePoints() const {
|
||||
return _invisiblePoints;
|
||||
}
|
||||
|
||||
HD_API
|
||||
void SetInvisibleFaces(VtIntArray const &invisibleFaces) {
|
||||
_invisibleFaces = invisibleFaces;
|
||||
}
|
||||
|
||||
HD_API
|
||||
VtIntArray const & GetInvisibleFaces() const {
|
||||
return _invisibleFaces;
|
||||
}
|
||||
/// @}
|
||||
|
||||
protected:
|
||||
PxOsdMeshTopology _topology;
|
||||
HdGeomSubsets _geomSubsets;
|
||||
VtIntArray _invisiblePoints;
|
||||
VtIntArray _invisibleFaces;
|
||||
int _refineLevel;
|
||||
int _numPoints;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_MESH_TOPOLOGY_H
|
||||
@@ -0,0 +1,262 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_MESH_UTIL_H
|
||||
#define PXR_IMAGING_HD_MESH_UTIL_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/imaging/hd/meshTopology.h"
|
||||
|
||||
#include "pxr/base/gf/vec2i.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <utility> // std::{min,max}, std::pair
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdQuadInfo
|
||||
/// A helper class for quadrangulation computation.
|
||||
|
||||
// v0 v2
|
||||
// +-----e2----+
|
||||
// \ | /
|
||||
// \ __c__ /
|
||||
// e0 e1
|
||||
// \ /
|
||||
// \ /
|
||||
// + v1
|
||||
//
|
||||
//
|
||||
// original points additional center and edge points
|
||||
// +------------ ... ----+--------------------------------+
|
||||
// | v0 v1 v2 vn | e0 e1 e2 c0, e3 e4 e5 c1 ... |
|
||||
// +------------ ... ----+--------------------------------+
|
||||
// ^
|
||||
// pointsOffset
|
||||
// <----- numAdditionalPoints ---->
|
||||
|
||||
struct HdQuadInfo {
|
||||
HdQuadInfo() : pointsOffset(0), numAdditionalPoints(0), maxNumVert(0) { }
|
||||
|
||||
/// Returns true if the mesh is all-quads.
|
||||
bool IsAllQuads() const { return numAdditionalPoints == 0; }
|
||||
|
||||
int pointsOffset;
|
||||
int numAdditionalPoints;
|
||||
int maxNumVert;
|
||||
std::vector<int> numVerts; // num vertices of non-quads
|
||||
std::vector<int> verts; // vertex indices of non-quads
|
||||
};
|
||||
|
||||
/// \class HdMeshUtil
|
||||
/// A collection of utility algorithms for generating triangulation
|
||||
/// and quadrangulation of an input topology.
|
||||
|
||||
class HdMeshUtil
|
||||
{
|
||||
public:
|
||||
HdMeshUtil(HdMeshTopology const* topology, SdfPath const& id)
|
||||
: _topology(topology), _id(id) {}
|
||||
virtual ~HdMeshUtil() {}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Triangulation
|
||||
|
||||
// In order to access per-face signals (face color, face selection etc)
|
||||
// we need a mapping from primitiveID to authored face index domain.
|
||||
// This is stored in primitiveParams, and computed along with indices.
|
||||
/*
|
||||
+--------+-------+
|
||||
/| \ |\ |\
|
||||
/ | \ 1 | \ 2 | \
|
||||
/ | \ | \ | \
|
||||
/ | \ | \ | 2 +
|
||||
/ 0 | 1 \ | 2 \ | /
|
||||
/ | \ | \ | /
|
||||
/ | \| \|/
|
||||
+-------+--------+-------+
|
||||
*/
|
||||
|
||||
/// Return a triangulation of the input topology. indices and
|
||||
/// primitiveParams are output parameters.
|
||||
HD_API
|
||||
void ComputeTriangleIndices(VtVec3iArray *indices,
|
||||
VtIntArray *primitiveParams,
|
||||
VtVec3iArray *trianglesEdgeIndices = nullptr);
|
||||
|
||||
/// Return a triangulation of a face-varying primvar. source is
|
||||
/// a buffer of size numElements and type corresponding to dataType
|
||||
/// (e.g. HdTypeFloatVec3); the result is a VtArray<T> of the
|
||||
/// correct type written to the variable "triangulated".
|
||||
/// This function returns false if it can't resolve dataType.
|
||||
HD_API
|
||||
bool ComputeTriangulatedFaceVaryingPrimvar(void const* source,
|
||||
int numElements,
|
||||
HdType dataType,
|
||||
VtValue *triangulated);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Quadrangulation
|
||||
|
||||
// In order to access per-face signals (face color, face selection etc)
|
||||
// we need a mapping from primitiveID to authored face index domain.
|
||||
// This is stored in primitiveParams, and computed along with indices.
|
||||
/*
|
||||
+--------+-------+
|
||||
/| | | \
|
||||
/ | | 2 | 2 /\
|
||||
/ | | \ / \
|
||||
/ 0 | 1 |------+ 2 +
|
||||
/\ /| | / \ /
|
||||
/ \/ | | 2 | 2 \/
|
||||
/ 0 | 0| | | /
|
||||
+-------+--------+-------+
|
||||
*/
|
||||
|
||||
/// Return the number of quadrangulated quads.
|
||||
/// If degenerated face is found, sets invalidFaceFound as true.
|
||||
HD_API
|
||||
static int ComputeNumQuads(VtIntArray const &numVerts,
|
||||
VtIntArray const &holeIndices,
|
||||
bool *invalidFaceFound=NULL);
|
||||
|
||||
|
||||
/// Generate a quadInfo struct for the input topology.
|
||||
HD_API
|
||||
void ComputeQuadInfo(HdQuadInfo* quadInfo);
|
||||
|
||||
/// Return quadrangulated indices of the input topology. indices and
|
||||
/// primitiveParams are output parameters.
|
||||
HD_API
|
||||
void ComputeQuadIndices(VtVec4iArray *indices,
|
||||
VtVec2iArray *primitiveParams,
|
||||
VtVec4iArray *quadsEdgeIndices = nullptr);
|
||||
|
||||
/// Return a quadrangulation of a per-vertex primvar. source is
|
||||
/// a buffer of size numElements and type corresponding to dataType
|
||||
/// (e.g. HdTypeFloatVec3); the result is a VtArray<T> of the
|
||||
/// correct type written to the variable "quadrangulated".
|
||||
/// This function returns false if it can't resolve dataType.
|
||||
HD_API
|
||||
bool ComputeQuadrangulatedPrimvar(HdQuadInfo const* qi,
|
||||
void const* source,
|
||||
int numElements,
|
||||
HdType dataType,
|
||||
VtValue *quadrangulated);
|
||||
|
||||
/// Return a quadrangulation of a face-varying primvar.
|
||||
/// source is a buffer of size numElements and type corresponding
|
||||
/// to dataType (e.g. HdTypeFloatVec3); the result is a VtArray<T> of the
|
||||
/// correct type written to the variable "quadrangulated".
|
||||
/// This function returns false if it can't resolve dataType.
|
||||
HD_API
|
||||
bool ComputeQuadrangulatedFaceVaryingPrimvar(void const* source,
|
||||
int numElements,
|
||||
HdType dataType,
|
||||
VtValue *quadrangulated);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Primitive param bit encoding
|
||||
|
||||
// Per-primitive coarse-face-param encoding/decoding functions
|
||||
static int EncodeCoarseFaceParam(int faceIndex, int edgeFlag) {
|
||||
return ((faceIndex << 2) | (edgeFlag & 3));
|
||||
}
|
||||
static int DecodeFaceIndexFromCoarseFaceParam(int coarseFaceParam) {
|
||||
return (coarseFaceParam >> 2);
|
||||
}
|
||||
static int DecodeEdgeFlagFromCoarseFaceParam(int coarseFaceParam) {
|
||||
return (coarseFaceParam & 3);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Authored edge id computation
|
||||
struct EdgeHash {
|
||||
// Use a custom hash so that edges (a,b) and (b,a) are equivalent
|
||||
inline size_t operator()(GfVec2i const& v) const {
|
||||
// Triangular numbers for 2-d hash.
|
||||
int theMin = v[0], theMax = v[1];
|
||||
if (theMin > theMax) {
|
||||
std::swap(theMin, theMax);
|
||||
}
|
||||
size_t x = theMin;
|
||||
size_t y = x + theMax;
|
||||
return x + (y * (y + 1)) / 2;
|
||||
}
|
||||
};
|
||||
|
||||
struct EdgeEquality {
|
||||
inline bool operator() (GfVec2i const& v1, GfVec2i const& v2) const {
|
||||
// The bitwise operators here give a small speedup in the generated
|
||||
// code since we avoid the conditional jumps required by
|
||||
// short-circuiting logical ops.
|
||||
return
|
||||
((v1[0] == v2[0]) & (v1[1] == v2[1])) |
|
||||
((v1[0] == v2[1]) & (v1[1] == v2[0]));
|
||||
}
|
||||
};
|
||||
|
||||
using EdgeMap = std::unordered_map<GfVec2i, int, EdgeHash, EdgeEquality>;
|
||||
using ReverseEdgeMap = std::unordered_map<int, GfVec2i>;
|
||||
|
||||
// Enumerates all the edges of the authored mesh topology, and returns a map
|
||||
// of (vertex indices pair, edge id).
|
||||
// If skipHoles is true, unshared edges of hole faces aren't enumerated.
|
||||
HD_API
|
||||
static EdgeMap ComputeAuthoredEdgeMap(HdMeshTopology const* topology,
|
||||
bool skipHoles = false);
|
||||
|
||||
// Given the map from (vertex indices pair, edge id) computed by
|
||||
// ComputeAuthoredEdgeMap, returns the reverse map (edge id, vertex indices
|
||||
// pair).
|
||||
HD_API
|
||||
static ReverseEdgeMap ComputeReverseEdgeMap(const EdgeMap &edgeMap);
|
||||
|
||||
// Translates an authored edge id to its vertex indices
|
||||
// Returns a pair, with first indicating success of the look up, and
|
||||
// second being the vertex indices for the edge.
|
||||
HD_API
|
||||
static std::pair<bool, GfVec2i>
|
||||
GetVertexIndicesForEdge(const ReverseEdgeMap &rEdgeMap, int authoredEdgeId);
|
||||
|
||||
// Translates an edge to its authored edge id
|
||||
// Returns a pair, with first indicating success of the look up, and
|
||||
// second being the authored edge id
|
||||
HD_API
|
||||
static std::pair<bool, int>
|
||||
GetAuthoredEdgeID(HdMeshTopology const* topology,
|
||||
GfVec2i edge);
|
||||
private:
|
||||
HdMeshTopology const* _topology;
|
||||
SdfPath const _id;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_MESH_UTIL_H
|
||||
@@ -0,0 +1,240 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_PERF_LOG_H
|
||||
#define PXR_IMAGING_HD_PERF_LOG_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/debugCodes.h"
|
||||
|
||||
#include "pxr/base/trace/trace.h"
|
||||
|
||||
#include "pxr/base/tf/mallocTag.h"
|
||||
#include "pxr/base/tf/singleton.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class SdfPath;
|
||||
class HdResourceRegistry;
|
||||
|
||||
// XXX: it would be nice to move this into Trace or use the existing Trace
|
||||
// counter mechanism, however we are restricted to TraceLite in the rocks.
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
// PERFORMANCE INSTURMENTATION MACROS //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
// Emits a trace scope tagged for the function.
|
||||
#define HD_TRACE_FUNCTION() TRACE_FUNCTION()
|
||||
// Emits a trace scope with the specified tag.
|
||||
#define HD_TRACE_SCOPE(tag) TRACE_SCOPE(tag)
|
||||
|
||||
// Adds a cache hit for the given cache name, the id is provided for debugging,
|
||||
// see HdPerfLog for details.
|
||||
#define HD_PERF_CACHE_HIT(name, id) \
|
||||
HdPerfLog::GetInstance().AddCacheHit(name, id);
|
||||
#define HD_PERF_CACHE_HIT_TAG(name, id, tag) \
|
||||
HdPerfLog::GetInstance().AddCacheHit(name, id, tag);
|
||||
|
||||
// Adds a cache miss for the given cache name, the id is provided for debugging,
|
||||
// see HdPerfLog for details.
|
||||
#define HD_PERF_CACHE_MISS(name, id) \
|
||||
HdPerfLog::GetInstance().AddCacheMiss(name, id);
|
||||
#define HD_PERF_CACHE_MISS_TAG(name, id, tag) \
|
||||
HdPerfLog::GetInstance().AddCacheMiss(name, id, tag);
|
||||
|
||||
// Increments/Decrements/Sets/Adds/Subtracts a named performance counter
|
||||
// see HdPerfLog for details.
|
||||
#define HD_PERF_COUNTER_INCR(name) \
|
||||
HdPerfLog::GetInstance().IncrementCounter(name);
|
||||
#define HD_PERF_COUNTER_DECR(name) \
|
||||
HdPerfLog::GetInstance().DecrementCounter(name);
|
||||
#define HD_PERF_COUNTER_SET(name, value) \
|
||||
HdPerfLog::GetInstance().SetCounter(name, value);
|
||||
#define HD_PERF_COUNTER_ADD(name, value) \
|
||||
HdPerfLog::GetInstance().AddCounter(name, value);
|
||||
#define HD_PERF_COUNTER_SUBTRACT(name, value) \
|
||||
HdPerfLog::GetInstance().SubtractCounter(name, value);
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
// PERFORMANCE LOG //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
/// \class HdPerfLog
|
||||
///
|
||||
/// Performance counter monitoring.
|
||||
///
|
||||
class HdPerfLog
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
static HdPerfLog& GetInstance() {
|
||||
return TfSingleton<HdPerfLog>::GetInstance();
|
||||
}
|
||||
|
||||
/// Tracks a cache hit for the named cache, the id and tag are reported
|
||||
/// when debug logging is enabled.
|
||||
HD_API
|
||||
void AddCacheHit(TfToken const& name,
|
||||
SdfPath const& id,
|
||||
TfToken const& tag=TfToken());
|
||||
|
||||
/// Tracks a cache miss for the named cache, the id and tag are reported
|
||||
/// when debug logging is enabled.
|
||||
HD_API
|
||||
void AddCacheMiss(TfToken const& name,
|
||||
SdfPath const& id,
|
||||
TfToken const& tag=TfToken());
|
||||
|
||||
HD_API
|
||||
void ResetCache(TfToken const& name);
|
||||
|
||||
/// Gets the hit ratio (numHits / totalRequests) of a cache performance
|
||||
/// counter.
|
||||
HD_API
|
||||
double GetCacheHitRatio(TfToken const& name);
|
||||
|
||||
/// Gets the number of hit hits for a cache performance counter.
|
||||
HD_API
|
||||
size_t GetCacheHits(TfToken const& name);
|
||||
|
||||
/// Gets the number of hit misses for a cache performance counter.
|
||||
HD_API
|
||||
size_t GetCacheMisses(TfToken const& name);
|
||||
|
||||
/// Returns the names of all cache performance counters.
|
||||
HD_API
|
||||
TfTokenVector GetCacheNames();
|
||||
|
||||
/// Returns a vector of all performance counter names.
|
||||
HD_API
|
||||
TfTokenVector GetCounterNames();
|
||||
|
||||
/// Increments a named counter by 1.0.
|
||||
HD_API
|
||||
void IncrementCounter(TfToken const& name);
|
||||
|
||||
/// Decrements a named counter by 1.0.
|
||||
HD_API
|
||||
void DecrementCounter(TfToken const& name);
|
||||
|
||||
/// Sets the value of a named counter.
|
||||
HD_API
|
||||
void SetCounter(TfToken const& name, double value);
|
||||
|
||||
/// Adds value to a named counter.
|
||||
HD_API
|
||||
void AddCounter(TfToken const& name, double value);
|
||||
|
||||
/// Subtracts value to a named counter.
|
||||
HD_API
|
||||
void SubtractCounter(TfToken const& name, double value);
|
||||
|
||||
/// Returns the current value of a named counter.
|
||||
HD_API
|
||||
double GetCounter(TfToken const& name);
|
||||
|
||||
/// Reset all conter values to 0.0.
|
||||
/// Note that this doesn't reset cache counters.
|
||||
HD_API
|
||||
void ResetCounters();
|
||||
|
||||
/// Enable performance logging.
|
||||
void Enable() { _enabled = true; }
|
||||
|
||||
/// Disable performance logging.
|
||||
void Disable() { _enabled = false; }
|
||||
|
||||
/// Add a resource registry to the tracking.
|
||||
HD_API
|
||||
void AddResourceRegistry(HdResourceRegistry * resourceRegistry);
|
||||
|
||||
/// Remove Resource Registry from the tracking.
|
||||
HD_API
|
||||
void RemoveResourceRegistry(HdResourceRegistry * resourceRegistry);
|
||||
|
||||
/// Returns a vector of resource registry.
|
||||
HD_API
|
||||
std::vector<HdResourceRegistry*> const& GetResourceRegistryVector();
|
||||
|
||||
private:
|
||||
|
||||
// Don't allow copies
|
||||
HdPerfLog(const HdPerfLog &) = delete;
|
||||
HdPerfLog &operator=(const HdPerfLog &) = delete;
|
||||
|
||||
friend class TfSingleton<HdPerfLog>;
|
||||
HD_API HdPerfLog();
|
||||
HD_API ~HdPerfLog();
|
||||
|
||||
// Tracks number of hits and misses and provides some convenience API.
|
||||
class _CacheEntry {
|
||||
public:
|
||||
_CacheEntry() : _hits(0), _misses(0) { }
|
||||
|
||||
void AddHit() {++_hits;}
|
||||
size_t GetHits() {return _hits;}
|
||||
|
||||
void AddMiss() {++_misses;}
|
||||
size_t GetMisses() {return _misses;}
|
||||
|
||||
size_t GetTotal() {return _hits+_misses;}
|
||||
double GetHitRatio() {return (double)_hits / GetTotal();}
|
||||
|
||||
void Reset() { _hits = 0; _misses = 0; }
|
||||
private:
|
||||
size_t _hits;
|
||||
size_t _misses;
|
||||
};
|
||||
|
||||
// Cache performance counters.
|
||||
typedef TfHashMap<TfToken, _CacheEntry, TfToken::HashFunctor> _CacheMap;
|
||||
_CacheMap _cacheMap;
|
||||
|
||||
// Named value counters.
|
||||
typedef TfHashMap<TfToken, double, TfToken::HashFunctor> _CounterMap;
|
||||
_CounterMap _counterMap;
|
||||
|
||||
// Resource registry vector.
|
||||
std::vector<HdResourceRegistry *> _resourceRegistryVector;
|
||||
|
||||
// Enable / disable performance tracking.
|
||||
bool _enabled;
|
||||
std::mutex _mutex;
|
||||
typedef std::lock_guard<std::mutex> _Lock;
|
||||
};
|
||||
|
||||
HD_API_TEMPLATE_CLASS(TfSingleton<HdPerfLog>);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_PERF_LOG_H
|
||||
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_PLUGIN_RENDER_DELEGATE_UNIQUE_HANDLE_H
|
||||
#define PXR_IMAGING_HD_PLUGIN_RENDER_DELEGATE_UNIQUE_HANDLE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/rendererPluginHandle.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRenderDelegate;
|
||||
|
||||
///
|
||||
/// A (movable) handle for a render delegate that was created using a
|
||||
/// a plugin.
|
||||
///
|
||||
/// The handle owns the render delegate (render delegate is destroyed
|
||||
/// when handle is dropped). The handle also can be queried what
|
||||
/// plugin was used to create the render delegate and ensures the
|
||||
/// plugin is kept alive until the render delegate is destroyed.
|
||||
/// In other words, the handle can be used just like a std::unique_ptr.
|
||||
///
|
||||
class HdPluginRenderDelegateUniqueHandle final
|
||||
{
|
||||
public:
|
||||
HdPluginRenderDelegateUniqueHandle() : _delegate(nullptr) { }
|
||||
HdPluginRenderDelegateUniqueHandle(const std::nullptr_t &)
|
||||
: _delegate(nullptr) { }
|
||||
|
||||
/// Transfer ownership
|
||||
HD_API
|
||||
HdPluginRenderDelegateUniqueHandle(HdPluginRenderDelegateUniqueHandle &&);
|
||||
|
||||
HD_API
|
||||
~HdPluginRenderDelegateUniqueHandle();
|
||||
|
||||
/// Transfer ownership
|
||||
HD_API
|
||||
HdPluginRenderDelegateUniqueHandle &operator=(
|
||||
HdPluginRenderDelegateUniqueHandle &&);
|
||||
|
||||
HD_API
|
||||
HdPluginRenderDelegateUniqueHandle &operator=(
|
||||
const std::nullptr_t &);
|
||||
|
||||
/// Get render delegate
|
||||
HdRenderDelegate *Get() const { return _delegate; }
|
||||
|
||||
HdRenderDelegate *operator->() const { return _delegate; }
|
||||
HdRenderDelegate &operator*() const { return *_delegate; }
|
||||
|
||||
/// Is the wrapped HdRenderDelegate valid?
|
||||
explicit operator bool() const { return _delegate; }
|
||||
|
||||
/// Get the id of the plugin used to create render delegate
|
||||
HD_API
|
||||
TfToken GetPluginId() const;
|
||||
|
||||
private:
|
||||
friend class HdRendererPlugin;
|
||||
|
||||
HdPluginRenderDelegateUniqueHandle(
|
||||
const HdRendererPluginHandle &plugin, HdRenderDelegate * delegate)
|
||||
: _plugin(plugin), _delegate(delegate) { }
|
||||
|
||||
HdRendererPluginHandle _plugin;
|
||||
HdRenderDelegate *_delegate;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_POINTS_H
|
||||
#define PXR_IMAGING_HD_POINTS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/rprim.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdPointsReprDesc
|
||||
///
|
||||
/// Descriptor to configure a drawItem for a repr.
|
||||
///
|
||||
struct HdPointsReprDesc {
|
||||
HdPointsReprDesc(
|
||||
HdPointsGeomStyle geomStyle = HdPointsGeomStyleInvalid)
|
||||
: geomStyle(geomStyle)
|
||||
{}
|
||||
|
||||
bool IsEmpty() const {
|
||||
return geomStyle == HdPointsGeomStyleInvalid;
|
||||
}
|
||||
|
||||
HdPointsGeomStyle geomStyle;
|
||||
};
|
||||
|
||||
/// Hydra Schema for a point cloud.
|
||||
///
|
||||
class HdPoints: public HdRprim {
|
||||
public:
|
||||
HD_API
|
||||
virtual ~HdPoints();
|
||||
|
||||
HD_API
|
||||
TfTokenVector const & GetBuiltinPrimvarNames() const override;
|
||||
|
||||
/// Configure geometric style of drawItems for \p reprName
|
||||
HD_API
|
||||
static void ConfigureRepr(TfToken const &reprName,
|
||||
const HdPointsReprDesc &desc);
|
||||
|
||||
protected:
|
||||
/// Constructor. instancerId, if specified, is the instancer which uses
|
||||
/// this point cloud as a prototype.
|
||||
HD_API
|
||||
HdPoints(SdfPath const& id);
|
||||
|
||||
typedef _ReprDescConfigs<HdPointsReprDesc> _PointsReprConfig;
|
||||
|
||||
HD_API
|
||||
static _PointsReprConfig::DescArray _GetReprDesc(TfToken const &reprName);
|
||||
|
||||
private:
|
||||
|
||||
// Class can not be default constructed or copied.
|
||||
HdPoints() = delete;
|
||||
HdPoints(const HdPoints &) = delete;
|
||||
HdPoints &operator =(const HdPoints &) = delete;
|
||||
|
||||
static _PointsReprConfig _reprDescConfig;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_POINTS_H
|
||||
@@ -0,0 +1,235 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_PRIM_GATHER_H
|
||||
#define PXR_IMAGING_HD_PRIM_GATHER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <vector>
|
||||
#include <tbb/enumerable_thread_specific.h>
|
||||
#include <tbb/blocked_range.h>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdPrimGather final {
|
||||
public:
|
||||
typedef bool (*FilterPredicateFn)(const SdfPath &path, const void *param);
|
||||
|
||||
HdPrimGather() = default;
|
||||
~HdPrimGather() = default;
|
||||
|
||||
///
|
||||
/// Filter takes a list of paths and returns a list of paths that
|
||||
/// match the following criteria:
|
||||
///
|
||||
/// - A path is prefixed by at least one include path
|
||||
/// - A path is not prefixed by an exclude path that has more elements
|
||||
/// than the include path with the most element that is a prefix
|
||||
/// of the path.
|
||||
///
|
||||
/// The list of paths to filter must be pre-sorted with
|
||||
/// ordering defined by std::less<SdfPath &>.
|
||||
///
|
||||
/// The list of include and exclude paths do not need to be pre-sorted.
|
||||
///
|
||||
/// If the same path appears in the list of include and exclude paths
|
||||
/// results are undefined.
|
||||
///
|
||||
/// The resulting set of paths are stored in results arg, the results
|
||||
/// might not be in sorted order.
|
||||
///
|
||||
HD_API
|
||||
void Filter(const SdfPathVector &paths,
|
||||
const SdfPathVector &includePaths,
|
||||
const SdfPathVector &excludePaths,
|
||||
SdfPathVector *results);
|
||||
|
||||
///
|
||||
/// PredicatedFilter takes a list of paths and returns a list of paths that
|
||||
/// match the following criteria:
|
||||
///
|
||||
/// - A path is prefixed by at least one include path
|
||||
/// - A path is not prefixed by an exclude path that has more elements
|
||||
/// than the include path with the most element that is a prefix
|
||||
/// of the path.
|
||||
/// - The predicate function for the path returns true.
|
||||
///
|
||||
/// The list of paths to filter must be pre-sorted with
|
||||
/// ordering defined by std::less<SdfPath &>.
|
||||
///
|
||||
/// The list of include and exclude paths do not need to be pre-sorted.
|
||||
///
|
||||
/// If the same path appears in the list of include and exclude paths
|
||||
/// results are undefined.
|
||||
///
|
||||
/// The predicate function has the prototype:
|
||||
/// bool Predicate(const SdfPath &path, void *param);
|
||||
///
|
||||
/// The function should return true if the path should appear in the results
|
||||
/// and false if not. The Predicate function may be called on worker
|
||||
/// threads and as such must be thread-safe.
|
||||
///
|
||||
/// The resulting set of paths are stored in results arg, the results
|
||||
/// might not be in sorted order.
|
||||
///
|
||||
HD_API
|
||||
void PredicatedFilter(const SdfPathVector &paths,
|
||||
const SdfPathVector &includePaths,
|
||||
const SdfPathVector &excludePaths,
|
||||
FilterPredicateFn predicateFn,
|
||||
void *predicateParam,
|
||||
SdfPathVector *results);
|
||||
|
||||
///
|
||||
/// Subtree is a simplified form of filter, that gathers
|
||||
/// all prims that meet the single rootPath prefix condition.
|
||||
///
|
||||
/// The list of paths to filter must be pre-sorted with
|
||||
/// ordering defined by std::less<SdfPath &>.
|
||||
///
|
||||
/// The returned result maintain the sorted order.
|
||||
///
|
||||
HD_API
|
||||
void Subtree(const SdfPathVector &paths,
|
||||
const SdfPath &rootPath,
|
||||
SdfPathVector *results);
|
||||
|
||||
///
|
||||
/// Subtree is a simplified form of filter, that gathers
|
||||
/// all prims that meet the single rootPath prefix condition.
|
||||
///
|
||||
/// The list of paths to filter must be pre-sorted with
|
||||
/// ordering defined by std::less<SdfPath &>.
|
||||
///
|
||||
/// Rather than returning a list the paths, it instead returns
|
||||
/// the start and end (inclusive) indexes into the paths
|
||||
/// vector of that subtree range.
|
||||
///
|
||||
/// If the rootPath wasn't found or an error occurred, that
|
||||
/// otherwise produces an invalid range. The method returns false.
|
||||
HD_API
|
||||
bool SubtreeAsRange(const SdfPathVector &paths,
|
||||
const SdfPath &rootPath,
|
||||
size_t *start,
|
||||
size_t *end);
|
||||
|
||||
private:
|
||||
struct _PathFilter {
|
||||
SdfPath _path;
|
||||
bool _includePath; // false = exclude path
|
||||
|
||||
_PathFilter(const SdfPath &path, bool includePath)
|
||||
: _path(path)
|
||||
, _includePath(includePath)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool operator >(const _PathFilter &other) const {
|
||||
return other._path < _path;
|
||||
}
|
||||
};
|
||||
typedef std::vector<_PathFilter> _PathFilterArray;
|
||||
|
||||
// While processing, the algorithm stores results as a set of ranges
|
||||
// rather than copying all the paths.
|
||||
// This to avoid copying the larger set of paths at intermediate
|
||||
// processing steps.
|
||||
struct _Range {
|
||||
size_t _start;
|
||||
size_t _end; // Inclusive
|
||||
|
||||
_Range(size_t start, size_t end)
|
||||
: _start(start)
|
||||
, _end(end)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
typedef std::vector<_Range> _RangeArray;
|
||||
typedef tbb::enumerable_thread_specific<_RangeArray> _ConcurrentRangeArray;
|
||||
typedef tbb::blocked_range<size_t> _ConcurrentRange;
|
||||
|
||||
|
||||
|
||||
_PathFilterArray _filterList;
|
||||
_RangeArray _gatheredRanges;
|
||||
_ConcurrentRangeArray _resultRanges;
|
||||
|
||||
|
||||
|
||||
size_t _FindLowerBound(const SdfPathVector &paths,
|
||||
size_t start,
|
||||
size_t end,
|
||||
const SdfPath &path) const;
|
||||
size_t _FindUpperBound(const SdfPathVector &paths,
|
||||
size_t start,
|
||||
size_t end,
|
||||
const SdfPath &path) const;
|
||||
|
||||
void _FilterRange(const SdfPathVector &paths,
|
||||
size_t start,
|
||||
size_t end,
|
||||
bool include);
|
||||
|
||||
void _SetupFilter(const SdfPathVector &includePaths,
|
||||
const SdfPathVector &excludePaths);
|
||||
|
||||
void _GatherPaths(const SdfPathVector &paths);
|
||||
|
||||
// Outer Loop called for each range in vector
|
||||
void _DoPredicateTestOnRange(const SdfPathVector &paths,
|
||||
const _Range &range,
|
||||
FilterPredicateFn predicateFn,
|
||||
void *predicateParam);
|
||||
|
||||
// Inner Loop over each prim in a sub range of _Range.
|
||||
void _DoPredicateTestOnPrims(const SdfPathVector &paths,
|
||||
_ConcurrentRange &range,
|
||||
FilterPredicateFn predicateFn,
|
||||
void *predicateParam);
|
||||
|
||||
template <class Iterator>
|
||||
static void _WriteResults(const SdfPathVector &paths,
|
||||
const Iterator &rangesBegin,
|
||||
const Iterator &rangesEnd,
|
||||
SdfPathVector *results);
|
||||
|
||||
void _FilterSubTree(const SdfPathVector &paths,
|
||||
const SdfPath &rootPath);
|
||||
|
||||
// No default copying or assignment
|
||||
HdPrimGather(const HdPrimGather &) = delete;
|
||||
HdPrimGather &operator =(const HdPrimGather &) = delete;
|
||||
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_PRIM_GATHER_H
|
||||
@@ -0,0 +1,228 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
|
||||
#define PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/imaging/hd/sortedIds.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdChangeTracker;
|
||||
class HdRenderDelegate;
|
||||
class HdRenderParam;
|
||||
class HdSceneDelegate;
|
||||
class SdfPath;
|
||||
using HdSceneDelegatePtrVector = std::vector<HdSceneDelegate*>;
|
||||
|
||||
/// This class is only used by the render index.
|
||||
/// It provides functionality to manage and store one class of prim
|
||||
/// such as a Sprim or Bprim.
|
||||
template <class PrimType>
|
||||
class Hd_PrimTypeIndex {
|
||||
public:
|
||||
Hd_PrimTypeIndex();
|
||||
~Hd_PrimTypeIndex();
|
||||
|
||||
///
|
||||
/// Initialize this prim index, specifying the typeId tokens
|
||||
/// that should be supported by this index.
|
||||
///
|
||||
void InitPrimTypes(const TfTokenVector &primTypes);
|
||||
|
||||
///
|
||||
/// Removes and frees all prims in this index.
|
||||
/// The render delegate is responsible for freeing the actual memory
|
||||
/// allocated to the prim.
|
||||
/// The prim is also removed from the change tracker.
|
||||
///
|
||||
void Clear(HdChangeTracker &tracker, HdRenderDelegate *renderDelegate);
|
||||
|
||||
///
|
||||
/// Add a new a prim to the render index identified by the globally unique
|
||||
/// identifier, primId.
|
||||
/// typeId is the type of the prim to create, which is allocated using
|
||||
/// the provided render delegate. The Scene delegate provided is
|
||||
/// associated with the prim and is the one used to pull the data for the
|
||||
/// prim during sync processing.
|
||||
/// As well as being inserted into this index, the prim is added to the
|
||||
/// change tracker, with the initial dirty state provided by the prim itself.
|
||||
///
|
||||
void InsertPrim(const TfToken &typeId,
|
||||
HdSceneDelegate *sceneDelegate,
|
||||
const SdfPath &primId,
|
||||
HdChangeTracker &tracker,
|
||||
HdRenderDelegate *renderDelegate);
|
||||
|
||||
///
|
||||
/// Removes the prim identifier by primId. TypeId is the type of that
|
||||
/// prim. Memory for the prim is deallocated using the render delegate.
|
||||
/// The prim is also removed from the change tracker.
|
||||
///
|
||||
void RemovePrim(const TfToken &typeId,
|
||||
const SdfPath &primId,
|
||||
HdChangeTracker &tracker,
|
||||
HdRenderDelegate *renderDelegate);
|
||||
|
||||
///
|
||||
/// Removes the subtree of prims identifier by root that are owned
|
||||
/// by the given scene delegate.
|
||||
/// This function affects all prim types.
|
||||
/// Memory for the prim is deallocated using the render delegate.
|
||||
/// The prim is also removed from the change tracker.
|
||||
///
|
||||
void RemoveSubtree(const SdfPath &root,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
HdChangeTracker &tracker,
|
||||
HdRenderDelegate *renderDelegate);
|
||||
|
||||
/// Obtains a modifiable pointer the prim with the given type and id.
|
||||
/// If no prim with the given id is in the index or the type id is
|
||||
/// incorrect, then nullptr is returned.
|
||||
PrimType *GetPrim(const TfToken &typeId,
|
||||
const SdfPath &primId) const;
|
||||
|
||||
///
|
||||
/// Obtain a prim, that implements the schema given by type id, that
|
||||
/// can be used as a substitute for any prim of that type in the event of
|
||||
/// an error.
|
||||
///
|
||||
/// Hydra guarantees that the prim is not null for any type that
|
||||
/// is supported by the back-end.
|
||||
///
|
||||
PrimType *GetFallbackPrim(TfToken const &typeId) const;
|
||||
|
||||
///
|
||||
/// Returns a list of Prim Ids in outPaths of prims that type match
|
||||
/// typeId who are namespace children of rootPath.
|
||||
/// rootPath does not need to match any prim in the index or
|
||||
/// it may point to a prim of a different type.
|
||||
///
|
||||
void GetPrimSubtree(const TfToken &typeId,
|
||||
const SdfPath &rootPath,
|
||||
SdfPathVector *outPaths);
|
||||
|
||||
///
|
||||
/// Uses the provided render delegate to create the fallback prims
|
||||
/// for use by the index. The prim types created are based on those
|
||||
/// specified by InitPrimTypes.
|
||||
///
|
||||
/// If the render delegate fails to create a prim, this function returns
|
||||
/// false and the index is remain uninitialized and shouldn't be used.
|
||||
///
|
||||
bool CreateFallbackPrims(HdRenderDelegate *renderDelegate);
|
||||
|
||||
///
|
||||
/// Clean-up function for the index. Uses the delegate to deallocate
|
||||
/// the memory used by the fallback prims. The index is returned to
|
||||
/// an uninitialized state and shouldn't be used, unless reinitialized.
|
||||
///
|
||||
void DestroyFallbackPrims(HdRenderDelegate *renderDelegate);
|
||||
|
||||
///
|
||||
/// Main Sync Processing function.
|
||||
///
|
||||
/// Will call the Sync function on all prims in the index that
|
||||
/// are marked dirty in the specified change tracker.
|
||||
/// Also updates an internal list of scene delegates for the dirty prims.
|
||||
///
|
||||
void SyncPrims(HdChangeTracker &tracker,
|
||||
HdRenderParam *renderParam);
|
||||
|
||||
/// Returns a vector of unique scene delegates corresponding to the dirty
|
||||
/// prims that were sync'd in SyncPrims.
|
||||
const HdSceneDelegatePtrVector& GetSceneDelegatesForDirtyPrims();
|
||||
|
||||
private:
|
||||
struct _PrimInfo {
|
||||
HdSceneDelegate *sceneDelegate;
|
||||
PrimType *prim;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<SdfPath, _PrimInfo, SdfPath::Hash> _PrimMap;
|
||||
|
||||
struct _PrimTypeEntry
|
||||
{
|
||||
_PrimMap primMap;
|
||||
Hd_SortedIds primIds; // Primarily for sub-tree searching
|
||||
PrimType *fallbackPrim;
|
||||
|
||||
_PrimTypeEntry()
|
||||
: primMap()
|
||||
, primIds()
|
||||
, fallbackPrim(nullptr)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::unordered_map<TfToken, size_t, TfToken::HashFunctor> _TypeIndex;
|
||||
|
||||
typedef std::vector<_PrimTypeEntry> _PrimTypeList;
|
||||
|
||||
_PrimTypeList _entries;
|
||||
_TypeIndex _index;
|
||||
HdSceneDelegatePtrVector _dirtyPrimDelegates;
|
||||
|
||||
|
||||
// Template methods that are expected to be specialized on PrimType.
|
||||
// These are to handle prim type specific function names on called objects.
|
||||
static void _TrackerInsertPrim(HdChangeTracker &tracker,
|
||||
const SdfPath &path,
|
||||
HdDirtyBits initialDirtyState);
|
||||
|
||||
static void _TrackerRemovePrim(HdChangeTracker &tracker,
|
||||
const SdfPath &path);
|
||||
|
||||
static HdDirtyBits _TrackerGetPrimDirtyBits(HdChangeTracker &tracker,
|
||||
const SdfPath &path);
|
||||
|
||||
static void _TrackerMarkPrimClean(HdChangeTracker &tracker,
|
||||
const SdfPath &path,
|
||||
HdDirtyBits dirtyBits);
|
||||
|
||||
static PrimType *_RenderDelegateCreatePrim(HdRenderDelegate *renderDelegate,
|
||||
const TfToken &typeId,
|
||||
const SdfPath &primId);
|
||||
static PrimType *_RenderDelegateCreateFallbackPrim(
|
||||
HdRenderDelegate *renderDelegate,
|
||||
const TfToken &typeId);
|
||||
|
||||
static void _RenderDelegateDestroyPrim(HdRenderDelegate *renderDelegate,
|
||||
PrimType *prim);
|
||||
|
||||
// No copying
|
||||
Hd_PrimTypeIndex(const Hd_PrimTypeIndex &) = delete;
|
||||
Hd_PrimTypeIndex &operator =(const Hd_PrimTypeIndex &) = delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
|
||||
@@ -0,0 +1,140 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_BUFFER_H
|
||||
#define PXR_IMAGING_HD_RENDER_BUFFER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/bprim.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
|
||||
#include "pxr/base/gf/vec2i.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
|
||||
|
||||
/// \class HdRenderBuffer
|
||||
///
|
||||
/// A render buffer is a handle to a data resource that can be rendered into,
|
||||
/// such as a 2d image for a draw target or auxiliary rendering output.
|
||||
///
|
||||
/// The render buffer can be used as an indexed prim, in which case it
|
||||
/// communicates with the scene delegate to get buffer properties, or it can
|
||||
/// be created out of band and supplied directly with allocation parameters.
|
||||
///
|
||||
/// Render buffers can be targeted by render passes. They also contain
|
||||
/// mapping functionality for reading and writing buffer data.
|
||||
class HdRenderBuffer : public HdBprim {
|
||||
public:
|
||||
// change tracking for HdRenderBuffer
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyDescription = 1 << 0,
|
||||
AllDirty = (DirtyDescription)
|
||||
};
|
||||
|
||||
HD_API
|
||||
HdRenderBuffer(SdfPath const& id);
|
||||
HD_API
|
||||
virtual ~HdRenderBuffer();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Prim API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Get initial invalidation state.
|
||||
HD_API
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
/// Get allocation information from the scene delegate.
|
||||
HD_API
|
||||
virtual void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
/// Deallocate before deletion.
|
||||
HD_API
|
||||
virtual void Finalize(HdRenderParam *renderParam) override;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Renderbuffer API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Allocate a buffer. Can be called from Sync(), or directly.
|
||||
/// If the buffer has already been allocated, calling Allocate() again
|
||||
/// will destroy the old buffer and allocate a new one.
|
||||
///
|
||||
/// A negative dimension or invalid format will cause an allocation error.
|
||||
/// If the requested buffer can't be allocated, the function will return
|
||||
/// false.
|
||||
virtual bool Allocate(GfVec3i const& dimensions,
|
||||
HdFormat format,
|
||||
bool multiSampled) = 0;
|
||||
|
||||
/// Get the buffer's width.
|
||||
virtual unsigned int GetWidth() const = 0;
|
||||
/// Get the buffer's height.
|
||||
virtual unsigned int GetHeight() const = 0;
|
||||
/// Get the buffer's depth.
|
||||
virtual unsigned int GetDepth() const = 0;
|
||||
/// Get the buffer's per-pixel format.
|
||||
virtual HdFormat GetFormat() const = 0;
|
||||
/// Get whether the buffer is multisampled.
|
||||
virtual bool IsMultiSampled() const = 0;
|
||||
|
||||
/// Map the buffer for reading.
|
||||
virtual void* Map() = 0;
|
||||
/// Unmap the buffer. It is no longer safe to read from the buffer.
|
||||
virtual void Unmap() = 0;
|
||||
/// Return whether the buffer is currently mapped by anybody.
|
||||
virtual bool IsMapped() const = 0;
|
||||
|
||||
/// Resolve the buffer so that reads reflect the latest writes.
|
||||
///
|
||||
/// Some buffer implementations may defer final processing of writes until
|
||||
/// a buffer is read, for efficiency; examples include OpenGL MSAA or
|
||||
/// multi-sampled raytraced buffers.
|
||||
virtual void Resolve() = 0;
|
||||
|
||||
/// Return whether the buffer is converged (whether the renderer is
|
||||
/// still adding samples or not).
|
||||
virtual bool IsConverged() const = 0;
|
||||
|
||||
/// This optional API returns a (type-erased) resource that backs this
|
||||
/// render buffer. For example, a render buffer implementation may allocate
|
||||
/// a gpu texture that holds the data of the buffer. This function allows
|
||||
/// other parts of Hydra, such as a HdTask to get access to this resource.
|
||||
virtual VtValue GetResource(bool multiSampled) const {return VtValue();}
|
||||
|
||||
protected:
|
||||
/// Deallocate the buffer, freeing any owned resources.
|
||||
virtual void _Deallocate() = 0;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RENDER_BUFFER_H
|
||||
@@ -0,0 +1,456 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_DELEGATE_H
|
||||
#define PXR_IMAGING_HD_RENDER_DELEGATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/aov.h"
|
||||
#include "pxr/imaging/hd/changeTracker.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class SdfPath;
|
||||
class HdRprim;
|
||||
class HdSprim;
|
||||
class HdBprim;
|
||||
class HdSceneDelegate;
|
||||
class HdRenderIndex;
|
||||
class HdRenderPass;
|
||||
class HdInstancer;
|
||||
class HdDriver;
|
||||
|
||||
using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
|
||||
using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
|
||||
using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
|
||||
using HdDriverVector = std::vector<HdDriver*>;
|
||||
|
||||
///
|
||||
/// The HdRenderParam is an opaque (to core Hydra) handle, to an object
|
||||
/// that is obtained from the render delegate and passed to each prim
|
||||
/// during Sync processing.
|
||||
///
|
||||
class HdRenderParam
|
||||
{
|
||||
public:
|
||||
HdRenderParam() {}
|
||||
HD_API
|
||||
virtual ~HdRenderParam();
|
||||
|
||||
private:
|
||||
// Hydra will not attempt to copy the class.
|
||||
HdRenderParam(const HdRenderParam &) = delete;
|
||||
HdRenderParam &operator =(const HdRenderParam &) = delete;
|
||||
};
|
||||
|
||||
typedef TfHashMap<TfToken, VtValue, TfToken::HashFunctor> HdRenderSettingsMap;
|
||||
|
||||
///
|
||||
/// HdRenderSettingDescriptor represents a render setting that a render delegate
|
||||
/// wants to export (e.g. to UI).
|
||||
///
|
||||
struct HdRenderSettingDescriptor
|
||||
{
|
||||
// A human readable name.
|
||||
std::string name;
|
||||
// The key for HdRenderDelegate::SetRenderSetting/GetRenderSetting.
|
||||
TfToken key;
|
||||
// The default value.
|
||||
VtValue defaultValue;
|
||||
};
|
||||
|
||||
typedef std::vector<HdRenderSettingDescriptor> HdRenderSettingDescriptorList;
|
||||
|
||||
/// \class HdRenderDelegate
|
||||
///
|
||||
class HdRenderDelegate
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
virtual ~HdRenderDelegate();
|
||||
|
||||
///
|
||||
/// Set list of driver objects, such as a rendering context / devices.
|
||||
/// This is automatically called from HdRenderIndex when a HdDriver is
|
||||
/// provided during its construction. Default implementation does nothing.
|
||||
///
|
||||
HD_API
|
||||
virtual void SetDrivers(HdDriverVector const& drivers);
|
||||
|
||||
///
|
||||
/// Returns a list of typeId's of all supported Rprims by this render
|
||||
/// delegate.
|
||||
///
|
||||
virtual const TfTokenVector &GetSupportedRprimTypes() const = 0;
|
||||
|
||||
///
|
||||
/// Returns a list of typeId's of all supported Sprims by this render
|
||||
/// delegate.
|
||||
///
|
||||
virtual const TfTokenVector &GetSupportedSprimTypes() const = 0;
|
||||
|
||||
|
||||
///
|
||||
/// Returns a list of typeId's of all supported Bprims by this render
|
||||
/// delegate.
|
||||
///
|
||||
virtual const TfTokenVector &GetSupportedBprimTypes() const = 0;
|
||||
|
||||
///
|
||||
/// Returns an opaque handle to a render param, that in turn is
|
||||
/// passed to each prim created by the render delegate during sync
|
||||
/// processing. This avoids the need to store a global state pointer
|
||||
/// in each prim.
|
||||
///
|
||||
/// The typical lifetime of the renderParam would match that of the
|
||||
/// RenderDelegate, however the minimal lifetime is that of the Sync
|
||||
/// processing. The param maybe queried multiple times during sync.
|
||||
///
|
||||
/// A render delegate may return null for the param.
|
||||
///
|
||||
HD_API
|
||||
virtual HdRenderParam *GetRenderParam() const;
|
||||
|
||||
///
|
||||
/// Returns a shared ptr to the resource registry of the current render
|
||||
/// delegate.
|
||||
///
|
||||
virtual HdResourceRegistrySharedPtr GetResourceRegistry() const = 0;
|
||||
|
||||
///
|
||||
/// Set a custom render setting on this render delegate.
|
||||
///
|
||||
HD_API
|
||||
virtual void SetRenderSetting(TfToken const& key, VtValue const& value);
|
||||
|
||||
///
|
||||
/// Get the current value for a render setting.
|
||||
///
|
||||
HD_API
|
||||
virtual VtValue GetRenderSetting(TfToken const& key) const;
|
||||
|
||||
///
|
||||
/// Get the current value for a render setting, taking a desired type
|
||||
/// and a fallback value in case of type mismatch.
|
||||
///
|
||||
template<typename T>
|
||||
T GetRenderSetting(TfToken const& key, T const& defValue) const {
|
||||
return GetRenderSetting(key).Cast<T>().GetWithDefault(defValue);
|
||||
}
|
||||
|
||||
///
|
||||
/// Get the backend-exported render setting descriptors.
|
||||
///
|
||||
HD_API
|
||||
virtual HdRenderSettingDescriptorList GetRenderSettingDescriptors() const;
|
||||
|
||||
///
|
||||
/// Get the current version of the render settings dictionary.
|
||||
///
|
||||
HD_API
|
||||
virtual unsigned int GetRenderSettingsVersion() const;
|
||||
|
||||
///
|
||||
/// Returns an open-format dictionary of render statistics
|
||||
///
|
||||
HD_API
|
||||
virtual VtDictionary GetRenderStats() const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Control of background rendering threads.
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Advertise whether this delegate supports pausing and resuming of
|
||||
/// background render threads. Default implementation returns false.
|
||||
///
|
||||
HD_API
|
||||
virtual bool IsPauseSupported() const;
|
||||
|
||||
///
|
||||
/// Pause all of this delegate's background rendering threads. Default
|
||||
/// implementation does nothing.
|
||||
///
|
||||
/// Returns \c true if successful.
|
||||
///
|
||||
HD_API
|
||||
virtual bool Pause();
|
||||
|
||||
///
|
||||
/// Resume all of this delegate's background rendering threads previously
|
||||
/// paused by a call to Pause. Default implementation does nothing.
|
||||
///
|
||||
/// Returns \c true if successful.
|
||||
///
|
||||
HD_API
|
||||
virtual bool Resume();
|
||||
|
||||
///
|
||||
/// Advertise whether this delegate supports stopping and restarting of
|
||||
/// background render threads. Default implementation returns false.
|
||||
///
|
||||
HD_API
|
||||
virtual bool IsStopSupported() const;
|
||||
|
||||
///
|
||||
/// Stop all of this delegate's background rendering threads. Default
|
||||
/// implementation does nothing.
|
||||
///
|
||||
/// Returns \c true if successful.
|
||||
///
|
||||
HD_API
|
||||
virtual bool Stop();
|
||||
|
||||
///
|
||||
/// Restart all of this delegate's background rendering threads previously
|
||||
/// stopped by a call to Stop. Default implementation does nothing.
|
||||
///
|
||||
/// Returns \c true if successful.
|
||||
///
|
||||
HD_API
|
||||
virtual bool Restart();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Renderpass Factory
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Request to create a new renderpass.
|
||||
/// \param index the render index to bind to the new renderpass.
|
||||
/// \param collection the rprim collection to bind to the new renderpass.
|
||||
/// \return A shared pointer to the new renderpass or empty on error.
|
||||
///
|
||||
virtual HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index,
|
||||
HdRprimCollection const& collection) = 0;
|
||||
|
||||
///
|
||||
/// Request to create a new renderpass state.
|
||||
/// The default implementation creates an HdRenderPassState instance,
|
||||
/// but derived render delegates may instantiate their own state type.
|
||||
/// \param shader The render pass shader to use. If null, a new
|
||||
/// HdRenderPassShared will be created.
|
||||
/// \return A shared pointer to the new renderpass state.
|
||||
///
|
||||
HD_API
|
||||
virtual HdRenderPassStateSharedPtr CreateRenderPassState() const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Instancer Factory
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Request to create a new instancer.
|
||||
/// \param id The unique identifier of this instancer.
|
||||
/// \return A pointer to the new instancer or nullptr on error.
|
||||
///
|
||||
virtual HdInstancer *CreateInstancer(HdSceneDelegate *delegate,
|
||||
SdfPath const& id) = 0;
|
||||
|
||||
virtual void DestroyInstancer(HdInstancer *instancer) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Prim Factories
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///
|
||||
/// Request to Allocate and Construct a new Rprim.
|
||||
/// \param typeId the type identifier of the prim to allocate
|
||||
/// \param rprimId a unique identifier for the prim
|
||||
/// \return A pointer to the new prim or nullptr on error.
|
||||
///
|
||||
virtual HdRprim *CreateRprim(TfToken const& typeId,
|
||||
SdfPath const& rprimId) = 0;
|
||||
|
||||
///
|
||||
/// Request to Destruct and deallocate the prim.
|
||||
///
|
||||
virtual void DestroyRprim(HdRprim *rPrim) = 0;
|
||||
|
||||
///
|
||||
/// Request to Allocate and Construct a new Sprim.
|
||||
/// \param typeId the type identifier of the prim to allocate
|
||||
/// \param sprimId a unique identifier for the prim
|
||||
/// \return A pointer to the new prim or nullptr on error.
|
||||
///
|
||||
virtual HdSprim *CreateSprim(TfToken const& typeId,
|
||||
SdfPath const& sprimId) = 0;
|
||||
|
||||
///
|
||||
/// Request to Allocate and Construct an Sprim to use as a standin, if there
|
||||
/// if an error with another another Sprim of the same type. For example,
|
||||
/// if another prim references a non-exisiting Sprim, the fallback could
|
||||
/// be used.
|
||||
///
|
||||
/// \param typeId the type identifier of the prim to allocate
|
||||
/// \return A pointer to the new prim or nullptr on error.
|
||||
///
|
||||
virtual HdSprim *CreateFallbackSprim(TfToken const& typeId) = 0;
|
||||
|
||||
///
|
||||
/// Request to Destruct and deallocate the prim.
|
||||
///
|
||||
virtual void DestroySprim(HdSprim *sprim) = 0;
|
||||
|
||||
///
|
||||
/// Request to Allocate and Construct a new Bprim.
|
||||
/// \param typeId the type identifier of the prim to allocate
|
||||
/// \param sprimId a unique identifier for the prim
|
||||
/// \return A pointer to the new prim or nullptr on error.
|
||||
///
|
||||
virtual HdBprim *CreateBprim(TfToken const& typeId,
|
||||
SdfPath const& bprimId) = 0;
|
||||
|
||||
|
||||
///
|
||||
/// Request to Allocate and Construct a Bprim to use as a standin, if there
|
||||
/// if an error with another another Bprim of the same type. For example,
|
||||
/// if another prim references a non-exisiting Bprim, the fallback could
|
||||
/// be used.
|
||||
///
|
||||
/// \param typeId the type identifier of the prim to allocate
|
||||
/// \return A pointer to the new prim or nullptr on error.
|
||||
///
|
||||
virtual HdBprim *CreateFallbackBprim(TfToken const& typeId) = 0;
|
||||
|
||||
///
|
||||
/// Request to Destruct and deallocate the prim.
|
||||
///
|
||||
virtual void DestroyBprim(HdBprim *bprim) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Sync, Execute & Dispatch Hooks
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Notification point from the Engine to the delegate.
|
||||
/// This notification occurs after all Sync's have completed and
|
||||
/// before task execution.
|
||||
///
|
||||
/// This notification gives the Render Delegate a chance to
|
||||
/// update and move memory that the render may need.
|
||||
///
|
||||
/// For example, the render delegate might fill primvar buffers or texture
|
||||
/// memory.
|
||||
///
|
||||
virtual void CommitResources(HdChangeTracker *tracker) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Materials
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Returns a token that indicates material bindings should be used,
|
||||
/// based on the indicated purpose. The default purpose is
|
||||
/// HdTokens->preview.
|
||||
///
|
||||
HD_API
|
||||
virtual TfToken GetMaterialBindingPurpose() const;
|
||||
|
||||
|
||||
/// \deprecated use GetMaterialRenderContexts()
|
||||
HD_API
|
||||
virtual TfToken GetMaterialNetworkSelector() const;
|
||||
|
||||
///
|
||||
/// Returns a list, in decending order of preference, that can be used to
|
||||
/// select among multiple material network implementations. The default
|
||||
/// list contains an empty token.
|
||||
///
|
||||
HD_API
|
||||
virtual TfTokenVector GetMaterialRenderContexts() const;
|
||||
|
||||
///
|
||||
/// Return true to indicate that the render delegate wants rprim primvars
|
||||
/// to be filtered by the scene delegate to reduce the amount of primvars
|
||||
/// that are send to the render delegate. For example the scene delegate
|
||||
/// may check the bound material primvar requirements and send only those
|
||||
/// to the render delegate. Return false to not apply primvar filtering in
|
||||
/// the scene delegate. Defaults to false.
|
||||
///
|
||||
HD_API
|
||||
virtual bool IsPrimvarFilteringNeeded() const;
|
||||
|
||||
///
|
||||
/// Returns the ordered list of shader source types that the render delegate
|
||||
/// supports.
|
||||
///
|
||||
HD_API
|
||||
virtual TfTokenVector GetShaderSourceTypes() const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// AOVs
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Returns a default AOV descriptor for the given named AOV, specifying
|
||||
/// things like preferred format.
|
||||
///
|
||||
HD_API
|
||||
virtual HdAovDescriptor GetDefaultAovDescriptor(TfToken const& name) const;
|
||||
|
||||
protected:
|
||||
/// This class must be derived from.
|
||||
HD_API
|
||||
HdRenderDelegate();
|
||||
/// Allow derived classes to pass construction-time render settings.
|
||||
HD_API
|
||||
HdRenderDelegate(HdRenderSettingsMap const& settingsMap);
|
||||
|
||||
///
|
||||
/// This class is not intended to be copied.
|
||||
///
|
||||
HdRenderDelegate(const HdRenderDelegate &) = delete;
|
||||
HdRenderDelegate &operator=(const HdRenderDelegate &) = delete;
|
||||
|
||||
HD_API
|
||||
void _PopulateDefaultSettings(
|
||||
HdRenderSettingDescriptorList const& defaultSettings);
|
||||
|
||||
/// Render settings state.
|
||||
HdRenderSettingsMap _settingsMap;
|
||||
unsigned int _settingsVersion;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RENDER_DELEGATE_H
|
||||
@@ -0,0 +1,530 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_INDEX_H
|
||||
#define PXR_IMAGING_HD_RENDER_INDEX_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/changeTracker.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
#include "pxr/imaging/hd/primTypeIndex.h"
|
||||
#include "pxr/imaging/hd/resourceRegistry.h"
|
||||
#include "pxr/imaging/hd/sortedIds.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
|
||||
#include "pxr/imaging/hf/perfLog.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/gf/vec4i.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
|
||||
#include <tbb/enumerable_thread_specific.h>
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRprim;
|
||||
class HdSprim;
|
||||
class HdBprim;
|
||||
class HdDrawItem;
|
||||
class HdRprimCollection;
|
||||
class HdSceneDelegate;
|
||||
class HdRenderDelegate;
|
||||
class HdExtComputation;
|
||||
class VtValue;
|
||||
class HdInstancer;
|
||||
class HdDriver;
|
||||
|
||||
using HdDirtyListSharedPtr = std::shared_ptr<class HdDirtyList>;
|
||||
|
||||
using HdTaskSharedPtr = std::shared_ptr<class HdTask>;
|
||||
|
||||
using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
|
||||
using HdTaskSharedPtrVector = std::vector<HdTaskSharedPtr>;
|
||||
using HdTaskContext = std::unordered_map<TfToken,
|
||||
VtValue,
|
||||
TfToken::HashFunctor>;
|
||||
using HdDriverVector = std::vector<HdDriver*>;
|
||||
|
||||
/// \class HdRenderIndex
|
||||
///
|
||||
/// The Hydra render index is a flattened representation of the client scene
|
||||
/// graph, which may be composed of several self-contained scene graphs, each of
|
||||
/// which provides a HdSceneDelegate adapter for data access.
|
||||
///
|
||||
/// Thus, multiple HdSceneDelegate's may be tied to the same HdRenderIndex.
|
||||
///
|
||||
/// The render index, however, is tied to a single HdRenderDelegate, which
|
||||
/// handles the actual creation and deletion of Hydra scene primitives. These
|
||||
/// include geometry and non-drawable objects (such as the camera and texture
|
||||
/// buffers). The render index simply holds a handle to these primitives, and
|
||||
/// tracks any changes to them via the HdChangeTracker.
|
||||
/// It also tracks computations and tasks that may update resources and render a
|
||||
/// subset of the renderable primitives.
|
||||
///
|
||||
/// The render index orchestrates the "syncing" of scene primitives, by
|
||||
/// providing the relevant scene delegate for data access, and leaves resource
|
||||
/// management to the rendering backend (via HdResourceRegistry).
|
||||
///
|
||||
/// It also provides "execution" functionality for application facing Hydra
|
||||
/// concepts (such as HdTask/HdRenderPass) in computing the set of HdDrawItems
|
||||
/// for a given HdRprimCollection, for rendering.
|
||||
///
|
||||
/// \sa
|
||||
/// HdChangeTracker
|
||||
/// HdDrawItem
|
||||
/// HdRenderDelegate
|
||||
/// HdRprimCollection
|
||||
/// HdSceneDelegate
|
||||
///
|
||||
/// \note
|
||||
/// The current design ties a HdRenderIndex to a HdRenderDelegate.
|
||||
/// However, the HdRenderIndex isn't tied to a viewer (viewport).
|
||||
/// It is common to have multiple viewers image the composed scene (for example,
|
||||
/// with different cameras), in which case the HdRenderIndex and
|
||||
/// HdRenderDelegate are shared by the viewers.
|
||||
///
|
||||
/// If two viewers use different HdRenderDelegate's, then it may unfortunately
|
||||
/// require populating two HdRenderIndex's.
|
||||
///
|
||||
class HdRenderIndex final
|
||||
{
|
||||
public:
|
||||
typedef std::vector<HdDrawItem const*> HdDrawItemPtrVector;
|
||||
|
||||
/// Create a render index with the given render delegate.
|
||||
/// Returns null if renderDelegate is null.
|
||||
/// The render delegate and render tasks may require access to a renderer's
|
||||
/// device provided by the application. The objects can be
|
||||
/// passed in as 'drivers'. Hgi is an example of a HdDriver.
|
||||
// hgi = Hgi::CreatePlatformDefaultHgi()
|
||||
// hgiDriver = new HdDriver<Hgi*>(HgiTokens→renderDriver, hgi)
|
||||
// HdRenderIndex::New(_renderDelegate, {_hgiDriver})
|
||||
HD_API
|
||||
static HdRenderIndex* New(
|
||||
HdRenderDelegate *renderDelegate,
|
||||
HdDriverVector const& drivers);
|
||||
|
||||
HD_API
|
||||
~HdRenderIndex();
|
||||
|
||||
/// Clear all r (render), s (state) and b (buffer) prims.
|
||||
HD_API
|
||||
void Clear();
|
||||
|
||||
/// Clear all entries in the render index under
|
||||
/// the given root and belong to a specified delegate.
|
||||
///
|
||||
/// Used for example to unload a delegate.
|
||||
HD_API
|
||||
void RemoveSubtree(const SdfPath &root, HdSceneDelegate* sceneDelegate);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Given a prim id, returns the path of the corresponding rprim
|
||||
/// or an empty path if none is found.
|
||||
HD_API
|
||||
SdfPath GetRprimPathFromPrimId(int primId) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Synchronization
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Adds the dirty list to the sync queue. The actual processing of the
|
||||
/// dirty list happens later in SyncAll().
|
||||
///
|
||||
/// This is typically called from HdRenderPass::Sync. However, the current
|
||||
/// call chain ties it to SyncAll, i.e.
|
||||
/// HdRenderIndex::SyncAll > .... > HdRenderPass::Sync > HdRenderIndex::Sync
|
||||
HD_API
|
||||
void EnqueuePrimsToSync(
|
||||
HdDirtyListSharedPtr const &dirtyList,
|
||||
HdRprimCollection const &collection);
|
||||
|
||||
/// Syncs input tasks, B & S prims, (external) computations and processes
|
||||
/// all pending dirty lists (which syncs the R prims). At the end of this
|
||||
/// step, all the resources that need to be updated have handles to their
|
||||
/// data sources.
|
||||
/// This is the first phase in Hydra's execution. See HdEngine::Execute
|
||||
HD_API
|
||||
void SyncAll(HdTaskSharedPtrVector *tasks, HdTaskContext *taskContext);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Execution
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns a list of relevant draw items that match the criteria specified
|
||||
// by renderTags and collection.
|
||||
/// The is typically called during render pass execution, which is the
|
||||
/// final phase in the Hydra's execution. See HdRenderPass::Execute
|
||||
HD_API
|
||||
HdDrawItemPtrVector GetDrawItems(HdRprimCollection const& collection,
|
||||
TfTokenVector const& renderTags);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Change Tracker
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
HdChangeTracker& GetChangeTracker() { return _tracker; }
|
||||
HdChangeTracker const& GetChangeTracker() const { return _tracker; }
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Renderable prims (e.g. meshes, basis curves)
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns whether the rprim type is supported by this render index.
|
||||
HD_API
|
||||
bool IsRprimTypeSupported(TfToken const& typeId) const;
|
||||
|
||||
/// Insert a rprim into index
|
||||
HD_API
|
||||
void InsertRprim(TfToken const& typeId,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
SdfPath const& rprimId);
|
||||
|
||||
/// Remove a rprim from index
|
||||
HD_API
|
||||
void RemoveRprim(SdfPath const& id);
|
||||
|
||||
/// Returns true if rprim \p id exists in index.
|
||||
bool HasRprim(SdfPath const& id) {
|
||||
return _rprimMap.find(id) != _rprimMap.end();
|
||||
}
|
||||
|
||||
/// Returns the rprim of id
|
||||
HD_API
|
||||
HdRprim const *GetRprim(SdfPath const &id) const;
|
||||
|
||||
/// Returns the scene delegate for the given rprim
|
||||
HD_API
|
||||
HdSceneDelegate *GetSceneDelegateForRprim(SdfPath const &id) const;
|
||||
|
||||
/// Query function to return the id's of the scene delegate and instancer
|
||||
/// associated with the Rprim at the given path.
|
||||
HD_API
|
||||
bool GetSceneDelegateAndInstancerIds(SdfPath const &id,
|
||||
SdfPath* sceneDelegateId,
|
||||
SdfPath* instancerId) const;
|
||||
|
||||
/// Returns the render tag for the given rprim
|
||||
HD_API
|
||||
TfToken GetRenderTag(SdfPath const& id) const;
|
||||
|
||||
/// Return the material tag for the given rprim
|
||||
HD_API
|
||||
TfToken GetMaterialTag(SdfPath const& id) const;
|
||||
|
||||
/// Returns a sorted list of all Rprims in the render index.
|
||||
/// The list is sorted by std::less<SdfPath>
|
||||
HD_API
|
||||
const SdfPathVector &GetRprimIds() { return _rprimIds.GetIds(); }
|
||||
|
||||
|
||||
/// Returns the subtree rooted under the given path.
|
||||
HD_API
|
||||
SdfPathVector GetRprimSubtree(SdfPath const& root);
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Instancer Support
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Insert an instancer into index
|
||||
HD_API
|
||||
void InsertInstancer(HdSceneDelegate* delegate,
|
||||
SdfPath const &id);
|
||||
|
||||
/// Remove an instancer from index
|
||||
HD_API
|
||||
void RemoveInstancer(SdfPath const& id);
|
||||
|
||||
/// Returns true if instancer \p id exists in index.
|
||||
bool HasInstancer(SdfPath const& id) {
|
||||
return _instancerMap.find(id) != _instancerMap.end();
|
||||
}
|
||||
|
||||
/// Returns the instancer of id
|
||||
HD_API
|
||||
HdInstancer *GetInstancer(SdfPath const &id) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Task Support
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Inserts a new task into the render index with an identifier of \p id.
|
||||
template <typename T>
|
||||
void InsertTask(HdSceneDelegate* delegate, SdfPath const& id);
|
||||
|
||||
/// Removes the given task from the RenderIndex.
|
||||
HD_API
|
||||
void RemoveTask(SdfPath const& id);
|
||||
|
||||
/// Returns true if a task exists in the index with the given \p id.
|
||||
bool HasTask(SdfPath const& id) {
|
||||
return _taskMap.find(id) != _taskMap.end();
|
||||
}
|
||||
|
||||
/// Returns the task for the given \p id.
|
||||
HD_API
|
||||
HdTaskSharedPtr const& GetTask(SdfPath const& id) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Scene state prims (e.g. camera, light)
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns whether the sprim type is supported by this render index.
|
||||
HD_API
|
||||
bool IsSprimTypeSupported(TfToken const& typeId) const;
|
||||
|
||||
/// Insert a sprim into index
|
||||
HD_API
|
||||
void InsertSprim(TfToken const& typeId,
|
||||
HdSceneDelegate* delegate,
|
||||
SdfPath const& sprimId);
|
||||
|
||||
HD_API
|
||||
void RemoveSprim(TfToken const& typeId, SdfPath const &id);
|
||||
|
||||
HD_API
|
||||
HdSprim *GetSprim(TfToken const& typeId, SdfPath const &id) const;
|
||||
|
||||
/// Returns the subtree rooted under the given path for the given sprim
|
||||
/// type.
|
||||
HD_API
|
||||
SdfPathVector GetSprimSubtree(TfToken const& typeId,
|
||||
SdfPath const& root);
|
||||
|
||||
/// Returns the fullback prim for the Sprim of the given type.
|
||||
HD_API
|
||||
HdSprim *GetFallbackSprim(TfToken const& typeId) const;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Buffer prims (e.g. textures, buffers)
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns whether the bprim type is supported by this render index.
|
||||
HD_API
|
||||
bool IsBprimTypeSupported(TfToken const& typeId) const;
|
||||
|
||||
/// Insert a bprim into index
|
||||
HD_API
|
||||
void InsertBprim(TfToken const& typeId,
|
||||
HdSceneDelegate* delegate,
|
||||
SdfPath const& bprimId);
|
||||
|
||||
HD_API
|
||||
void RemoveBprim(TfToken const& typeId, SdfPath const &id);
|
||||
|
||||
HD_API
|
||||
HdBprim *GetBprim(TfToken const& typeId, SdfPath const &id) const;
|
||||
|
||||
/// Returns the subtree rooted under the given path for the given bprim
|
||||
/// type.
|
||||
HD_API
|
||||
SdfPathVector GetBprimSubtree(TfToken const& typeId,
|
||||
SdfPath const& root);
|
||||
|
||||
/// Returns the fallback prim for the Bprim of the given type.
|
||||
HD_API
|
||||
HdBprim *GetFallbackBprim(TfToken const& typeId) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Render Delegate
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Currently, a render index only supports connection to one type of
|
||||
/// render delegate, due to the inserted information and change tracking
|
||||
/// being specific to that delegate type.
|
||||
HD_API
|
||||
HdRenderDelegate *GetRenderDelegate() const;
|
||||
|
||||
// The render delegate may require access to a render context / device
|
||||
// that is provided by the application.
|
||||
HD_API
|
||||
HdDriverVector const& GetDrivers() const;
|
||||
|
||||
/// Returns a shared ptr to the resource registry of the current render
|
||||
/// delegate.
|
||||
HD_API
|
||||
HdResourceRegistrySharedPtr GetResourceRegistry() const;
|
||||
|
||||
private:
|
||||
// The render index constructor is private so we can check
|
||||
// renderDelegate before construction: see HdRenderIndex::New(...).
|
||||
HdRenderIndex(
|
||||
HdRenderDelegate *renderDelegate,
|
||||
HdDriverVector const& drivers);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Private Helper methods
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
// Go through all RPrims and reallocate their instance ids
|
||||
// This is called once we have exhausted all all 24bit instance ids.
|
||||
void _CompactPrimIds();
|
||||
|
||||
// Allocate the next available instance id to the prim
|
||||
void _AllocatePrimId(HdRprim* prim);
|
||||
|
||||
// Inserts the task into the index and updates tracking state.
|
||||
// _TrackDelegateTask is called by the inlined InsertTask<T>, so it needs
|
||||
// to be marked HD_API.
|
||||
HD_API
|
||||
void _TrackDelegateTask(HdSceneDelegate* delegate,
|
||||
SdfPath const& taskId,
|
||||
HdTaskSharedPtr const& task);
|
||||
|
||||
template <typename T>
|
||||
static inline const TfToken & _GetTypeId();
|
||||
|
||||
void _RemoveRprimSubtree(const SdfPath &root,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
void _RemoveInstancerSubtree(const SdfPath &root,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
void _RemoveExtComputationSubtree(const SdfPath &root,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
void _RemoveTaskSubtree(const SdfPath &root,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Index State
|
||||
// ---------------------------------------------------------------------- //
|
||||
struct _RprimInfo {
|
||||
HdSceneDelegate *sceneDelegate;
|
||||
HdRprim *rprim;
|
||||
};
|
||||
|
||||
struct _TaskInfo {
|
||||
HdSceneDelegate *sceneDelegate;
|
||||
HdTaskSharedPtr task;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<SdfPath, _TaskInfo, SdfPath::Hash> _TaskMap;
|
||||
typedef TfHashMap<SdfPath, _RprimInfo, SdfPath::Hash> _RprimMap;
|
||||
typedef std::vector<SdfPath> _RprimPrimIDVector;
|
||||
|
||||
typedef Hd_PrimTypeIndex<HdSprim> _SprimIndex;
|
||||
typedef Hd_PrimTypeIndex<HdBprim> _BprimIndex;
|
||||
|
||||
_RprimMap _rprimMap;
|
||||
Hd_SortedIds _rprimIds;
|
||||
|
||||
_RprimPrimIDVector _rprimPrimIdMap;
|
||||
|
||||
_TaskMap _taskMap;
|
||||
|
||||
_SprimIndex _sprimIndex;
|
||||
_BprimIndex _bprimIndex;
|
||||
|
||||
HdChangeTracker _tracker;
|
||||
|
||||
typedef TfHashMap<SdfPath, HdInstancer*, SdfPath::Hash> _InstancerMap;
|
||||
_InstancerMap _instancerMap;
|
||||
|
||||
struct _SyncQueueEntry {
|
||||
HdDirtyListSharedPtr dirtyList;
|
||||
HdRprimCollection collection;
|
||||
|
||||
};
|
||||
typedef std::vector<_SyncQueueEntry> _SyncQueue;
|
||||
_SyncQueue _syncQueue;
|
||||
|
||||
/// With the removal of task-based collection include/exclude path
|
||||
/// filtering, HdDirtyLists were generating their lists of dirty rprim IDs
|
||||
/// by looking through every rprim in the render index. When the number of
|
||||
/// tasks/render passes/dirty lists grew large, this resulted in
|
||||
/// significant overhead and lots of duplication of work.
|
||||
/// Instead, the render index itself now takes care of generating the
|
||||
/// complete list of dirty rprim IDs when requested by the HdDirtyList.
|
||||
/// During SyncAll(), the first HdDirtyList to request the list of dirty
|
||||
/// IDs for a given HdDirtyBits mask triggers the render index to produce
|
||||
/// that list and cache it in a map. Subsequent requests reuse the cached
|
||||
/// list. At the end of SyncAll(), the map is cleared in preparation for
|
||||
/// the next sync.
|
||||
std::unordered_map<HdDirtyBits, const SdfPathVector> _dirtyRprimIdsMap;
|
||||
|
||||
friend class HdDirtyList;
|
||||
const SdfPathVector& _GetDirtyRprimIds(HdDirtyBits mask);
|
||||
|
||||
HdRenderDelegate *_renderDelegate;
|
||||
HdDriverVector _drivers;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Sync State
|
||||
// ---------------------------------------------------------------------- //
|
||||
TfTokenVector _activeRenderTags;
|
||||
unsigned int _renderTagVersion;
|
||||
|
||||
/// Register the render delegate's list of supported prim types.
|
||||
void _InitPrimTypes();
|
||||
|
||||
/// Creates fallback prims for each supported prim type.
|
||||
bool _CreateFallbackPrims();
|
||||
|
||||
/// Release the fallback prims.
|
||||
void _DestroyFallbackPrims();
|
||||
|
||||
void _GatherRenderTags(const HdTaskSharedPtrVector *tasks);
|
||||
|
||||
typedef tbb::enumerable_thread_specific<HdDrawItemPtrVector>
|
||||
_ConcurrentDrawItems;
|
||||
|
||||
void _AppendDrawItems(const SdfPathVector &rprimIds,
|
||||
size_t begin,
|
||||
size_t end,
|
||||
HdRprimCollection const& collection,
|
||||
_ConcurrentDrawItems* result);
|
||||
|
||||
/// Register core hydra reprs. Only ever called once, the first time
|
||||
/// a render index is created.
|
||||
/// XXX: This code should move to the application layer.
|
||||
static void _ConfigureReprs();
|
||||
|
||||
// Remove default constructor
|
||||
HdRenderIndex() = delete;
|
||||
|
||||
// Don't allow copies
|
||||
HdRenderIndex(const HdRenderIndex &) = delete;
|
||||
HdRenderIndex &operator=(const HdRenderIndex &) = delete;
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
HdRenderIndex::InsertTask(HdSceneDelegate* delegate, SdfPath const& id)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
HF_MALLOC_TAG_FUNCTION();
|
||||
|
||||
HdTaskSharedPtr task = std::make_shared<T>(delegate, id);
|
||||
_TrackDelegateTask(delegate, id, task);
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RENDER_INDEX_H
|
||||
@@ -0,0 +1,166 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_PASS_H
|
||||
#define PXR_IMAGING_HD_RENDER_PASS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/changeTracker.h"
|
||||
#include "pxr/imaging/hd/rprimCollection.h"
|
||||
#include "pxr/imaging/hd/task.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRenderIndex;
|
||||
class HdSceneDelegate;
|
||||
|
||||
using HdDirtyListSharedPtr = std::shared_ptr<class HdDirtyList>;
|
||||
using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
|
||||
using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
|
||||
|
||||
/// \class HdRenderPass
|
||||
///
|
||||
/// An abstract class representing a single render iteration over a set of prims
|
||||
/// (the HdRprimCollection), for the camera/viewport parameters in
|
||||
/// HdRenderPassState.
|
||||
///
|
||||
/// Conceptually, a rendering task may be broken down into one or more
|
||||
/// HdRenderPass(es).
|
||||
///
|
||||
/// An HdRenderPass has two phases, Sync() and Execute(), in line with Hydra's
|
||||
/// execution phases (See HdEngine::Execute)
|
||||
///
|
||||
/// The base class implementation of Sync() takes care of syncing collection
|
||||
/// changes with the HdRenderIndex via HdDirtyList, and allows derived classes
|
||||
/// to track collection changes (via _MarkCollectionDirty) and sync additional
|
||||
/// resources (via _Sync)
|
||||
///
|
||||
/// Renderer backends implement _Execute, wherein the HdDrawItem(s) for the
|
||||
/// collection may be consumed via HdRenderIndex::GetDrawItems.
|
||||
/// Typically, the HdRenderPassState argument of _Execute is made available via
|
||||
/// the HdTaskContext.
|
||||
///
|
||||
/// \note
|
||||
/// Rendering backends are expected to specialize this abstract class, and
|
||||
/// return the specialized object via HdRenderDelegate::CreateRenderPass
|
||||
///
|
||||
class HdRenderPass
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
HdRenderPass(HdRenderIndex *index, HdRprimCollection const& collection);
|
||||
HD_API
|
||||
virtual ~HdRenderPass();
|
||||
|
||||
/// Returns the HdRprimCollection to be drawn by this RenderPass.
|
||||
HdRprimCollection const& GetRprimCollection() const { return _collection; }
|
||||
|
||||
/// Sets the HdRprimCollection, note that this may invalidate internal
|
||||
/// caches used to accelerate drawing.
|
||||
HD_API
|
||||
void SetRprimCollection(HdRprimCollection const& col);
|
||||
|
||||
/// Returns the dirty list (maintained in the change tracker) for
|
||||
/// efficient traversal
|
||||
HdDirtyListSharedPtr const &GetDirtyList() const {
|
||||
return _dirtyList;
|
||||
}
|
||||
|
||||
/// Return the render index
|
||||
HdRenderIndex* GetRenderIndex() const { return _renderIndex; }
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Synchronization
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Sync the render pass resources
|
||||
HD_API
|
||||
void Sync();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Prepare
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Prepare renderpass data
|
||||
HD_API
|
||||
void Prepare(TfTokenVector const &renderTags);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Execution
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Execute a subset of buckets of this renderpass.
|
||||
HD_API
|
||||
void Execute(HdRenderPassStateSharedPtr const &renderPassState,
|
||||
TfTokenVector const &renderTags);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Optional API hooks for progressive rendering
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
virtual bool IsConverged() const { return true; }
|
||||
|
||||
protected:
|
||||
/// Virtual API: Execute the buckets corresponding to renderTags;
|
||||
/// renderTags.empty() implies execute everything.
|
||||
virtual void _Execute(HdRenderPassStateSharedPtr const &renderPassState,
|
||||
TfTokenVector const &renderTags) = 0;
|
||||
|
||||
/// Optional API: let derived classes mark their collection tracking as dirty.
|
||||
virtual void _MarkCollectionDirty() {}
|
||||
|
||||
/// Optional API: let derived classes sync data.
|
||||
virtual void _Sync() {}
|
||||
|
||||
/// Optional API: let derived classes prepare data.
|
||||
virtual void _Prepare(TfTokenVector const &renderTags) {}
|
||||
|
||||
private:
|
||||
|
||||
// Don't allow copies
|
||||
HdRenderPass(const HdRenderPass &) = delete;
|
||||
HdRenderPass &operator=(const HdRenderPass &) = delete;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// \name Change Tracking State
|
||||
// ---------------------------------------------------------------------- //
|
||||
// The renderIndex to which this renderPass belongs
|
||||
// (can't change after construction)
|
||||
HdRenderIndex * const _renderIndex;
|
||||
|
||||
// cached dirty prims list
|
||||
HdDirtyListSharedPtr _dirtyList;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// \name Core RenderPass State
|
||||
// ---------------------------------------------------------------------- //
|
||||
HdRprimCollection _collection;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RENDER_PASS_H
|
||||
@@ -0,0 +1,410 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_PASS_STATE_H
|
||||
#define PXR_IMAGING_HD_RENDER_PASS_STATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/aov.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
|
||||
#include "pxr/imaging/cameraUtil/framing.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/vec2f.h"
|
||||
#include "pxr/base/gf/vec4d.h"
|
||||
#include "pxr/base/gf/vec4f.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
|
||||
using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
|
||||
|
||||
class HdCamera;
|
||||
|
||||
/// \class HdRenderPassState
|
||||
///
|
||||
/// A set of rendering parameters used among render passes.
|
||||
///
|
||||
/// Parameters are expressed as GL states, uniforms or shaders.
|
||||
///
|
||||
class HdRenderPassState
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
HdRenderPassState();
|
||||
HD_API
|
||||
virtual ~HdRenderPassState();
|
||||
|
||||
/// Schedule to update renderPassState parameters.
|
||||
/// e.g. camera matrix, override color, id blend factor.
|
||||
/// Prepare, called once per frame after the sync phase, but prior to
|
||||
/// the commit phase.
|
||||
HD_API
|
||||
virtual void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Camera and framing state
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
using ClipPlanesVector = std::vector<GfVec4d>;
|
||||
|
||||
/// Camera setter API
|
||||
///
|
||||
/// Sets the camera transform (aka view inverse matrix) and physical
|
||||
/// parameters, the framing information and a possible overide value
|
||||
/// for the window policy used to conform the camera frustum if its
|
||||
/// aspect ratio is not matching the display window.
|
||||
///
|
||||
/// Note: using std::pair<bool, ...> here instead of std::optional<...>
|
||||
/// since the latter is only available in C++17 or later.
|
||||
HD_API
|
||||
void SetCameraAndFraming(
|
||||
HdCamera const *camera,
|
||||
CameraUtilFraming const &framing,
|
||||
const std::pair<bool, CameraUtilConformWindowPolicy> &
|
||||
overrideWindowPolicy);
|
||||
|
||||
/// Get camera
|
||||
HdCamera const *
|
||||
GetCamera() const { return _camera; }
|
||||
|
||||
/// Get framing information determining how the filmback plane maps
|
||||
/// to pixels.
|
||||
const CameraUtilFraming &
|
||||
GetFraming() const { return _framing; }
|
||||
|
||||
/// The override value for the window policy to conform the camera
|
||||
/// frustum that can be specified by the application.
|
||||
const std::pair<bool, CameraUtilConformWindowPolicy> &
|
||||
GetOverrideWindowPolicy() const { return _overrideWindowPolicy; }
|
||||
|
||||
/// The resolved window policy to conform the camera frustum.
|
||||
/// This is either the override value specified by the application or
|
||||
/// the value from the scene delegate's camera.
|
||||
HD_API
|
||||
CameraUtilConformWindowPolicy
|
||||
GetWindowPolicy() const;
|
||||
|
||||
/// Camera setter API
|
||||
/// The view, projection and clipping plane info of the camera will be used.
|
||||
///
|
||||
/// \deprecated Use the more expressive SetCameraAndFraming instead.
|
||||
HD_API
|
||||
void SetCameraAndViewport(HdCamera const *camera,
|
||||
GfVec4d const& viewport);
|
||||
/// Camera getter API
|
||||
///
|
||||
/// For backwards compatibility, use the worldToView matrix of the HdCamera
|
||||
/// if given. Otherwise, use the HdCamera's transform.
|
||||
///
|
||||
/// The HdRenderPassState also has a fallback value for the view
|
||||
/// matrix that is used if no HdCamera was specified, that can be set with,
|
||||
/// e.g.g, HdStRenderPassState::SetCameraFramingState.
|
||||
///
|
||||
HD_API
|
||||
GfMatrix4d GetWorldToViewMatrix() const;
|
||||
|
||||
/// It is expected that an HdCamera was specified that has physically based
|
||||
/// attributes. The projection matrix is computed from those attributes and
|
||||
/// the conform window policy is applied.
|
||||
///
|
||||
/// For backwards compatibility with scene and render delegates:
|
||||
/// if the HdCamera has no physically based attributes (more precisely,
|
||||
/// the scene delegate provided a VtValue for focalLength that is either
|
||||
/// empty or 1.0f), the HdCamera's projection matrix is used.
|
||||
/// The HdRenderPassState also has a fallback value for the projection
|
||||
/// matrix that is used if no HdCamera was specified, that can be set with,
|
||||
/// e.g.g, HdStRenderPassState::SetCameraFramingState.
|
||||
///
|
||||
HD_API
|
||||
GfMatrix4d GetProjectionMatrix() const;
|
||||
|
||||
/// Only use when clients did not specify a camera framing.
|
||||
///
|
||||
/// \deprecated
|
||||
GfVec4f const & GetViewport() const { return _viewport; }
|
||||
|
||||
HD_API
|
||||
ClipPlanesVector const & GetClipPlanes() const;
|
||||
|
||||
GfMatrix4d GetCullMatrix() const { return _cullMatrix; }
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Application rendering state
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Set an override color for rendering where the R, G and B components
|
||||
/// are the color and the alpha component is the blend value
|
||||
HD_API
|
||||
void SetOverrideColor(GfVec4f const &color);
|
||||
const GfVec4f& GetOverrideColor() const { return _overrideColor; }
|
||||
|
||||
/// Set a wireframe color for rendering where the R, G and B components
|
||||
/// are the color and the alpha component is the blend value
|
||||
HD_API
|
||||
void SetWireframeColor(GfVec4f const &color);
|
||||
const GfVec4f& GetWireframeColor() const { return _wireframeColor; }
|
||||
|
||||
HD_API
|
||||
void SetMaskColor(GfVec4f const &color);
|
||||
const GfVec4f& GetMaskColor() const { return _maskColor; }
|
||||
|
||||
HD_API
|
||||
void SetIndicatorColor(GfVec4f const &color);
|
||||
const GfVec4f& GetIndicatorColor() const { return _indicatorColor; }
|
||||
|
||||
/// Set a point color for rendering where the R, G and B components
|
||||
/// are the color and the alpha component is the blend value
|
||||
HD_API
|
||||
void SetPointColor(GfVec4f const &color);
|
||||
const GfVec4f& GetPointColor() const { return _pointColor; }
|
||||
|
||||
/// Set the point size for unselected points.
|
||||
HD_API
|
||||
void SetPointSize(float size);
|
||||
float GetPointSize() const { return _pointSize; }
|
||||
|
||||
/// Set the point size for selected points.
|
||||
HD_API
|
||||
void SetPointSelectedSize(float size);
|
||||
float GetPointSelectedSize() const { return _pointSelectedSize; }
|
||||
|
||||
/// XXX: Hacky way of disabling lighting
|
||||
HD_API
|
||||
void SetLightingEnabled(bool enabled);
|
||||
bool GetLightingEnabled() const { return _lightingEnabled; }
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Render pipeline state
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Set the attachments for this renderpass to render into.
|
||||
HD_API
|
||||
void SetAovBindings(HdRenderPassAovBindingVector const &aovBindings);
|
||||
HD_API
|
||||
HdRenderPassAovBindingVector const& GetAovBindings() const;
|
||||
|
||||
/// Returns true if the render pass wants to render into the multi-sample
|
||||
/// aovs. Returns false if the render wants to render into the resolve aovs.
|
||||
HD_API
|
||||
void SetUseAovMultiSample(bool state);
|
||||
HD_API
|
||||
bool GetUseAovMultiSample() const;
|
||||
|
||||
HD_API
|
||||
void SetCullStyle(HdCullStyle cullStyle);
|
||||
HD_API
|
||||
HdCullStyle GetCullStyle() const { return _cullStyle; }
|
||||
|
||||
HD_API
|
||||
void SetAlphaThreshold(float alphaThreshold);
|
||||
float GetAlphaThreshold() const { return _alphaThreshold; }
|
||||
|
||||
HD_API
|
||||
void SetTessLevel(float level);
|
||||
float GetTessLevel() const { return _tessLevel; }
|
||||
|
||||
HD_API
|
||||
void SetDrawingRange(GfVec2f const &drawRange);
|
||||
GfVec2f GetDrawingRange() const { return _drawRange; } // in pixel
|
||||
GfVec2f GetDrawingRangeNDC() const { // in ndc
|
||||
return GfVec2f(2*_drawRange[0]/_viewport[2],
|
||||
2*_drawRange[1]/_viewport[3]);
|
||||
}
|
||||
|
||||
HD_API
|
||||
void SetDepthBiasUseDefault(bool useDefault);
|
||||
bool GetDepthBiasUseDefault() const { return _depthBiasUseDefault; }
|
||||
|
||||
HD_API
|
||||
void SetDepthBiasEnabled(bool enabled);
|
||||
bool GetDepthBiasEnabled() const { return _depthBiasEnabled; }
|
||||
|
||||
HD_API
|
||||
void SetDepthBias(float constantFactor, float slopeFactor);
|
||||
|
||||
HD_API
|
||||
void SetDepthFunc(HdCompareFunction depthFunc);
|
||||
HdCompareFunction GetDepthFunc() const { return _depthFunc; }
|
||||
|
||||
HD_API
|
||||
void SetEnableDepthMask(bool state);
|
||||
HD_API
|
||||
bool GetEnableDepthMask();
|
||||
|
||||
HD_API
|
||||
void SetEnableDepthTest(bool enabled);
|
||||
HD_API
|
||||
bool GetEnableDepthTest() const;
|
||||
|
||||
HD_API
|
||||
void SetStencil(HdCompareFunction func, int ref, int mask,
|
||||
HdStencilOp fail, HdStencilOp zfail, HdStencilOp zpass);
|
||||
HdCompareFunction GetStencilFunc() const { return _stencilFunc; }
|
||||
int GetStencilRef() const { return _stencilRef; }
|
||||
int GetStencilMask() const { return _stencilMask; }
|
||||
HdStencilOp GetStencilFailOp() const { return _stencilFailOp; }
|
||||
HdStencilOp GetStencilDepthFailOp() const { return _stencilZFailOp; }
|
||||
HdStencilOp GetStencilDepthPassOp() const { return _stencilZPassOp; }
|
||||
HD_API
|
||||
void SetStencilEnabled(bool enabled);
|
||||
HD_API
|
||||
bool GetStencilEnabled() const;
|
||||
|
||||
HD_API
|
||||
void SetLineWidth(float width);
|
||||
float GetLineWidth() const { return _lineWidth; }
|
||||
|
||||
HD_API
|
||||
void SetBlend(HdBlendOp colorOp,
|
||||
HdBlendFactor colorSrcFactor,
|
||||
HdBlendFactor colorDstFactor,
|
||||
HdBlendOp alphaOp,
|
||||
HdBlendFactor alphaSrcFactor,
|
||||
HdBlendFactor alphaDstFactor);
|
||||
HdBlendOp GetBlendColorOp() { return _blendColorOp; }
|
||||
HdBlendFactor GetBlendColorSrcFactor() { return _blendColorSrcFactor; }
|
||||
HdBlendFactor GetBlendColorDstFactor() { return _blendColorDstFactor; }
|
||||
HdBlendOp GetBlendAlphaOp() { return _blendAlphaOp; }
|
||||
HdBlendFactor GetBlendAlphaSrcFactor() { return _blendAlphaSrcFactor; }
|
||||
HdBlendFactor GetBlendAlphaDstFactor() { return _blendAlphaDstFactor; }
|
||||
HD_API
|
||||
void SetBlendConstantColor(GfVec4f const & color);
|
||||
const GfVec4f& GetBlendConstantColor() const { return _blendConstantColor; }
|
||||
HD_API
|
||||
void SetBlendEnabled(bool enabled);
|
||||
|
||||
HD_API
|
||||
void SetAlphaToCoverageEnabled(bool enabled);
|
||||
bool GetAlphaToCoverageEnabled() const { return _alphaToCoverageEnabled; }
|
||||
|
||||
HD_API
|
||||
void SetColorMaskUseDefault(bool useDefault);
|
||||
bool GetColorMaskUseDefault() const { return _colorMaskUseDefault;}
|
||||
|
||||
enum ColorMask {
|
||||
ColorMaskNone,
|
||||
ColorMaskRGB,
|
||||
ColorMaskRGBA
|
||||
};
|
||||
|
||||
HD_API
|
||||
void SetColorMasks(std::vector<ColorMask> const& masks);
|
||||
std::vector<ColorMask> const& GetColorMasks() const { return _colorMasks; }
|
||||
|
||||
protected:
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Camera and framing state
|
||||
// ---------------------------------------------------------------------- //
|
||||
HdCamera const *_camera;
|
||||
GfVec4f _viewport;
|
||||
CameraUtilFraming _framing;
|
||||
std::pair<bool, CameraUtilConformWindowPolicy> _overrideWindowPolicy;
|
||||
// TODO: This is only used for CPU culling, should compute it on the fly.
|
||||
GfMatrix4d _cullMatrix;
|
||||
|
||||
// Used by applications setting the view matrix directly instead of
|
||||
// using an HdCamera. Will be removed eventually.
|
||||
GfMatrix4d _worldToViewMatrix;
|
||||
// Used by applications setting the projection matrix directly instead
|
||||
// of using an HdCamera. Will be removed eventually.
|
||||
GfMatrix4d _projectionMatrix;
|
||||
// Used by applications setting the clip planes directly instead
|
||||
// of using an HdCamera. Will be removed eventually.
|
||||
ClipPlanesVector _clipPlanes;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Application rendering state
|
||||
// ---------------------------------------------------------------------- //
|
||||
GfVec4f _overrideColor;
|
||||
GfVec4f _wireframeColor;
|
||||
GfVec4f _pointColor;
|
||||
float _pointSize;
|
||||
bool _lightingEnabled;
|
||||
|
||||
GfVec4f _maskColor;
|
||||
GfVec4f _indicatorColor;
|
||||
float _pointSelectedSize;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Render pipeline state
|
||||
// ---------------------------------------------------------------------- //
|
||||
float _alphaThreshold;
|
||||
float _tessLevel;
|
||||
GfVec2f _drawRange;
|
||||
|
||||
bool _depthBiasUseDefault; // inherit existing state, ignore values below.
|
||||
bool _depthBiasEnabled;
|
||||
float _depthBiasConstantFactor;
|
||||
float _depthBiasSlopeFactor;
|
||||
HdCompareFunction _depthFunc;
|
||||
bool _depthMaskEnabled;
|
||||
bool _depthTestEnabled;
|
||||
|
||||
HdCullStyle _cullStyle;
|
||||
|
||||
// Stencil RenderPassState
|
||||
HdCompareFunction _stencilFunc;
|
||||
int _stencilRef;
|
||||
int _stencilMask;
|
||||
HdStencilOp _stencilFailOp;
|
||||
HdStencilOp _stencilZFailOp;
|
||||
HdStencilOp _stencilZPassOp;
|
||||
bool _stencilEnabled;
|
||||
|
||||
// Line width
|
||||
float _lineWidth;
|
||||
|
||||
// Blending
|
||||
HdBlendOp _blendColorOp;
|
||||
HdBlendFactor _blendColorSrcFactor;
|
||||
HdBlendFactor _blendColorDstFactor;
|
||||
HdBlendOp _blendAlphaOp;
|
||||
HdBlendFactor _blendAlphaSrcFactor;
|
||||
HdBlendFactor _blendAlphaDstFactor;
|
||||
GfVec4f _blendConstantColor;
|
||||
bool _blendEnabled;
|
||||
|
||||
// alpha to coverage
|
||||
bool _alphaToCoverageEnabled;
|
||||
|
||||
bool _colorMaskUseDefault;
|
||||
std::vector<ColorMask> _colorMasks;
|
||||
|
||||
HdRenderPassAovBindingVector _aovBindings;
|
||||
bool _useMultiSampleAov;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RENDER_PASS_STATE_H
|
||||
@@ -0,0 +1,368 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_THREAD_H
|
||||
#define PXR_IMAGING_HD_RENDER_THREAD_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class HdRenderThread
|
||||
///
|
||||
/// HdRenderThread is a utility that specific render delegates can choose to
|
||||
/// use depending on their needs. It provides a system for rendering in a
|
||||
/// background thread, and synchronizing between hydra (either in the main
|
||||
/// thread, or the sync threadpool) and the rendering thread.
|
||||
///
|
||||
/// \section HdRenderThread_StateMachine State Machine
|
||||
///
|
||||
/// The render thread is implemented in terms of a state machine, and hydra
|
||||
/// requests to the render thread are implemented in terms of transitions on
|
||||
/// that state machine.
|
||||
///
|
||||
/// States:
|
||||
/// - \em StateInitial - indicates the render thread hasn't been started.
|
||||
/// - \em StateIdle - indicates the render thread is running, but not rendering.
|
||||
/// - \em StateRendering - indicates the render thread is rendering.
|
||||
/// - \em StateTerminated - indicates the render thread is shutting down.
|
||||
///
|
||||
/// Transitions:
|
||||
/// - StartThread(): StateInitial => StateIdle
|
||||
/// - StartRender(): StateIdle, StateRendering => StateRendering
|
||||
/// - StopRender(): StateIdle, StateRendering => StateIdle
|
||||
/// - StopThread(): StateIdle, StateRendering => StateTerminated
|
||||
/// - StopThread(): StateTerminated => StateInitial
|
||||
///
|
||||
/// \section HdRenderThread_Usage Example Usage
|
||||
///
|
||||
/// \code{.cpp}
|
||||
/// class ExampleRenderDelegate : HdRenderDelegate {
|
||||
/// public:
|
||||
/// ExampleRenderDelegate() {
|
||||
/// _renderThread.SetRenderCallback(
|
||||
/// std::bind(&ExampleRenderDelegate::_RenderCallback, this));
|
||||
/// _renderThread.StartThread();
|
||||
/// }
|
||||
/// ~ExampleRenderDelegate() {
|
||||
/// _renderThread.StopThread();
|
||||
/// }
|
||||
/// private:
|
||||
/// void _RenderCallback() {
|
||||
/// bool renderComplete = false;
|
||||
/// while(!renderComplete) {
|
||||
/// // Check if we have been asked to pause.
|
||||
/// while(_renderThread.IsPauseRequested()) {
|
||||
/// if(_renderThread.IsStopRequested()) {
|
||||
/// break;
|
||||
/// }
|
||||
/// std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
/// }
|
||||
/// if(_renderThread.IsStopRequested()) {
|
||||
/// break;
|
||||
/// }
|
||||
/// // generate N pixels.
|
||||
/// auto lock = _renderThread.LockFramebuffer();
|
||||
/// // resolve pixels to shared buffer.
|
||||
/// // Set renderComplete = true when finished rendering.
|
||||
/// }
|
||||
/// }
|
||||
/// HdRenderThread _renderThread;
|
||||
/// };
|
||||
///
|
||||
/// class ExampleRenderParam : HdRenderParam {
|
||||
/// public:
|
||||
/// ExampleRenderParam(HdRenderThread* renderThread, SceneData *scene);
|
||||
/// SceneData* AcquireSceneForEdit() {
|
||||
/// _renderThread->StopRender();
|
||||
/// return _scene;
|
||||
/// }
|
||||
/// };
|
||||
///
|
||||
/// class ExamplePrim : HdMesh {
|
||||
/// public:
|
||||
/// void Sync(...) {
|
||||
/// SceneData *scene = renderParam->AcquireSceneForEdit();
|
||||
/// ...
|
||||
/// }
|
||||
/// };
|
||||
///
|
||||
/// class ExampleRenderPass : HdRenderPass {
|
||||
/// public:
|
||||
/// ExampleRenderPass(HdRenderThread *renderThread);
|
||||
/// protected:
|
||||
/// void _Execute(...) {
|
||||
/// _renderThread->StartRendering();
|
||||
/// auto lock = _renderThread->LockFramebuffer();
|
||||
/// // blit pixels from shared to application buffer.
|
||||
/// }
|
||||
/// };
|
||||
/// \endcode
|
||||
///
|
||||
/// Having a locked and shared framebuffer is important if you want to avoid
|
||||
/// tearing, or if the rendering API disallows multithreaded access to buffers
|
||||
/// (for example, if your framebuffers are on a GPU). It might be unnecessary
|
||||
/// for some renderers.
|
||||
///
|
||||
/// Stopping the render only when you're about to make a scene edit means that
|
||||
/// long-running renders aren't interrupted if the scene is static. Hiding the
|
||||
/// renderer's scene data handle behind AcquireSceneForEdit helps callers
|
||||
/// use the synchronization mechanisms correctly.
|
||||
///
|
||||
/// The render is restarted at the last possible second, in the render pass,
|
||||
/// after we know scene edits are done.
|
||||
///
|
||||
/// The render callback should use IsStopRequested() as a cancellation
|
||||
/// mechanism.
|
||||
///
|
||||
class HdRenderThread {
|
||||
public:
|
||||
|
||||
HD_API
|
||||
HdRenderThread();
|
||||
|
||||
HD_API
|
||||
~HdRenderThread();
|
||||
|
||||
/// \anchor Management
|
||||
/// \name API for thread management
|
||||
///
|
||||
/// Methods to configure, start, and stop the render thread. These functions
|
||||
/// are not threadsafe.
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Set the rendering callback for the render thread to use.
|
||||
HD_API
|
||||
void SetRenderCallback(std::function<void()> renderCallback);
|
||||
|
||||
/// Set the shutdown callback for the render thread to use. This will be
|
||||
/// called once, right before the render thread exits, regardless of whether
|
||||
/// the render callback has been called. This can be used to clean up
|
||||
/// thread-specific rendering resources.
|
||||
HD_API
|
||||
void SetShutdownCallback(std::function<void()> shutdownCallback);
|
||||
|
||||
/// Start the rendering background thread.
|
||||
/// Note: it's an error to call this function when the render thread is
|
||||
/// already running, but it's acceptable to stop the render thread and then
|
||||
/// start it again.
|
||||
HD_API
|
||||
void StartThread();
|
||||
|
||||
/// Stop the rendering background thread. This function will ask the render
|
||||
/// thread to transition to StateTerminated, and then join on the thread,
|
||||
/// so it will block. After this function returns, the rendering state
|
||||
/// machine will be back in its initial state, and the render thread can be
|
||||
/// started again.
|
||||
HD_API
|
||||
void StopThread();
|
||||
|
||||
/// Check whether the background thread is running (i.e. StartThread was
|
||||
/// called successfully, but StopThread has not been).
|
||||
HD_API
|
||||
bool IsThreadRunning();
|
||||
|
||||
/// @}
|
||||
|
||||
/// \anchor HydraAPI
|
||||
/// \name API for hydra threads
|
||||
///
|
||||
/// Methods for hydra to communicate with the render thread. These methods
|
||||
/// can be called from the application thread or hydra threadpool threads.
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Ask the render thread to start rendering. This call is a no-op if the
|
||||
/// render thread is already rendering. Otherwise, it may block briefly.
|
||||
/// This is threadsafe against the render thread, but it shouldn't be
|
||||
/// called at the same time as StopRender(), and it shouldn't be called
|
||||
/// from multiple hydra threads at once.
|
||||
HD_API
|
||||
void StartRender();
|
||||
|
||||
/// Ask the render thread to stop rendering, and block until the render
|
||||
/// thread is idle. This is fully threadsafe, and can be called from
|
||||
/// multiple hydra threads at once.
|
||||
HD_API
|
||||
void StopRender();
|
||||
|
||||
/// Query whether the render thread is currently rendering. This is set by
|
||||
/// StartRender() and reset after the render callback exits, or reset by
|
||||
/// StopRender() if the render callback never runs. This does not
|
||||
/// block, and is fully threadsafe.
|
||||
HD_API
|
||||
bool IsRendering();
|
||||
|
||||
/// Ask the render thread to pause rendering. The speed at which the
|
||||
/// renderer actually enters the pause state depends on the delegate.
|
||||
HD_API
|
||||
void PauseRender();
|
||||
|
||||
/// Ask the render thread to resume rendering. Pause and Resume calls do
|
||||
/// not need to be paired. The last call (to Pause or Resume) decides the
|
||||
/// current state.
|
||||
HD_API
|
||||
void ResumeRender();
|
||||
|
||||
/// @}
|
||||
|
||||
/// \anchor RenderThreadAPI
|
||||
/// \name API for hydra threads
|
||||
///
|
||||
/// Methods for the render thread to communicate with hydra. These should
|
||||
/// only be called from the render thread, from inside the render callback.
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Query whether hydra has asked to interrupt the current frame since
|
||||
/// the last time StartRender() was called. The render callback can check
|
||||
/// this to determine whether to cancel rendering.
|
||||
HD_API
|
||||
bool IsStopRequested();
|
||||
|
||||
/// Query whether hydra has asked to pause rendering. This will continue
|
||||
/// to return true until a request has been made for rendering to resume.
|
||||
/// Remember to check for a stop request while paused.
|
||||
HD_API
|
||||
bool IsPauseRequested();
|
||||
|
||||
/// Query whether the pause/resume state has changed since the last time
|
||||
/// we called IsPauseDirty.
|
||||
HD_API
|
||||
bool IsPauseDirty();
|
||||
|
||||
/// @}
|
||||
|
||||
/// \anchor CommonAPI
|
||||
/// \name API for both hydra and render threads
|
||||
///
|
||||
/// Methods for both hydra and the render threads to synchronize access to
|
||||
/// other data.
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Return a scoped lock on the render delegate's framebuffer. Hydra and the
|
||||
/// render thread can use this to synchronize blits between render-thread
|
||||
/// owned resources, and application-owned resources.
|
||||
HD_API
|
||||
std::unique_lock<std::mutex> LockFramebuffer();
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
// _RenderLoop implements the render thread's state machine; see
|
||||
// \ref HdRenderThread_StateMachine for details. It runs in a background
|
||||
// thread and manages synchronization with hydra. To implement rendering,
|
||||
// it calls out to the render callback provided via SetRenderCallback.
|
||||
void _RenderLoop();
|
||||
|
||||
// _renderCallback is the render-delegate-provided function responsible for
|
||||
// actually rendering. It's called from _RenderLoop.
|
||||
std::function<void()> _renderCallback;
|
||||
|
||||
// _shutdownCallback is the render-delegate-provided function responsible
|
||||
// for cleaning up thread-specific resources. It's called once, right
|
||||
// before _RenderLoop exits.
|
||||
std::function<void()> _shutdownCallback;
|
||||
|
||||
// A placeholder initial value for _renderCallback.
|
||||
static void _DefaultRenderCallback();
|
||||
|
||||
// A placeholder initial value for _shutdownCallback.
|
||||
static void _DefaultShutdownCallback();
|
||||
|
||||
// The state enumeration of the render thread state machine; see
|
||||
// \ref HdRenderThread_StateMachine for details.
|
||||
enum State {
|
||||
// Initial constructed state. Render thread is not running.
|
||||
StateInitial,
|
||||
// Render thread is running and ready for scene edits. No rendering
|
||||
// is taking place.
|
||||
StateIdle,
|
||||
// Render thread is running and rendering; no scene edits are allowed.
|
||||
StateRendering,
|
||||
// Render thread is shutting down.
|
||||
StateTerminated,
|
||||
};
|
||||
|
||||
// _requestedState is set by hydra to direct the render thread's state
|
||||
// machine; see \ref HdRenderThread_StateMachine for details.
|
||||
// _requestedState is protected by a mutex/condition variable combination.
|
||||
// The render thread holds _requestedStateMutex while rendering; the
|
||||
// frequency with which it can give it up is the interruption frequency.
|
||||
//
|
||||
// StartRender() and StopRender() lock and write to _requestedState.
|
||||
// _RenderLoop() locks and reads _requestedState.
|
||||
State _requestedState;
|
||||
std::mutex _requestedStateMutex;
|
||||
std::condition_variable _requestedStateCV;
|
||||
|
||||
// _enableRender provides an out-of-band way for hydra to cancel a
|
||||
// render while the render thread is still holding _requestedStateMutex.
|
||||
//
|
||||
// StartRender() and StopRender() will write true/false to _enableRender.
|
||||
// IsStopRequested() will read from _enableRender.
|
||||
std::atomic_flag _enableRender;
|
||||
// _stopRequested keeps track of whether _enableRender has gone low since
|
||||
// the last time the render callback was called (since _enableRender is
|
||||
// reset on read).
|
||||
bool _stopRequested;
|
||||
|
||||
// _pauseRender provides a properly locked boolean flag that holds the
|
||||
// current pause state of the thread. Toggled by calling PauseRender and
|
||||
// ResumeRender, tested by IsPauseRequested.
|
||||
std::atomic<bool> _pauseRender;
|
||||
|
||||
// _pauseDirty provides a properly locked boolean flag that holds the
|
||||
// current dirtyness of the pause state of the thread. Toggled by
|
||||
// calling PauseRender and ResumeRender, tested by IsPauseDirty.
|
||||
std::atomic<bool> _pauseDirty;
|
||||
|
||||
// _rendering records whether the render thread is currently inside the
|
||||
// render callback, or planning to be inside the render callback.
|
||||
// It is managed by StartRender(), StopRender(), and _RenderLoop().
|
||||
// IsRendering() will read from _rendering.
|
||||
std::atomic<bool> _rendering;
|
||||
|
||||
// _renderThread is the background render thread; it runs _RenderLoop().
|
||||
std::thread _renderThread;
|
||||
|
||||
// _frameBufferMutex protects access to the render delegate's framebuffer,
|
||||
// and provides an optional synchronization point for blits between the
|
||||
// render thread's resources and the application's resources.
|
||||
std::mutex _frameBufferMutex;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RENDER_THREAD_H
|
||||
@@ -0,0 +1,121 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDERER_PLUGIN_H
|
||||
#define PXR_IMAGING_HD_RENDERER_PLUGIN_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hf/pluginBase.h"
|
||||
#include "pxr/imaging/hd/renderDelegate.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class SdfPath;
|
||||
class HdRenderIndex;
|
||||
class HdPluginRenderDelegateUniqueHandle;
|
||||
|
||||
///
|
||||
/// This class defines a renderer plugin interface for Hydra.
|
||||
/// A renderer plugin is a dynamically discovered and loaded at run-time using
|
||||
/// the Plug system.
|
||||
///
|
||||
/// This object has singleton behavior, in that is instantiated once per
|
||||
/// library (managed by the plugin registry).
|
||||
///
|
||||
/// The class is used to factory objects that provide delegate support
|
||||
/// to other parts of the Hydra Ecosystem.
|
||||
///
|
||||
class HdRendererPlugin : public HfPluginBase {
|
||||
public:
|
||||
|
||||
///
|
||||
/// Create a render delegate through the plugin and wrap it in a
|
||||
/// handle that keeps this plugin alive until render delegate is
|
||||
/// destroyed. Initial settings can be passed in.
|
||||
///
|
||||
HD_API
|
||||
HdPluginRenderDelegateUniqueHandle CreateDelegate(
|
||||
HdRenderSettingsMap const &settingsMap = {});
|
||||
|
||||
///
|
||||
/// Look-up plugin id in plugin registry.
|
||||
///
|
||||
HD_API
|
||||
TfToken GetPluginId() const;
|
||||
|
||||
///
|
||||
/// Clients should use CreateDelegate since this method
|
||||
/// will eventually become protected, use CreateRenderDelegateHandle
|
||||
/// instead.
|
||||
///
|
||||
/// Factory a Render Delegate object, that Hydra can use to
|
||||
/// factory prims and communicate with a renderer.
|
||||
///
|
||||
virtual HdRenderDelegate *CreateRenderDelegate() = 0;
|
||||
|
||||
///
|
||||
/// Clients should use CreateDelegate since this method
|
||||
/// will eventually become protected.
|
||||
///
|
||||
/// Factory a Render Delegate object, that Hydra can use to
|
||||
/// factory prims and communicate with a renderer. Pass in initial
|
||||
/// settings...
|
||||
///
|
||||
HD_API
|
||||
virtual HdRenderDelegate *CreateRenderDelegate(
|
||||
HdRenderSettingsMap const& settingsMap);
|
||||
|
||||
///
|
||||
/// Clients should use CreateDelegate since this method
|
||||
/// will eventually become protected.
|
||||
///
|
||||
/// Release the object factoried by CreateRenderDelegate().
|
||||
///
|
||||
virtual void DeleteRenderDelegate(HdRenderDelegate *renderDelegate) = 0;
|
||||
|
||||
///
|
||||
/// Returns \c true if this renderer plugin is supported in the running
|
||||
/// process and \c false if not.
|
||||
///
|
||||
/// This gives the plugin a chance to perform some runtime checks to make
|
||||
/// sure that the system meets minimum requirements.
|
||||
///
|
||||
virtual bool IsSupported() const = 0;
|
||||
|
||||
protected:
|
||||
HdRendererPlugin() = default;
|
||||
HD_API
|
||||
~HdRendererPlugin() override;
|
||||
|
||||
private:
|
||||
// This class doesn't require copy support.
|
||||
HdRendererPlugin(const HdRendererPlugin &) = delete;
|
||||
HdRendererPlugin &operator =(const HdRendererPlugin &) = delete;
|
||||
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RENDERER_PLUGIN_H
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDERER_PLUGIN_HANDLE_H
|
||||
#define PXR_IMAGING_HD_RENDERER_PLUGIN_HANDLE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/renderDelegate.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRendererPlugin;
|
||||
class HdPluginRenderDelegateUniqueHandle;
|
||||
|
||||
///
|
||||
/// A handle for HdRendererPlugin also storing the plugin id.
|
||||
///
|
||||
/// Alleviates the need to ever call, e.g., ReleasePlugin since it
|
||||
/// automatically decreases and increases the plugin's reference
|
||||
/// counts with the plugin registry.
|
||||
///
|
||||
class HdRendererPluginHandle final
|
||||
{
|
||||
public:
|
||||
HdRendererPluginHandle() : _plugin(nullptr) { }
|
||||
HdRendererPluginHandle(const std::nullptr_t &) : _plugin(nullptr) { }
|
||||
|
||||
HD_API
|
||||
HdRendererPluginHandle(const HdRendererPluginHandle &);
|
||||
|
||||
HD_API
|
||||
~HdRendererPluginHandle();
|
||||
|
||||
HD_API
|
||||
HdRendererPluginHandle &operator=(const HdRendererPluginHandle &);
|
||||
|
||||
HD_API
|
||||
HdRendererPluginHandle &operator=(const std::nullptr_t &);
|
||||
|
||||
/// Get the wrapped HdRendererPlugin
|
||||
HdRendererPlugin *Get() const { return _plugin; }
|
||||
|
||||
HdRendererPlugin *operator->() const { return _plugin; }
|
||||
HdRendererPlugin &operator*() const { return *_plugin; }
|
||||
|
||||
/// Is the wrapped HdRendererPlugin valid?
|
||||
explicit operator bool() const { return _plugin; }
|
||||
|
||||
private:
|
||||
friend class HdRendererPluginRegistry;
|
||||
friend class HdRendererPlugin;
|
||||
|
||||
HdRendererPluginHandle(HdRendererPlugin * const plugin)
|
||||
: _plugin(plugin) { }
|
||||
|
||||
HdRendererPlugin *_plugin;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDERER_PLUGIN_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_RENDERER_PLUGIN_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/renderDelegate.h"
|
||||
#include "pxr/base/tf/singleton.h"
|
||||
#include "pxr/imaging/hf/pluginRegistry.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdRendererPlugin;
|
||||
class HdRendererPluginHandle;
|
||||
class HdPluginRenderDelegateUniqueHandle;
|
||||
|
||||
class HdRendererPluginRegistry final : public HfPluginRegistry
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Returns the singleton registry for \c HdRendererPlugin
|
||||
///
|
||||
HD_API
|
||||
static HdRendererPluginRegistry &GetInstance();
|
||||
|
||||
///
|
||||
/// Entry point for defining an HdRendererPlugin plugin.
|
||||
///
|
||||
template<typename T, typename... Bases>
|
||||
static void Define();
|
||||
|
||||
///
|
||||
/// Returns the id of plugin to use as the default
|
||||
///
|
||||
HD_API
|
||||
TfToken GetDefaultPluginId();
|
||||
|
||||
///
|
||||
/// \deprecated Use GetOrCreateRendererPlugin instead.
|
||||
///
|
||||
/// Returns the renderer plugin for the given id or null
|
||||
/// if not found. The reference count on the returned
|
||||
/// delegate is incremented.
|
||||
///
|
||||
HD_API
|
||||
HdRendererPlugin *GetRendererPlugin(const TfToken &pluginId);
|
||||
|
||||
///
|
||||
/// Returns the renderer plugin for the given id or a null handle
|
||||
/// if not found. The plugin is wrapped in a handle that automatically
|
||||
/// increments and decrements the reference count and also stores the
|
||||
/// plugin id.
|
||||
///
|
||||
HD_API
|
||||
HdRendererPluginHandle GetOrCreateRendererPlugin(const TfToken &pluginId);
|
||||
|
||||
///
|
||||
/// Returns a render delegate created by the plugin with the given name
|
||||
/// if the plugin is supported using given initial settings.
|
||||
/// The render delegate is wrapped in a movable handle that
|
||||
/// keeps the plugin alive until the render delegate is destroyed by
|
||||
/// dropping the handle.
|
||||
///
|
||||
HD_API
|
||||
HdPluginRenderDelegateUniqueHandle CreateRenderDelegate(
|
||||
const TfToken &pluginId,
|
||||
const HdRenderSettingsMap &settingsMap = {});
|
||||
|
||||
private:
|
||||
// Friend required by TfSingleton to access constructor (as it is private).
|
||||
friend class TfSingleton<HdRendererPluginRegistry>;
|
||||
|
||||
// Singleton gets private constructed
|
||||
HdRendererPluginRegistry();
|
||||
~HdRendererPluginRegistry() override;
|
||||
|
||||
//
|
||||
/// This class is not intended to be copied.
|
||||
///
|
||||
HdRendererPluginRegistry(const HdRendererPluginRegistry &) = delete;
|
||||
HdRendererPluginRegistry &operator=(const HdRendererPluginRegistry &) = delete;
|
||||
};
|
||||
|
||||
|
||||
template<typename T, typename... Bases>
|
||||
void HdRendererPluginRegistry::Define()
|
||||
{
|
||||
HfPluginRegistry::Define<T, HdRendererPlugin, Bases...>();
|
||||
}
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RENDERER_PLUGIN_REGISTRY_H
|
||||
@@ -0,0 +1,197 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_REPR_H
|
||||
#define PXR_IMAGING_HD_REPR_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/drawItem.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class HdReprSelector
|
||||
///
|
||||
/// Describes one or more authored display representations for an rprim.
|
||||
/// Display opinions are separated by the topology index they represent.
|
||||
/// This allows the application to specify one or more topological
|
||||
/// representations for a given HdRprim.
|
||||
/// For some visualizations, an application may choose to provide an opinion for
|
||||
/// the display of the refined surface, the unrefined hull and the points
|
||||
/// separately from the rprim's authored opinions.
|
||||
/// HdReprSelector allows these opinions to compose/merge into a final composite
|
||||
/// representation to be used for rendering.
|
||||
///
|
||||
class HdReprSelector
|
||||
{
|
||||
public:
|
||||
explicit HdReprSelector()
|
||||
: refinedToken()
|
||||
, unrefinedToken()
|
||||
, pointsToken() { }
|
||||
|
||||
explicit HdReprSelector(TfToken const &token)
|
||||
: refinedToken(token)
|
||||
, unrefinedToken()
|
||||
, pointsToken() { }
|
||||
|
||||
explicit HdReprSelector(
|
||||
TfToken const &refined,
|
||||
TfToken const &unrefined)
|
||||
: refinedToken(refined)
|
||||
, unrefinedToken(unrefined)
|
||||
, pointsToken() { }
|
||||
|
||||
explicit HdReprSelector(
|
||||
TfToken const &refined,
|
||||
TfToken const &unrefined,
|
||||
TfToken const &points)
|
||||
: refinedToken(refined)
|
||||
, unrefinedToken(unrefined)
|
||||
, pointsToken(points) { }
|
||||
|
||||
/// Currenly support upto 3 topology tokens.
|
||||
static const size_t MAX_TOPOLOGY_REPRS = 3;
|
||||
|
||||
/// Returns true if the passed in reprToken is in the set of tokens
|
||||
/// for any topology index.
|
||||
HD_API
|
||||
bool Contains(const TfToken &reprToken) const;
|
||||
|
||||
/// Returns true if the topology token at an index is active, i.e., neither
|
||||
/// empty nor disabled.
|
||||
HD_API
|
||||
bool IsActiveRepr(size_t topologyIndex) const;
|
||||
|
||||
/// Returns true if any of the topology tokens is valid, i.e., neither
|
||||
/// empty nor disabled.
|
||||
HD_API
|
||||
bool AnyActiveRepr() const;
|
||||
|
||||
/// Returns a selector that is the composite of this selector 'over'
|
||||
/// the passed in selector.
|
||||
/// For each token that IsEmpty in this selector return the corresponding
|
||||
/// token in the passed in selector.
|
||||
/// Effectively this performs a merge operation where this selector wins
|
||||
/// for each topological index it has an opinion on.
|
||||
HD_API
|
||||
HdReprSelector CompositeOver(const HdReprSelector &under) const;
|
||||
|
||||
HD_API
|
||||
bool operator==(const HdReprSelector &rhs) const;
|
||||
|
||||
HD_API
|
||||
bool operator!=(const HdReprSelector &rhs) const;
|
||||
|
||||
HD_API
|
||||
bool operator<(const HdReprSelector &rhs) const;
|
||||
|
||||
HD_API
|
||||
size_t Hash() const;
|
||||
|
||||
HD_API
|
||||
char const* GetText() const;
|
||||
|
||||
HD_API
|
||||
friend std::ostream &operator <<(std::ostream &stream,
|
||||
HdReprSelector const& t);
|
||||
|
||||
|
||||
HD_API
|
||||
TfToken const &operator[](size_t topologyIndex) const;
|
||||
|
||||
private:
|
||||
// TfHash support.
|
||||
template <class HashState>
|
||||
friend void
|
||||
TfHashAppend(HashState &h, HdReprSelector const &rs) {
|
||||
h.Append(rs.refinedToken, rs.unrefinedToken, rs.pointsToken);
|
||||
}
|
||||
|
||||
TfToken refinedToken;
|
||||
TfToken unrefinedToken;
|
||||
TfToken pointsToken;
|
||||
};
|
||||
|
||||
|
||||
/// \class HdRepr
|
||||
///
|
||||
/// An HdRepr refers to a (single) topological representation of an rprim, and
|
||||
/// owns the draw item(s) that visually represent it. The draw items are
|
||||
/// populated by the rprim.
|
||||
/// The relevant compositional hierarchy is:
|
||||
///
|
||||
/// HdRprim
|
||||
/// |
|
||||
/// +--HdRepr(s)
|
||||
/// |
|
||||
/// +--HdDrawItem(s)
|
||||
///
|
||||
/// When multiple topological representations are required for an rprim, we use
|
||||
/// HdReprSelector to compose the individual representations.
|
||||
///
|
||||
class HdRepr final
|
||||
{
|
||||
public:
|
||||
using DrawItemUniquePtr = std::unique_ptr<HdDrawItem>;
|
||||
using DrawItemUniquePtrVector = std::vector<DrawItemUniquePtr>;
|
||||
|
||||
HD_API
|
||||
HdRepr();
|
||||
HD_API
|
||||
~HdRepr();
|
||||
|
||||
/// Returns the draw items for this representation.
|
||||
const DrawItemUniquePtrVector& GetDrawItems() const {
|
||||
return _drawItems;
|
||||
}
|
||||
|
||||
/// Transfers ownership of a draw item to this repr.
|
||||
void AddDrawItem(std::unique_ptr<HdDrawItem> &&item) {
|
||||
_drawItems.push_back(std::move(item));
|
||||
}
|
||||
|
||||
/// Returns the draw item at the requested index.
|
||||
///
|
||||
/// Note that the pointer returned is owned by this object and must not be
|
||||
/// deleted.
|
||||
HdDrawItem* GetDrawItem(size_t index) const {
|
||||
return _drawItems[index].get();
|
||||
}
|
||||
|
||||
private:
|
||||
// Noncopyable
|
||||
HdRepr(const HdRepr&) = delete;
|
||||
HdRepr& operator=(const HdRepr&) = delete;
|
||||
|
||||
private:
|
||||
DrawItemUniquePtrVector _drawItems;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_REPR_H
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RESOURCE_H
|
||||
#define PXR_IMAGING_HD_RESOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdResourceSharedPtr = std::shared_ptr<class HdResource>;
|
||||
|
||||
/// \class HdResource
|
||||
///
|
||||
/// Base class for all GPU resource objects.
|
||||
///
|
||||
class HdResource
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
HdResource(TfToken const & role);
|
||||
HD_API
|
||||
virtual ~HdResource();
|
||||
|
||||
/// Returns the role of the GPU data in this resource.
|
||||
TfToken const & GetRole() const {return _role;}
|
||||
|
||||
/// Returns the size of the resource allocated in the GPU
|
||||
HD_API
|
||||
size_t GetSize() const {return _size;}
|
||||
|
||||
protected:
|
||||
/// Stores the size of the resource allocated in the GPU
|
||||
HD_API
|
||||
void SetSize(size_t size);
|
||||
|
||||
private:
|
||||
|
||||
// Don't allow copies.
|
||||
HdResource(const HdResource &) = delete;
|
||||
HdResource &operator=(const HdResource &) = delete;
|
||||
|
||||
|
||||
const TfToken _role;
|
||||
size_t _size;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RESOURCE_H
|
||||
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RESOURCE_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_RESOURCE_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
|
||||
#include "pxr/imaging/hf/perfLog.h"
|
||||
|
||||
#include "pxr/base/tf/singleton.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
|
||||
|
||||
/// \class HdResourceRegistry
|
||||
///
|
||||
/// A central registry for resources.
|
||||
///
|
||||
class HdResourceRegistry {
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdResourceRegistry");
|
||||
|
||||
HD_API
|
||||
HdResourceRegistry();
|
||||
|
||||
HD_API
|
||||
virtual ~HdResourceRegistry();
|
||||
|
||||
/// Commits all in-flight source data.
|
||||
HD_API
|
||||
void Commit();
|
||||
|
||||
/// cleanup all buffers and remove if empty
|
||||
HD_API
|
||||
void GarbageCollect();
|
||||
|
||||
/// Globally unique id for texture, see HdRenderIndex::GetTextureKey() for
|
||||
/// details.
|
||||
typedef size_t TextureKey;
|
||||
|
||||
/// Invalidate any shaders registered with this registry.
|
||||
HD_API
|
||||
virtual void InvalidateShaderRegistry();
|
||||
|
||||
/// Generic method to inform RenderDelegate a resource needs to be reloaded.
|
||||
/// This method can be used by the application to inform the renderDelegate
|
||||
/// that a resource, which may not have any prim representation in Hydra,
|
||||
/// needs to be reloaded. For example a texture found in a material network.
|
||||
/// The `path` can be absolute or relative. It should usually match the
|
||||
/// path found for textures during HdMaterial::Sync.
|
||||
HD_API
|
||||
virtual void ReloadResource(
|
||||
TfToken const& resourceType,
|
||||
std::string const& path);
|
||||
|
||||
/// Returns a report of resource allocation by role in bytes and
|
||||
/// a summary total allocation of GPU memory in bytes for this registry.
|
||||
HD_API
|
||||
virtual VtDictionary GetResourceAllocation() const;
|
||||
|
||||
protected:
|
||||
/// A hook for derived registries to perform additional resource commits.
|
||||
HD_API
|
||||
virtual void _Commit();
|
||||
|
||||
/// Hooks for derived registries to perform additional GC when
|
||||
/// GarbageCollect() is invoked.
|
||||
HD_API
|
||||
virtual void _GarbageCollect();
|
||||
|
||||
private:
|
||||
// Not copyable
|
||||
HdResourceRegistry(const HdResourceRegistry&) = delete;
|
||||
HdResourceRegistry& operator=(const HdResourceRegistry&) = delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RESOURCE_REGISTRY_H
|
||||
@@ -0,0 +1,396 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RPRIM_H
|
||||
#define PXR_IMAGING_HD_RPRIM_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/changeTracker.h"
|
||||
#include "pxr/imaging/hd/drawItem.h"
|
||||
#include "pxr/imaging/hd/rprimSharedData.h"
|
||||
#include "pxr/imaging/hd/repr.h"
|
||||
#include "pxr/imaging/hd/sceneDelegate.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/gf/range3d.h"
|
||||
#include "pxr/base/arch/inttypes.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdBufferSource;
|
||||
class HdDrawItem;
|
||||
class HdMaterial;
|
||||
class HdRenderIndex;
|
||||
class HdRenderParam;
|
||||
|
||||
using HdReprSharedPtr = std::shared_ptr<HdRepr>;
|
||||
|
||||
using HdBufferSourceSharedPtr = std::shared_ptr<HdBufferSource>;
|
||||
using HdBufferSourceSharedPtrVector = std::vector<HdBufferSourceSharedPtr>;
|
||||
|
||||
using HdBufferSpecVector = std::vector<struct HdBufferSpec>;
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<HdBufferArrayRange>;
|
||||
|
||||
using HdComputationSharedPtr = std::shared_ptr<class HdComputation>;
|
||||
using HdComputationSharedPtrVector = std::vector<HdComputationSharedPtr>;
|
||||
|
||||
/// \class HdRprim
|
||||
///
|
||||
/// The render engine state for a given rprim from the scene graph. All data
|
||||
/// access (aside from local caches) is delegated to the HdSceneDelegate.
|
||||
///
|
||||
class HdRprim {
|
||||
public:
|
||||
HD_API
|
||||
HdRprim(SdfPath const& id);
|
||||
|
||||
HD_API
|
||||
virtual ~HdRprim();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Rprim Hydra Engine API : Pre-Sync & Sync-Phase
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the set of dirty bits that should be
|
||||
/// added to the change tracker for this prim, when this prim is inserted.
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const = 0;
|
||||
|
||||
/// This function gives an Rprim the chance to "early exit" from dirty
|
||||
/// bit propagation, delegate sync and rprim sync altogether. It is
|
||||
/// a temporary measure to prevent unnecessary work, like in the case of
|
||||
/// invisible prims. The dirty bits in the change tracker remain the same.
|
||||
/// See the implementation for the finer details.
|
||||
HD_API
|
||||
bool CanSkipDirtyBitPropagationAndSync(HdDirtyBits bits) const;
|
||||
|
||||
/// This function gives an Rprim the chance to set additional dirty bits
|
||||
/// based on those set in the change tracker, before passing the dirty bits
|
||||
/// to the scene delegate.
|
||||
/// It calls into _PropagateDirtyBits, which gives the Rprim an opportunity
|
||||
/// to specify the additional data needed to process the requested changes.
|
||||
///
|
||||
/// The return value is the new set of dirty bits.
|
||||
HD_API
|
||||
HdDirtyBits PropagateRprimDirtyBits(HdDirtyBits bits);
|
||||
|
||||
/// Initialize the representation of this Rprim by calling _InitRepr.
|
||||
/// This is called prior to dirty bit propagation & sync, the first time the
|
||||
/// repr is used, or when the authored representation is dirty.
|
||||
///
|
||||
/// dirtyBits is an in/out value. It is initialized to the dirty bits
|
||||
/// from the change tracker. InitRepr can then set additional dirty bits
|
||||
/// if additional data is required from the scene delegate when this
|
||||
/// repr is synced.
|
||||
HD_API
|
||||
void InitRepr(HdSceneDelegate* delegate,
|
||||
TfToken const &reprToken,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
/// Pull invalidated scene data and prepare/update the renderable
|
||||
/// representation.
|
||||
///
|
||||
/// This function is told which scene data to pull through the
|
||||
/// dirtyBits parameter. The first time it's called, dirtyBits comes
|
||||
/// from _GetInitialDirtyBits(), which provides initial dirty state,
|
||||
/// but after that it's driven by invalidation tracking in the scene
|
||||
/// delegate.
|
||||
///
|
||||
/// The contract for this function is that the prim can only pull on scene
|
||||
/// delegate buffers that are marked dirty. Scene delegates can and do
|
||||
/// implement just-in-time data schemes that mean that pulling on clean
|
||||
/// data will be at best incorrect, and at worst a crash.
|
||||
///
|
||||
/// This function is called in parallel from worker threads, so it needs
|
||||
/// to be threadsafe; calls into HdSceneDelegate are ok.
|
||||
///
|
||||
/// \param sceneDelegate The data source for this geometry item.
|
||||
/// \param renderParam A render delegate object that holds rendering
|
||||
/// parameters that scene geometry may use.
|
||||
/// \param dirtyBits A specifier for which scene data has changed.
|
||||
/// \param reprToken The representation that needs to be updated. This is
|
||||
/// useful for backends that support multiple display
|
||||
/// representations for an rprim. A given representation
|
||||
/// may choose to pull on a subset of the dirty state.
|
||||
/// \param dirtyBits On input specifies which state is dirty and can be
|
||||
/// pulled from the scene delegate.
|
||||
/// On output specifies which bits are still dirty and
|
||||
/// were not cleaned by the sync.
|
||||
virtual void Sync(HdSceneDelegate *delegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits,
|
||||
TfToken const &reprToken) = 0;
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Rprim Hydra Engine API : Execute Phase
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the draw items for the requested repr token, if any.
|
||||
/// These draw items should be constructed and cached beforehand by Sync().
|
||||
/// If no draw items exist, or reprToken cannot be found, nullptr will be
|
||||
/// returned.
|
||||
HD_API
|
||||
const HdRepr::DrawItemUniquePtrVector &
|
||||
GetDrawItems(TfToken const& reprToken) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Rprim Hydra Engine API : Cleanup
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Finalizes object resources. This function might not delete resources,
|
||||
/// but it should deal with resource ownership so that the rprim is
|
||||
/// deletable.
|
||||
HD_API
|
||||
virtual void Finalize(HdRenderParam *renderParam);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Rprim Data API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the identifier of this Rprim. This is both used in the
|
||||
/// RenderIndex and the SceneDelegate and acts as the associative key for
|
||||
/// the Rprim in both contexts.
|
||||
SdfPath const& GetId() const { return _sharedData.rprimID; }
|
||||
|
||||
/// Return the unique instance id
|
||||
int32_t GetPrimId() const { return _primId; };
|
||||
|
||||
/// Set the unique instance id
|
||||
HD_API
|
||||
void SetPrimId(int32_t primId);
|
||||
|
||||
/// Returns the identifier of the instancer (if any) for this Rprim. If this
|
||||
/// Rprim is not instanced, an empty SdfPath will be returned.
|
||||
SdfPath const& GetInstancerId() const { return _instancerId; }
|
||||
|
||||
/// Returns the path of the material to which this Rprim is bound. The
|
||||
/// material object itself can be fetched from the RenderIndex using
|
||||
/// this identifier.
|
||||
SdfPath const& GetMaterialId() const { return _materialId; }
|
||||
|
||||
/// Sets a new material binding to be used by this rprim
|
||||
HD_API
|
||||
void SetMaterialId(SdfPath const& materialId);
|
||||
|
||||
/// The MaterialTag allows rprims to be organized into different
|
||||
/// collections based on properties of the prim's material.
|
||||
/// E.g. A renderer may wish to organize opaque and translucent prims
|
||||
/// into different collections so they can be rendered seperately.
|
||||
TfToken const& GetMaterialTag() const { return _sharedData.materialTag; }
|
||||
|
||||
/// Sets the material tag used by the rprim.
|
||||
HD_API
|
||||
void SetMaterialTag(TfToken const& materialTag);
|
||||
|
||||
HdReprSelector const& GetReprSelector() const {
|
||||
return _authoredReprSelector;
|
||||
}
|
||||
|
||||
/// Returns the render tag associated to this rprim
|
||||
inline TfToken GetRenderTag(HdSceneDelegate* delegate) const;
|
||||
|
||||
/// Returns the bounds of the rprim in local, untransformed space.
|
||||
inline GfRange3d GetExtent(HdSceneDelegate* delegate) const;
|
||||
|
||||
/// Primvar Query
|
||||
inline HdPrimvarDescriptorVector
|
||||
GetPrimvarDescriptors(HdSceneDelegate* delegate,
|
||||
HdInterpolation interpolation) const;
|
||||
|
||||
/// Returns the names of built-in primvars, i.e. primvars that
|
||||
/// are part of the core geometric schema for this prim.
|
||||
HD_API
|
||||
virtual TfTokenVector const & GetBuiltinPrimvarNames() const = 0;
|
||||
|
||||
inline VtValue
|
||||
GetPrimvar(HdSceneDelegate* delegate, const TfToken &name) const;
|
||||
|
||||
inline VtValue
|
||||
GetIndexedPrimvar(HdSceneDelegate* delegate, const TfToken &name,
|
||||
VtIntArray *indices) const;
|
||||
|
||||
HD_API
|
||||
VtMatrix4dArray GetInstancerTransforms(HdSceneDelegate* delegate);
|
||||
|
||||
/// Returns true if any dirty flags are set for this rprim.
|
||||
HD_API
|
||||
bool IsDirty(HdChangeTracker &changeTracker) const;
|
||||
|
||||
/// Is the prim itself visible
|
||||
bool IsVisible() const { return _sharedData.visible; }
|
||||
|
||||
HD_API
|
||||
void UpdateReprSelector(HdSceneDelegate* delegate,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
protected:
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Rprim Hydra Engine API : Pre-Sync & Sync-Phase
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// This callback from Rprim gives the prim an opportunity to set
|
||||
/// additional dirty bits based on those already set. This is done
|
||||
/// before the dirty bits are passed to the scene delegate, so can be
|
||||
/// used to communicate that extra information is needed by the prim to
|
||||
/// process the changes.
|
||||
///
|
||||
/// The return value is the new set of dirty bits, which replaces the bits
|
||||
/// passed in.
|
||||
///
|
||||
/// See HdRprim::PropagateRprimDirtyBits()
|
||||
virtual HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const = 0;
|
||||
|
||||
/// Initialize the given representation of this Rprim.
|
||||
/// This is called prior to syncing the prim, the first time the repr
|
||||
/// is used.
|
||||
///
|
||||
/// reprToken is the name of the representation to initalize.
|
||||
///
|
||||
/// dirtyBits is an in/out value. It is initialized to the dirty bits
|
||||
/// from the change tracker. InitRepr can then set additional dirty bits
|
||||
/// if additional data is required from the scene delegate when this
|
||||
/// repr is synced. InitRepr occurs before dirty bit propagation.
|
||||
///
|
||||
/// See HdRprim::InitRepr()
|
||||
virtual void _InitRepr(TfToken const &reprToken,
|
||||
HdDirtyBits *dirtyBits) = 0;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Rprim Shared API
|
||||
// ---------------------------------------------------------------------- //
|
||||
HD_API
|
||||
HdReprSharedPtr const & _GetRepr(TfToken const &reprToken) const;
|
||||
|
||||
HD_API
|
||||
void _UpdateVisibility(HdSceneDelegate *sceneDelegate,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
HD_API
|
||||
void _UpdateInstancer(HdSceneDelegate *sceneDelegate,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
private:
|
||||
SdfPath _instancerId;
|
||||
SdfPath _materialId;
|
||||
|
||||
// Used for id renders.
|
||||
int32_t _primId;
|
||||
|
||||
protected:
|
||||
// shared data across reprs: bufferArrayRanges, bounds, visibility
|
||||
HdRprimSharedData _sharedData;
|
||||
|
||||
// authored repr selector
|
||||
HdReprSelector _authoredReprSelector;
|
||||
|
||||
// total number of reprs is relatively small (less than 5 or so
|
||||
// in most case), we use linear container for efficiency.
|
||||
typedef std::vector<std::pair<TfToken, HdReprSharedPtr> >
|
||||
_ReprVector;
|
||||
_ReprVector _reprs;
|
||||
|
||||
struct _ReprComparator {
|
||||
_ReprComparator(TfToken const &name) : _name(name) {}
|
||||
bool operator() (const std::pair<TfToken, HdReprSharedPtr> &e) const {
|
||||
return _name == e.first;
|
||||
}
|
||||
private:
|
||||
TfToken _name;
|
||||
};
|
||||
|
||||
|
||||
// Repr configuration descriptors. All concrete types (HdMesh, HdPoints ..)
|
||||
// have this static map to lookup descriptors for the given reprToken.
|
||||
//
|
||||
// N : # of descriptors for the repr.
|
||||
//
|
||||
template<typename DESC_TYPE, int N=1>
|
||||
struct _ReprDescConfigs {
|
||||
typedef std::array<DESC_TYPE, N> DescArray;
|
||||
static const int MAX_DESCS = N;
|
||||
|
||||
DescArray Find(TfToken const &reprToken) const {
|
||||
// linear search, we expect only a handful reprs configured.
|
||||
TF_FOR_ALL (it, _configs) {
|
||||
if (it->first == reprToken) return it->second;
|
||||
}
|
||||
TF_CODING_ERROR("Repr %s not found", reprToken.GetText());
|
||||
return DescArray();
|
||||
}
|
||||
void AddOrUpdate(TfToken const &reprToken, DescArray descs) {
|
||||
for (auto& config : _configs) {
|
||||
if (config.first == reprToken) {
|
||||
// Overrwrite the existing entry.
|
||||
config.second = descs;
|
||||
return;
|
||||
}
|
||||
}
|
||||
_configs.push_back(std::make_pair(reprToken, descs));
|
||||
}
|
||||
std::vector<std::pair<TfToken, DescArray> > _configs;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Delegate API Wrappers
|
||||
//
|
||||
TfToken
|
||||
HdRprim::GetRenderTag(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetRenderTag(GetId());
|
||||
}
|
||||
|
||||
GfRange3d
|
||||
HdRprim::GetExtent(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetExtent(GetId());
|
||||
}
|
||||
|
||||
inline HdPrimvarDescriptorVector
|
||||
HdRprim::GetPrimvarDescriptors(HdSceneDelegate* delegate,
|
||||
HdInterpolation interpolation) const
|
||||
{
|
||||
return delegate->GetPrimvarDescriptors(GetId(), interpolation);
|
||||
}
|
||||
|
||||
inline VtValue
|
||||
HdRprim::GetPrimvar(HdSceneDelegate* delegate, const TfToken &name) const
|
||||
{
|
||||
return delegate->Get(GetId(), name);
|
||||
}
|
||||
|
||||
inline VtValue
|
||||
HdRprim::GetIndexedPrimvar(HdSceneDelegate* delegate, const TfToken &name,
|
||||
VtIntArray *indices) const
|
||||
{
|
||||
return delegate->GetIndexedPrimvar(GetId(), name, indices);
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RPRIM_H
|
||||
@@ -0,0 +1,232 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RPRIM_COLLECTION_H
|
||||
#define PXR_IMAGING_HD_RPRIM_COLLECTION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/repr.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class HdRprimCollection
|
||||
///
|
||||
/// A named, semantic collection of objects.
|
||||
///
|
||||
/// Note that the collection object itself doesn't hold HdRprim objects, rather
|
||||
/// it acts as an addressing mechanism to identify a specific group of HdRprim
|
||||
/// objects that can be requested from the HdRenderIndex.
|
||||
///
|
||||
/// HdDirtyList provides the above algorithmic functionality, while HdRenderPass
|
||||
/// uses HdRprimCollection to concisely represent the HdRprim's it operates on.
|
||||
///
|
||||
/// \sa
|
||||
/// HdRenderPass
|
||||
/// HdDirtyList
|
||||
///
|
||||
class HdRprimCollection {
|
||||
public:
|
||||
HD_API
|
||||
HdRprimCollection();
|
||||
|
||||
/// Constructs an rprim collection with \p reprSelector. \p if forcedRepr is
|
||||
/// set to true, prims authored repr will be ignored.
|
||||
/// If \p materialTag is provided, only prims who's material have
|
||||
/// a matching tag will end up in the collection. This can be used to make
|
||||
/// seperate collections for e.g. opaque vs translucent prims.
|
||||
/// An empty materialTag opts-out of using material tags entirely and will
|
||||
/// return all prims in the collection, regardless of their material tags.
|
||||
HD_API
|
||||
HdRprimCollection(TfToken const& name,
|
||||
HdReprSelector const& reprSelector,
|
||||
bool forcedRepr=false,
|
||||
TfToken const& materialTag = TfToken());
|
||||
|
||||
/// Constructs an rprim collection, excluding all Rprims not prefixed by \p
|
||||
/// rootPath. \p if forcedRepr is set to true, prims authored repr will be
|
||||
/// ignored.
|
||||
/// If \p materialTag is provided, only prims who's material have
|
||||
/// a matching tag will end up in the collection. This can be used to make
|
||||
/// seperate collections for e.g. opaque vs translucent prims.
|
||||
/// An empty materialTag opts-out of using material tags entirely and will
|
||||
/// return all prims in the collection, regardless of their material tags.
|
||||
HD_API
|
||||
HdRprimCollection(TfToken const& name,
|
||||
HdReprSelector const& reprSelector,
|
||||
SdfPath const& rootPath,
|
||||
bool forcedRepr=false,
|
||||
TfToken const& materialTag = TfToken());
|
||||
|
||||
/// Copy constructor.
|
||||
HD_API
|
||||
HdRprimCollection(HdRprimCollection const& col);
|
||||
|
||||
// Destructor.
|
||||
HD_API
|
||||
virtual ~HdRprimCollection();
|
||||
|
||||
/// Constructs and returns a collection with the root and exclude paths
|
||||
/// swapped.
|
||||
HD_API
|
||||
HdRprimCollection CreateInverseCollection() const;
|
||||
|
||||
/// Returns the semantic name of this collection.
|
||||
///
|
||||
/// The semantic name represents the entire collection of prims, for
|
||||
/// example "visible", "selected", etc.
|
||||
TfToken const& GetName() const {
|
||||
return _name;
|
||||
}
|
||||
|
||||
/// Sets the semantic name of this collection.
|
||||
void SetName(TfToken const& name) {
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/// Returns the representation name.
|
||||
///
|
||||
/// The repr selector corresponds to specific aspects of the requested set
|
||||
/// of Rprims, for example one can request "hullAndPoints" repr which
|
||||
/// would cause both the hull and points representations of all prims named
|
||||
/// by the collection to be included.
|
||||
HdReprSelector const& GetReprSelector() const {
|
||||
return _reprSelector;
|
||||
}
|
||||
|
||||
void SetReprSelector(HdReprSelector const& reprSelector) {
|
||||
_reprSelector = reprSelector;
|
||||
}
|
||||
|
||||
bool IsForcedRepr() const {
|
||||
return _forcedRepr;
|
||||
}
|
||||
|
||||
void SetForcedRepr(bool flag) {
|
||||
_forcedRepr = flag;
|
||||
}
|
||||
|
||||
/// Returns the paths at which all Rprims must be rooted to be included in
|
||||
/// this collection. Defaults to a vector containing only
|
||||
/// SdfPath::AbsoluteRootPath().
|
||||
///
|
||||
/// Note that this vector is always sorted.
|
||||
HD_API
|
||||
SdfPathVector const& GetRootPaths() const;
|
||||
|
||||
/// Sets all root paths for this collection, replacing any existing paths
|
||||
/// that were present previously. All paths must be absolute. Duplicate
|
||||
/// paths are allowed, but may result in performance degradation.
|
||||
HD_API
|
||||
void SetRootPaths(SdfPathVector const& rootPaths);
|
||||
|
||||
/// Sets the path at which all Rprims must be rooted to be included in this
|
||||
/// collection, replacing any existing root paths that were previously
|
||||
/// specified.
|
||||
HD_API
|
||||
void SetRootPath(SdfPath const& rootPath);
|
||||
|
||||
/// Sets all exclude paths for this collection. All paths must be absolute.
|
||||
/// Duplicate paths are allowed, but may result in performance degradation.
|
||||
HD_API
|
||||
void SetExcludePaths(SdfPathVector const& excludePaths);
|
||||
|
||||
/// Returns the excluded paths
|
||||
///
|
||||
/// Note that this vector is always sorted.
|
||||
HD_API
|
||||
SdfPathVector const& GetExcludePaths() const;
|
||||
|
||||
/// A MaterialTag can be used to ensure only prims whos material have
|
||||
/// a matching tag will end up in the collection. Different rendering
|
||||
/// backends can control what material properties are useful for splitting
|
||||
/// up collections. For example, when Stream finds the 'translucent'
|
||||
/// MaterialTag in a material it will transfer this tag onto the
|
||||
/// prim's DrawItem. This ensures that opaque and translucent prims end up
|
||||
/// in different collections so they can be rendered seperately.
|
||||
/// A path-tracer backend may find the translucent MaterialTag on a material
|
||||
/// and choose NOT to transfer the tag onto the DrawItem because the
|
||||
/// backend wants to render opaque and translucent prims in the same
|
||||
/// collection.
|
||||
HD_API
|
||||
void SetMaterialTag(TfToken const& tag);
|
||||
|
||||
HD_API
|
||||
TfToken const& GetMaterialTag() const;
|
||||
|
||||
HD_API
|
||||
size_t ComputeHash() const;
|
||||
|
||||
struct Hash {
|
||||
size_t operator()(HdRprimCollection const& value) const {
|
||||
return value.ComputeHash();
|
||||
}
|
||||
};
|
||||
|
||||
// TfHash support.
|
||||
template <class HashState>
|
||||
friend void TfHashAppend(HashState &h, HdRprimCollection const &rc) {
|
||||
h.Append(rc._name,
|
||||
rc._reprSelector,
|
||||
rc._forcedRepr,
|
||||
rc._rootPaths,
|
||||
rc._excludePaths,
|
||||
rc._materialTag);
|
||||
}
|
||||
|
||||
HD_API
|
||||
bool operator==(HdRprimCollection const & lhs) const;
|
||||
HD_API
|
||||
bool operator!=(HdRprimCollection const & lhs) const;
|
||||
|
||||
private:
|
||||
HD_API
|
||||
friend std::ostream & operator <<(std::ostream &out,
|
||||
HdRprimCollection const & v);
|
||||
|
||||
TfToken _name;
|
||||
HdReprSelector _reprSelector;
|
||||
bool _forcedRepr;
|
||||
TfToken _materialTag;
|
||||
SdfPathVector _rootPaths;
|
||||
SdfPathVector _excludePaths;
|
||||
};
|
||||
|
||||
// VtValue requirements
|
||||
HD_API
|
||||
std::ostream& operator<<(std::ostream& out, HdRprimCollection const & v);
|
||||
|
||||
// Overload hash_value for HdRprimCollection. Used by things like boost::hash.
|
||||
HD_API
|
||||
size_t hash_value(HdRprimCollection const &col);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RPRIM_COLLECTION_H
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RPRIM_SHARED_DATA_H
|
||||
#define PXR_IMAGING_HD_RPRIM_SHARED_DATA_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferArrayRange.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/gf/bbox3d.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
// HdRprimSharedData is an assortment of data being shared across HdReprs,
|
||||
// owned by HdRprim. HdDrawItem holds a const pointer to HdRprimSharedData.
|
||||
//
|
||||
// HdRprim
|
||||
// |
|
||||
// +--HdRepr(s)
|
||||
// | |
|
||||
// | +--HdDrawItem(s)-----.
|
||||
// | |
|
||||
// +--HdRprimSharedData <---'
|
||||
//
|
||||
|
||||
struct HdRprimSharedData {
|
||||
HdRprimSharedData(int barContainerSize)
|
||||
: barContainer(barContainerSize)
|
||||
, bounds()
|
||||
, instancerLevels(0)
|
||||
, visible(true)
|
||||
, rprimID()
|
||||
, materialTag(HdMaterialTagTokens->defaultMaterialTag)
|
||||
{ }
|
||||
|
||||
HdRprimSharedData(int barContainerSize,
|
||||
bool visible)
|
||||
: barContainer(barContainerSize)
|
||||
, bounds()
|
||||
, instancerLevels(0)
|
||||
, visible(visible)
|
||||
, rprimID()
|
||||
, materialTag(HdMaterialTagTokens->defaultMaterialTag)
|
||||
{ }
|
||||
|
||||
// BufferArrayRange array
|
||||
HdBufferArrayRangeContainer barContainer;
|
||||
|
||||
// Used for CPU frustum culling.
|
||||
GfBBox3d bounds;
|
||||
|
||||
// The number of levels of instancing applied to this rprim.
|
||||
int instancerLevels;
|
||||
|
||||
// Used for authored/delegate visibility.
|
||||
bool visible;
|
||||
|
||||
// The owning Rprim's identifier.
|
||||
SdfPath rprimID;
|
||||
|
||||
// Used to organize drawItems into collections based on material properties.
|
||||
TfToken materialTag;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RPRIM_SHARED_DATA_H
|
||||
@@ -0,0 +1,863 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_SCENE_DELEGATE_H
|
||||
#define PXR_IMAGING_HD_SCENE_DELEGATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
|
||||
#include "pxr/imaging/hd/aov.h"
|
||||
#include "pxr/imaging/hd/basisCurvesTopology.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/meshTopology.h"
|
||||
#include "pxr/imaging/hd/renderIndex.h"
|
||||
#include "pxr/imaging/hd/repr.h"
|
||||
#include "pxr/imaging/hd/timeSampleArray.h"
|
||||
|
||||
#include "pxr/imaging/pxOsd/subdivTags.h"
|
||||
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/gf/vec2i.h"
|
||||
#include "pxr/base/tf/hash.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdExtComputationContext;
|
||||
|
||||
/// A shared pointer to a vector of id's.
|
||||
typedef std::shared_ptr<SdfPathVector> HdIdVectorSharedPtr;
|
||||
|
||||
/// Instancer context: a pair of instancer paths and instance indices.
|
||||
typedef std::vector<std::pair<SdfPath, int>> HdInstancerContext;
|
||||
|
||||
/// \class HdSyncRequestVector
|
||||
///
|
||||
/// The SceneDelegate is requested to synchronize prims as the result of
|
||||
/// executing a specific render pass, the following data structure is passed
|
||||
/// back to the delegate to drive synchronization.
|
||||
///
|
||||
struct HdSyncRequestVector {
|
||||
// The Prims to synchronize in this request.
|
||||
SdfPathVector IDs;
|
||||
|
||||
// The HdChangeTracker::DirtyBits that are set for each Prim.
|
||||
std::vector<HdDirtyBits> dirtyBits;
|
||||
};
|
||||
|
||||
/// \struct HdDisplayStyle
|
||||
///
|
||||
/// Describes how the geometry of a prim should be displayed.
|
||||
///
|
||||
struct HdDisplayStyle {
|
||||
/// The prim refine level, in the range [0, 8].
|
||||
int refineLevel;
|
||||
|
||||
/// Is the prim flat shaded.
|
||||
bool flatShadingEnabled;
|
||||
|
||||
/// Is the prim displacement shaded.
|
||||
bool displacementEnabled;
|
||||
|
||||
/// Does the prim act "transparent" to allow occluded selection to show
|
||||
/// through?
|
||||
bool occludedSelectionShowsThrough;
|
||||
|
||||
/// Creates a default DisplayStyle.
|
||||
/// - refineLevel is 0.
|
||||
/// - flatShading is disabled.
|
||||
/// - displacement is enabled.
|
||||
HdDisplayStyle()
|
||||
: refineLevel(0)
|
||||
, flatShadingEnabled(false)
|
||||
, displacementEnabled(true)
|
||||
, occludedSelectionShowsThrough(false)
|
||||
{ }
|
||||
|
||||
/// Creates a DisplayStyle.
|
||||
/// \param refineLevel_ the refine level to display.
|
||||
/// Valid range is [0, 8].
|
||||
/// \param flatShading enables flat shading, defaults to false.
|
||||
/// \param displacement enables displacement shading, defaults to false.
|
||||
/// \param occludedSelectionShowsThrough controls whether the prim lets
|
||||
/// occluded selection show through it, defaults to false.
|
||||
HdDisplayStyle(int refineLevel_,
|
||||
bool flatShading = false,
|
||||
bool displacement = true,
|
||||
bool occludedSelectionShowsThrough_ = false)
|
||||
: refineLevel(std::max(0, refineLevel_))
|
||||
, flatShadingEnabled(flatShading)
|
||||
, displacementEnabled(displacement)
|
||||
, occludedSelectionShowsThrough(occludedSelectionShowsThrough_)
|
||||
{
|
||||
if (refineLevel_ < 0) {
|
||||
TF_CODING_ERROR("negative refine level is not supported");
|
||||
} else if (refineLevel_ > 8) {
|
||||
TF_CODING_ERROR("refine level > 8 is not supported");
|
||||
}
|
||||
}
|
||||
|
||||
HdDisplayStyle(HdDisplayStyle const& rhs) = default;
|
||||
~HdDisplayStyle() = default;
|
||||
|
||||
bool operator==(HdDisplayStyle const& rhs) const {
|
||||
return refineLevel == rhs.refineLevel
|
||||
&& flatShadingEnabled == rhs.flatShadingEnabled
|
||||
&& displacementEnabled == rhs.displacementEnabled
|
||||
&& occludedSelectionShowsThrough ==
|
||||
rhs.occludedSelectionShowsThrough;
|
||||
}
|
||||
bool operator!=(HdDisplayStyle const& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
/// \struct HdPrimvarDescriptor
|
||||
///
|
||||
/// Describes a primvar.
|
||||
struct HdPrimvarDescriptor {
|
||||
/// Name of the primvar.
|
||||
TfToken name;
|
||||
/// Interpolation (data-sampling rate) of the primvar.
|
||||
HdInterpolation interpolation;
|
||||
/// Optional "role" indicating a desired interpretation --
|
||||
/// for example, to distinguish color/vector/point/normal.
|
||||
/// See HdPrimvarRoleTokens; default is HdPrimvarRoleTokens->none.
|
||||
TfToken role;
|
||||
/// Optional bool, true if primvar is indexed. This value should be checked
|
||||
/// before calling "GetIndexedPrimvar"
|
||||
bool indexed;
|
||||
|
||||
HdPrimvarDescriptor() {}
|
||||
HdPrimvarDescriptor(TfToken const& name_,
|
||||
HdInterpolation interp_,
|
||||
TfToken const& role_=HdPrimvarRoleTokens->none,
|
||||
bool indexed_=false)
|
||||
: name(name_), interpolation(interp_), role(role_), indexed(indexed_)
|
||||
{ }
|
||||
bool operator==(HdPrimvarDescriptor const& rhs) const {
|
||||
return name == rhs.name && role == rhs.role
|
||||
&& interpolation == rhs.interpolation;
|
||||
}
|
||||
bool operator!=(HdPrimvarDescriptor const& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::vector<HdPrimvarDescriptor> HdPrimvarDescriptorVector;
|
||||
|
||||
/// \struct HdExtComputationPrimvarDescriptor
|
||||
///
|
||||
/// Extends HdPrimvarDescriptor to describe a primvar that takes
|
||||
/// data from the output of an ExtComputation.
|
||||
///
|
||||
/// The structure contains the id of the source ExtComputation in the
|
||||
/// render index, the name of an output from that computation from which
|
||||
/// the primvar will take data along with a valueType which describes
|
||||
/// the type of the expected data.
|
||||
struct HdExtComputationPrimvarDescriptor : public HdPrimvarDescriptor {
|
||||
SdfPath sourceComputationId;
|
||||
TfToken sourceComputationOutputName;
|
||||
HdTupleType valueType;
|
||||
|
||||
HdExtComputationPrimvarDescriptor() {}
|
||||
HdExtComputationPrimvarDescriptor(
|
||||
TfToken const& name_,
|
||||
HdInterpolation interp_,
|
||||
TfToken const & role_,
|
||||
SdfPath const & sourceComputationId_,
|
||||
TfToken const & sourceComputationOutputName_,
|
||||
HdTupleType const & valueType_)
|
||||
: HdPrimvarDescriptor(name_, interp_, role_, false)
|
||||
, sourceComputationId(sourceComputationId_)
|
||||
, sourceComputationOutputName(sourceComputationOutputName_)
|
||||
, valueType(valueType_)
|
||||
{ }
|
||||
bool operator==(HdExtComputationPrimvarDescriptor const& rhs) const {
|
||||
return HdPrimvarDescriptor::operator==(rhs) &&
|
||||
sourceComputationId == rhs.sourceComputationId &&
|
||||
sourceComputationOutputName == rhs.sourceComputationOutputName &&
|
||||
valueType == rhs.valueType;
|
||||
}
|
||||
bool operator!=(HdExtComputationPrimvarDescriptor const& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::vector<HdExtComputationPrimvarDescriptor>
|
||||
HdExtComputationPrimvarDescriptorVector;
|
||||
|
||||
/// \struct HdExtComputationInputDescriptor
|
||||
///
|
||||
/// Describes an input to an ExtComputation that takes data from
|
||||
/// the output of another ExtComputation.
|
||||
///
|
||||
/// The structure contains the name of the input and the id of the
|
||||
/// source ExtComputation in the render index, and which output of
|
||||
/// that computation to bind the input to.
|
||||
struct HdExtComputationInputDescriptor {
|
||||
TfToken name;
|
||||
SdfPath sourceComputationId;
|
||||
TfToken sourceComputationOutputName;
|
||||
|
||||
HdExtComputationInputDescriptor() {}
|
||||
HdExtComputationInputDescriptor(
|
||||
TfToken const & name_,
|
||||
SdfPath const & sourceComputationId_,
|
||||
TfToken const & sourceComputationOutputName_)
|
||||
: name(name_), sourceComputationId(sourceComputationId_)
|
||||
, sourceComputationOutputName(sourceComputationOutputName_)
|
||||
{ }
|
||||
|
||||
bool operator==(HdExtComputationInputDescriptor const& rhs) const {
|
||||
return name == rhs.name &&
|
||||
sourceComputationId == rhs.sourceComputationId &&
|
||||
sourceComputationOutputName == rhs.sourceComputationOutputName;
|
||||
}
|
||||
bool operator!=(HdExtComputationInputDescriptor const& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::vector<HdExtComputationInputDescriptor>
|
||||
HdExtComputationInputDescriptorVector;
|
||||
|
||||
/// \struct HdExtComputationOutputDescriptor
|
||||
///
|
||||
/// Describes an output of an ExtComputation.
|
||||
///
|
||||
/// The structure contains the name of the output along with a valueType
|
||||
/// which describes the type of the computation output data.
|
||||
struct HdExtComputationOutputDescriptor {
|
||||
TfToken name;
|
||||
HdTupleType valueType;
|
||||
|
||||
HdExtComputationOutputDescriptor() {}
|
||||
HdExtComputationOutputDescriptor(
|
||||
TfToken const & name_,
|
||||
HdTupleType const & valueType_)
|
||||
: name(name_), valueType(valueType_)
|
||||
{ }
|
||||
|
||||
bool operator==(HdExtComputationOutputDescriptor const& rhs) const {
|
||||
return name == rhs.name &&
|
||||
valueType == rhs.valueType;
|
||||
}
|
||||
bool operator!=(HdExtComputationOutputDescriptor const& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::vector<HdExtComputationOutputDescriptor>
|
||||
HdExtComputationOutputDescriptorVector;
|
||||
|
||||
/// \struct HdVolumeFieldDescriptor
|
||||
///
|
||||
/// Description of a single field related to a volume primitive.
|
||||
///
|
||||
struct HdVolumeFieldDescriptor {
|
||||
TfToken fieldName;
|
||||
TfToken fieldPrimType;
|
||||
SdfPath fieldId;
|
||||
|
||||
HdVolumeFieldDescriptor() {}
|
||||
HdVolumeFieldDescriptor(
|
||||
TfToken const & fieldName_,
|
||||
TfToken const & fieldPrimType_,
|
||||
SdfPath const & fieldId_)
|
||||
: fieldName(fieldName_), fieldPrimType(fieldPrimType_), fieldId(fieldId_)
|
||||
{ }
|
||||
};
|
||||
|
||||
typedef std::vector<HdVolumeFieldDescriptor>
|
||||
HdVolumeFieldDescriptorVector;
|
||||
|
||||
/// \class HdSceneDelegate
|
||||
///
|
||||
/// Adapter class providing data exchange with the client scene graph.
|
||||
///
|
||||
class HdSceneDelegate {
|
||||
public:
|
||||
/// Constructor used for nested delegate objects which share a RenderIndex.
|
||||
HD_API
|
||||
HdSceneDelegate(HdRenderIndex *parentIndex,
|
||||
SdfPath const& delegateID);
|
||||
|
||||
HD_API
|
||||
virtual ~HdSceneDelegate();
|
||||
|
||||
/// Returns the RenderIndex owned by this delegate.
|
||||
HdRenderIndex& GetRenderIndex() { return *_index; }
|
||||
|
||||
/// Returns the ID of this delegate, which is used as a prefix for all
|
||||
/// objects it creates in the RenderIndex.
|
||||
///
|
||||
/// The default value is SdfPath::AbsoluteRootPath().
|
||||
SdfPath const& GetDelegateID() const { return _delegateID; }
|
||||
|
||||
/// Synchronizes the delegate state for the given request vector.
|
||||
HD_API
|
||||
virtual void Sync(HdSyncRequestVector* request);
|
||||
|
||||
/// Opportunity for the delegate to clean itself up after
|
||||
/// performing parrellel work during sync phase
|
||||
HD_API
|
||||
virtual void PostSyncCleanup();
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Options
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
/// Returns true if the named option is enabled by the delegate.
|
||||
HD_API
|
||||
virtual bool IsEnabled(TfToken const& option) const;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Rprim Aspects
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
/// Gets the topological mesh data for a given prim.
|
||||
HD_API
|
||||
virtual HdMeshTopology GetMeshTopology(SdfPath const& id);
|
||||
|
||||
/// Gets the topological curve data for a given prim.
|
||||
HD_API
|
||||
virtual HdBasisCurvesTopology GetBasisCurvesTopology(SdfPath const& id);
|
||||
|
||||
/// Gets the subdivision surface tags (sharpness, holes, etc).
|
||||
HD_API
|
||||
virtual PxOsdSubdivTags GetSubdivTags(SdfPath const& id);
|
||||
|
||||
|
||||
/// Gets the axis aligned bounds of a prim.
|
||||
/// The returned bounds are in the local space of the prim
|
||||
/// (transform is yet to be applied) and should contain the
|
||||
/// bounds of any child prims.
|
||||
///
|
||||
/// The returned bounds does not include any displacement that
|
||||
/// might occur as the result of running shaders on the prim.
|
||||
HD_API
|
||||
virtual GfRange3d GetExtent(SdfPath const & id);
|
||||
|
||||
/// Returns the object space transform, including all parent transforms.
|
||||
HD_API
|
||||
virtual GfMatrix4d GetTransform(SdfPath const & id);
|
||||
|
||||
/// Returns the authored visible state of the prim.
|
||||
HD_API
|
||||
virtual bool GetVisible(SdfPath const & id);
|
||||
|
||||
/// Returns the doubleSided state for the given prim.
|
||||
HD_API
|
||||
virtual bool GetDoubleSided(SdfPath const & id);
|
||||
|
||||
/// Returns the cullstyle for the given prim.
|
||||
HD_API
|
||||
virtual HdCullStyle GetCullStyle(SdfPath const &id);
|
||||
|
||||
/// Returns the shading style for the given prim.
|
||||
HD_API
|
||||
virtual VtValue GetShadingStyle(SdfPath const &id);
|
||||
|
||||
/// Returns the refinement level for the given prim in the range [0,8].
|
||||
///
|
||||
/// The refinement level indicates how many iterations to apply when
|
||||
/// subdividing subdivision surfaces or other refinable primitives.
|
||||
HD_API
|
||||
virtual HdDisplayStyle GetDisplayStyle(SdfPath const& id);
|
||||
|
||||
/// Returns a named value.
|
||||
HD_API
|
||||
virtual VtValue Get(SdfPath const& id, TfToken const& key);
|
||||
|
||||
/// Returns a named primvar value. If \a *outIndices is not nullptr and the
|
||||
/// primvar has indices, it will return the unflattened primvar and set
|
||||
/// \a *outIndices to the primvar's associated indices, clearing the array
|
||||
/// if the primvar is not indexed.
|
||||
HD_API
|
||||
virtual VtValue GetIndexedPrimvar(SdfPath const& id,
|
||||
TfToken const& key,
|
||||
VtIntArray *outIndices);
|
||||
|
||||
/// Returns the authored repr (if any) for the given prim.
|
||||
HD_API
|
||||
virtual HdReprSelector GetReprSelector(SdfPath const &id);
|
||||
|
||||
/// Returns the render tag that will be used to bucket prims during
|
||||
/// render pass bucketing.
|
||||
HD_API
|
||||
virtual TfToken GetRenderTag(SdfPath const& id);
|
||||
|
||||
/// Returns the prim categories.
|
||||
HD_API
|
||||
virtual VtArray<TfToken> GetCategories(SdfPath const& id);
|
||||
|
||||
/// Returns the categories for all instances in the instancer.
|
||||
HD_API
|
||||
virtual std::vector<VtArray<TfToken>>
|
||||
GetInstanceCategories(SdfPath const &instancerId);
|
||||
|
||||
/// Returns the coordinate system bindings, or a nullptr if none are bound.
|
||||
HD_API
|
||||
virtual HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const& id);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Motion samples
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
/// Store up to \a maxSampleCount transform samples in \a *sampleValues.
|
||||
/// Returns the union of the authored samples and the boundaries
|
||||
/// of the current camera shutter interval. If this number is greater
|
||||
/// than maxSampleCount, you might want to call this function again
|
||||
/// to get all the authored data.
|
||||
/// Sample times are relative to the scene delegate's current time.
|
||||
/// \see GetTransform()
|
||||
HD_API
|
||||
virtual size_t
|
||||
SampleTransform(SdfPath const & id,
|
||||
size_t maxSampleCount,
|
||||
float *sampleTimes,
|
||||
GfMatrix4d *sampleValues);
|
||||
|
||||
/// Convenience form of SampleTransform() that takes an HdTimeSampleArray.
|
||||
/// This function returns the union of the authored transform samples
|
||||
/// and the boundaries of the current camera shutter interval.
|
||||
template <unsigned int CAPACITY>
|
||||
void
|
||||
SampleTransform(SdfPath const & id,
|
||||
HdTimeSampleArray<GfMatrix4d, CAPACITY> *sa) {
|
||||
size_t authoredSamples =
|
||||
SampleTransform(id, CAPACITY, sa->times.data(), sa->values.data());
|
||||
if (authoredSamples > CAPACITY) {
|
||||
sa->Resize(authoredSamples);
|
||||
size_t authoredSamplesSecondAttempt =
|
||||
SampleTransform(
|
||||
id,
|
||||
authoredSamples,
|
||||
sa->times.data(),
|
||||
sa->values.data());
|
||||
// Number of samples should be consisntent through multiple
|
||||
// invokations of the sampling function.
|
||||
TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
|
||||
}
|
||||
sa->count = authoredSamples;
|
||||
}
|
||||
|
||||
/// Store up to \a maxSampleCount transform samples in \a *sampleValues.
|
||||
/// Returns the union of the authored samples and the boundaries
|
||||
/// of the current camera shutter interval. If this number is greater
|
||||
/// than maxSampleCount, you might want to call this function again
|
||||
/// to get all the authored data.
|
||||
/// Sample times are relative to the scene delegate's current time.
|
||||
/// \see GetInstancerTransform()
|
||||
HD_API
|
||||
virtual size_t
|
||||
SampleInstancerTransform(SdfPath const &instancerId,
|
||||
size_t maxSampleCount,
|
||||
float *sampleTimes,
|
||||
GfMatrix4d *sampleValues);
|
||||
|
||||
/// Convenience form of SampleInstancerTransform()
|
||||
/// that takes an HdTimeSampleArray.
|
||||
/// This function returns the union of the authored samples
|
||||
/// and the boundaries of the current camera shutter interval.
|
||||
template <unsigned int CAPACITY>
|
||||
void
|
||||
SampleInstancerTransform(SdfPath const &instancerId,
|
||||
HdTimeSampleArray<GfMatrix4d, CAPACITY> *sa) {
|
||||
size_t authoredSamples =
|
||||
SampleInstancerTransform(
|
||||
instancerId,
|
||||
CAPACITY,
|
||||
sa->times.data(),
|
||||
sa->values.data());
|
||||
if (authoredSamples > CAPACITY) {
|
||||
sa->Resize(authoredSamples);
|
||||
size_t authoredSamplesSecondAttempt =
|
||||
SampleInstancerTransform(
|
||||
instancerId,
|
||||
authoredSamples,
|
||||
sa->times.data(),
|
||||
sa->values.data());
|
||||
// Number of samples should be consisntent through multiple
|
||||
// invokations of the sampling function.
|
||||
TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
|
||||
}
|
||||
sa->count = authoredSamples;
|
||||
}
|
||||
|
||||
/// Store up to \a maxSampleCount primvar samples in \a *samplesValues.
|
||||
/// Returns the union of the authored samples and the boundaries
|
||||
/// of the current camera shutter interval. If this number is greater
|
||||
/// than maxSampleCount, you might want to call this function again
|
||||
/// to get all the authored data.
|
||||
///
|
||||
/// Sample values that are array-valued will have a size described
|
||||
/// by the HdPrimvarDescriptor as applied to the toplogy.
|
||||
///
|
||||
/// For example, this means that a mesh that is fracturing over time
|
||||
/// will return samples with the same number of points; the number
|
||||
/// of points will change as the scene delegate is resynchronized
|
||||
/// to represent the scene at a time with different topology.
|
||||
///
|
||||
/// Sample times are relative to the scene delegate's current time.
|
||||
///
|
||||
/// \see Get()
|
||||
HD_API
|
||||
virtual size_t
|
||||
SamplePrimvar(SdfPath const& id,
|
||||
TfToken const& key,
|
||||
size_t maxSampleCount,
|
||||
float *sampleTimes,
|
||||
VtValue *sampleValues);
|
||||
|
||||
/// Convenience form of SamplePrimvar() that takes an HdTimeSampleArray.
|
||||
/// This function returns the union of the authored samples
|
||||
/// and the boundaries of the current camera shutter interval.
|
||||
template <unsigned int CAPACITY>
|
||||
void
|
||||
SamplePrimvar(SdfPath const &id,
|
||||
TfToken const& key,
|
||||
HdTimeSampleArray<VtValue, CAPACITY> *sa);
|
||||
|
||||
/// SamplePrimvar() for getting an unflattened primvar and its indices. If
|
||||
/// \a *sampleIndices is not nullptr and the primvar has indices, it will
|
||||
/// return unflattened primvar samples in \a *sampleValues and the primvar's
|
||||
/// sampled indices in \a *sampleIndices, clearing the \a *sampleIndices
|
||||
/// array if the primvar is not indexed.
|
||||
HD_API
|
||||
virtual size_t
|
||||
SampleIndexedPrimvar(SdfPath const& id,
|
||||
TfToken const& key,
|
||||
size_t maxSampleCount,
|
||||
float *sampleTimes,
|
||||
VtValue *sampleValues,
|
||||
VtIntArray *sampleIndices);
|
||||
|
||||
/// Convenience form of SampleIndexedPrimvar() that takes
|
||||
/// HdTimeSampleArrays. This function returns the union of the authored
|
||||
/// samples and the boundaries of the current camera shutter interval.
|
||||
template <unsigned int CAPACITY>
|
||||
void
|
||||
SampleIndexedPrimvar(SdfPath const &id,
|
||||
TfToken const& key,
|
||||
HdIndexedTimeSampleArray<VtValue, CAPACITY> *sa);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Instancer prototypes
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
/// Gets the extracted indices array of the prototype id used in the
|
||||
/// instancer.
|
||||
///
|
||||
/// example
|
||||
/// instances: 0, 1, 2, 3, 4, 5
|
||||
/// protoypes: A, B, A, A, B, C
|
||||
///
|
||||
/// GetInstanceIndices(A) : [0, 2, 3]
|
||||
/// GetInstanceIndices(B) : [1, 4]
|
||||
/// GetInstanceIndices(C) : [5]
|
||||
/// GetInstanceIndices(D) : []
|
||||
///
|
||||
HD_API
|
||||
virtual VtIntArray GetInstanceIndices(SdfPath const &instancerId,
|
||||
SdfPath const &prototypeId);
|
||||
|
||||
/// Returns the instancer transform.
|
||||
HD_API
|
||||
virtual GfMatrix4d GetInstancerTransform(SdfPath const &instancerId);
|
||||
|
||||
/// Returns the parent instancer of the given rprim or instancer.
|
||||
HD_API
|
||||
virtual SdfPath GetInstancerId(SdfPath const& primId);
|
||||
|
||||
/// Returns a list of prototypes of this instancer. The intent is to let
|
||||
/// renderers cache instance indices by giving them a complete set of prims
|
||||
/// to call GetInstanceIndices(instancer, prototype) on.
|
||||
/// XXX: This is currently unused, but may be used in the future.
|
||||
HD_API
|
||||
virtual SdfPathVector GetInstancerPrototypes(SdfPath const& instancerId);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Path Translation
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
/// Returns the scene address of the prim corresponding to the given
|
||||
/// rprim/instance index. This is designed to give paths in scene namespace,
|
||||
/// rather than hydra namespace, so it always strips the delegate ID.
|
||||
HD_API
|
||||
virtual SdfPath GetScenePrimPath(SdfPath const& rprimId,
|
||||
int instanceIndex,
|
||||
HdInstancerContext *instancerContext = nullptr);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Material Aspects
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
/// Returns the material ID bound to the rprim \p rprimId.
|
||||
HD_API
|
||||
virtual SdfPath GetMaterialId(SdfPath const &rprimId);
|
||||
|
||||
// Returns a material resource which contains the information
|
||||
// needed to create a material.
|
||||
HD_API
|
||||
virtual VtValue GetMaterialResource(SdfPath const &materialId);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Renderbuffer Aspects
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
/// Returns the allocation descriptor for a given render buffer prim.
|
||||
HD_API
|
||||
virtual HdRenderBufferDescriptor GetRenderBufferDescriptor(SdfPath const& id);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Light Aspects
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
// Returns a single value for a given light and parameter.
|
||||
HD_API
|
||||
virtual VtValue GetLightParamValue(SdfPath const &id,
|
||||
TfToken const ¶mName);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Camera Aspects
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
/// Returns a single value for a given camera and parameter.
|
||||
/// See HdCameraTokens for the list of paramters.
|
||||
HD_API
|
||||
virtual VtValue GetCameraParamValue(SdfPath const& cameraId,
|
||||
TfToken const& paramName);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Volume Aspects
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
HD_API
|
||||
virtual HdVolumeFieldDescriptorVector
|
||||
GetVolumeFieldDescriptors(SdfPath const &volumeId);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name ExtComputation Aspects
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
///
|
||||
/// For the given computation id, returns a list of inputs which
|
||||
/// will be requested from the scene delegate using the Get() method.
|
||||
///
|
||||
/// See GetExtComputationInputDescriptors and
|
||||
/// GetExtComputationOutpuDescriptors for descriptions of other
|
||||
/// computation inputs and outputs.
|
||||
HD_API
|
||||
virtual TfTokenVector
|
||||
GetExtComputationSceneInputNames(SdfPath const& computationId);
|
||||
|
||||
///
|
||||
/// For the given computation id, returns a list of computation
|
||||
/// input descriptors.
|
||||
///
|
||||
/// See HdExtComputationInputDecriptor
|
||||
HD_API
|
||||
virtual HdExtComputationInputDescriptorVector
|
||||
GetExtComputationInputDescriptors(SdfPath const& computationId);
|
||||
|
||||
/// For the given computation id, returns a list of computation
|
||||
/// output descriptors.
|
||||
///
|
||||
/// See HdExtComputationOutputDescriptor
|
||||
HD_API
|
||||
virtual HdExtComputationOutputDescriptorVector
|
||||
GetExtComputationOutputDescriptors(SdfPath const& computationId);
|
||||
|
||||
|
||||
/// Returns a list of primvar names that should be bound to
|
||||
/// a generated output from an ExtComputation for the given prim id and
|
||||
/// interpolation mode. Binding information is obtained through
|
||||
/// GetExtComputationPrimvarDesc()
|
||||
/// Returns a structure describing source information for a primvar
|
||||
/// that is bound to an ExtComputation. See HdExtComputationPrimvarDesc
|
||||
/// for the expected information to be returned.
|
||||
HD_API
|
||||
virtual HdExtComputationPrimvarDescriptorVector
|
||||
GetExtComputationPrimvarDescriptors(SdfPath const& id,
|
||||
HdInterpolation interpolationMode);
|
||||
|
||||
/// Returns a single value for a given computation id and input token.
|
||||
/// The token may be a computation input or a computation config parameter.
|
||||
HD_API
|
||||
virtual VtValue GetExtComputationInput(SdfPath const& computationId,
|
||||
TfToken const& input);
|
||||
|
||||
/// Return up to \a maxSampleCount samples for a given computation id and
|
||||
/// input token.
|
||||
/// The token may be a computation input or a computation config parameter.
|
||||
/// Returns the union of the authored samples and the boundaries
|
||||
/// of the current camera shutter interval. If this number is greater
|
||||
/// than maxSampleCount, you might want to call this function again
|
||||
/// to get all the authored data.
|
||||
HD_API
|
||||
virtual size_t SampleExtComputationInput(SdfPath const& computationId,
|
||||
TfToken const& input,
|
||||
size_t maxSampleCount,
|
||||
float *sampleTimes,
|
||||
VtValue *sampleValues);
|
||||
|
||||
/// Convenience form of SampleExtComputationInput() that takes an
|
||||
/// HdTimeSampleArray.
|
||||
/// Returns the union of the authored samples and the boundaries
|
||||
/// of the current camera shutter interval.
|
||||
template <unsigned int CAPACITY>
|
||||
void SampleExtComputationInput(SdfPath const& computationId,
|
||||
TfToken const& input,
|
||||
HdTimeSampleArray<VtValue, CAPACITY> *sa) {
|
||||
size_t authoredSamples = SampleExtComputationInput(
|
||||
computationId, input, CAPACITY,
|
||||
sa->times.data(), sa->values.data());
|
||||
|
||||
if (authoredSamples > CAPACITY) {
|
||||
sa->Resize(authoredSamples);
|
||||
size_t authoredSamplesSecondAttempt = SampleExtComputationInput(
|
||||
computationId, input, authoredSamples,
|
||||
sa->times.data(), sa->values.data());
|
||||
// Number of samples should be consisntent through multiple
|
||||
// invokations of the sampling function.
|
||||
TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
|
||||
}
|
||||
sa->count = authoredSamples;
|
||||
}
|
||||
|
||||
/// Returns the kernel source assigned to the computation at the path id.
|
||||
/// If the string is empty the computation has no GPU kernel and the
|
||||
/// CPU callback should be used.
|
||||
HD_API
|
||||
virtual std::string GetExtComputationKernel(SdfPath const& computationId);
|
||||
|
||||
/// Requests the scene delegate run the ExtComputation with the given id.
|
||||
/// The context contains the input values that delegate requested through
|
||||
/// GetExtComputationInputNames().
|
||||
///
|
||||
/// The scene delegate is expected to set each output identified by
|
||||
/// GetExtComputationOutputNames() on the context.
|
||||
///
|
||||
/// Hydra may invoke the computation on a different thread from
|
||||
/// what HdEngine::Execute() was called on. It may also invoke
|
||||
/// many computations in parallel.
|
||||
HD_API
|
||||
virtual void InvokeExtComputation(SdfPath const& computationId,
|
||||
HdExtComputationContext *context);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Primitive Variables
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
/// Returns descriptors for all primvars of the given interpolation type.
|
||||
HD_API
|
||||
virtual HdPrimvarDescriptorVector
|
||||
GetPrimvarDescriptors(SdfPath const& id, HdInterpolation interpolation);
|
||||
|
||||
// -----------------------------------------------------------------------//
|
||||
/// \name Task Aspects
|
||||
// -----------------------------------------------------------------------//
|
||||
HD_API
|
||||
virtual TfTokenVector GetTaskRenderTags(SdfPath const& taskId);
|
||||
|
||||
private:
|
||||
HdRenderIndex *_index;
|
||||
SdfPath _delegateID;
|
||||
|
||||
HdSceneDelegate() = delete;
|
||||
HdSceneDelegate(HdSceneDelegate &) = delete;
|
||||
HdSceneDelegate &operator=(HdSceneDelegate &) = delete;
|
||||
};
|
||||
|
||||
template <unsigned int CAPACITY>
|
||||
void
|
||||
HdSceneDelegate::SamplePrimvar(SdfPath const &id,
|
||||
TfToken const& key,
|
||||
HdTimeSampleArray<VtValue, CAPACITY> *sa) {
|
||||
size_t authoredSamples =
|
||||
SamplePrimvar(
|
||||
id,
|
||||
key,
|
||||
CAPACITY,
|
||||
sa->times.data(),
|
||||
sa->values.data());
|
||||
if (authoredSamples > CAPACITY) {
|
||||
sa->Resize(authoredSamples);
|
||||
size_t authoredSamplesSecondAttempt =
|
||||
SamplePrimvar(
|
||||
id,
|
||||
key,
|
||||
authoredSamples,
|
||||
sa->times.data(),
|
||||
sa->values.data());
|
||||
// Number of samples should be consistent through multiple
|
||||
// invocations of the sampling function.
|
||||
TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
|
||||
}
|
||||
sa->count = authoredSamples;
|
||||
}
|
||||
|
||||
template <unsigned int CAPACITY>
|
||||
void
|
||||
HdSceneDelegate::SampleIndexedPrimvar(SdfPath const &id,
|
||||
TfToken const& key,
|
||||
HdIndexedTimeSampleArray<VtValue, CAPACITY> *sa) {
|
||||
size_t authoredSamples =
|
||||
SampleIndexedPrimvar(
|
||||
id,
|
||||
key,
|
||||
CAPACITY,
|
||||
sa->times.data(),
|
||||
sa->values.data(),
|
||||
sa->indices.data());
|
||||
if (authoredSamples > CAPACITY) {
|
||||
sa->Resize(authoredSamples);
|
||||
size_t authoredSamplesSecondAttempt =
|
||||
SampleIndexedPrimvar(
|
||||
id,
|
||||
key,
|
||||
authoredSamples,
|
||||
sa->times.data(),
|
||||
sa->values.data(),
|
||||
sa->indices.data());
|
||||
// Number of samples should be consistent through multiple
|
||||
// invocations of the sampling function.
|
||||
TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
|
||||
}
|
||||
sa->count = authoredSamples;
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_SCENE_DELEGATE_H
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_SCENE_EXT_COMP_INPUT_SOURCE_H
|
||||
#define PXR_IMAGING_HD_SCENE_EXT_COMP_INPUT_SOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/extCompInputSource.h"
|
||||
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// An Hd Buffer Source Computation that is used to bind an ExtComputation input
|
||||
/// to a value provided by the scene delegate.
|
||||
///
|
||||
class Hd_SceneExtCompInputSource : public Hd_ExtCompInputSource {
|
||||
public:
|
||||
/// Constructs the computation, binding inputName to the provided value.
|
||||
HD_API
|
||||
Hd_SceneExtCompInputSource(const TfToken &inputName, const VtValue &value);
|
||||
|
||||
HD_API
|
||||
virtual ~Hd_SceneExtCompInputSource() = default;
|
||||
|
||||
/// Set the state of the computation to resolved and returns true.
|
||||
HD_API
|
||||
virtual bool Resolve() override;
|
||||
|
||||
/// Returns the value associated with this input.
|
||||
HD_API
|
||||
virtual const VtValue &GetValue() const override;
|
||||
|
||||
protected:
|
||||
/// Returns if this computation binding is valid.
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
VtValue _value;
|
||||
|
||||
// No copying, assignment or default construction.
|
||||
Hd_SceneExtCompInputSource() = delete;
|
||||
Hd_SceneExtCompInputSource(const Hd_SceneExtCompInputSource &) = delete;
|
||||
Hd_SceneExtCompInputSource &operator = (const Hd_SceneExtCompInputSource &)
|
||||
= delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_SCENE_EXT_COMP_INPUT_SOURCE_H
|
||||
@@ -0,0 +1,166 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_SELECTION_H
|
||||
#define PXR_IMAGING_HD_SELECTION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/gf/vec4f.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdSelectionSharedPtr = std::shared_ptr<class HdSelection>;
|
||||
|
||||
/// \class HdSelection
|
||||
///
|
||||
/// HdSelection holds a collection of selected items per selection mode.
|
||||
/// The items may be rprims, instances of an rprim and subprimitives of an
|
||||
/// rprim, such as elements (faces for meshes, individual curves for basis
|
||||
/// curves), edges & points. Each item is referred to by the render index path.
|
||||
///
|
||||
/// It current supports active and rollover selection modes, and may be
|
||||
/// inherited for customization.
|
||||
///
|
||||
class HdSelection {
|
||||
public:
|
||||
/// Selection modes allow differentiation in selection highlight behavior.
|
||||
enum HighlightMode {
|
||||
HighlightModeSelect = 0, // Active selection
|
||||
HighlightModeLocate, // Rollover selection
|
||||
|
||||
HighlightModeCount
|
||||
};
|
||||
|
||||
HdSelection() = default;
|
||||
|
||||
HD_API
|
||||
virtual ~HdSelection();
|
||||
|
||||
/// ------------------------ Population API --------------------------------
|
||||
HD_API
|
||||
void AddRprim(HighlightMode const &mode,
|
||||
SdfPath const &renderIndexPath);
|
||||
|
||||
HD_API
|
||||
void AddInstance(HighlightMode const &mode,
|
||||
SdfPath const &renderIndexPath,
|
||||
VtIntArray const &instanceIndex=VtIntArray());
|
||||
|
||||
HD_API
|
||||
void AddElements(HighlightMode const &mode,
|
||||
SdfPath const &renderIndexPath,
|
||||
VtIntArray const &elementIndices);
|
||||
|
||||
HD_API
|
||||
void AddEdges(HighlightMode const &mode,
|
||||
SdfPath const &renderIndexPath,
|
||||
VtIntArray const &edgeIndices);
|
||||
|
||||
HD_API
|
||||
void AddPoints(HighlightMode const &mode,
|
||||
SdfPath const &renderIndexPath,
|
||||
VtIntArray const &pointIndices);
|
||||
|
||||
// Special handling for points: we allow a set of selected point indices to
|
||||
// also specify a color to use for highlighting.
|
||||
HD_API
|
||||
void AddPoints(HighlightMode const &mode,
|
||||
SdfPath const &renderIndexPath,
|
||||
VtIntArray const &pointIndices,
|
||||
GfVec4f const &pointColor);
|
||||
|
||||
// XXX: Ideally, this should be per instance, if we want to support
|
||||
// selection of subprims (faces/edges/points) per instance of an rprim.
|
||||
// By making this per rprim, all selected instances of the rprim will share
|
||||
// the same subprim highlighting.
|
||||
struct PrimSelectionState {
|
||||
PrimSelectionState() : fullySelected(false) {}
|
||||
|
||||
bool fullySelected;
|
||||
// Use a vector of VtIntArray to avoid copying the indices data.
|
||||
// This way, we support multiple Add<Subprim> operations without
|
||||
// having to consolidate the indices each time.
|
||||
std::vector<VtIntArray> instanceIndices;
|
||||
std::vector<VtIntArray> elementIndices;
|
||||
std::vector<VtIntArray> edgeIndices;
|
||||
std::vector<VtIntArray> pointIndices;
|
||||
std::vector<int> pointColorIndices;
|
||||
};
|
||||
|
||||
/// ---------------------------- Query API ---------------------------------
|
||||
|
||||
// Returns a pointer to the selection state for the rprim path if selected.
|
||||
// Returns nullptr otherwise.
|
||||
HD_API
|
||||
PrimSelectionState const *
|
||||
GetPrimSelectionState(HighlightMode const &mode,
|
||||
SdfPath const &renderIndexPath) const;
|
||||
|
||||
// Returns the selected rprim render index paths for all the selection
|
||||
// modes. The vector returned may contain duplicates.
|
||||
HD_API
|
||||
SdfPathVector
|
||||
GetAllSelectedPrimPaths() const;
|
||||
|
||||
// Returns the selected rprim render index paths for the given mode.
|
||||
HD_API
|
||||
SdfPathVector
|
||||
GetSelectedPrimPaths(HighlightMode const &mode) const;
|
||||
|
||||
HD_API
|
||||
std::vector<GfVec4f> const& GetSelectedPointColors() const;
|
||||
|
||||
// Returns true if nothing is selected.
|
||||
HD_API
|
||||
bool IsEmpty() const;
|
||||
|
||||
private:
|
||||
void _AddPoints(HighlightMode const &mode,
|
||||
SdfPath const &renderIndexPath,
|
||||
VtIntArray const &pointIndices,
|
||||
int pointColorIndex);
|
||||
|
||||
void _GetSelectionPrimPathsForMode(HighlightMode const &mode,
|
||||
SdfPathVector *paths) const;
|
||||
|
||||
protected:
|
||||
typedef std::unordered_map<SdfPath, PrimSelectionState, SdfPath::Hash>
|
||||
_PrimSelectionStateMap;
|
||||
// Keep track of selection per selection mode.
|
||||
_PrimSelectionStateMap _selMap[HighlightModeCount];
|
||||
|
||||
// Track all colors used for point selection highlighting.
|
||||
std::vector<GfVec4f> _selectedPointColors;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_SELECTION_H
|
||||
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_SMOOTH_NORMALS_H
|
||||
#define PXR_IMAGING_HD_SMOOTH_NORMALS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/computation.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/base/gf/vec3d.h"
|
||||
#include "pxr/base/gf/vec3f.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class Hd_VertexAdjacency;
|
||||
|
||||
/// \class Hd_SmoothNormals
|
||||
///
|
||||
/// Hd_SmoothNormals encapsulates mesh smooth normals information.
|
||||
/// It uses passed-in adjacency information and points data to compute
|
||||
/// smooth per-vertex normals. It does this by averaging face normals of
|
||||
/// faces surrounding a vertex.
|
||||
///
|
||||
class Hd_SmoothNormals final {
|
||||
public:
|
||||
/// Computes the smooth normals result using the supplied adjacency
|
||||
/// information and points data. Returns an array of the same size and
|
||||
/// type as the source points, with optional packing.
|
||||
HD_API
|
||||
static VtArray<GfVec3f> ComputeSmoothNormals(
|
||||
Hd_VertexAdjacency const * adjacency,
|
||||
int numPoints,
|
||||
GfVec3f const * pointsPtr);
|
||||
HD_API
|
||||
static VtArray<GfVec3d> ComputeSmoothNormals(
|
||||
Hd_VertexAdjacency const * adjacency,
|
||||
int numPoints,
|
||||
GfVec3d const * pointsPtr);
|
||||
HD_API
|
||||
static VtArray<HdVec4f_2_10_10_10_REV> ComputeSmoothNormalsPacked(
|
||||
Hd_VertexAdjacency const * adjacency,
|
||||
int numPoints,
|
||||
GfVec3f const * pointsPtr);
|
||||
HD_API
|
||||
static VtArray<HdVec4f_2_10_10_10_REV> ComputeSmoothNormalsPacked(
|
||||
Hd_VertexAdjacency const * adjacency,
|
||||
int numPoints,
|
||||
GfVec3d const * pointsPtr);
|
||||
|
||||
private:
|
||||
Hd_SmoothNormals() = delete;
|
||||
~Hd_SmoothNormals() = delete;
|
||||
};
|
||||
|
||||
/// \class Hd_SmoothNormalsComputation
|
||||
///
|
||||
/// Smooth normal computation CPU.
|
||||
///
|
||||
class Hd_SmoothNormalsComputation : public HdComputedBufferSource {
|
||||
public:
|
||||
HD_API
|
||||
Hd_SmoothNormalsComputation(Hd_VertexAdjacency const *adjacency,
|
||||
HdBufferSourceSharedPtr const &points,
|
||||
TfToken const &dstName,
|
||||
HdBufferSourceSharedPtr const &adjacencyBuilder,
|
||||
bool packed);
|
||||
|
||||
/// overrides
|
||||
HD_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
HD_API
|
||||
virtual bool Resolve() override;
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
Hd_VertexAdjacency const *_adjacency;
|
||||
HdBufferSourceSharedPtr _points;
|
||||
TfToken _dstName;
|
||||
HdBufferSourceSharedPtr _adjacencyBuilder;
|
||||
bool _packed;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_SMOOTH_NORMALS_H
|
||||
@@ -0,0 +1,91 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_SORTED_IDS_H
|
||||
#define PXR_IMAGING_HD_SORTED_IDS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// Manages a container of Hydra Ids in a sorted order.
|
||||
///
|
||||
/// For performance reasons, sorting of the list is deferred
|
||||
/// due to inserting a large number of items at once.
|
||||
///
|
||||
/// The class chooses the type of sort based on how many unsorted items
|
||||
/// there are in the list.
|
||||
///
|
||||
class Hd_SortedIds {
|
||||
public:
|
||||
HD_API
|
||||
Hd_SortedIds();
|
||||
|
||||
HD_API
|
||||
~Hd_SortedIds() = default;
|
||||
|
||||
HD_API
|
||||
Hd_SortedIds(Hd_SortedIds &&other);
|
||||
|
||||
/// Sorts the ids if needed and returns the sorted list of ids.
|
||||
HD_API
|
||||
const SdfPathVector &GetIds();
|
||||
|
||||
/// Add a new id to the collection
|
||||
HD_API
|
||||
void Insert(const SdfPath &id);
|
||||
|
||||
/// Remove an id from the collection.
|
||||
HD_API
|
||||
void Remove(const SdfPath &id);
|
||||
|
||||
/// Remove a range of id from the collection.
|
||||
/// Range defined by position index in sorted list.
|
||||
/// end is inclusive.
|
||||
HD_API
|
||||
void RemoveRange(size_t start, size_t end);
|
||||
|
||||
/// Removes all ids from the collection.
|
||||
HD_API
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
SdfPathVector _ids;
|
||||
size_t _sortedCount;
|
||||
ptrdiff_t _afterLastDeletePoint;
|
||||
|
||||
void _InsertSort();
|
||||
void _FullSort();
|
||||
void _Sort();
|
||||
|
||||
Hd_SortedIds(const Hd_SortedIds &) = delete;
|
||||
Hd_SortedIds &operator =(const Hd_SortedIds &) = delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_SORTED_IDS_H
|
||||
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_SPRIM_H
|
||||
#define PXR_IMAGING_HD_SPRIM_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
class HdRenderParam;
|
||||
|
||||
/// \class HdSprim
|
||||
///
|
||||
/// Sprim (state prim) is a base class of managing state for non-drawable
|
||||
/// scene entity (e.g. camera, light). Similar to Rprim, Sprim communicates
|
||||
/// scene delegate and tracks the changes through change tracker, then updates
|
||||
/// data cached in Hd (either on CPU or GPU).
|
||||
///
|
||||
/// Unlike Rprim, Sprim doesn't produce draw items. The data cached in HdSprim
|
||||
/// may be used by HdTask or by HdShader.
|
||||
///
|
||||
/// The lifetime of HdSprim is owned by HdRenderIndex.
|
||||
///
|
||||
class HdSprim {
|
||||
public:
|
||||
HD_API
|
||||
HdSprim(SdfPath const & id);
|
||||
HD_API
|
||||
virtual ~HdSprim();
|
||||
|
||||
/// Returns the identifier by which this state is known. This
|
||||
/// identifier is a common associative key used by the SceneDelegate,
|
||||
/// RenderIndex, and for binding to the state (e.g. camera, light)
|
||||
SdfPath const& GetId() const { return _id; }
|
||||
|
||||
/// Synchronizes state from the delegate to this object.
|
||||
/// @param[in, out] dirtyBits: On input specifies which state is
|
||||
/// is dirty and can be pulled from the scene
|
||||
/// delegate.
|
||||
/// On output specifies which bits are still
|
||||
/// dirty and were not cleaned by the sync.
|
||||
///
|
||||
virtual void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) = 0;
|
||||
|
||||
/// Finalizes object resources. This function might not delete resources,
|
||||
/// but it should deal with resource ownership so that the sprim is
|
||||
/// deletable.
|
||||
HD_API
|
||||
virtual void Finalize(HdRenderParam *renderParam);
|
||||
|
||||
/// Returns the minimal set of dirty bits to place in the
|
||||
/// change tracker for use in the first sync of this prim.
|
||||
/// Typically this would be all dirty bits.
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const = 0;
|
||||
|
||||
private:
|
||||
SdfPath _id;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_SPRIM_H
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_STRATEGY_BASE_H
|
||||
#define PXR_IMAGING_HD_STRATEGY_BASE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/bufferArray.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdBufferArraySharedPtr = std::shared_ptr<class HdBufferArray>;
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
|
||||
|
||||
/// \class HdAggregationStrategy
|
||||
///
|
||||
/// Aggregation strategy base class.
|
||||
///
|
||||
class HdAggregationStrategy {
|
||||
public:
|
||||
/// Aggregation ID
|
||||
typedef size_t AggregationId;
|
||||
|
||||
HD_API
|
||||
virtual ~HdAggregationStrategy();
|
||||
|
||||
/// Factory for creating HdBufferArray
|
||||
virtual HdBufferArraySharedPtr CreateBufferArray(
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint) = 0;
|
||||
|
||||
/// Factory for creating HdBufferArrayRange
|
||||
virtual HdBufferArrayRangeSharedPtr CreateBufferArrayRange() = 0;
|
||||
|
||||
|
||||
/// Returns id for given bufferSpecs to be used for aggregation
|
||||
virtual AggregationId ComputeAggregationId(
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint) const = 0;
|
||||
|
||||
/// Returns the buffer specs from a given buffer array
|
||||
virtual HdBufferSpecVector GetBufferSpecs(
|
||||
HdBufferArraySharedPtr const &bufferArray) const = 0;
|
||||
|
||||
/// Returns the accumulated GPU resource allocation
/// for items in the BufferArray passed as parameter
|
||||
virtual size_t GetResourceAllocation(
|
||||
HdBufferArraySharedPtr const &bufferArray,
|
||||
VtDictionary &result) const = 0;
|
||||
|
||||
/// (Optional) called to Flush consolidated / staging buffers.
|
||||
HD_API
|
||||
virtual void Flush() {}
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_STRATEGY_BASE_H
|
||||
@@ -0,0 +1,288 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_TASK_H
|
||||
#define PXR_IMAGING_HD_TASK_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/driver.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
|
||||
#include "pxr/imaging/hd/sceneDelegate.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdTaskSharedPtr = std::shared_ptr<class HdTask>;
|
||||
using HdTaskSharedPtrVector = std::vector<HdTaskSharedPtr>;
|
||||
|
||||
// We want to use token as a key not std::string, so use an unordered_map over
|
||||
// VtDictionary
|
||||
using HdTaskContext =
|
||||
std::unordered_map<TfToken, VtValue, TfToken::HashFunctor>;
|
||||
|
||||
class HdTask {
|
||||
public:
|
||||
/// Construct a new task.
|
||||
/// If the task is going to be added to the render index, id
|
||||
/// should be an absolute scene path.
|
||||
/// If the task isn't going to be added to the render index
|
||||
/// an empty path should be used for id.
|
||||
HD_API
|
||||
HdTask(SdfPath const& id);
|
||||
|
||||
HD_API
|
||||
virtual ~HdTask();
|
||||
|
||||
/// Sync Phase: Obtain task state from Scene delegate based on
|
||||
/// change processing.
|
||||
///
|
||||
/// This function might only be called if dirtyBits is not 0,
|
||||
/// so isn't guaranteed to be called every time HdEngine::Execute() is run
|
||||
/// with this task.
|
||||
///
|
||||
/// However, this is the only time when the task should communicate with
|
||||
/// with the scene delegate responsible for the task and should be
|
||||
/// used to pull all changed data. As outside the Sync phase, the scene
|
||||
/// delegate may not have the data available.
|
||||
///
|
||||
/// Tasks maybe synced in parallel and out of order.
|
||||
///
|
||||
/// The ctx parameter is present for legacy reason and shouldn't be used
|
||||
/// once the task has moved to using the 3-phase mechanism.
|
||||
///
|
||||
/// After a task has been synced, it is expected that it produces a
|
||||
/// collection identifying the prims that are important to the task. This
|
||||
/// collection is used to filter the prims in the scene so only the
|
||||
/// Relevant prims get synced.
|
||||
///
|
||||
/// Note about inter-prim dependencies:
|
||||
/// Quite often tasks need to access other prims, such as a camera prim
|
||||
/// for example. These other prims have not been synced yet when sync is
|
||||
/// called. Therefore, it is not recommended to access these prims during
|
||||
/// the sync phase. Instead a task should store the path to the prim
|
||||
/// to be resolved to an actual prim during the "prepare" phase.
|
||||
|
||||
virtual void Sync(HdSceneDelegate* delegate,
|
||||
HdTaskContext* ctx,
|
||||
HdDirtyBits* dirtyBits) = 0;
|
||||
|
||||
/// Prepare Phase: Resolve bindings and manage resources.
|
||||
///
|
||||
/// The Prepare phase happens before the Data Commit phase.
|
||||
/// All tasks in the task list get called for every execute.
|
||||
/// At this time all Tasks and other prims have completed the phase synced.
|
||||
///
|
||||
/// This is an opportunity for the task to pull data from other prims
|
||||
/// (such as a camera prim), but accessing the render index.
|
||||
///
|
||||
/// The task can also use the phase to create, register and update temporary
|
||||
/// resources with the resource registry or other render delegate
|
||||
/// specific mechanism.
|
||||
///
|
||||
/// Tasks are always "Prepared" in execution order.
|
||||
///
|
||||
/// Inter-task communication is achievable via the task context.
|
||||
/// The same task context is used for the prepare and execution phases.
|
||||
/// Data in the task context isn't guaranteed to persist across calls
|
||||
/// to HdEngine::Execute().
|
||||
virtual void Prepare(HdTaskContext* ctx,
|
||||
HdRenderIndex* renderIndex) = 0;
|
||||
|
||||
/// Execute Phase: Runs the task.
|
||||
///
|
||||
/// The execution phase should trigger render delegate processing,
|
||||
/// such as issuing draw commands.
|
||||
///
|
||||
/// Task execution is non-parallel and ordered.
|
||||
///
|
||||
/// The task context is the same as used by the prepare step and is used
|
||||
/// for inter-task communication.
|
||||
virtual void Execute(HdTaskContext* ctx) = 0;
|
||||
|
||||
/// Render Tag Gather.
|
||||
///
|
||||
/// Is called during the Sync phase after the task has been sync'ed.
|
||||
///
|
||||
/// The task should return the render tags it wants to be appended to the
|
||||
/// active set.
|
||||
///
|
||||
/// Hydra prims are marked up with a render tag and only prims
|
||||
/// marked with the render tags in the current active set are Sync'ed.
|
||||
///
|
||||
/// Hydra's core will combine the sets from each task and deduplicated the
|
||||
/// result. So tasks don't need to co-ordinate with each other to
|
||||
/// Optimize the set.
|
||||
///
|
||||
/// For those tasks that use HdRenderPass, is the typically the set passed
|
||||
/// to HdRenderPass's Execute method.
|
||||
///
|
||||
/// The default implementation returns an empty set
|
||||
HD_API
|
||||
virtual const TfTokenVector &GetRenderTags() const;
|
||||
|
||||
SdfPath const& GetId() const { return _id; }
|
||||
|
||||
/// Returns the minimal set of dirty bits to place in the
|
||||
/// change tracker for use in the first sync of this prim.
|
||||
/// Typically this would be all dirty bits.
|
||||
HD_API
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const;
|
||||
|
||||
|
||||
protected:
|
||||
/// Check if the shared context contains a value for the given id.
|
||||
HD_API
|
||||
static bool _HasTaskContextData(HdTaskContext const* ctx,
|
||||
TfToken const& id);
|
||||
|
||||
/// Extracts a typed value out of the task context at the given id.
|
||||
/// If the id is missing or of the wrong type, the code will
|
||||
/// throw a verify error, return false and outValue will be unmodified.
|
||||
/// in case of success, the return value is true and the value is
|
||||
/// copied into outValue.
|
||||
///
|
||||
/// outValue must not be null.
|
||||
template <class T>
|
||||
static bool _GetTaskContextData(HdTaskContext const* ctx,
|
||||
TfToken const& id,
|
||||
T* outValue);
|
||||
|
||||
/// Extracts a typed value out of the task context at the given id.
|
||||
/// If the id is missing or of the wrong type, the code will
|
||||
/// throw a verify error, return false and outValue will be unmodified.
|
||||
/// in case of success, the return value is true and the value is
|
||||
/// copied into outValue.
|
||||
///
|
||||
/// outValue must not be null.
|
||||
template <class T>
|
||||
bool _GetTaskParams(HdSceneDelegate* delegate,
|
||||
T* outValue);
|
||||
|
||||
HD_API
|
||||
TfTokenVector _GetTaskRenderTags(HdSceneDelegate* delegate);
|
||||
|
||||
/// Extract an object from a HdDriver inside the task context.
|
||||
/// Returns nullptr if driver was not found.
|
||||
template <class T>
|
||||
static T _GetDriver(
|
||||
HdTaskContext const* ctx,
|
||||
TfToken const& driverName);
|
||||
|
||||
private:
|
||||
SdfPath _id;
|
||||
|
||||
HdTask() = delete;
|
||||
HdTask(const HdTask &) = delete;
|
||||
HdTask &operator =(const HdTask &) = delete;
|
||||
};
|
||||
|
||||
// Inline template body
|
||||
template <class T>
|
||||
bool
|
||||
HdTask::_GetTaskContextData(HdTaskContext const* ctx,
|
||||
TfToken const& id,
|
||||
T* outValue)
|
||||
{
|
||||
TF_DEV_AXIOM(outValue != nullptr);
|
||||
|
||||
if (!ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HdTaskContext::const_iterator valueIt = ctx->find(id);
|
||||
if (valueIt == ctx->cend()) {
|
||||
TF_CODING_ERROR("Token %s missing from task context", id.GetText());
|
||||
return false;
|
||||
}
|
||||
|
||||
const VtValue &valueVt = (valueIt->second);
|
||||
if (!valueVt.IsHolding<T>()) {
|
||||
TF_CODING_ERROR("Token %s in task context is of mismatched type",
|
||||
id.GetText());
|
||||
return false;
|
||||
}
|
||||
|
||||
*outValue = valueVt.UncheckedGet<T>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool
|
||||
HdTask::_GetTaskParams(HdSceneDelegate* delegate,
|
||||
T* outValue)
|
||||
{
|
||||
TF_DEV_AXIOM(outValue != nullptr);
|
||||
|
||||
SdfPath const& taskId = GetId();
|
||||
|
||||
VtValue valueVt = delegate->Get(taskId, HdTokens->params);
|
||||
if (!valueVt.IsHolding<T>()) {
|
||||
TF_CODING_ERROR("Task params for %s is of unexpected type",
|
||||
taskId.GetText());
|
||||
return false;
|
||||
}
|
||||
|
||||
*outValue = valueVt.UncheckedGet<T>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T
|
||||
HdTask::_GetDriver(
|
||||
HdTaskContext const* ctx,
|
||||
TfToken const& driverName)
|
||||
{
|
||||
auto it = ctx->find(HdTokens->drivers);
|
||||
if (it != ctx->end()) {
|
||||
VtValue const& value = it->second;
|
||||
if (value.IsHolding<HdDriverVector>()) {
|
||||
HdDriverVector const& drivers= value.UncheckedGet<HdDriverVector>();
|
||||
for (HdDriver* hdDriver : drivers) {
|
||||
if (hdDriver->name == driverName) {
|
||||
if (hdDriver->driver.IsHolding<T>()) {
|
||||
return hdDriver->driver.UncheckedGet<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_TASK_H
|
||||
@@ -0,0 +1,292 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_TIME_SAMPLE_ARRAY_H
|
||||
#define PXR_IMAGING_HD_TIME_SAMPLE_ARRAY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include "pxr/base/gf/math.h"
|
||||
#include "pxr/base/gf/quatf.h"
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
#include "pxr/base/tf/smallVector.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Resample two neighboring samples.
|
||||
template <typename T>
|
||||
inline T HdResampleNeighbors(float alpha, const T& v0, const T& v1)
|
||||
{
|
||||
return GfLerp(alpha, v0, v1);
|
||||
}
|
||||
|
||||
/// Specialization for HdQuatf: spherical linear interpolation.
|
||||
HD_API
|
||||
inline GfQuatf HdResampleNeighbors(float alpha,
|
||||
const GfQuatf &v0,
|
||||
const GfQuatf &v1)
|
||||
{
|
||||
return GfSlerp(double(alpha), v0, v1);
|
||||
}
|
||||
|
||||
/// Specialization for VtArray: component-wise resampling.
|
||||
template <typename T>
|
||||
inline VtArray<T> HdResampleNeighbors(float alpha,
|
||||
const VtArray<T>& v0,
|
||||
const VtArray<T>& v1)
|
||||
{
|
||||
VtArray<T> r(v0.size());
|
||||
for (size_t i=0; i < r.size(); ++i) {
|
||||
r[i] = HdResampleNeighbors(alpha, v0[i], v1[i]);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Specialization for VtValue: interpolate the held values.
|
||||
HD_API
|
||||
VtValue HdResampleNeighbors(float alpha, const VtValue& v0, const VtValue& v1);
|
||||
|
||||
/// Resample a function described by an ordered array of samples,
|
||||
/// using a linear reconstruction filter evaluated at the given
|
||||
/// parametric position u. The function is considered constant
|
||||
/// outside the supplied sample range.
|
||||
template <typename T>
|
||||
T HdResampleRawTimeSamples(
|
||||
float u,
|
||||
size_t numSamples,
|
||||
const float *us,
|
||||
const T *vs)
|
||||
{
|
||||
if (numSamples == 0) {
|
||||
TF_CODING_ERROR("HdResampleRawTimeSamples: Zero samples provided");
|
||||
return T();
|
||||
}
|
||||
|
||||
size_t i=0;
|
||||
for (; i < numSamples; ++i) {
|
||||
if (us[i] == u) {
|
||||
// Fast path for exact parameter match.
|
||||
return vs[i];
|
||||
}
|
||||
if (us[i] > u) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == 0) {
|
||||
// u is before the first sample.
|
||||
return vs[0];
|
||||
} else if (i == numSamples) {
|
||||
// u is after the last sample.
|
||||
return vs[numSamples-1];
|
||||
} else if (us[i] == us[i-1]) {
|
||||
// Neighboring samples have identical parameter.
|
||||
// Arbitrarily choose a sample.
|
||||
TF_WARN("HdResampleRawTimeSamples: overlapping samples at %f; "
|
||||
"using first sample", us[i]);
|
||||
return vs[i-1];
|
||||
} else {
|
||||
// Linear blend of neighboring samples.
|
||||
float alpha = (us[i]-u) / (us[i]-us[i-1]);
|
||||
return HdResampleNeighbors(alpha, vs[i-1], vs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Resample a function described by an ordered array of samples and sample
|
||||
/// indices, using a linear reconstruction filter evaluated at the given
|
||||
/// parametric position u. The function is considered constant outside the
|
||||
/// supplied sample range.
|
||||
template <typename T>
|
||||
std::pair<T, VtIntArray> HdResampleRawTimeSamples(
|
||||
float u,
|
||||
size_t numSamples,
|
||||
const float *us,
|
||||
const T *vs,
|
||||
const VtIntArray *is)
|
||||
{
|
||||
if (numSamples == 0) {
|
||||
TF_CODING_ERROR("HdResampleRawTimeSamples: Zero samples provided");
|
||||
return std::pair<T, VtIntArray>(T(), VtIntArray(0));
|
||||
}
|
||||
|
||||
size_t i=0;
|
||||
for (; i < numSamples; ++i) {
|
||||
if (us[i] == u) {
|
||||
// Fast path for exact parameter match.
|
||||
return std::pair<T, VtIntArray>(vs[i], is[i]);
|
||||
}
|
||||
if (us[i] > u) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == 0) {
|
||||
// u is before the first sample.
|
||||
return std::pair<T, VtIntArray>(vs[0], is[0]);
|
||||
} else if (i == numSamples) {
|
||||
// u is after the last sample.
|
||||
return std::pair<T, VtIntArray>(vs[numSamples-1], is[numSamples-1]);
|
||||
} else if (us[i] == us[i-1]) {
|
||||
// Neighboring samples have identical parameter.
|
||||
// Arbitrarily choose a sample.
|
||||
TF_WARN("HdResampleRawTimeSamples: overlapping samples at %f; "
|
||||
"using first sample", us[i]);
|
||||
return std::pair<T, VtIntArray>(vs[i-1], is[i-1]);
|
||||
} else {
|
||||
// Linear blend of neighboring samples for values
|
||||
// Hold earlier value for indices
|
||||
float alpha = (us[i]-u) / (us[i]-us[i-1]);
|
||||
return std::pair<T, VtIntArray>(
|
||||
HdResampleNeighbors(alpha, vs[i-1], vs[i]),
|
||||
is[i-1]);
|
||||
}
|
||||
}
|
||||
|
||||
/// An array of a value sampled over time, in struct-of-arrays layout.
|
||||
/// This is provided as a convenience for time-sampling attributes.
|
||||
/// This type has static capacity but dynamic size, providing
|
||||
/// a limited ability to handle variable sampling without requiring
|
||||
/// heap allocation.
|
||||
template<typename TYPE, unsigned int CAPACITY>
|
||||
struct HdTimeSampleArray
|
||||
{
|
||||
HdTimeSampleArray() {
|
||||
times.resize(CAPACITY);
|
||||
values.resize(CAPACITY);
|
||||
count = 0;
|
||||
}
|
||||
|
||||
HdTimeSampleArray(const HdTimeSampleArray& rhs) {
|
||||
times = rhs.times;
|
||||
values = rhs.values;
|
||||
count = rhs.count;
|
||||
}
|
||||
|
||||
HdTimeSampleArray& operator=(const HdTimeSampleArray& rhs) {
|
||||
times = rhs.times;
|
||||
values = rhs.values;
|
||||
count = rhs.count;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Resize the internal buffers.
|
||||
virtual void Resize(unsigned int newSize) {
|
||||
times.resize(newSize);
|
||||
values.resize(newSize);
|
||||
count = newSize;
|
||||
}
|
||||
|
||||
/// Convience method for invoking HdResampleRawTimeSamples
|
||||
/// on this HdTimeSampleArray.
|
||||
TYPE Resample(float u) const {
|
||||
return HdResampleRawTimeSamples(u, count, times.data(), values.data());
|
||||
}
|
||||
|
||||
/// Unbox an HdTimeSampleArray holding boxed VtValue<VtArray<T>>
|
||||
/// samples into an array holding VtArray<T> samples.
|
||||
///
|
||||
/// Similar to VtValue::Get(), this will issue a coding error if the
|
||||
/// VtValue is not holding the expected type.
|
||||
///
|
||||
/// \see VtValue::Get()
|
||||
void UnboxFrom(HdTimeSampleArray<VtValue, CAPACITY> const& box) {
|
||||
Resize(box.count);
|
||||
times = box.times;
|
||||
for (size_t i=0; i < box.count; ++i) {
|
||||
if (box.values[i].GetArraySize() > 0) {
|
||||
values[i] = box.values[i].template Get<TYPE>();
|
||||
} else {
|
||||
values[i] = TYPE();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t count;
|
||||
TfSmallVector<float, CAPACITY> times;
|
||||
TfSmallVector<TYPE, CAPACITY> values;
|
||||
};
|
||||
|
||||
/// An array of a value and its indices sampled over time, in struct-of-arrays
|
||||
/// layout.
|
||||
template<typename TYPE, unsigned int CAPACITY>
|
||||
struct HdIndexedTimeSampleArray : public HdTimeSampleArray<TYPE, CAPACITY>
|
||||
{
|
||||
HdIndexedTimeSampleArray() : HdTimeSampleArray<TYPE, CAPACITY>() {
|
||||
indices.resize(CAPACITY);
|
||||
}
|
||||
|
||||
HdIndexedTimeSampleArray(const HdIndexedTimeSampleArray& rhs) :
|
||||
HdTimeSampleArray<TYPE, CAPACITY>(rhs) {
|
||||
indices = rhs.indices;
|
||||
}
|
||||
|
||||
HdIndexedTimeSampleArray&
|
||||
operator=(const HdIndexedTimeSampleArray& rhs) {
|
||||
this->times = rhs.times;
|
||||
this->values = rhs.values;
|
||||
this->count = rhs.count;
|
||||
indices = rhs.indices;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Resize the internal buffers.
|
||||
void Resize(unsigned int newSize) override {
|
||||
HdTimeSampleArray<TYPE, CAPACITY>::Resize(newSize);
|
||||
indices.resize(newSize);
|
||||
}
|
||||
|
||||
/// Convience method for invoking HdResampleRawTimeSamples
|
||||
/// on this HdIndexedTimeSampleArray.
|
||||
std::pair<TYPE, VtIntArray> ResampleIndexed(float u) const {
|
||||
return HdResampleRawTimeSamples(u, this->count, this->times.data(),
|
||||
this->values.data(), indices.data());
|
||||
}
|
||||
|
||||
/// Unbox an HdIndexedTimeSampleArray holding boxed VtValue<VtArray<T>>
|
||||
/// samples into an array holding VtArray<T> samples.
|
||||
///
|
||||
/// Similar to VtValue::Get(), this will issue a coding error if the
|
||||
/// VtValue is not holding the expected type.
|
||||
///
|
||||
/// \see VtValue::Get()
|
||||
void
|
||||
UnboxFrom(HdIndexedTimeSampleArray<VtValue, CAPACITY> const& box) {
|
||||
Resize(box.count);
|
||||
this->times = box.times;
|
||||
indices = box.indices;
|
||||
for (size_t i=0; i < box.count; ++i) {
|
||||
if (box.values[i].GetArraySize() > 0) {
|
||||
this->values[i] = box.values[i].template Get<TYPE>();
|
||||
} else {
|
||||
this->values[i] = TYPE();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TfSmallVector<VtIntArray, CAPACITY> indices;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_TIME_SAMPLE_ARRAY_H
|
||||
@@ -0,0 +1,373 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_TOKENS_H
|
||||
#define PXR_IMAGING_HD_TOKENS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
#define HD_TOKENS \
|
||||
(accelerations) \
|
||||
(adjacency) \
|
||||
(bboxLocalMin) \
|
||||
(bboxLocalMax) \
|
||||
(bbox) \
|
||||
(bezier) \
|
||||
(bSpline) \
|
||||
(camera) \
|
||||
(catmullRom) \
|
||||
(collection) \
|
||||
(computeShader) \
|
||||
(coordSysBindings) \
|
||||
(cubic) \
|
||||
(cullStyle) \
|
||||
(doubleSided) \
|
||||
(dispatchCount) \
|
||||
(displayColor) \
|
||||
(displayOpacity) \
|
||||
(displayStyle) \
|
||||
(drawDispatch) \
|
||||
(drawingShader) \
|
||||
(drawingCoord0) \
|
||||
(drawingCoord1) \
|
||||
(drawingCoord2) \
|
||||
(drawingCoordI) \
|
||||
(drivers) \
|
||||
(edgeIndices) \
|
||||
(elementCount) \
|
||||
(elementsVisibility) \
|
||||
(extent) \
|
||||
(faceColors) \
|
||||
(filters) \
|
||||
(full) \
|
||||
(geometry) \
|
||||
(hermite) \
|
||||
(hullIndices) \
|
||||
(indices) \
|
||||
(isFlipped) \
|
||||
(itemsDrawn) \
|
||||
(layout) \
|
||||
(leftHanded) \
|
||||
(linear) \
|
||||
(lightLink) \
|
||||
(lightFilterLink) \
|
||||
(materialParams) \
|
||||
(nonperiodic) \
|
||||
(normals) \
|
||||
(params) \
|
||||
(patchParam) \
|
||||
(periodic) \
|
||||
(pinned) \
|
||||
(points) \
|
||||
(pointsIndices) \
|
||||
(power) \
|
||||
(preview) \
|
||||
(pointsVisibility) \
|
||||
(primvar) \
|
||||
(primID) \
|
||||
(primitiveParam) \
|
||||
(quadInfo) \
|
||||
(renderTags) \
|
||||
(rightHanded) \
|
||||
(segmented) \
|
||||
(shadowLink) \
|
||||
(subdivTags) \
|
||||
(taskState) \
|
||||
(taskParams) \
|
||||
(topology) \
|
||||
(topologyVisibility) \
|
||||
(totalItemCount) \
|
||||
(transform) \
|
||||
(transformInverse) \
|
||||
(velocities) \
|
||||
(visibility) \
|
||||
(widths)
|
||||
|
||||
#define HD_INSTANCER_TOKENS \
|
||||
(culledInstanceIndices) \
|
||||
(instancer) \
|
||||
(instancerTransform) \
|
||||
(instancerTransformInverse) \
|
||||
(instanceIndices) \
|
||||
(instanceIndexBase) \
|
||||
(instanceTransform) \
|
||||
(rotate) \
|
||||
(scale) \
|
||||
(translate)
|
||||
|
||||
#define HD_REPR_TOKENS \
|
||||
(disabled) \
|
||||
(hull) \
|
||||
(points) \
|
||||
(smoothHull) \
|
||||
(refined) \
|
||||
(refinedWire) \
|
||||
(refinedWireOnSurf) \
|
||||
(wire) \
|
||||
(wireOnSurf)
|
||||
|
||||
#define HD_PERF_TOKENS \
|
||||
(adjacencyBufSize) \
|
||||
(basisCurvesTopology) \
|
||||
(bufferSourcesResolved) \
|
||||
(bufferArrayRangeMigrated) \
|
||||
(bufferArrayRangeContainerResized) \
|
||||
(collectionsRefreshed) \
|
||||
(computationsCommited) \
|
||||
(drawBatches) \
|
||||
(drawCalls) \
|
||||
(dirtyLists) \
|
||||
(dirtyListsRebuilt) \
|
||||
(garbageCollected) \
|
||||
(garbageCollectedSsbo) \
|
||||
(garbageCollectedUbo) \
|
||||
(garbageCollectedVbo) \
|
||||
(gpuMemoryUsed) \
|
||||
(instBasisCurvesTopology) \
|
||||
(instBasisCurvesTopologyRange) \
|
||||
(instExtComputationDataRange) \
|
||||
(instMeshTopology) \
|
||||
(instMeshTopologyRange) \
|
||||
(instPrimvarRange) \
|
||||
(instVertexAdjacency) \
|
||||
(meshTopology) \
|
||||
(nonUniformSize) \
|
||||
(numCompletedSamples) \
|
||||
(quadrangulateCPU) \
|
||||
(quadrangulateGPU) \
|
||||
(quadrangulateFaceVarying) \
|
||||
(quadrangulatedVerts) \
|
||||
(rebuildBatches) \
|
||||
(singleBufferSize) \
|
||||
(ssboSize) \
|
||||
(skipInvisibleRprimSync) \
|
||||
(subdivisionRefineCPU) \
|
||||
(subdivisionRefineGPU) \
|
||||
(textureMemory) \
|
||||
(triangulateFaceVarying) \
|
||||
(uboSize) \
|
||||
(vboRelocated)
|
||||
|
||||
#define HD_SHADER_TOKENS \
|
||||
(alphaThreshold) \
|
||||
(clipPlanes) \
|
||||
(commonShaderSource) \
|
||||
(computeShader) \
|
||||
(cullStyle) \
|
||||
(drawRange) \
|
||||
(environmentMap) \
|
||||
(fragmentShader) \
|
||||
(geometryShader) \
|
||||
(indicatorColor) \
|
||||
(lightingBlendAmount) \
|
||||
(overrideColor) \
|
||||
(maskColor) \
|
||||
(projectionMatrix) \
|
||||
(pointColor) \
|
||||
(pointSize) \
|
||||
(pointSelectedSize) \
|
||||
(materialTag) \
|
||||
(tessControlShader) \
|
||||
(tessEvalShader) \
|
||||
(tessLevel) \
|
||||
(viewport) \
|
||||
(vertexShader) \
|
||||
(wireframeColor) \
|
||||
(worldToViewMatrix) \
|
||||
(worldToViewInverseMatrix)
|
||||
|
||||
// Deprecated. Use: HdStMaterialTagTokens
|
||||
#define HD_MATERIALTAG_TOKENS \
|
||||
(defaultMaterialTag)
|
||||
|
||||
/* Terminal keys used in material networks.
|
||||
*/
|
||||
#define HD_MATERIAL_TERMINAL_TOKENS \
|
||||
(surface) \
|
||||
(displacement) \
|
||||
(volume) \
|
||||
(light) \
|
||||
(lightFilter)
|
||||
|
||||
#define HD_RENDERTAG_TOKENS \
|
||||
(geometry) \
|
||||
(guide) \
|
||||
(hidden) \
|
||||
(proxy) \
|
||||
(render)
|
||||
|
||||
#define HD_OPTION_TOKENS \
|
||||
(parallelRprimSync)
|
||||
|
||||
#define HD_PRIMTYPE_TOKENS \
|
||||
/* Rprims */ \
|
||||
(mesh) \
|
||||
(basisCurves) \
|
||||
(points) \
|
||||
(volume) \
|
||||
\
|
||||
/* Sprims */ \
|
||||
(camera) \
|
||||
(drawTarget) \
|
||||
(material) \
|
||||
(coordSys) \
|
||||
/* Sprims Lights */ \
|
||||
(simpleLight) \
|
||||
(cylinderLight) \
|
||||
(diskLight) \
|
||||
(distantLight) \
|
||||
(domeLight) \
|
||||
(light) \
|
||||
(lightFilter) \
|
||||
(pluginLight) \
|
||||
(rectLight) \
|
||||
(sphereLight) \
|
||||
/* Sprims ExtComputations */ \
|
||||
(extComputation) \
|
||||
\
|
||||
/* Bprims */ \
|
||||
(renderBuffer)
|
||||
|
||||
#define HD_PRIMVAR_ROLE_TOKENS \
|
||||
((none, "")) \
|
||||
(color) \
|
||||
(vector) \
|
||||
(normal) \
|
||||
(point) \
|
||||
(textureCoordinate)
|
||||
|
||||
/* Schema for "Alternate Output Values" rendering,
|
||||
* describing which values a renderpass should
|
||||
* compute and write at render time.
|
||||
*/
|
||||
#define HD_AOV_TOKENS \
|
||||
/* Standard rendering outputs */ \
|
||||
\
|
||||
/* HdAovTokens->color represents the final
|
||||
* fragment RGBA color. For correct compositing
|
||||
* using Hydra, it should have pre-multiplied alpha.
|
||||
*/ \
|
||||
(color) \
|
||||
/* HdAovTokens->depth represents the clip-space
|
||||
* depth of the final fragment.
|
||||
*/ \
|
||||
(depth) \
|
||||
/* HdAovTokens->cameraDepth represents the camera-space
|
||||
* depth of the final fragment.
|
||||
*/ \
|
||||
(cameraDepth) \
|
||||
/* ID rendering - these tokens represent the
|
||||
* prim, instance, and subprim ids of the final
|
||||
* fragment.
|
||||
*/ \
|
||||
(primId) \
|
||||
(instanceId) \
|
||||
(elementId) \
|
||||
(edgeId) \
|
||||
(pointId) \
|
||||
/* Geometric data */ \
|
||||
(Peye) \
|
||||
(Neye) \
|
||||
(patchCoord) \
|
||||
(primitiveParam) \
|
||||
(normal) \
|
||||
/* Others we might want to add:
|
||||
* https://rmanwiki.pixar.com/display/REN/Arbitrary+Output+Variables
|
||||
* - curvature
|
||||
* - tangent
|
||||
* - velocity
|
||||
*/ \
|
||||
/* Primvars:
|
||||
* The tokens don't try to enumerate primvars,
|
||||
* but instead provide an identifying namespace.
|
||||
* The "color" primvar is addressable as "primvars:color".
|
||||
*/ \
|
||||
((primvars, "primvars:")) \
|
||||
/* Light path expressions:
|
||||
* Applicable only to raytracers, these tell
|
||||
* the renderer to output specific shading
|
||||
* components for specific classes of lightpath.
|
||||
*
|
||||
* Lightpath syntax is defined here:
|
||||
* https://rmanwiki.pixar.com/display/REN/Light+Path+Expressions
|
||||
* ... so for example, you could specify
|
||||
* "lpe:CD[<L.>O]"
|
||||
*/ \
|
||||
((lpe, "lpe:")) \
|
||||
/* Shader signals:
|
||||
* This tells the renderer to output a partial shading signal,
|
||||
* whether from the BXDF (e.g. bxdf.diffuse) or from an intermediate
|
||||
* shading node (e.g. fractal.rgb).
|
||||
* XXX: The exact format is TBD.
|
||||
*/ \
|
||||
((shader, "shader:"))
|
||||
|
||||
HD_API
|
||||
TfToken HdAovTokensMakePrimvar(TfToken const& primvar);
|
||||
|
||||
HD_API
|
||||
TfToken HdAovTokensMakeLpe(TfToken const& lpe);
|
||||
|
||||
HD_API
|
||||
TfToken HdAovTokensMakeShader(TfToken const& shader);
|
||||
|
||||
/* Schema for application-configurable render settings. */
|
||||
#define HD_RENDER_SETTINGS_TOKENS \
|
||||
/* General graphical options */ \
|
||||
(enableShadows) \
|
||||
(enableSceneMaterials) \
|
||||
(enableSceneLights) \
|
||||
/* Raytracer sampling settings */ \
|
||||
(convergedVariance) \
|
||||
(convergedSamplesPerPixel) \
|
||||
/* thread limit settings */ \
|
||||
(threadLimit)
|
||||
|
||||
#define HD_RESOURCE_TYPE_TOKENS \
|
||||
(texture) \
|
||||
(shaderFile)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdTokens, HD_API, HD_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdInstancerTokens, HD_API, HD_INSTANCER_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdReprTokens, HD_API, HD_REPR_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdPerfTokens, HD_API, HD_PERF_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdShaderTokens, HD_API, HD_SHADER_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMaterialTagTokens, HD_API, HD_MATERIALTAG_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMaterialTerminalTokens, HD_API,
|
||||
HD_MATERIAL_TERMINAL_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdRenderTagTokens, HD_API, HD_RENDERTAG_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdOptionTokens, HD_API, HD_OPTION_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdPrimTypeTokens, HD_API, HD_PRIMTYPE_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdPrimvarRoleTokens, HD_API, HD_PRIMVAR_ROLE_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdAovTokens, HD_API, HD_AOV_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdRenderSettingsTokens, HD_API, HD_RENDER_SETTINGS_TOKENS);
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdResourceTypeTokens, HD_API, HD_RESOURCE_TYPE_TOKENS);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_TOKENS_H
|
||||
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_TOPOLOGY_H
|
||||
#define PXR_IMAGING_HD_TOPOLOGY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/arch/inttypes.h"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdTopology {
|
||||
public:
|
||||
typedef uint64_t ID;
|
||||
|
||||
HdTopology() {};
|
||||
virtual ~HdTopology() {};
|
||||
|
||||
/// Returns the hash value of this topology to be used for instancing.
|
||||
virtual ID ComputeHash() const = 0;
|
||||
};
|
||||
|
||||
HD_API
|
||||
std::ostream& operator << (std::ostream &out, HdTopology const &);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_TOPOLOGY_H
|
||||
|
||||
@@ -0,0 +1,453 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_TYPES_H
|
||||
#define PXR_IMAGING_HD_TYPES_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \enum HdWrap
|
||||
///
|
||||
/// Enumerates wrapping attributes type values.
|
||||
///
|
||||
/// <ul>
|
||||
/// <li>\b HdWrapClamp Clamp coordinate to range [1/(2N),1-1/(2N)] where N is the size of the texture in the direction of clamping</li>
|
||||
/// <li>\b HdWrapRepeat Creates a repeating pattern</li>
|
||||
/// <li>\b HdWrapBlack Clamp coordinate to range [-1/(2N),1+1/(2N)] where N is the size of the texture in the direction of clamping</li>
|
||||
/// <li>\b HdWrapMirror Creates a mirrored repeating pattern.</li>
|
||||
/// <li>\b HdWrapNoOpinion No opinion. The data texture can define its own wrap mode that we can use instead. Fallback to HdWrapBlack</li>
|
||||
/// <li>\b HdWrapLegacyNoOpinionFallbackRepeat (deprecated) Similar to HdWrapNoOpinon but fallback to HdWrapRepeat</li>
|
||||
/// <li>\b HdWrapUseMetadata (deprecated) Alias for HdWrapNoOpinion</li>
|
||||
/// <li>\b HdWrapLegacy (deprecated) Alias for HdWrapLegacyNoOpinionFallbackRepeat</li>
|
||||
/// </ul>
|
||||
///
|
||||
enum HdWrap
|
||||
{
|
||||
HdWrapClamp,
|
||||
HdWrapRepeat,
|
||||
HdWrapBlack,
|
||||
HdWrapMirror,
|
||||
|
||||
HdWrapNoOpinion,
|
||||
HdWrapLegacyNoOpinionFallbackRepeat, // deprecated
|
||||
|
||||
HdWrapUseMetadata = HdWrapNoOpinion, // deprecated alias
|
||||
HdWrapLegacy = HdWrapLegacyNoOpinionFallbackRepeat // deprecated alias
|
||||
};
|
||||
|
||||
/// \enum HdMinFilter
|
||||
///
|
||||
/// Enumerates minFilter attribute type values.
|
||||
///
|
||||
/// <ul>
|
||||
/// <li>\b HdMinFilterNearest Nearest to center of the pixel</li>
|
||||
/// <li>\b HdMinFilterLinear Weighted average od the four texture elements closest to the pixel</li>
|
||||
/// <li>\b HdMinFilterNearestMipmapNearest Nearest to center of the pixel from the nearest mipmaps</li>
|
||||
/// <li>\b HdMinFilterLinearMipmapNeares Weighted average using texture elements from the nearest mipmaps</li>
|
||||
/// <li>\b HdMinFilterNearestMipmapLinear Weighted average of the nearest pixels from the two nearest mipmaps</li>
|
||||
/// <li>\b HdMinFilterLinearMipmapLinear WeightedAverage of the weighted averages from the nearest mipmaps</li>
|
||||
/// </ul>
|
||||
///
|
||||
enum HdMinFilter
|
||||
{
|
||||
HdMinFilterNearest,
|
||||
HdMinFilterLinear,
|
||||
HdMinFilterNearestMipmapNearest,
|
||||
HdMinFilterLinearMipmapNearest,
|
||||
HdMinFilterNearestMipmapLinear,
|
||||
HdMinFilterLinearMipmapLinear,
|
||||
};
|
||||
|
||||
/// \enum HdMagFilter
|
||||
///
|
||||
/// Enumerates magFilter attribute type values.
|
||||
///
|
||||
/// <ul>
|
||||
/// <li>HdFilterNearest Nearest to center of the pixel</li>
|
||||
/// <li>HdFilterLinear Weighted average of the four texture elements closest to the pixel</li>
|
||||
/// </ul>
|
||||
///
|
||||
enum HdMagFilter
|
||||
{
|
||||
HdMagFilterNearest,
|
||||
HdMagFilterLinear,
|
||||
};
|
||||
|
||||
/// \class HdSamplerParameters
|
||||
///
|
||||
/// Collection of standard parameters such as wrap modes to sample a texture.
|
||||
///
|
||||
class HdSamplerParameters {
|
||||
public:
|
||||
HdWrap wrapS;
|
||||
HdWrap wrapT;
|
||||
HdWrap wrapR;
|
||||
HdMinFilter minFilter;
|
||||
HdMagFilter magFilter;
|
||||
|
||||
HD_API
|
||||
bool operator==(const HdSamplerParameters &other) const;
|
||||
|
||||
HD_API
|
||||
bool operator!=(const HdSamplerParameters &other) const;
|
||||
};
|
||||
|
||||
///
|
||||
/// Type representing a set of dirty bits.
|
||||
///
|
||||
typedef uint32_t HdDirtyBits;
|
||||
|
||||
// GL Spec 2.3.5.2 (signed case, eq 2.4)
|
||||
inline int HdConvertFloatToFixed(float v, int b)
|
||||
{
|
||||
return int(
|
||||
std::round(
|
||||
std::min(std::max(v, -1.0f), 1.0f) * (float(1 << (b-1)) - 1.0f)));
|
||||
}
|
||||
|
||||
// GL Spec 2.3.5.1 (signed case, eq 2.2)
|
||||
inline float HdConvertFixedToFloat(int v, int b)
|
||||
{
|
||||
return float(
|
||||
std::max(-1.0f,
|
||||
(v / (float(1 << (b-1)) - 1.0f))));
|
||||
}
|
||||
|
||||
///
|
||||
/// HdVec4f_2_10_10_10_REV is a compact representation of a GfVec4f.
|
||||
/// It uses 10 bits for x, y, and z, and 2 bits for w.
|
||||
///
|
||||
/// XXX We expect this type to move again as we continue work on
|
||||
/// refactoring the GL dependencies.
|
||||
///
|
||||
struct HdVec4f_2_10_10_10_REV
|
||||
{
|
||||
HdVec4f_2_10_10_10_REV() { }
|
||||
|
||||
template <typename Vec3Type>
|
||||
HdVec4f_2_10_10_10_REV(Vec3Type const &value) {
|
||||
x = HdConvertFloatToFixed(value[0], 10);
|
||||
y = HdConvertFloatToFixed(value[1], 10);
|
||||
z = HdConvertFloatToFixed(value[2], 10);
|
||||
w = 0;
|
||||
}
|
||||
|
||||
HdVec4f_2_10_10_10_REV(int const value) {
|
||||
HdVec4f_2_10_10_10_REV const* other =
|
||||
reinterpret_cast<HdVec4f_2_10_10_10_REV const*>(&value);
|
||||
x = other->x;
|
||||
y = other->y;
|
||||
z = other->z;
|
||||
w = other->w;
|
||||
}
|
||||
|
||||
template <typename Vec3Type>
|
||||
Vec3Type GetAsVec() const {
|
||||
return Vec3Type(HdConvertFixedToFloat(x, 10),
|
||||
HdConvertFixedToFloat(y, 10),
|
||||
HdConvertFixedToFloat(z, 10));
|
||||
}
|
||||
|
||||
int GetAsInt() const {
|
||||
int const* asInt = reinterpret_cast<int const*>(this);
|
||||
return *asInt;
|
||||
}
|
||||
|
||||
bool operator==(const HdVec4f_2_10_10_10_REV &other) const {
|
||||
return (other.w == w &&
|
||||
other.z == z &&
|
||||
other.y == y &&
|
||||
other.x == x);
|
||||
}
|
||||
bool operator!=(const HdVec4f_2_10_10_10_REV &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
int x : 10;
|
||||
int y : 10;
|
||||
int z : 10;
|
||||
int w : 2;
|
||||
};
|
||||
|
||||
/// \enum HdType
|
||||
///
|
||||
/// HdType describes the type of an attribute value used in Hd.
|
||||
///
|
||||
/// HdType values have a specific machine representation and size.
|
||||
/// See HdDataSizeOfType().
|
||||
///
|
||||
/// HdType specifies a scalar, vector, or matrix type. Vector and
|
||||
/// matrix types can be unpacked into the underlying "component"
|
||||
/// type; see HdGetComponentType().
|
||||
///
|
||||
/// HdType is intended to span the common set of attribute types
|
||||
/// used in shading languages such as GLSL. However, it currently
|
||||
/// does not include non-4x4 matrix types, nor struct types.
|
||||
///
|
||||
/// Fixed-size array types are represented by the related class
|
||||
/// HdTupleType. HdTupleType is used anywhere there is a
|
||||
/// possibility of an array of values.
|
||||
///
|
||||
/// ## Value arrays and attribute buffers
|
||||
///
|
||||
/// Attribute data is often stored in linear buffers. These buffers
|
||||
/// have multiple dimensions and it is important to distinguish them:
|
||||
///
|
||||
/// - "Components" refer to the scalar components that comprise a vector
|
||||
/// or matrix. For example, a vec3 has 3 components, a mat4 has
|
||||
/// 16 components, and a float has a single component.
|
||||
///
|
||||
/// - "Elements" refer to external concepts that entries in a buffer
|
||||
/// associate with. Typically these are pieces of geometry,
|
||||
/// such as faces or vertices.
|
||||
///
|
||||
/// - "Arrays" refer to the idea that each element may associate
|
||||
/// with a fixed-size array of values. For example, one approach
|
||||
/// to motion blur might store a size-2 array of HdFloatMat4
|
||||
/// values for each element of geometry, holding the transforms
|
||||
/// at the beginning and ending of the camera shutter interval.
|
||||
///
|
||||
/// Combining these concepts in an example, a primvar buffer might hold
|
||||
/// data for 10 vertices (the elements) with each vertex having a
|
||||
/// 2 entries (an array) of 4x4 matrices (with 16 components each).
|
||||
/// As a packed linear buffer, this would occupy 10*2*16==320 floats.
|
||||
///
|
||||
/// It is important to distinguish components from array entries,
|
||||
/// and arrays from elements. HdType and HdTupleType only
|
||||
/// addresses components and arrays; elements are tracked by buffers.
|
||||
/// See for example HdBufferSource::GetNumElements().
|
||||
///
|
||||
/// In other words, HdType and HdTupleType describe values.
|
||||
/// Buffers describe elements and all other details regarding buffer
|
||||
/// layout, such as offset/stride used to interleave attribute data.
|
||||
///
|
||||
/// For more background, see the OpenGL discussion on data types:
|
||||
/// - https://www.khronos.org/opengl/wiki/OpenGL_Type
|
||||
///
|
||||
enum HdType
|
||||
{
|
||||
HdTypeInvalid=-1,
|
||||
|
||||
/// Corresponds to GL_BOOL
|
||||
HdTypeBool=0,
|
||||
HdTypeUInt8,
|
||||
HdTypeUInt16,
|
||||
HdTypeInt8,
|
||||
HdTypeInt16,
|
||||
|
||||
/// Corresponds to GL_INT
|
||||
HdTypeInt32,
|
||||
/// A 2-component vector with Int32-valued components.
|
||||
HdTypeInt32Vec2,
|
||||
/// A 3-component vector with Int32-valued components.
|
||||
HdTypeInt32Vec3,
|
||||
/// A 4-component vector with Int32-valued components.
|
||||
HdTypeInt32Vec4,
|
||||
|
||||
/// An unsigned 32-bit integer. Corresponds to GL_UNSIGNED_INT.
|
||||
HdTypeUInt32,
|
||||
/// A 2-component vector with UInt32-valued components.
|
||||
HdTypeUInt32Vec2,
|
||||
/// A 3-component vector with UInt32-valued components.
|
||||
HdTypeUInt32Vec3,
|
||||
/// A 4-component vector with UInt32-valued components.
|
||||
HdTypeUInt32Vec4,
|
||||
|
||||
/// Corresponds to GL_FLOAT
|
||||
HdTypeFloat,
|
||||
/// Corresponds to GL_FLOAT_VEC2
|
||||
HdTypeFloatVec2,
|
||||
/// Corresponds to GL_FLOAT_VEC3
|
||||
HdTypeFloatVec3,
|
||||
/// Corresponds to GL_FLOAT_VEC4
|
||||
HdTypeFloatVec4,
|
||||
/// Corresponds to GL_FLOAT_MAT3
|
||||
HdTypeFloatMat3,
|
||||
/// Corresponds to GL_FLOAT_MAT4
|
||||
HdTypeFloatMat4,
|
||||
|
||||
/// Corresponds to GL_DOUBLE
|
||||
HdTypeDouble,
|
||||
/// Corresponds to GL_DOUBLE_VEC2
|
||||
HdTypeDoubleVec2,
|
||||
/// Corresponds to GL_DOUBLE_VEC3
|
||||
HdTypeDoubleVec3,
|
||||
/// Corresponds to GL_DOUBLE_VEC4
|
||||
HdTypeDoubleVec4,
|
||||
/// Corresponds to GL_DOUBLE_MAT3
|
||||
HdTypeDoubleMat3,
|
||||
/// Corresponds to GL_DOUBLE_MAT4
|
||||
HdTypeDoubleMat4,
|
||||
|
||||
HdTypeHalfFloat,
|
||||
HdTypeHalfFloatVec2,
|
||||
HdTypeHalfFloatVec3,
|
||||
HdTypeHalfFloatVec4,
|
||||
|
||||
/// Packed, reverse-order encoding of a 4-component vector into Int32.
|
||||
/// Corresponds to GL_INT_2_10_10_10_REV.
|
||||
/// \see HdVec4f_2_10_10_10_REV
|
||||
HdTypeInt32_2_10_10_10_REV,
|
||||
};
|
||||
|
||||
/// HdTupleType represents zero, one, or more values of the same HdType.
|
||||
/// It can be used to represent fixed-size array types, as well as single
|
||||
/// values. See HdType for more discussion about arrays.
|
||||
struct HdTupleType {
|
||||
HdType type;
|
||||
size_t count;
|
||||
|
||||
bool operator< (HdTupleType const& rhs) const {
|
||||
return (type < rhs.type) || (type == rhs.type && count < rhs.count);
|
||||
}
|
||||
bool operator== (HdTupleType const& rhs) const {
|
||||
return type == rhs.type && count == rhs.count;
|
||||
}
|
||||
bool operator!= (HdTupleType const& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
// Support TfHash.
|
||||
template <class HashState>
|
||||
void
|
||||
TfHashAppend(HashState &h, HdTupleType const &tt)
|
||||
{
|
||||
h.Append(tt.type, tt.count);
|
||||
}
|
||||
|
||||
/// Returns a direct pointer to the data held by a VtValue.
|
||||
/// Returns nullptr if the VtValue is empty or holds a type unknown to Hd.
|
||||
HD_API
|
||||
const void* HdGetValueData(const VtValue &);
|
||||
|
||||
/// Returns the HdTupleType that describes the given VtValue.
|
||||
/// For scalar, vector, and matrix types, the count is 1.
|
||||
/// For any VtArray type, the count is the number of array members.
|
||||
HD_API
|
||||
HdTupleType HdGetValueTupleType(const VtValue &);
|
||||
|
||||
/// Return the component type for the given value type.
|
||||
/// For vectors and matrices, this is the scalar type of their components.
|
||||
/// For scalars, this is the type itself.
|
||||
/// As an example, the component type of HdTypeFloatMat4 is HdTypeFloat.
|
||||
HD_API
|
||||
HdType HdGetComponentType(HdType);
|
||||
|
||||
/// Return the count of components in the given value type.
|
||||
/// For example, HdTypeFloatVec3 has 3 components.
|
||||
HD_API
|
||||
size_t HdGetComponentCount(HdType t);
|
||||
|
||||
/// Return the size, in bytes, of a single value of the given type.
|
||||
HD_API
|
||||
size_t HdDataSizeOfType(HdType);
|
||||
|
||||
/// Return the size, in bytes, of a value with HdTupleType.
|
||||
HD_API
|
||||
size_t HdDataSizeOfTupleType(HdTupleType);
|
||||
|
||||
/// \enum HdFormat
|
||||
///
|
||||
/// HdFormat describes the memory format of image buffers used in Hd.
|
||||
/// It's similar to HdType but with more specific associated semantics.
|
||||
///
|
||||
/// The list of supported formats is modelled after Vulkan and DXGI, though
|
||||
/// Hydra only supports a subset. Endian-ness is explicitly not captured;
|
||||
/// color data is assumed to always be RGBA.
|
||||
///
|
||||
/// For reference, see:
|
||||
/// https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#VkFormat
|
||||
enum HdFormat
|
||||
{
|
||||
HdFormatInvalid=-1,
|
||||
|
||||
// UNorm8 - a 1-byte value representing a float between 0 and 1.
|
||||
// float value = (unorm / 255.0f);
|
||||
HdFormatUNorm8=0,
|
||||
HdFormatUNorm8Vec2,
|
||||
HdFormatUNorm8Vec3,
|
||||
HdFormatUNorm8Vec4,
|
||||
|
||||
// SNorm8 - a 1-byte value representing a float between -1 and 1.
|
||||
// float value = max(snorm / 127.0f, -1.0f);
|
||||
HdFormatSNorm8,
|
||||
HdFormatSNorm8Vec2,
|
||||
HdFormatSNorm8Vec3,
|
||||
HdFormatSNorm8Vec4,
|
||||
|
||||
// Float16 - a 2-byte IEEE half-precision float.
|
||||
HdFormatFloat16,
|
||||
HdFormatFloat16Vec2,
|
||||
HdFormatFloat16Vec3,
|
||||
HdFormatFloat16Vec4,
|
||||
|
||||
// Float32 - a 4-byte IEEE float.
|
||||
HdFormatFloat32,
|
||||
HdFormatFloat32Vec2,
|
||||
HdFormatFloat32Vec3,
|
||||
HdFormatFloat32Vec4,
|
||||
|
||||
// UInt16 - a 2-byte unsigned integer
|
||||
HdFormatUInt16,
|
||||
HdFormatUInt16Vec2,
|
||||
HdFormatUInt16Vec3,
|
||||
HdFormatUInt16Vec4,
|
||||
|
||||
// Int32 - a 4-byte signed integer
|
||||
HdFormatInt32,
|
||||
HdFormatInt32Vec2,
|
||||
HdFormatInt32Vec3,
|
||||
HdFormatInt32Vec4,
|
||||
|
||||
// Depth-stencil format
|
||||
HdFormatFloat32UInt8,
|
||||
|
||||
HdFormatCount
|
||||
};
|
||||
|
||||
/// Return the single-channel version of a given format.
|
||||
HD_API
|
||||
HdFormat HdGetComponentFormat(HdFormat f);
|
||||
|
||||
/// Return the count of components in the given format.
|
||||
HD_API
|
||||
size_t HdGetComponentCount(HdFormat f);
|
||||
|
||||
/// Return the size of a single element of the given format.
|
||||
/// For block formats, this will return 0.
|
||||
HD_API
|
||||
size_t HdDataSizeOfFormat(HdFormat f);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_TYPES_H
|
||||
@@ -0,0 +1,521 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_UNIT_TEST_DELEGATE_H
|
||||
#define PXR_IMAGING_HD_UNIT_TEST_DELEGATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/material.h"
|
||||
#include "pxr/imaging/hd/sceneDelegate.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
#include "pxr/imaging/pxOsd/tokens.h"
|
||||
|
||||
#include "pxr/base/gf/vec3f.h"
|
||||
#include "pxr/base/gf/vec3d.h"
|
||||
#include "pxr/base/gf/vec4f.h"
|
||||
#include "pxr/base/gf/vec4d.h"
|
||||
#include "pxr/base/gf/matrix4f.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class HdUnitTestDelegate
|
||||
///
|
||||
/// A simple delegate class for unit test driver.
|
||||
///
|
||||
class HdUnitTestDelegate : public HdSceneDelegate {
|
||||
public:
|
||||
HD_API
|
||||
HdUnitTestDelegate(HdRenderIndex *parentIndex,
|
||||
SdfPath const& delegateID);
|
||||
|
||||
void SetUseInstancePrimvars(bool v) { _hasInstancePrimvars = v; }
|
||||
|
||||
HD_API
|
||||
void SetRefineLevel(int level);
|
||||
|
||||
HD_API
|
||||
void SetVisibility(bool vis);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
HD_API
|
||||
void AddMesh(SdfPath const& id);
|
||||
|
||||
HD_API
|
||||
void AddMesh(SdfPath const &id,
|
||||
GfMatrix4f const &transform,
|
||||
VtVec3fArray const &points,
|
||||
VtIntArray const &numVerts,
|
||||
VtIntArray const &verts,
|
||||
bool guide=false,
|
||||
SdfPath const &instancerId=SdfPath(),
|
||||
TfToken const &scheme=PxOsdOpenSubdivTokens->catmullClark,
|
||||
TfToken const &orientation=HdTokens->rightHanded,
|
||||
bool doubleSided=false);
|
||||
|
||||
HD_API
|
||||
void AddMesh(SdfPath const &id,
|
||||
GfMatrix4f const &transform,
|
||||
VtVec3fArray const &points,
|
||||
VtIntArray const &numVerts,
|
||||
VtIntArray const &verts,
|
||||
VtIntArray const &holes,
|
||||
PxOsdSubdivTags const &subdivTags,
|
||||
VtValue const &color,
|
||||
HdInterpolation colorInterpolation,
|
||||
VtValue const &opacity,
|
||||
HdInterpolation opacityInterpolation,
|
||||
bool guide=false,
|
||||
SdfPath const &instancerId=SdfPath(),
|
||||
TfToken const &scheme=PxOsdOpenSubdivTokens->catmullClark,
|
||||
TfToken const &orientation=HdTokens->rightHanded,
|
||||
bool doubleSided=false);
|
||||
|
||||
/// Add a cube
|
||||
HD_API
|
||||
void AddCube(SdfPath const &id, GfMatrix4f const &transform, bool guide=false,
|
||||
SdfPath const &instancerId=SdfPath(),
|
||||
TfToken const &scheme=PxOsdOpenSubdivTokens->catmullClark);
|
||||
|
||||
/// Add a grid with division x*y
|
||||
HD_API
|
||||
void AddGrid(SdfPath const &id, int x, int y, GfMatrix4f const &transform,
|
||||
bool rightHanded=true, bool doubleSided=false,
|
||||
SdfPath const &instancerId=SdfPath());
|
||||
|
||||
/// Add a grid with division x*y
|
||||
HD_API
|
||||
void AddGridWithFaceColor(SdfPath const &id, int x, int y,
|
||||
GfMatrix4f const &transform,
|
||||
bool rightHanded=true, bool doubleSided=false,
|
||||
SdfPath const &instancerId=SdfPath());
|
||||
|
||||
/// Add a grid with division x*y
|
||||
HD_API
|
||||
void AddGridWithVertexColor(SdfPath const &id, int x, int y,
|
||||
GfMatrix4f const &transform,
|
||||
bool rightHanded=true, bool doubleSided=false,
|
||||
SdfPath const &instancerId=SdfPath());
|
||||
|
||||
/// Add a grid with division x*y
|
||||
HD_API
|
||||
void AddGridWithFaceVaryingColor(SdfPath const &id, int x, int y,
|
||||
GfMatrix4f const &transform,
|
||||
bool rightHanded=true, bool doubleSided=false,
|
||||
SdfPath const &instancerId=SdfPath());
|
||||
|
||||
// Add a grid with division x*y and a custom color
|
||||
HD_API
|
||||
void AddGridWithCustomColor(SdfPath const &id, int nx, int ny,
|
||||
GfMatrix4f const &transform,
|
||||
VtValue const &color,
|
||||
HdInterpolation colorInterpolation,
|
||||
bool rightHanded=true, bool doubleSided=false,
|
||||
SdfPath const &instancerId=SdfPath());
|
||||
|
||||
/// Add a triangle, quad and pentagon.
|
||||
HD_API
|
||||
void AddPolygons(SdfPath const &id, GfMatrix4f const &transform,
|
||||
HdInterpolation colorInterp,
|
||||
SdfPath const &instancerId=SdfPath());
|
||||
|
||||
/// Add a subdiv with various tags
|
||||
HD_API
|
||||
void AddSubdiv(SdfPath const &id, GfMatrix4f const &transform,
|
||||
SdfPath const &insatancerId=SdfPath());
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
HD_API
|
||||
void AddBasisCurves(SdfPath const &id,
|
||||
VtVec3fArray const &points,
|
||||
VtIntArray const &curveVertexCounts,
|
||||
VtVec3fArray const &normals,
|
||||
TfToken const &type,
|
||||
TfToken const &basis,
|
||||
VtValue const &color,
|
||||
HdInterpolation colorInterpolation,
|
||||
VtValue const &opacity,
|
||||
HdInterpolation opacityInterpolation,
|
||||
VtValue const &width,
|
||||
HdInterpolation widthInterpolation,
|
||||
SdfPath const &instancerId=SdfPath());
|
||||
|
||||
/// Add a basis curves prim containing two curves
|
||||
HD_API
|
||||
void AddCurves(SdfPath const &id, TfToken const &type, TfToken const &basis,
|
||||
GfMatrix4f const &transform,
|
||||
HdInterpolation colorInterp=HdInterpolationConstant,
|
||||
HdInterpolation widthInterp=HdInterpolationConstant,
|
||||
bool authoredNormals=false,
|
||||
SdfPath const &instancerId=SdfPath());
|
||||
|
||||
HD_API
|
||||
void AddPoints(SdfPath const &id,
|
||||
VtVec3fArray const &points,
|
||||
VtValue const &color,
|
||||
HdInterpolation colorInterpolation,
|
||||
VtValue const &opacity,
|
||||
HdInterpolation opacityInterpolation,
|
||||
VtValue const &width,
|
||||
HdInterpolation widthInterpolation,
|
||||
SdfPath const &instancerId=SdfPath());
|
||||
|
||||
/// Add a points prim
|
||||
HD_API
|
||||
void AddPoints(SdfPath const &id,
|
||||
GfMatrix4f const &transform,
|
||||
HdInterpolation colorInterp=HdInterpolationConstant,
|
||||
HdInterpolation widthInterp=HdInterpolationConstant,
|
||||
SdfPath const &instancerId=SdfPath());
|
||||
|
||||
/// Instancer
|
||||
HD_API
|
||||
void AddInstancer(SdfPath const &id,
|
||||
SdfPath const &parentId=SdfPath(),
|
||||
GfMatrix4f const &rootTransform=GfMatrix4f(1));
|
||||
|
||||
HD_API
|
||||
void SetInstancerProperties(SdfPath const &id,
|
||||
VtIntArray const &prototypeIndex,
|
||||
VtVec3fArray const &scale,
|
||||
VtVec4fArray const &rotate,
|
||||
VtVec3fArray const &translate);
|
||||
|
||||
HD_API
|
||||
void UpdateInstancer(SdfPath const& rprimId, SdfPath const& instancerId);
|
||||
|
||||
/// Primvars
|
||||
HD_API
|
||||
void AddPrimvar(SdfPath const& id,
|
||||
TfToken const& name,
|
||||
VtValue const& value,
|
||||
HdInterpolation const& interp,
|
||||
TfToken const& role);
|
||||
|
||||
HD_API
|
||||
void UpdatePrimvarValue(SdfPath const& id,
|
||||
TfToken const& name,
|
||||
VtValue const& value);
|
||||
|
||||
HD_API
|
||||
void RemovePrimvar(SdfPath const& id, TfToken const& name);
|
||||
|
||||
/// Transform
|
||||
HD_API
|
||||
void UpdateTransform(SdfPath const& id, GfMatrix4f const& mat);
|
||||
|
||||
/// Material
|
||||
HD_API
|
||||
void AddMaterialResource(SdfPath const &id,
|
||||
VtValue materialResource);
|
||||
|
||||
/// Update a material resource
|
||||
HD_API
|
||||
void UpdateMaterialResource(SdfPath const &materialId,
|
||||
VtValue materialResource);
|
||||
|
||||
HD_API
|
||||
void BindMaterial(SdfPath const &rprimId, SdfPath const &materialId);
|
||||
|
||||
/// Example to update a material binding on the fly
|
||||
HD_API
|
||||
void RebindMaterial(SdfPath const &rprimId, SdfPath const &materialId);
|
||||
|
||||
/// Render buffers
|
||||
HD_API
|
||||
void AddRenderBuffer(SdfPath const &id, GfVec3i const& dims,
|
||||
HdFormat format, bool multiSampled);
|
||||
|
||||
/// Camera
|
||||
HD_API
|
||||
void AddCamera(SdfPath const &id);
|
||||
HD_API
|
||||
void UpdateCamera(SdfPath const &id, TfToken const &key, VtValue value);
|
||||
|
||||
/// Tasks
|
||||
template<typename T>
|
||||
void AddTask(SdfPath const &id) {
|
||||
GetRenderIndex().InsertTask<T>(this, id);
|
||||
_tasks[id] = _Task();
|
||||
}
|
||||
HD_API
|
||||
void UpdateTask(SdfPath const &id, TfToken const &key, VtValue value);
|
||||
|
||||
/// Remove a prim
|
||||
HD_API
|
||||
void Remove(SdfPath const &id);
|
||||
|
||||
/// Clear all prims
|
||||
HD_API
|
||||
void Clear();
|
||||
|
||||
// Hides an rprim, invalidating all collections it was in.
|
||||
HD_API
|
||||
void HideRprim(SdfPath const &id);
|
||||
|
||||
// Un-hides an rprim, invalidating all collections it was in.
|
||||
HD_API
|
||||
void UnhideRprim(SdfPath const &id);
|
||||
|
||||
// set per-prim repr
|
||||
HD_API
|
||||
void SetReprSelector(SdfPath const &id, HdReprSelector const &reprSelector);
|
||||
|
||||
// set per-prim refine level
|
||||
HD_API
|
||||
void SetRefineLevel(SdfPath const &id, int refineLevel);
|
||||
|
||||
// set per-prim visibility
|
||||
HD_API
|
||||
void SetVisibility(SdfPath const &id, bool vis);
|
||||
|
||||
/// Marks an rprim in the RenderIndex as dirty with the given dirty flags.
|
||||
HD_API
|
||||
void MarkRprimDirty(SdfPath path, HdDirtyBits flag);
|
||||
|
||||
HD_API
|
||||
void UpdatePositions(SdfPath const &id, float time);
|
||||
HD_API
|
||||
void UpdateRprims(float time);
|
||||
HD_API
|
||||
void UpdateInstancerPrimvars(float time);
|
||||
HD_API
|
||||
void UpdateInstancerPrototypes(float time);
|
||||
HD_API
|
||||
void UpdateCurvePrimvarsInterpMode(float time);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// utility functions generating test case
|
||||
// ---------------------------------------------------------------------- //
|
||||
HD_API
|
||||
GfVec3f PopulateBasicTestSet();
|
||||
HD_API
|
||||
GfVec3f PopulateInvalidPrimsSet();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// See HdSceneDelegate for documentation of virtual methods.
|
||||
// ---------------------------------------------------------------------- //
|
||||
HD_API
|
||||
virtual HdMeshTopology GetMeshTopology(SdfPath const& id) override;
|
||||
HD_API
|
||||
virtual HdBasisCurvesTopology GetBasisCurvesTopology(SdfPath const& id)
|
||||
override;
|
||||
HD_API
|
||||
virtual TfToken GetRenderTag(SdfPath const& id) override;
|
||||
HD_API
|
||||
virtual PxOsdSubdivTags GetSubdivTags(SdfPath const& id) override;
|
||||
HD_API
|
||||
virtual GfRange3d GetExtent(SdfPath const & id) override;
|
||||
HD_API
|
||||
virtual GfMatrix4d GetTransform(SdfPath const & id) override;
|
||||
HD_API
|
||||
virtual bool GetVisible(SdfPath const & id) override;
|
||||
HD_API
|
||||
virtual bool GetDoubleSided(SdfPath const & id) override;
|
||||
HD_API
|
||||
virtual HdDisplayStyle GetDisplayStyle(SdfPath const & id) override;
|
||||
HD_API
|
||||
virtual VtValue Get(SdfPath const& id, TfToken const& key) override;
|
||||
HD_API
|
||||
virtual HdReprSelector GetReprSelector(SdfPath const &id) override;
|
||||
HD_API
|
||||
virtual HdPrimvarDescriptorVector
|
||||
GetPrimvarDescriptors(SdfPath const& id,
|
||||
HdInterpolation interpolation) override;
|
||||
|
||||
HD_API
|
||||
virtual VtIntArray GetInstanceIndices(SdfPath const& instancerId,
|
||||
SdfPath const& prototypeId) override;
|
||||
|
||||
HD_API
|
||||
virtual GfMatrix4d GetInstancerTransform(SdfPath const& instancerId)
|
||||
override;
|
||||
|
||||
HD_API
|
||||
virtual SdfPath GetMaterialId(SdfPath const& rprimId) override;
|
||||
|
||||
HD_API
|
||||
virtual SdfPath GetInstancerId(SdfPath const& primId) override;
|
||||
|
||||
HD_API
|
||||
virtual VtValue GetMaterialResource(SdfPath const &materialId) override;
|
||||
|
||||
HD_API
|
||||
virtual VtValue GetCameraParamValue(SdfPath const &cameraId,
|
||||
TfToken const ¶mName) override;
|
||||
|
||||
HD_API
|
||||
virtual HdRenderBufferDescriptor GetRenderBufferDescriptor(
|
||||
SdfPath const& id) override;
|
||||
|
||||
private:
|
||||
// ---------------------------------------------------------------------- //
|
||||
// private utility methods
|
||||
// ---------------------------------------------------------------------- //
|
||||
VtValue _GetPrimvarValue(SdfPath const& id, TfToken const& name);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// internal types
|
||||
// ---------------------------------------------------------------------- //
|
||||
struct _Mesh {
|
||||
_Mesh() { }
|
||||
_Mesh(TfToken const &scheme,
|
||||
TfToken const &orientation,
|
||||
GfMatrix4f const &transform,
|
||||
VtVec3fArray const &points,
|
||||
VtIntArray const &numVerts,
|
||||
VtIntArray const &verts,
|
||||
VtIntArray const &holes,
|
||||
PxOsdSubdivTags const &subdivTags,
|
||||
bool guide,
|
||||
bool doubleSided) :
|
||||
scheme(scheme), orientation(orientation),
|
||||
transform(transform),
|
||||
points(points), numVerts(numVerts), verts(verts),
|
||||
holes(holes), subdivTags(subdivTags), guide(guide),
|
||||
doubleSided(doubleSided) { }
|
||||
|
||||
TfToken scheme;
|
||||
TfToken orientation;
|
||||
GfMatrix4f transform;
|
||||
VtVec3fArray points;
|
||||
VtIntArray numVerts;
|
||||
VtIntArray verts;
|
||||
VtIntArray holes;
|
||||
PxOsdSubdivTags subdivTags;
|
||||
bool guide;
|
||||
bool doubleSided;
|
||||
HdReprSelector reprSelector;
|
||||
};
|
||||
struct _Curves {
|
||||
_Curves() { }
|
||||
_Curves(VtVec3fArray const &points,
|
||||
VtIntArray const &curveVertexCounts,
|
||||
TfToken const &type,
|
||||
TfToken const &basis) :
|
||||
points(points), curveVertexCounts(curveVertexCounts),
|
||||
type(type), basis(basis) { }
|
||||
|
||||
VtVec3fArray points;
|
||||
VtIntArray curveVertexCounts;
|
||||
TfToken type;
|
||||
TfToken basis;
|
||||
};
|
||||
struct _Points {
|
||||
_Points() { }
|
||||
_Points(VtVec3fArray const &points) : points(points) { }
|
||||
|
||||
VtVec3fArray points;
|
||||
};
|
||||
struct _Instancer {
|
||||
_Instancer() { }
|
||||
_Instancer(VtVec3fArray const &scale,
|
||||
VtVec4fArray const &rotate,
|
||||
VtVec3fArray const &translate,
|
||||
GfMatrix4f const &rootTransform) :
|
||||
scale(scale), rotate(rotate), translate(translate),
|
||||
rootTransform(rootTransform) {
|
||||
}
|
||||
VtVec3fArray scale;
|
||||
VtVec4fArray rotate;
|
||||
VtVec3fArray translate;
|
||||
VtIntArray prototypeIndices;
|
||||
GfMatrix4f rootTransform;
|
||||
|
||||
std::vector<SdfPath> prototypes;
|
||||
};
|
||||
struct _Primvar {
|
||||
_Primvar() {}
|
||||
_Primvar(TfToken const& _name,
|
||||
VtValue const& _value,
|
||||
HdInterpolation const& _interp,
|
||||
TfToken const& _role) :
|
||||
name(_name),
|
||||
value(_value),
|
||||
interp(_interp),
|
||||
role(_role) {}
|
||||
|
||||
TfToken name;
|
||||
VtValue value;
|
||||
HdInterpolation interp;
|
||||
TfToken role;
|
||||
};
|
||||
using _Primvars = std::vector<_Primvar>;
|
||||
// Given an rprim id and primvar name, looks up the primvars map (see below)
|
||||
// and returns true with the iterator to the entry if it was found.
|
||||
bool _FindPrimvar(SdfPath const& id,
|
||||
TfToken const& name,
|
||||
_Primvars::iterator *pvIt);
|
||||
|
||||
struct _Camera {
|
||||
VtDictionary params;
|
||||
};
|
||||
struct _Light {
|
||||
VtDictionary params;
|
||||
};
|
||||
struct _Task {
|
||||
VtDictionary params;
|
||||
};
|
||||
struct _RenderBuffer {
|
||||
_RenderBuffer() {}
|
||||
_RenderBuffer(GfVec3i const &d, HdFormat f, bool ms)
|
||||
: dims(d), format(f), multiSampled(ms) {}
|
||||
GfVec3i dims;
|
||||
HdFormat format;
|
||||
bool multiSampled;
|
||||
};
|
||||
|
||||
std::map<SdfPath, _Mesh> _meshes;
|
||||
std::map<SdfPath, _Curves> _curves;
|
||||
std::map<SdfPath, _Points> _points;
|
||||
std::map<SdfPath, _Instancer> _instancers;
|
||||
std::map<SdfPath, _Primvars> _primvars;
|
||||
std::map<SdfPath, VtValue> _materials;
|
||||
std::map<SdfPath, _Camera> _cameras;
|
||||
std::map<SdfPath, _RenderBuffer> _renderBuffers;
|
||||
std::map<SdfPath, _Light> _lights;
|
||||
std::map<SdfPath, _Task> _tasks;
|
||||
TfHashSet<SdfPath, SdfPath::Hash> _hiddenRprims;
|
||||
|
||||
typedef std::map<SdfPath, SdfPath> SdfPathMap;
|
||||
SdfPathMap _materialBindings;
|
||||
SdfPathMap _instancerBindings;
|
||||
|
||||
bool _hasInstancePrimvars;
|
||||
int _refineLevel;
|
||||
bool _visibility;
|
||||
std::map<SdfPath, int> _refineLevels;
|
||||
std::map<SdfPath, bool> _visibilities;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_UNIT_TEST_DELEGATE_H
|
||||
Loaded 100 of 15675 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user