add usd-21-11-win64_py39

This commit is contained in:
Sébastien Albert committed 2021-12-07 17:43:55 +01:00
1 parent 41d23e71ba
commit ba5e1f7e67
15684 files changed
+3069957

No files matched your search

+47
View File
@@ -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
+138
View File
@@ -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
+47
View File
@@ -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
+32
View File
@@ -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
+97
View File
@@ -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
+290
View File
@@ -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_ */
+47
View File
@@ -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
+139
View File
@@ -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
+128
View File
@@ -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
+173
View File
@@ -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
+305
View File
@@ -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
+360
View File
@@ -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
+80
View File
@@ -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
+45
View File
@@ -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
+240
View File
@@ -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
+84
View File
@@ -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
+179
View File
@@ -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
+176
View File
@@ -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
+80
View File
@@ -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
+78
View File
@@ -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
+186
View File
@@ -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
+47
View File
@@ -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
+124
View File
@@ -0,0 +1,124 @@
//
// 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) \
(surfaceShaderUnlit) \
(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
+136
View File
@@ -0,0 +1,136 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_BASIS_CURVES_SCHEMA_H
#define PXR_IMAGING_HD_BASIS_CURVES_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/basisCurvesTopologySchema.h"
#include "pxr/imaging/hd/geomSubsetsSchema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDBASISCURVES_SCHEMA_TOKENS \
(basisCurves) \
(topology) \
(geomSubsets) \
TF_DECLARE_PUBLIC_TOKENS(HdBasisCurvesSchemaTokens, HD_API,
HDBASISCURVES_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdBasisCurvesSchema : public HdSchema
{
public:
HdBasisCurvesSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdBasisCurvesTopologySchema GetTopology();
HD_API
HdGeomSubsetsSchema GetGeomSubsets();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdContainerDataSourceHandle &topology,
const HdContainerDataSourceHandle &geomSubsets
);
/// \class HdBasisCurvesSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetTopology(
const HdContainerDataSourceHandle &topology);
HD_API
Builder &SetGeomSubsets(
const HdContainerDataSourceHandle &geomSubsets);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdContainerDataSourceHandle _topology;
HdContainerDataSourceHandle _geomSubsets;
};
/// Retrieves a container data source with the schema's default name token
/// "basisCurves" from the parent container and constructs a
/// HdBasisCurvesSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdBasisCurvesSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the topology data source can be found.
/// This is often useful for checking intersection against the
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
HD_API
static const HdDataSourceLocator &GetTopologyLocator();
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the geomsubsets data source can be found.
/// This is often useful for checking intersection against the
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
HD_API
static const HdDataSourceLocator &GetGeomSubsetsLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -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_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();
}
/// Returns the number of points implied by vertex counts and indices
HD_API
size_t GetNumPoints() const {
return _numPoints;
}
/// 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;
size_t _numPoints;
};
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,143 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_BASIS_CURVES_TOPOLOGY_SCHEMA_H
#define PXR_IMAGING_HD_BASIS_CURVES_TOPOLOGY_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDBASISCURVESTOPOLOGY_SCHEMA_TOKENS \
(topology) \
(curveVertexCounts) \
(curveIndices) \
(basis) \
(type) \
(wrap) \
TF_DECLARE_PUBLIC_TOKENS(HdBasisCurvesTopologySchemaTokens, HD_API,
HDBASISCURVESTOPOLOGY_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdBasisCurvesTopologySchema : public HdSchema
{
public:
HdBasisCurvesTopologySchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdIntArrayDataSourceHandle GetCurveVertexCounts();
HD_API
HdIntArrayDataSourceHandle GetCurveIndices();
HD_API
HdTokenDataSourceHandle GetBasis();
HD_API
HdTokenDataSourceHandle GetType();
HD_API
HdTokenDataSourceHandle GetWrap();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdIntArrayDataSourceHandle &curveVertexCounts,
const HdIntArrayDataSourceHandle &curveIndices,
const HdTokenDataSourceHandle &basis,
const HdTokenDataSourceHandle &type,
const HdTokenDataSourceHandle &wrap
);
/// \class HdBasisCurvesTopologySchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetCurveVertexCounts(
const HdIntArrayDataSourceHandle &curveVertexCounts);
HD_API
Builder &SetCurveIndices(
const HdIntArrayDataSourceHandle &curveIndices);
HD_API
Builder &SetBasis(
const HdTokenDataSourceHandle &basis);
HD_API
Builder &SetType(
const HdTokenDataSourceHandle &type);
HD_API
Builder &SetWrap(
const HdTokenDataSourceHandle &wrap);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdIntArrayDataSourceHandle _curveVertexCounts;
HdIntArrayDataSourceHandle _curveIndices;
HdTokenDataSourceHandle _basis;
HdTokenDataSourceHandle _type;
HdTokenDataSourceHandle _wrap;
};
/// Retrieves a container data source with the schema's default name token
/// "topology" from the parent container and constructs a
/// HdBasisCurvesTopologySchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdBasisCurvesTopologySchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+303
View File
@@ -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
+97
View File
@@ -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
+207
View File
@@ -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
+172
View File
@@ -0,0 +1,172 @@
//
// 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;
/// Returns true if this needs a staging buffer for CPU to GPU copies.
virtual bool RequiresStaging() 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
+81
View File
@@ -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
+257
View File
@@ -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
+130
View File
@@ -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
+263
View File
@@ -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
+170
View File
@@ -0,0 +1,170 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_CAMERA_SCHEMA_H
#define PXR_IMAGING_HD_CAMERA_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDCAMERA_SCHEMA_TOKENS \
(camera) \
(projection) \
(horizontalAperture) \
(verticalAperture) \
(horizontalApertureOffset) \
(verticalApertureOffset) \
(focalLength) \
(clippingRange) \
(perspective) \
(orthographic) \
TF_DECLARE_PUBLIC_TOKENS(HdCameraSchemaTokens, HD_API,
HDCAMERA_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdCameraSchema : public HdSchema
{
public:
HdCameraSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdTokenDataSourceHandle GetProjection();
HD_API
HdFloatDataSourceHandle GetHorizontalAperture();
HD_API
HdFloatDataSourceHandle GetVerticalAperture();
HD_API
HdFloatDataSourceHandle GetHorizontalApertureOffset();
HD_API
HdFloatDataSourceHandle GetVerticalApertureOffset();
HD_API
HdFloatDataSourceHandle GetFocalLength();
HD_API
HdVec2fDataSourceHandle GetClippingRange();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdTokenDataSourceHandle &projection,
const HdFloatDataSourceHandle &horizontalAperture,
const HdFloatDataSourceHandle &verticalAperture,
const HdFloatDataSourceHandle &horizontalApertureOffset,
const HdFloatDataSourceHandle &verticalApertureOffset,
const HdFloatDataSourceHandle &focalLength,
const HdVec2fDataSourceHandle &clippingRange
);
/// \class HdCameraSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetProjection(
const HdTokenDataSourceHandle &projection);
HD_API
Builder &SetHorizontalAperture(
const HdFloatDataSourceHandle &horizontalAperture);
HD_API
Builder &SetVerticalAperture(
const HdFloatDataSourceHandle &verticalAperture);
HD_API
Builder &SetHorizontalApertureOffset(
const HdFloatDataSourceHandle &horizontalApertureOffset);
HD_API
Builder &SetVerticalApertureOffset(
const HdFloatDataSourceHandle &verticalApertureOffset);
HD_API
Builder &SetFocalLength(
const HdFloatDataSourceHandle &focalLength);
HD_API
Builder &SetClippingRange(
const HdVec2fDataSourceHandle &clippingRange);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdTokenDataSourceHandle _projection;
HdFloatDataSourceHandle _horizontalAperture;
HdFloatDataSourceHandle _verticalAperture;
HdFloatDataSourceHandle _horizontalApertureOffset;
HdFloatDataSourceHandle _verticalApertureOffset;
HdFloatDataSourceHandle _focalLength;
HdVec2fDataSourceHandle _clippingRange;
};
/// Retrieves a container data source with the schema's default name token
/// "camera" from the parent container and constructs a
/// HdCameraSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdCameraSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
/// Returns token data source for use as projection value.
/// Values of...
/// - HdCameraSchemaTokens->perspective
/// - HdCameraSchemaTokens->orthographic
/// ...will be stored statically and reused for future calls.
HD_API
static HdTokenDataSourceHandle BuildProjectionDataSource(
const TfToken &projection);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+81
View File
@@ -0,0 +1,81 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_CATEGORIES_SCHEMA_H
#define PXR_IMAGING_HD_CATEGORIES_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDCATEGORIES_SCHEMA_TOKENS \
(categories) \
TF_DECLARE_PUBLIC_TOKENS(HdCategoriesSchemaTokens, HD_API,
HDCATEGORIES_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdCategoriesSchema : public HdSchema
{
public:
HdCategoriesSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
VtArray<TfToken> GetIncludedCategoryNames();
bool IsIncludedInCategory(const TfToken &categoryName);
static HdContainerDataSourceHandle BuildRetained(
size_t includedNameCount,
TfToken *includedNames,
size_t excludedNameCount,
TfToken *excludedNames);
/// Retrieves a container data source with the schema's default name token
/// "categories" from the parent container and constructs a
/// HdCategoriesSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdCategoriesSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+674
View File
@@ -0,0 +1,674 @@
//
// 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 HdRetainedSceneIndex;
/// \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,
CustomBitsMask = 0x7f << 24,
};
// 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 help build a stable dirty list 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 varying flag is set.
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);
/// Retrieve the current version number of the rprim render tag set
/// XXX Rename to GetRprimRenderTagVersion
HD_API
unsigned GetRenderTagVersion() const;
/// Retrieve the current version number of the task's render tags opinion.
HD_API
unsigned GetTaskRenderTagsVersion() 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);
/// Insert a dependency between \p sprimId and parent sprim
/// \p parentSprimId.
HD_API
void AddSprimSprimDependency(SdfPath const& parentSprimId,
SdfPath const& sprimId);
/// Remove a dependency between \p sprimId and parent sprim
/// \p parentSprimId.
HD_API
void RemoveSprimSprimDependency(SdfPath const& parentSprimId,
SdfPath const& sprimId);
/// Remove all dependencies involving \p sprimId as a parent or child.
HD_API
void RemoveSprimFromSprimSprimDependencies(SdfPath const& sprimId);
// ---------------------------------------------------------------------- //
/// @}
/// \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;
// Provides forward and reverse-association between sprims and the child
// sprims that reference them. For example, a light prim (child) who needs
// to know when its light filter (parent) is modified.
// Maps parent sprim to child sprim.
_DependencyMap _sprimSprimTargetDependencies;
// Maps child sprim to parent sprim.
_DependencyMap _sprimSprimSourceDependencies;
// 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 render tag opinion of rprims.
unsigned _rprimRenderTagVersion;
// Used to detect changes to the render tags opinion of tasks.
unsigned _taskRenderTagsVersion;
// Allow HdRenderIndex to provide a scene index to forward dirty
// information. This is necessary to accommodate legacy HdSceneDelegate
// based applications that rely on the HdChangeTracker for invalidating
// state on Hydra prims.
friend class HdRenderIndex;
// Does not take ownership. The HdRenderIndex manages the lifetime of this
// scene index.
HdRetainedSceneIndex * _emulationSceneIndex;
void _SetTargetSceneIndex(HdRetainedSceneIndex *emulationSceneIndex);
// Private methods which implement the behaviors of their public
// equivalents. The public versions check to see if legacy emulation is
// active. If so, they dirty the HdRetainedSceneIndex member instead
// of directly acting. If legacy render delegate emulation is active, these
// will eventually make their way back to the private methods via
// HdSceneIndexAdapterSceneDelegate. This prevents dirtying cycles while
// allowing single HdRenderIndex/HdChangeTracker instances to be used for
// both ends of emulation.
friend class HdSceneIndexAdapterSceneDelegate;
void _MarkRprimDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
void _MarkSprimDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
void _MarkBprimDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
void _MarkInstancerDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HD_CHANGE_TRACKER_H
+113
View File
@@ -0,0 +1,113 @@
//
// Copyright 2021 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_COMMAND_H
#define PXR_IMAGING_HD_COMMAND_H
#include "pxr/pxr.h"
#include "pxr/imaging/hd/api.h"
#include "pxr/base/vt/dictionary.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/tf/token.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdCommandArgDescriptor
///
/// A bundle of state describing an argument to a command. See \c
/// HdCommandDescriptor for more information about commands.
///
struct HdCommandArgDescriptor
{
HdCommandArgDescriptor();
HdCommandArgDescriptor(const TfToken &argName,
const VtValue &defaultValue_)
: argName(argName)
, defaultValue(defaultValue_)
{}
///
/// The name of the argument
///
const TfToken argName;
///
/// Default value for this argument
///
const VtValue defaultValue;
};
using HdCommandArgDescriptors = std::vector<HdCommandArgDescriptor>;
///
/// Command arguments are a map of tokens to values
///
using HdCommandArgs = VtDictionary;
/// \class HdCommandDescriptor
///
/// A bundle of state describing a "command". A command is simply a token
/// that can be invoked and delivered to the render delegate.
///
struct HdCommandDescriptor
{
HdCommandDescriptor();
explicit HdCommandDescriptor(
const TfToken &name_,
const std::string &description_="",
const HdCommandArgDescriptors &args_=HdCommandArgDescriptors())
: commandName(name_)
, commandDescription(description_)
, commandArgs(args_)
{}
///
/// A token representing a command that can be invoked.
///
const TfToken commandName;
///
/// A description of the command suitable for display in a UI for example.
///
const std::string commandDescription;
///
/// List of arguments this command supports, may be empty.
///
const HdCommandArgDescriptors commandArgs;
};
using HdCommandDescriptors = std::vector<HdCommandDescriptor>;
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HD_COMMAND_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
+85
View File
@@ -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
+90
View File
@@ -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,81 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_COORD_SYS_BINDING_SCHEMA_H
#define PXR_IMAGING_HD_COORD_SYS_BINDING_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDCOORDSYSBINDING_SCHEMA_TOKENS \
(coordSysBinding) \
TF_DECLARE_PUBLIC_TOKENS(HdCoordSysBindingSchemaTokens, HD_API,
HDCOORDSYSBINDING_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdCoordSysBindingSchema : public HdSchema
{
public:
HdCoordSysBindingSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
HD_API
static HdContainerDataSourceHandle
BuildRetained(
size_t count,
TfToken *names,
HdDataSourceBaseHandle *values);
HdPathDataSourceHandle GetCoordSysBinding(TfToken const &name);
/// Retrieves a container data source with the schema's default name token
/// "coordSysBinding" from the parent container and constructs a
/// HdCoordSysBindingSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdCoordSysBindingSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+243
View File
@@ -0,0 +1,243 @@
//
// Copyright 2021 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_DATASOURCE_H
#define PXR_IMAGING_HD_DATASOURCE_H
#include "pxr/pxr.h"
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/dataSourceLocator.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/vt/value.h"
#include <iosfwd>
#include <memory>
#include <vector>
#include <atomic>
PXR_NAMESPACE_OPEN_SCOPE
/// HD_DECLARE_DATASOURCE_ABSTRACT
/// Used for non-instantiable classes, this defines a set of functions
/// for manipulating handles to this type of datasource.
#define HD_DECLARE_DATASOURCE_ABSTRACT(type) \
using Handle = std::shared_ptr<type>; \
using AtomicHandle = Handle; \
static Handle AtomicLoad(AtomicHandle &ptr) { \
return std::atomic_load(&ptr); \
} \
static void AtomicStore(AtomicHandle &ptr, Handle &v) { \
std::atomic_store(&ptr, v); \
} \
static Handle Cast(const HdDataSourceBase::Handle &v) { \
return std::dynamic_pointer_cast<type>(v); \
}
/// HD_DECLARE_DATASOURCE
/// Used for instantiable classes, this defines functions for manipulating
/// and allocating handles to this type of datasource.
///
/// Use of this macro in derived classes is important to make sure that
/// core and client code share the same handle type and allocator.
#define HD_DECLARE_DATASOURCE(type) \
HD_DECLARE_DATASOURCE_ABSTRACT(type) \
template <typename ... Args> \
static Handle New(Args&& ... args) { \
return Handle(new type(std::forward<Args>(args) ... )); \
}
#define HD_DECLARE_DATASOURCE_HANDLES(type) \
using type##Handle = type::Handle; \
using type##AtomicHandle = type::AtomicHandle;
/// \class HdDataSourceBase
///
/// Represents an object which can produce scene data.
/// \sa HdContainerDataSource HdVectorDataSource HdSampledDataSource
/// Note that most derived classes will have standard API for allocation
/// and handle manipulation. Derived classes that don't support instantiation
/// should use HD_DECLARE_DATASOURCE_ABSTRACT, which omits the
/// definition of ::New().
///
class HdDataSourceBase
{
public:
HD_DECLARE_DATASOURCE_ABSTRACT(HdDataSourceBase)
HD_API
virtual ~HdDataSourceBase() = 0;
};
HD_DECLARE_DATASOURCE_HANDLES(HdDataSourceBase);
/// \class HdContainerDataSource
///
/// A datasource representing structured (named, hierarchical) data, for
/// example a geometric primitive or a sub-object like a material definition.
/// Note that implementations are responsible for providing cache invalidation,
/// if necessary.
///
class HdContainerDataSource : public HdDataSourceBase
{
public:
HD_DECLARE_DATASOURCE_ABSTRACT(HdContainerDataSource);
/// Returns \c true if the container has a child datasource of the given
/// name, in which case \p Get(name) is expected to be non-null. This call
/// is expected to be threadsafe.
virtual bool Has(const TfToken &name) = 0;
/// Returns the list of names for which \p Get(...) is expected to return
/// a non-null value. This call is expected to be threadsafe.
virtual TfTokenVector GetNames() = 0;
/// Returns the child datasource of the given name. This call is expected
/// to be threadsafe.
virtual HdDataSourceBaseHandle Get(const TfToken &name) = 0;
/// A convenience function: given \p container, return the descendant
/// identified by \p locator, which may be at any depth. Returns
/// \p container itself on an empty locator, or null if \p locator doesn't
/// identify a valid descendant.
HD_API
static HdDataSourceBaseHandle Get(
const Handle &container,
const HdDataSourceLocator &locator);
};
HD_DECLARE_DATASOURCE_HANDLES(HdContainerDataSource);
/// \class HdVectorDataSource
///
/// A datasource representing indexed data. This should be used when a scene
/// index is expected to manipulate the indexing; for array-valued data, a
/// \p HdSampledDataSource can be used instead. Note that implementations are
/// responsible for providing cache invalidation, if necessary.
///
class HdVectorDataSource : public HdDataSourceBase
{
public:
HD_DECLARE_DATASOURCE_ABSTRACT(HdVectorDataSource);
/// Return the number of elements in this datasource. This call is
/// expected to be threadsafe.
virtual size_t GetNumElements() = 0;
/// Return the element at position \p element in this datasource. This
/// is expected to return non-null for the range [0, \p numElements).
/// This call is expected to be threadsafe.
virtual HdDataSourceBaseHandle GetElement(size_t element) = 0;
};
HD_DECLARE_DATASOURCE_HANDLES(HdVectorDataSource);
/// \class HdSampledDataSource
///
/// A datasource representing time-sampled values. Note that implementations
/// are responsible for providing cache invalidation, if necessary.
///
class HdSampledDataSource : public HdDataSourceBase
{
public:
HD_DECLARE_DATASOURCE_ABSTRACT(HdSampledDataSource);
using Time = float;
/// Returns the value of this data source at frame-relative time
/// \p shutterOffset. The caller does not track the frame; the scene
/// index producing this datasource is responsible for that, if applicable.
/// Note that, although this call returns a VtValue for each shutter
/// offset, the type of the held value is expected to be the same across
/// all shutter offsets. This call is expected to be threadsafe.
virtual VtValue GetValue(Time shutterOffset) = 0;
/// Given a shutter window of interest (\p startTime and \p endTime
/// relative to the current frame), return a list of sample times for the
/// caller to query with GetValue such that the caller can reconstruct the
/// signal over the shutter window. For a sample-based attribute, this
/// might be a list of times when samples are defined. For a procedural
/// scene, this might be a generated distribution. Note that the returned
/// samples don't need to be within \p startTime and \p endTime; if
/// a boundary sample is outside of the window, implementers can return it,
/// and callers should expect it and interpolate to \p startTime or
/// \p endTime accordingly. If this call returns \p true, the caller is
/// expected to pass the list of \p outSampleTimes to \p GetValue. If this
/// call returns \p false, this value is uniform across the shutter window
/// and the caller should call \p GetValue(0) to get that uniform value.
virtual bool GetContributingSampleTimesForInterval(
Time startTime,
Time endTime,
std::vector<Time> * outSampleTimes) = 0;
};
HD_DECLARE_DATASOURCE_HANDLES(HdSampledDataSource);
/// \class HdTypedSampledDataSource
///
/// A datasource representing a concretely-typed sampled value.
///
template <typename T>
class HdTypedSampledDataSource : public HdSampledDataSource
{
public:
HD_DECLARE_DATASOURCE_ABSTRACT(HdTypedSampledDataSource<T>);
using Type = T;
/// Returns the value of this data source at frame-relative time
/// \p shutterOffset, as type \p T.
virtual T GetTypedValue(Time shutterOffset) = 0;
};
/// \class HdBlockDataSource
///
/// A datasource representing the absence of a datasource. If a container has
/// a child datasource which is a block datasource, that's equivalent to that
/// child being null. This type is useful when composing containers, where a
/// block might shadow sampled data, and sampled data might shadow nullptr.
///
class HdBlockDataSource : public HdDataSourceBase
{
public:
HD_DECLARE_DATASOURCE(HdBlockDataSource);
HdBlockDataSource(){}
};
HD_DECLARE_DATASOURCE_HANDLES(HdBlockDataSource);
// Utilities //////////////////////////////////////////////////////////////////
/// Print a datasource to a stream, for debugging/testing.
void HdDebugPrintDataSource(
std::ostream &,
HdDataSourceBaseHandle,
int indentLevel = 0);
/// Print a datasource to stdout, for debugging/testing
void HdDebugPrintDataSource(HdDataSourceBaseHandle, int indentLevel = 0);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HD_DATASOURCE_H
@@ -0,0 +1,136 @@
//
// Copyright 2021 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_DATA_SOURCE_LEGACY_PRIM_H
#define PXR_IMAGING_HD_DATA_SOURCE_LEGACY_PRIM_H
#include "pxr/imaging/hd/sceneIndex.h"
#include "pxr/imaging/hd/api.h"
#include "pxr/base/tf/staticTokens.h"
PXR_NAMESPACE_OPEN_SCOPE
class HdSceneDelegate;
class HdExtComputationContext;
#define HD_LEGACY_PRIMTYPE_TOKENS \
/* Bprims */ \
(openvdbAsset) \
(field3dAsset)
TF_DECLARE_PUBLIC_TOKENS(HdLegacyPrimTypeTokens, HD_API,
HD_LEGACY_PRIMTYPE_TOKENS);
/// \class HdExtComputationCallbackDataSource
///
/// This is a data source which holds a legacy ext computation. It is used
/// only during emulation of legacy scene delegates but is exposed here as it
/// is used by HdSceneIndexAdapterSceneDelegate for emulation of legacy
/// render delegates.
///
class HdExtComputationCallbackDataSource : public HdDataSourceBase
{
public:
HD_DECLARE_DATASOURCE(HdExtComputationCallbackDataSource);
HdExtComputationCallbackDataSource(
const SdfPath &id, HdSceneDelegate *sceneDelegate)
: _id(id), _sceneDelegate(sceneDelegate) {}
void Invoke(HdExtComputationContext *context);
private:
SdfPath _id;
HdSceneDelegate *_sceneDelegate;
};
HD_DECLARE_DATASOURCE_HANDLES(HdExtComputationCallbackDataSource);
/// \class HdDataSourceLegacyPrim
///
/// This is an HdContainerDataSource which represents a prim-level data source
/// for adapting HdSceneDelegate calls into the forms defined by HdSchemas
/// during emulation of legacy scene delegates.
///
class HdDataSourceLegacyPrim : public HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(HdDataSourceLegacyPrim);
bool Has(const TfToken &name) override;
TfTokenVector GetNames() override;
HdDataSourceBaseHandle Get(const TfToken &name) override;
/// This clears internal cached values and is currently called only by
/// HdLegacyPrimSceneIndex in response to its own DirtyPrims method
void PrimDirtied(const HdDataSourceLocatorSet &locators);
/// Return which locators PrimDirtied will respond to...
static const HdDataSourceLocatorSet &GetCachedLocators();
private:
HdDataSourceLegacyPrim(
SdfPath id,
TfToken type,
HdSceneDelegate *sceneDelegate);
HdDataSourceBaseHandle _GetPrimvarsDataSource();
HdDataSourceBaseHandle _GetExtComputationPrimvarsDataSource();
HdDataSourceBaseHandle _GetMaterialBindingDataSource();
HdDataSourceBaseHandle _GetXformDataSource();
HdDataSourceBaseHandle _GetMaterialDataSource();
HdDataSourceBaseHandle _GetDisplayStyleDataSource();
HdDataSourceBaseHandle _GetInstancedByDataSource();
HdDataSourceBaseHandle _GetInstancerTopologyDataSource();
HdDataSourceBaseHandle _GetVolumeFieldBindingDataSource();
HdDataSourceBaseHandle _GetCoordSysBindingDataSource();
HdDataSourceBaseHandle _GetVisibilityDataSource();
HdDataSourceBaseHandle _GetPurposeDataSource();
HdDataSourceBaseHandle _GetExtentDataSource();
HdDataSourceBaseHandle _GetCategoriesDataSource();
HdDataSourceBaseHandle _GetInstanceCategoriesDataSource();
private:
SdfPath _id;
TfToken _type;
HdSceneDelegate *_sceneDelegate;
std::atomic_bool _primvarsBuilt;
bool _extComputationPrimvarsBuilt : 1;
HdContainerDataSourceAtomicHandle _primvars;
HdContainerDataSourceHandle _extComputationPrimvars;
// Note: _instancerTopology needs to be an atomic handle, since
// some downstream customers of it (render index sync, hdSt instancer sync)
// are not threadsafe.
HdContainerDataSourceAtomicHandle _instancerTopology;
};
HD_DECLARE_DATASOURCE_HANDLES(HdDataSourceLegacyPrim);
bool HdLegacyPrimTypeIsVolumeField(TfToken const &primType);
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+285
View File
@@ -0,0 +1,285 @@
//
// Copyright 2021 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_DATASOURCELOCATOR_H
#define PXR_IMAGING_HD_DATASOURCELOCATOR_H
#include "pxr/pxr.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/smallVector.h"
#include "pxr/base/tf/hash.h"
#include "pxr/imaging/hd/api.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdDataSourceLocator
///
/// Represents an object that can identify the location of a data source.
/// Data Source Locators are meant to be short lists of tokens that, taken
/// together, can represent the location of a given data source.
///
class HdDataSourceLocator
{
public:
/// Returns a common empty locator.
///
/// This is an often needed locator and is quicker to get this way rather
/// than creating your own empty one.
HD_API
static const HdDataSourceLocator &EmptyLocator();
/// Creates an empty locator.
///
/// If all you need is an empty locator, see EmptyLocator().
///
HD_API
HdDataSourceLocator();
/// The following constructors take a number of tokens and build a locator
/// with the apporpriate number of tokens in the given order.
///
/// These are convenience constructors for commonly used patterns. Note
/// that we generally expect a very small number of entities in a locator,
/// which is why we haven't gone with a more general N-way solution.
///
HD_API
explicit HdDataSourceLocator(const TfToken &t1);
HD_API
HdDataSourceLocator(const TfToken &t1, const TfToken &t2);
HD_API
HdDataSourceLocator(const TfToken &t1, const TfToken &t2,
const TfToken &t3);
HD_API
HdDataSourceLocator(const TfToken &t1, const TfToken &t2, const TfToken &t3,
const TfToken &t4);
HD_API
HdDataSourceLocator(const TfToken &t1, const TfToken &t2, const TfToken &t3,
const TfToken &t4, const TfToken &t5);
HD_API
HdDataSourceLocator(const TfToken &t1, const TfToken &t2, const TfToken &t3,
const TfToken &t4, const TfToken &t5,
const TfToken &t6);
/// Builds a data source locator from the \p tokens array of the given
/// \p count.
///
HD_API
HdDataSourceLocator(size_t count, const TfToken *tokens);
/// Copy constructor
HdDataSourceLocator(const HdDataSourceLocator &rhs) = default;
/// Returns the number of elements (tokens) in this data source.
HD_API
size_t GetElementCount() const;
/// Returns the element (token) at index \p i.
///
/// If \p i is out of bounds, the behavior is undefined.
///
HD_API
const TfToken &GetElement(size_t i) const;
/// Returns the first element, or empty token if none.
HD_API
const TfToken &GetFirstElement() const;
/// Returns the last element, or empty token if none.
HD_API
const TfToken &GetLastElement() const;
/// Returns a copy of this data source locator with the last element
/// replaced by the one given by \p name. If this data source locator is
/// empty an identical copy is returned.
///
HD_API
HdDataSourceLocator ReplaceLastElement(const TfToken &name) const;
/// Returns a copy of this data source locator with the last element
/// removed.
///
HD_API
HdDataSourceLocator RemoveLastElement() const;
/// Returns a copy of this data source locator with the first element
/// removed.
///
HD_API
HdDataSourceLocator RemoveFirstElement() const;
/// Appends \p name to this data source locator.
HD_API
HdDataSourceLocator Append(const TfToken &name) const;
/// Appends all of the elements in \p locator to this data source locator.
HD_API
HdDataSourceLocator Append(const HdDataSourceLocator &locator) const;
/// Prepends \p name to this data source locator.
HD_API
HdDataSourceLocator Prepend(const TfToken &name) const;
/// Prepends all of the elements in \p locator to this data source locator.
HD_API
HdDataSourceLocator Prepend(const HdDataSourceLocator &locator) const;
/// Returns \c true if this data source locator has \p prefix as a prefix.
HD_API
bool HasPrefix(const HdDataSourceLocator &prefix) const;
/// Returns a data source locator that represents the common prefix
/// between this data source and \p other.
///
HD_API
HdDataSourceLocator GetCommonPrefix(const HdDataSourceLocator &other) const;
/// Returns a copy of this data source locator with \p oldPrefix replaced
/// by \p newPrefix.
///
HD_API
HdDataSourceLocator ReplacePrefix(
const HdDataSourceLocator &oldPrefix,
const HdDataSourceLocator &newPrefix) const;
/// Returns \c true if either this or other are equal to or contain one
/// another
///
HD_API
bool Intersects(const HdDataSourceLocator &other) const;
inline bool operator==(const HdDataSourceLocator &rhs) const {
return _tokens == rhs._tokens;
}
inline bool operator!=(const HdDataSourceLocator &rhs) const {
return _tokens != rhs._tokens;
}
HD_API
bool operator<(const HdDataSourceLocator &rhs) const;
inline bool IsEmpty() const {
return _tokens.empty();
}
/// Returns a string representation of this data source locator with the
/// given \p delimiter inserted between each element.
///
HD_API
std::string GetString(const char *delimiter = "/") const;
template <class HashState>
friend void TfHashAppend(HashState &h, HdDataSourceLocator const &myObj) {
h.AppendContiguous(myObj._tokens.data(), myObj._tokens.size());
}
inline size_t Hash() const;
private:
using _TokenVector = TfSmallVector<TfToken, 6>;
_TokenVector _tokens;
};
inline size_t
HdDataSourceLocator::Hash() const
{
return TfHash()(*this);
}
//-----------------------------------------------------------------------------
///
/// \class HdDataSourceLocatorSet
///
/// Represents a set of data source locators.
///
class HdDataSourceLocatorSet
{
private:
using _Locators = TfSmallVector<HdDataSourceLocator, 8>;
public:
using const_iterator = typename _Locators::const_iterator;
explicit HdDataSourceLocatorSet() {}
HdDataSourceLocatorSet(const HdDataSourceLocator &locator);
// Initializer list constructor.
HdDataSourceLocatorSet(
const std::initializer_list<const HdDataSourceLocator> &l);
/// Copy Ctor
HdDataSourceLocatorSet(const HdDataSourceLocatorSet &rhs) = default;
/// Move Ctor.
HdDataSourceLocatorSet(HdDataSourceLocatorSet &&rhs) = default;
/// Move assignment operator.
HdDataSourceLocatorSet &operator=(HdDataSourceLocatorSet &&rhs) = default;
/// Copy assignment operator.
HdDataSourceLocatorSet &operator=(const HdDataSourceLocatorSet &rhs)
= default;
HD_API
void insert(const HdDataSourceLocator &locator);
HD_API
void insert(const HdDataSourceLocatorSet &locatorSet);
/// append() is semantically equivalent to insert(), but works much faster
/// if \p locator would be added to the end of the set, lexicographically.
HD_API
void append(const HdDataSourceLocator &locator);
bool operator==(const HdDataSourceLocatorSet &rhs) const {
return _locators == rhs._locators;
}
bool operator!=(const HdDataSourceLocatorSet &rhs) const {
return !(*this == rhs);
}
HD_API
const_iterator begin() const;
HD_API
const_iterator end() const;
HD_API
bool Intersects(const HdDataSourceLocator &locator) const;
HD_API
bool Intersects(const HdDataSourceLocatorSet &locatorSet) const;
HD_API
bool IsEmpty() const;
private:
void _InsertAndDeleteSuffixes(_Locators::iterator *position,
const HdDataSourceLocator &locator);
_Locators _locators;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HD_DATASOURCELOCATOR_H
+120
View File
@@ -0,0 +1,120 @@
//
// Copyright 2021 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_DATASOURCETYPEDEFS_H
#define PXR_IMAGING_HD_DATASOURCETYPEDEFS_H
#include "pxr/pxr.h"
#include "pxr/imaging/hd/dataSource.h"
#include "pxr/imaging/hd/dataSourceLocator.h"
#include "pxr/imaging/hd/types.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/vec2f.h"
#include "pxr/base/tf/staticTokens.h"
#include "pxr/base/vt/array.h"
#include "pxr/usd/sdf/path.h"
#include "pxr/usd/sdf/assetPath.h"
PXR_NAMESPACE_OPEN_SCOPE
// Numeric
using HdIntDataSource = HdTypedSampledDataSource<int>;
using HdIntDataSourceHandle = HdIntDataSource::Handle;
using HdIntArrayDataSource = HdTypedSampledDataSource<VtArray<int>>;
using HdIntArrayDataSourceHandle = HdIntArrayDataSource::Handle;
using HdSizetDataSource = HdTypedSampledDataSource<size_t>;
using HdSizetDataSourceHandle = HdSizetDataSource::Handle;
using HdFloatDataSource = HdTypedSampledDataSource<float>;
using HdFloatDataSourceHandle = HdFloatDataSource::Handle;
using HdFloatArrayDataSource = HdTypedSampledDataSource<VtArray<float>>;
using HdFloatArrayDataSourceHandle = HdFloatArrayDataSource::Handle;
// Bool
using HdBoolDataSource = HdTypedSampledDataSource<bool>;
using HdBoolDataSourceHandle = HdBoolDataSource::Handle;
using HdBoolArrayDataSource = HdTypedSampledDataSource<VtArray<bool>>;
using HdBoolArrayDataSourceHandle = HdBoolArrayDataSource::Handle;
// String
using HdTokenDataSource = HdTypedSampledDataSource<TfToken>;
using HdTokenDataSourceHandle = HdTokenDataSource::Handle;
using HdTokenArrayDataSource = HdTypedSampledDataSource<VtArray<TfToken>>;
using HdTokenArrayDataSourceHandle = HdTokenArrayDataSource::Handle;
using HdPathDataSource = HdTypedSampledDataSource<SdfPath>;
using HdPathDataSourceHandle = HdPathDataSource::Handle;
using HdPathArrayDataSource = HdTypedSampledDataSource<VtArray<SdfPath>>;
using HdPathArrayDataSourceHandle = HdPathArrayDataSource::Handle;
using HdStringDataSource = HdTypedSampledDataSource<std::string>;
using HdStringDataSourceHandle = HdStringDataSource::Handle;
using HdAssetPathDataSource = HdTypedSampledDataSource<SdfAssetPath>;
using HdAssetPathDataSourceHandle = HdAssetPathDataSource::Handle;
// Linear algebra
using HdVec2iDataSource = HdTypedSampledDataSource<GfVec2i>;
using HdVec2iDataSourceHandle = HdVec2iDataSource::Handle;
using HdVec2fDataSource = HdTypedSampledDataSource<GfVec2f>;
using HdVec2fDataSourceHandle = HdVec2fDataSource::Handle;
using HdVec2fArrayDataSource = HdTypedSampledDataSource<VtArray<GfVec2f>>;
using HdVec2fArrayDataSourceHandle = HdVec2fArrayDataSource::Handle;
using HdVec3iDataSource = HdTypedSampledDataSource<GfVec3i>;
using HdVec3iDataSourceHandle = HdVec3iDataSource::Handle;
using HdVec3fDataSource = HdTypedSampledDataSource<GfVec3f>;
using HdVec3fDataSourceHandle = HdVec3fDataSource::Handle;
using HdVec3fArrayDataSource = HdTypedSampledDataSource<VtArray<GfVec3f>>;
using HdVec3fArrayDataSourceHandle = HdVec3fArrayDataSource::Handle;
using HdVec4iDataSource = HdTypedSampledDataSource<GfVec4i>;
using HdVec4iDataSourceHandle = HdVec4iDataSource::Handle;
using HdVec3dDataSource = HdTypedSampledDataSource<GfVec3d>;
using HdVec3dDataSourceHandle = HdVec3dDataSource::Handle;
using HdVec3dArrayDataSource = HdTypedSampledDataSource<VtArray<GfVec3d>>;
using HdVec3dArrayDataSourceHandle = HdVec3dArrayDataSource::Handle;
using HdMatrixDataSource = HdTypedSampledDataSource<GfMatrix4d>;
using HdMatrixDataSourceHandle = HdMatrixDataSource::Handle;
using HdMatrixArrayDataSource = HdTypedSampledDataSource<VtArray<GfMatrix4d>>;
using HdMatrixArrayDataSourceHandle = HdMatrixArrayDataSource::Handle;
// Locator
using HdLocatorDataSource = HdTypedSampledDataSource<HdDataSourceLocator>;
using HdLocatorDataSourceHandle = HdLocatorDataSource::Handle;
// Enum
using HdFormatDataSource = HdTypedSampledDataSource<HdFormat>;
using HdFormatDataSourceHandle = HdFormatDataSource::Handle;
using HdTupleTypeDataSource = HdTypedSampledDataSource<HdTupleType>;
using HdTupleTypeDataSourceHandle = HdTupleTypeDataSource::Handle;
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HD_DATASOURCETYPEDEFS_H
+76
View File
@@ -0,0 +1,76 @@
//
// 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_SYNC_ALL,
HD_TASK_ADDED,
HD_TASK_REMOVED,
HD_VARYING_STATE
);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HD_DEBUG_CODES_H
@@ -0,0 +1,78 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_DEPENDENCIES_SCHEMA_H
#define PXR_IMAGING_HD_DEPENDENCIES_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/dependencySchema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDDEPENDENCIES_SCHEMA_TOKENS \
(__dependencies) \
TF_DECLARE_PUBLIC_TOKENS(HdDependenciesSchemaTokens, HD_API,
HDDEPENDENCIES_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdDependenciesSchema : public HdSchema
{
public:
HdDependenciesSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
using EntryPair = std::pair<TfToken, HdDependencySchema>;
using EntryVector = TfSmallVector<EntryPair, 8>;
EntryVector GetEntries();
/// Retrieves a container data source with the schema's default name token
/// "__dependencies" from the parent container and constructs a
/// HdDependenciesSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdDependenciesSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+112
View File
@@ -0,0 +1,112 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_DEPENDENCY_SCHEMA_H
#define PXR_IMAGING_HD_DEPENDENCY_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDDEPENDENCY_SCHEMA_TOKENS \
(dependedOnPrimPath) \
(dependedOnDataSourceLocator) \
(affectedDataSourceLocator) \
TF_DECLARE_PUBLIC_TOKENS(HdDependencySchemaTokens, HD_API,
HDDEPENDENCY_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdDependencySchema : public HdSchema
{
public:
HdDependencySchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdPathDataSourceHandle GetDependedOnPrimPath();
HD_API
HdLocatorDataSourceHandle GetDependedOnDataSourceLocator();
HD_API
HdLocatorDataSourceHandle GetAffectedDataSourceLocator();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdPathDataSourceHandle &dependedOnPrimPath,
const HdLocatorDataSourceHandle &dependedOnDataSourceLocator,
const HdLocatorDataSourceHandle &affectedDataSourceLocator
);
/// \class HdDependencySchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetDependedOnPrimPath(
const HdPathDataSourceHandle &dependedOnPrimPath);
HD_API
Builder &SetDependedOnDataSourceLocator(
const HdLocatorDataSourceHandle &dependedOnDataSourceLocator);
HD_API
Builder &SetAffectedDataSourceLocator(
const HdLocatorDataSourceHandle &affectedDataSourceLocator);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdPathDataSourceHandle _dependedOnPrimPath;
HdLocatorDataSourceHandle _dependedOnDataSourceLocator;
HdLocatorDataSourceHandle _affectedDataSourceLocator;
};
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,64 @@
//
// Copyright 2021 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_BITS_TRANSLATOR_H
#define PXR_IMAGING_HD_DIRTY_BITS_TRANSLATOR_H
#include "pxr/pxr.h"
#include "pxr/base/tf/token.h"
#include "pxr/imaging/hd/dataSourceLocator.h"
#include "pxr/imaging/hd/types.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdDirtyBitsTranslator
///
/// A set of optimized functions for translating between dirty bits and
/// datasource locators for different prim types.
class HdDirtyBitsTranslator
{
public:
// Dirty bits to locators.
static void RprimDirtyBitsToLocatorSet(TfToken const& primType,
const HdDirtyBits bits, HdDataSourceLocatorSet *set);
static void SprimDirtyBitsToLocatorSet(TfToken const& primType,
const HdDirtyBits bits, HdDataSourceLocatorSet *set);
static void BprimDirtyBitsToLocatorSet(TfToken const& primType,
const HdDirtyBits bits, HdDataSourceLocatorSet *set);
static void InstancerDirtyBitsToLocatorSet(TfToken const& primType,
const HdDirtyBits bits, HdDataSourceLocatorSet *set);
// Locators to dirty bits.
static HdDirtyBits RprimLocatorSetToDirtyBits(TfToken const& primType,
HdDataSourceLocatorSet const& set);
static HdDirtyBits SprimLocatorSetToDirtyBits(TfToken const& primType,
HdDataSourceLocatorSet const& set);
static HdDirtyBits BprimLocatorSetToDirtyBits(TfToken const& primType,
HdDataSourceLocatorSet const& set);
static HdDirtyBits InstancerLocatorSetToDirtyBits(TfToken const& primType,
HdDataSourceLocatorSet const& set);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HD_DIRTY_BITS_TRANSLATOR_H
+154
View File
@@ -0,0 +1,154 @@
//
// 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/repr.h"
#include "pxr/imaging/hd/rprimCollection.h"
#include "pxr/imaging/hd/types.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
class HdRenderIndex;
class HdChangeTracker;
using HdReprSelectorVector = std::vector<HdReprSelector>;
/// \class HdDirtyList
///
/// Used for faster iteration of dirty Rprims by the render index.
///
/// GetDirtyRprims() implicitly refreshes and caches 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
/// cleaning the scene dirty bits, until HdChangeTracker::ResetVaryingState
/// clears it 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
explicit HdDirtyList(HdRenderIndex &index);
/// Returns a reference of dirty rprim ids.
/// If the change tracker hasn't changed any state since the last time
/// GetDirtyRprims gets called, and if the tracked filtering parameters
/// (set via UpdateRenderTagsAndReprSelectors) are the same, it simply
/// returns an empty list.
/// Otherwise depending on what changed, it will return a list of
/// Rprim ids to be synced.
/// Therefore, it is expected that GetDirtyRprims is called _only once_
/// per render index sync.
HD_API
SdfPathVector const& GetDirtyRprims();
/// Updates the tracked filtering parameters.
/// This typically comes from the tasks submitted to HdEngine::Execute.
HD_API
void UpdateRenderTagsAndReprSelectors(
TfTokenVector const &tags, HdReprSelectorVector const &reprs);
/// Sets the flag to prune to dirty list to just the varying Rprims on
/// the next call to GetDirtyRprims.
void PruneToVaryingRprims() {
_pruneDirtyList = true;
}
private:
HdChangeTracker & _GetChangeTracker() const;
void _UpdateDirtyIdsIfNeeded();
// Note: Can't use a const ref to the renderIndex because
// HdRenderIndex::GetRprimIds() isn't a const member fn.
HdRenderIndex &_renderIndex;
TfTokenVector _trackedRenderTags;
HdReprSelectorVector _trackedReprs;
SdfPathVector _dirtyIds;
unsigned int _sceneStateVersion;
unsigned int _rprimIndexVersion;
unsigned int _rprimRenderTagVersion;
unsigned int _varyingStateVersion;
bool _rebuildDirtyList;
bool _pruneDirtyList;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HD_DIRTY_LIST_H
+269
View File
@@ -0,0 +1,269 @@
//
// 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 _materialTag;
}
HD_API
void SetMaterialTag(TfToken const &materialTag) {
_materialTag = materialTag;
}
TopologyToPrimvarVector const &GetFvarTopologyToPrimvarVector() const {
return _sharedData->fvarTopologyToPrimvarVector;
}
/// 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;
/// The materialTag allows the draw items of 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 _materialTag;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HD_DRAW_ITEM_H
+141
View File
@@ -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
+48
View File
@@ -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
+99
View File
@@ -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
+247
View File
@@ -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
+162
View File
@@ -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,112 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_INPUT_COMPUTATION_SCHEMA_H
#define PXR_IMAGING_HD_EXT_COMPUTATION_INPUT_COMPUTATION_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDEXTCOMPUTATIONINPUTCOMPUTATION_SCHEMA_TOKENS \
(name) \
(sourceComputation) \
(sourceComputationOutputName) \
TF_DECLARE_PUBLIC_TOKENS(HdExtComputationInputComputationSchemaTokens, HD_API,
HDEXTCOMPUTATIONINPUTCOMPUTATION_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdExtComputationInputComputationSchema : public HdSchema
{
public:
HdExtComputationInputComputationSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdTokenDataSourceHandle GetName();
HD_API
HdPathDataSourceHandle GetSourceComputation();
HD_API
HdTokenDataSourceHandle GetSourceComputationOutputName();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdTokenDataSourceHandle &name,
const HdPathDataSourceHandle &sourceComputation,
const HdTokenDataSourceHandle &sourceComputationOutputName
);
/// \class HdExtComputationInputComputationSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetName(
const HdTokenDataSourceHandle &name);
HD_API
Builder &SetSourceComputation(
const HdPathDataSourceHandle &sourceComputation);
HD_API
Builder &SetSourceComputationOutputName(
const HdTokenDataSourceHandle &sourceComputationOutputName);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdTokenDataSourceHandle _name;
HdPathDataSourceHandle _sourceComputation;
HdTokenDataSourceHandle _sourceComputationOutputName;
};
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,104 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_OUTPUT_SCHEMA_H
#define PXR_IMAGING_HD_EXT_COMPUTATION_OUTPUT_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDEXTCOMPUTATIONOUTPUT_SCHEMA_TOKENS \
(name) \
(valueType) \
TF_DECLARE_PUBLIC_TOKENS(HdExtComputationOutputSchemaTokens, HD_API,
HDEXTCOMPUTATIONOUTPUT_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdExtComputationOutputSchema : public HdSchema
{
public:
HdExtComputationOutputSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdTokenDataSourceHandle GetName();
HD_API
HdTupleTypeDataSourceHandle GetValueType();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdTokenDataSourceHandle &name,
const HdTupleTypeDataSourceHandle &valueType
);
/// \class HdExtComputationOutputSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetName(
const HdTokenDataSourceHandle &name);
HD_API
Builder &SetValueType(
const HdTupleTypeDataSourceHandle &valueType);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdTokenDataSourceHandle _name;
HdTupleTypeDataSourceHandle _valueType;
};
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,140 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_PRIMVAR_SCHEMA_H
#define PXR_IMAGING_HD_EXT_COMPUTATION_PRIMVAR_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/primvarSchema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDEXTCOMPUTATIONPRIMVAR_SCHEMA_TOKENS \
(interpolation) \
(role) \
(sourceComputation) \
(sourceComputationOutputName) \
(valueType) \
TF_DECLARE_PUBLIC_TOKENS(HdExtComputationPrimvarSchemaTokens, HD_API,
HDEXTCOMPUTATIONPRIMVAR_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdExtComputationPrimvarSchema : public HdSchema
{
public:
HdExtComputationPrimvarSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdTokenDataSourceHandle GetInterpolation();
HD_API
HdTokenDataSourceHandle GetRole();
HD_API
HdPathDataSourceHandle GetSourceComputation();
HD_API
HdTokenDataSourceHandle GetSourceComputationOutputName();
HD_API
HdTupleTypeDataSourceHandle GetValueType();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdTokenDataSourceHandle &interpolation,
const HdTokenDataSourceHandle &role,
const HdPathDataSourceHandle &sourceComputation,
const HdTokenDataSourceHandle &sourceComputationOutputName,
const HdTupleTypeDataSourceHandle &valueType
);
/// \class HdExtComputationPrimvarSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetInterpolation(
const HdTokenDataSourceHandle &interpolation);
HD_API
Builder &SetRole(
const HdTokenDataSourceHandle &role);
HD_API
Builder &SetSourceComputation(
const HdPathDataSourceHandle &sourceComputation);
HD_API
Builder &SetSourceComputationOutputName(
const HdTokenDataSourceHandle &sourceComputationOutputName);
HD_API
Builder &SetValueType(
const HdTupleTypeDataSourceHandle &valueType);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdTokenDataSourceHandle _interpolation;
HdTokenDataSourceHandle _role;
HdPathDataSourceHandle _sourceComputation;
HdTokenDataSourceHandle _sourceComputationOutputName;
HdTupleTypeDataSourceHandle _valueType;
};
// these return statically allocated instances for the common cases.
static HdTokenDataSourceHandle BuildInterpolationDataSource(
TfToken interpolation) {
return HdPrimvarSchema::BuildInterpolationDataSource(interpolation);
}
static HdTokenDataSourceHandle BuildRoleDataSource(TfToken role) {
return HdPrimvarSchema::BuildRoleDataSource(role);
}
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,76 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_PRIMVARS_SCHEMA_H
#define PXR_IMAGING_HD_EXT_COMPUTATION_PRIMVARS_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/extComputationPrimvarSchema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDEXTCOMPUTATIONPRIMVARS_SCHEMA_TOKENS \
(extComputationPrimvars) \
TF_DECLARE_PUBLIC_TOKENS(HdExtComputationPrimvarsSchemaTokens, HD_API,
HDEXTCOMPUTATIONPRIMVARS_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdExtComputationPrimvarsSchema : public HdSchema
{
public:
HdExtComputationPrimvarsSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
TfTokenVector GetExtComputationPrimvarNames();
HdExtComputationPrimvarSchema GetPrimvar(const TfToken &name);
/// Retrieves a container data source with the schema's default name token
/// "extComputationPrimvars" from the parent container and constructs a
/// HdExtComputationPrimvarsSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdExtComputationPrimvarsSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,202 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_SCHEMA_H
#define PXR_IMAGING_HD_EXT_COMPUTATION_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDEXTCOMPUTATION_SCHEMA_TOKENS \
(extComputation) \
(inputValues) \
(inputComputations) \
(outputs) \
(glslKernel) \
(cpuCallback) \
(dispatchCount) \
(elementCount) \
TF_DECLARE_PUBLIC_TOKENS(HdExtComputationSchemaTokens, HD_API,
HDEXTCOMPUTATION_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdExtComputationSchema : public HdSchema
{
public:
HdExtComputationSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdContainerDataSourceHandle GetInputValues();
HD_API
HdVectorDataSourceHandle GetInputComputations();
HD_API
HdVectorDataSourceHandle GetOutputs();
HD_API
HdStringDataSourceHandle GetGlslKernel();
HD_API
HdDataSourceBaseHandle GetCpuCallback();
HD_API
HdSizetDataSourceHandle GetDispatchCount();
HD_API
HdSizetDataSourceHandle GetElementCount();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdContainerDataSourceHandle &inputValues,
const HdVectorDataSourceHandle &inputComputations,
const HdVectorDataSourceHandle &outputs,
const HdStringDataSourceHandle &glslKernel,
const HdDataSourceBaseHandle &cpuCallback,
const HdSizetDataSourceHandle &dispatchCount,
const HdSizetDataSourceHandle &elementCount
);
/// \class HdExtComputationSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetInputValues(
const HdContainerDataSourceHandle &inputValues);
HD_API
Builder &SetInputComputations(
const HdVectorDataSourceHandle &inputComputations);
HD_API
Builder &SetOutputs(
const HdVectorDataSourceHandle &outputs);
HD_API
Builder &SetGlslKernel(
const HdStringDataSourceHandle &glslKernel);
HD_API
Builder &SetCpuCallback(
const HdDataSourceBaseHandle &cpuCallback);
HD_API
Builder &SetDispatchCount(
const HdSizetDataSourceHandle &dispatchCount);
HD_API
Builder &SetElementCount(
const HdSizetDataSourceHandle &elementCount);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdContainerDataSourceHandle _inputValues;
HdVectorDataSourceHandle _inputComputations;
HdVectorDataSourceHandle _outputs;
HdStringDataSourceHandle _glslKernel;
HdDataSourceBaseHandle _cpuCallback;
HdSizetDataSourceHandle _dispatchCount;
HdSizetDataSourceHandle _elementCount;
};
/// Retrieves a container data source with the schema's default name token
/// "extComputation" from the parent container and constructs a
/// HdExtComputationSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdExtComputationSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the inputvalues data source can be found.
/// This is often useful for checking intersection against the
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
HD_API
static const HdDataSourceLocator &GetInputValuesLocator();
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the inputcomputations data source can be found.
/// This is often useful for checking intersection against the
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
HD_API
static const HdDataSourceLocator &GetInputComputationsLocator();
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the outputs data source can be found.
/// This is often useful for checking intersection against the
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
HD_API
static const HdDataSourceLocator &GetOutputsLocator();
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the dispatchcount data source can be found.
/// This is often useful for checking intersection against the
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
HD_API
static const HdDataSourceLocator &GetDispatchCountLocator();
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the elementcount data source can be found.
/// This is often useful for checking intersection against the
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
HD_API
static const HdDataSourceLocator &GetElementCountLocator();
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the glslkernel data source can be found.
/// This is often useful for checking intersection against the
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
HD_API
static const HdDataSourceLocator &GetGlslKernelLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -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, &times);
// 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
+119
View File
@@ -0,0 +1,119 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_EXTENT_SCHEMA_H
#define PXR_IMAGING_HD_EXTENT_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDEXTENT_SCHEMA_TOKENS \
(extent) \
(min) \
(max) \
TF_DECLARE_PUBLIC_TOKENS(HdExtentSchemaTokens, HD_API,
HDEXTENT_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdExtentSchema : public HdSchema
{
public:
HdExtentSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdVec3dDataSourceHandle GetMin();
HD_API
HdVec3dDataSourceHandle GetMax();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdVec3dDataSourceHandle &min,
const HdVec3dDataSourceHandle &max
);
/// \class HdExtentSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetMin(
const HdVec3dDataSourceHandle &min);
HD_API
Builder &SetMax(
const HdVec3dDataSourceHandle &max);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdVec3dDataSourceHandle _min;
HdVec3dDataSourceHandle _max;
};
/// Retrieves a container data source with the schema's default name token
/// "extent" from the parent container and constructs a
/// HdExtentSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdExtentSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+69
View File
@@ -0,0 +1,69 @@
//
// 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) \
(fieldName)
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,127 @@
//
// Copyright 2021 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_FILTERING_SCENE_INDEX_H
#define PXR_IMAGING_HD_FILTERING_SCENE_INDEX_H
#include "pxr/pxr.h"
#include <set>
#include <unordered_map>
#include "pxr/base/tf/declarePtrs.h"
#include "pxr/base/tf/singleton.h"
#include "pxr/usd/sdf/path.h"
#include "pxr/imaging/hd/dataSource.h"
#include "pxr/imaging/hd/dataSourceLocator.h"
#include "pxr/imaging/hd/sceneIndex.h"
PXR_NAMESPACE_OPEN_SCOPE
TF_DECLARE_WEAK_AND_REF_PTRS(HdFilteringSceneIndexBase);
///
/// \class HdFilteringSceneIndexBase
///
/// An abstract base class for scene indexes that have one or more input scene
/// indexes which serve as a basis for their own scene.
///
class HdFilteringSceneIndexBase : public HdSceneIndexBase
{
public:
virtual std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const = 0;
};
TF_DECLARE_WEAK_AND_REF_PTRS(HdSingleInputFilteringSceneIndexBase);
///
/// \class HdSingleInputFilteringSceneIndexBase
///
/// An abstract base class for a filtering scene index that observes a single
/// input scene index.
///
class HdSingleInputFilteringSceneIndexBase : public HdFilteringSceneIndexBase
{
public:
std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const final;
protected:
HdSingleInputFilteringSceneIndexBase(
const HdSceneIndexBaseRefPtr &inputSceneIndex);
virtual void _PrimsAdded(
const HdSceneIndexBase &sender,
const HdSceneIndexObserver::AddedPrimEntries &entries) = 0;
virtual void _PrimsRemoved(
const HdSceneIndexBase &sender,
const HdSceneIndexObserver::RemovedPrimEntries &entries) = 0;
virtual void _PrimsDirtied(
const HdSceneIndexBase &sender,
const HdSceneIndexObserver::DirtiedPrimEntries &entries) = 0;
const HdSceneIndexBaseRefPtr &_GetInputSceneIndex() const {
return _inputSceneIndex;
}
private:
HdSceneIndexBaseRefPtr _inputSceneIndex;
friend class _Observer;
class _Observer : public HdSceneIndexObserver
{
public:
_Observer(HdSingleInputFilteringSceneIndexBase *owner)
: _owner(owner) {}
void PrimsAdded(
const HdSceneIndexBase &sender,
const AddedPrimEntries &entries) override;
void PrimsRemoved(
const HdSceneIndexBase &sender,
const RemovedPrimEntries &entries) override;
void PrimsDirtied(
const HdSceneIndexBase &sender,
const DirtiedPrimEntries &entries) override;
private:
HdSingleInputFilteringSceneIndexBase *_owner;
};
_Observer _observer;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HD_FILTERING_SCENE_INDEX_H
+109
View File
@@ -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,150 @@
//
// Copyright 2021 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_FLATTENING_SCENE_H
#define PXR_IMAGING_HD_FLATTENING_SCENE_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/filteringSceneIndex.h"
#include "pxr/usd/sdf/pathTable.h"
PXR_NAMESPACE_OPEN_SCOPE
class HdFlatteningSceneIndex;
TF_DECLARE_REF_PTRS(HdFlatteningSceneIndex);
///
/// \class HdFlatteningSceneIndex
///
/// A scene index that observes an input scene index and produces a comparable
/// scene in which inherited state is represented at leaf prims.
///
/// This kind of representation is typically required for legacy-style
/// render delegates that require all the information to be available at the
/// leaf prims.
///
class HdFlatteningSceneIndex : public HdSingleInputFilteringSceneIndexBase
{
public:
/// Creates a new flattening scene index.
///
static HdFlatteningSceneIndexRefPtr New(
const HdSceneIndexBaseRefPtr &inputScene) {
return TfCreateRefPtr(new HdFlatteningSceneIndex(inputScene));
}
HD_API
~HdFlatteningSceneIndex() override;
// satisfying HdSceneIndexBase
HD_API
HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
HD_API
SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
protected:
HD_API
HdFlatteningSceneIndex(const HdSceneIndexBaseRefPtr &inputScene);
// satisfying HdSingleInputFilteringSceneIndexBase
void _PrimsAdded(
const HdSceneIndexBase &sender,
const HdSceneIndexObserver::AddedPrimEntries &entries) override;
void _PrimsRemoved(
const HdSceneIndexBase &sender,
const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
void _PrimsDirtied(
const HdSceneIndexBase &sender,
const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
private:
// members
struct _PrimEntry
{
HdSceneIndexPrim prim;
};
using _PrimEntryTable = SdfPathTable<_PrimEntry>;
_PrimEntryTable _prims;
HdContainerDataSourceHandle _identityXform;
HdContainerDataSourceHandle _identityVis;
HdContainerDataSourceHandle _identityPurpose;
// methods
void _DirtyHierarchy(
const SdfPath &primPath,
const HdDataSourceLocatorSet &dirtyLocators,
HdSceneIndexObserver::DirtiedPrimEntries *dirtyEntries);
// ------------------------------------------------------------------------
friend class _PrimLevelWrappingDataSource;
/// wraps the input scene's prim-level data sources in order to deliver
/// overriden value
class _PrimLevelWrappingDataSource : public HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(_PrimLevelWrappingDataSource);
_PrimLevelWrappingDataSource(
const HdFlatteningSceneIndex &scene,
const SdfPath &primPath,
HdContainerDataSourceHandle inputDataSource);
void UpdateInputDataSource(HdContainerDataSourceHandle inputDataSource);
bool PrimDirtied(const HdDataSourceLocatorSet &locators);
bool Has(const TfToken &name) override;
TfTokenVector GetNames() override;
HdDataSourceBaseHandle Get(const TfToken &name) override;
private:
HdDataSourceBaseHandle _GetXform();
HdDataSourceBaseHandle _GetVis();
HdDataSourceBaseHandle _GetPurpose();
const HdFlatteningSceneIndex &_sceneIndex;
SdfPath _primPath;
HdContainerDataSourceHandle _inputDataSource;
HdContainerDataSourceAtomicHandle _computedXformDataSource;
HdContainerDataSourceAtomicHandle _computedVisDataSource;
HdContainerDataSourceAtomicHandle _computedPurposeDataSource;
};
HD_DECLARE_DATASOURCE_HANDLES(_PrimLevelWrappingDataSource);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+67
View File
@@ -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
+117
View File
@@ -0,0 +1,117 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_GEOM_SUBSET_SCHEMA_H
#define PXR_IMAGING_HD_GEOM_SUBSET_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDGEOMSUBSET_SCHEMA_TOKENS \
(type) \
(indices) \
(typeFaceSet) \
(typePointSet) \
(typeCurveSet) \
TF_DECLARE_PUBLIC_TOKENS(HdGeomSubsetSchemaTokens, HD_API,
HDGEOMSUBSET_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdGeomSubsetSchema : public HdSchema
{
public:
HdGeomSubsetSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdTokenDataSourceHandle GetType();
HD_API
HdIntArrayDataSourceHandle GetIndices();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdTokenDataSourceHandle &type,
const HdIntArrayDataSourceHandle &indices
);
/// \class HdGeomSubsetSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetType(
const HdTokenDataSourceHandle &type);
HD_API
Builder &SetIndices(
const HdIntArrayDataSourceHandle &indices);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdTokenDataSourceHandle _type;
HdIntArrayDataSourceHandle _indices;
};
/// Returns token data source for use as type value.
/// Values of...
/// - HdGeomSubsetSchemaTokens->typeFaceSet
/// - HdGeomSubsetSchemaTokens->typePointSet
/// - HdGeomSubsetSchemaTokens->typeCurveSet
/// ...will be stored statically and reused for future calls.
HD_API
static HdTokenDataSourceHandle BuildTypeDataSource(
const TfToken &type);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,72 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_GEOM_SUBSETS_SCHEMA_H
#define PXR_IMAGING_HD_GEOM_SUBSETS_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/geomSubsetSchema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDGEOMSUBSETS_SCHEMA_TOKENS \
(geomSubsets) \
TF_DECLARE_PUBLIC_TOKENS(HdGeomSubsetsSchemaTokens, HD_API,
HDGEOMSUBSETS_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdGeomSubsetsSchema : public HdSchema
{
public:
HdGeomSubsetsSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
TfTokenVector GetIds();
HdGeomSubsetSchema GetGeomSubset(const TfToken & id);
/// Retrieves a container data source with the schema's default name token
/// "geomSubsets" from the parent container and constructs a
/// HdGeomSubsetsSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdGeomSubsetsSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,111 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_INSTANCE_CATEGORIES_SCHEMA_H
#define PXR_IMAGING_HD_INSTANCE_CATEGORIES_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDINSTANCECATEGORIES_SCHEMA_TOKENS \
(instanceCategories) \
(categoriesValues) \
TF_DECLARE_PUBLIC_TOKENS(HdInstanceCategoriesSchemaTokens, HD_API,
HDINSTANCECATEGORIES_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdInstanceCategoriesSchema : public HdSchema
{
public:
HdInstanceCategoriesSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdVectorDataSourceHandle GetCategoriesValues();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdVectorDataSourceHandle &categoriesValues
);
/// \class HdInstanceCategoriesSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetCategoriesValues(
const HdVectorDataSourceHandle &categoriesValues);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdVectorDataSourceHandle _categoriesValues;
};
/// Retrieves a container data source with the schema's default name token
/// "instanceCategories" from the parent container and constructs a
/// HdInstanceCategoriesSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdInstanceCategoriesSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+287
View File
@@ -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 &&registryLock,
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
+121
View File
@@ -0,0 +1,121 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_INSTANCE_SCHEMA_H
#define PXR_IMAGING_HD_INSTANCE_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDINSTANCE_SCHEMA_TOKENS \
(instancer) \
(path) \
TF_DECLARE_PUBLIC_TOKENS(HdInstanceSchemaTokens, HD_API,
HDINSTANCE_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
// This schema can be considered the opposite of instancerTopology's
// "instanceLocations". When the scene coalesces scene prims into multiple
// instances of a single prototype, it inserts "instance" prims at the site
// of de-duplication. The instancer prim added to manage the prototype
// uses "instanceLocations" to point back to all of these instance prims.
//
// The instance prims aren't directly useful for rendering but can be useful
// for scene processing and data aggregation.
class HdInstanceSchema : public HdSchema
{
public:
HdInstanceSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdPathArrayDataSourceHandle GetPath();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdPathArrayDataSourceHandle &path
);
/// \class HdInstanceSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetPath(
const HdPathArrayDataSourceHandle &path);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdPathArrayDataSourceHandle _path;
};
/// Retrieves a container data source with the schema's default name token
/// "instancer" from the parent container and constructs a
/// HdInstanceSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdInstanceSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+131
View File
@@ -0,0 +1,131 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_INSTANCED_BY_SCHEMA_H
#define PXR_IMAGING_HD_INSTANCED_BY_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDINSTANCEDBY_SCHEMA_TOKENS \
(instancedBy) \
(paths) \
TF_DECLARE_PUBLIC_TOKENS(HdInstancedBySchemaTokens, HD_API,
HDINSTANCEDBY_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
// A schema marking a prim as instanced by another prim.
//
// Many renderers need to know not what prototypes an instancer has, but
// rather what instancers a prototype has; this is encoded in
// "instancedBy". A prim is "instancedBy" /Instancer if /Instancer has
// a prototype path that's a parent of the prim. A complicating exception is
// if /A instances /A/B, which instances /A/B/C, we don't consider /A to be
// instancing /A/B/C directly; this is to support nested explicit instancing
// of things like leaves/trees/forests.
//
// This value is computed based on the instancer topology of instancer prims in
// the scene.
//
// Note: if multiple instancers reference a prototype, it's possible for
// instancedBy to contain multiple entries. Some renderers may be able to
// read this directly, but some may need to duplicate prims with an op so that
// each prim has a single instancer, depending on how the renderer exposes
// instancing.
class HdInstancedBySchema : public HdSchema
{
public:
HdInstancedBySchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdPathArrayDataSourceHandle GetPaths();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdPathArrayDataSourceHandle &paths
);
/// \class HdInstancedBySchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetPaths(
const HdPathArrayDataSourceHandle &paths);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdPathArrayDataSourceHandle _paths;
};
/// Retrieves a container data source with the schema's default name token
/// "instancedBy" from the parent container and constructs a
/// HdInstancedBySchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdInstancedBySchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+182
View File
@@ -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,177 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_INSTANCER_TOPOLOGY_SCHEMA_H
#define PXR_IMAGING_HD_INSTANCER_TOPOLOGY_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDINSTANCERTOPOLOGY_SCHEMA_TOKENS \
(instancerTopology) \
(prototypes) \
(instanceIndices) \
(mask) \
(instanceLocations) \
TF_DECLARE_PUBLIC_TOKENS(HdInstancerTopologySchemaTokens, HD_API,
HDINSTANCERTOPOLOGY_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
// Since the instancing schema is complicated:
//
// An instancer is a prim at a certain scenegraph location that causes other
// prims to be duplicated. The instancer can also hold instance-varying data
// like constant primvars or material relationships.
//
// The important things an instancer has is:
// 1.) Instancer topology, describing how exactly the prims are duplicated;
// 2.) Instance-rate data, meaning data that varies per instance, such as
// primvars or material bindings.
//
// If an instancer causes prims "/A" and "/B" to be duplicated, we encode that
// by setting prototypes = ["/A", "/B"]. Note that "/A" and "/B" can be
// subtrees, not direct gprims. instanceIndices encodes both multiplicity
// and position in arrays of instance-rate data, per prototype path; if
// instanceIndices = { [0,2], [1] }, then we draw /A twice (with instance
// primvar indices 0 and 2); and /B once (with instance primvar index 1).
// Mask is an auxiliary parameter that can be used to deactivate certain
// instances; mask = [true, true, false] would disable the
// second copy of "/A". An empty mask array is the same as all-true.
//
// Scenes generally specify instancing in one of two ways:
// 1.) Explicit instancing: prim /Instancer wants to draw its subtree at
// an array of locations. This is a data expansion form.
// 2.) Implicit instancing: prims /X and /Y are marked as being identical,
// and scene load replaces them with a single prim and an instancer.
// This is a data coalescing form.
//
// For implicit instancing, we want to know the original paths of /X and /Y,
// for doing things like resolving inheritance. This is encoded in the
// "instanceLocations" path, while the prototype prims (e.g. /_Prototype/Cube,
// the deduplicated version of /X/Cube and /Y/Cube) is encoded in the
// "prototypes" path.
//
// For explicit instancing, the "instanceLocations" attribute is meaningless
// and should be left null.
class HdInstancerTopologySchema : public HdSchema
{
public:
HdInstancerTopologySchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdPathArrayDataSourceHandle GetPrototypes();
// Note: expected to be a vector of HdIntArrayDataSource.
HD_API
HdVectorDataSourceHandle GetInstanceIndices();
HD_API
HdBoolArrayDataSourceHandle GetMask();
HD_API
HdPathArrayDataSourceHandle GetInstanceLocations();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdPathArrayDataSourceHandle &prototypes,
const HdVectorDataSourceHandle &instanceIndices,
const HdBoolArrayDataSourceHandle &mask,
const HdPathArrayDataSourceHandle &instanceLocations
);
/// \class HdInstancerTopologySchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetPrototypes(
const HdPathArrayDataSourceHandle &prototypes);
HD_API
Builder &SetInstanceIndices(
const HdVectorDataSourceHandle &instanceIndices);
HD_API
Builder &SetMask(
const HdBoolArrayDataSourceHandle &mask);
HD_API
Builder &SetInstanceLocations(
const HdPathArrayDataSourceHandle &instanceLocations);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdPathArrayDataSourceHandle _prototypes;
HdVectorDataSourceHandle _instanceIndices;
HdBoolArrayDataSourceHandle _mask;
HdPathArrayDataSourceHandle _instanceLocations;
};
// HELPERS
VtArray<int> ComputeInstanceIndicesForProto(SdfPath const &path);
/// Retrieves a container data source with the schema's default name token
/// "instancerTopology" from the parent container and constructs a
/// HdInstancerTopologySchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdInstancerTopologySchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,174 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_LEGACY_DISPLAY_STYLE_SCHEMA_H
#define PXR_IMAGING_HD_LEGACY_DISPLAY_STYLE_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDLEGACYDISPLAYSTYLE_SCHEMA_TOKENS \
(displayStyle) \
(refineLevel) \
(flatShadingEnabled) \
(displacementEnabled) \
(occludedSelectionShowsThrough) \
(shadingStyle) \
(reprSelector) \
(cullStyle) \
TF_DECLARE_PUBLIC_TOKENS(HdLegacyDisplayStyleSchemaTokens, HD_API,
HDLEGACYDISPLAYSTYLE_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdLegacyDisplayStyleSchema : public HdSchema
{
public:
HdLegacyDisplayStyleSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdIntDataSourceHandle GetRefineLevel();
HD_API
HdBoolDataSourceHandle GetFlatShadingEnabled();
HD_API
HdBoolDataSourceHandle GetDisplacementEnabled();
HD_API
HdBoolDataSourceHandle GetOccludedSelectionShowsThrough();
HD_API
HdTokenDataSourceHandle GetShadingStyle();
HD_API
HdTokenArrayDataSourceHandle GetReprSelector();
HD_API
HdTokenDataSourceHandle GetCullStyle();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdIntDataSourceHandle &refineLevel,
const HdBoolDataSourceHandle &flatShadingEnabled,
const HdBoolDataSourceHandle &displacementEnabled,
const HdBoolDataSourceHandle &occludedSelectionShowsThrough,
const HdTokenDataSourceHandle &shadingStyle,
const HdTokenArrayDataSourceHandle &reprSelector,
const HdTokenDataSourceHandle &cullStyle
);
/// \class HdLegacyDisplayStyleSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetRefineLevel(
const HdIntDataSourceHandle &refineLevel);
HD_API
Builder &SetFlatShadingEnabled(
const HdBoolDataSourceHandle &flatShadingEnabled);
HD_API
Builder &SetDisplacementEnabled(
const HdBoolDataSourceHandle &displacementEnabled);
HD_API
Builder &SetOccludedSelectionShowsThrough(
const HdBoolDataSourceHandle &occludedSelectionShowsThrough);
HD_API
Builder &SetShadingStyle(
const HdTokenDataSourceHandle &shadingStyle);
HD_API
Builder &SetReprSelector(
const HdTokenArrayDataSourceHandle &reprSelector);
HD_API
Builder &SetCullStyle(
const HdTokenDataSourceHandle &cullStyle);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdIntDataSourceHandle _refineLevel;
HdBoolDataSourceHandle _flatShadingEnabled;
HdBoolDataSourceHandle _displacementEnabled;
HdBoolDataSourceHandle _occludedSelectionShowsThrough;
HdTokenDataSourceHandle _shadingStyle;
HdTokenArrayDataSourceHandle _reprSelector;
HdTokenDataSourceHandle _cullStyle;
};
/// Retrieves a container data source with the schema's default name token
/// "displayStyle" from the parent container and constructs a
/// HdLegacyDisplayStyleSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdLegacyDisplayStyleSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the reprselector data source can be found.
/// This is often useful for checking intersection against the
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
HD_API
static const HdDataSourceLocator &GetReprSelectorLocator();
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the cullstyle data source can be found.
/// This is often useful for checking intersection against the
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
HD_API
static const HdDataSourceLocator &GetCullStyleLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,63 @@
//
// Copyright 2021 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_LEGACY_PRIM_SCENE_INDEX_H
#define PXR_IMAGING_HD_LEGACY_PRIM_SCENE_INDEX_H
#include "pxr/imaging/hd/retainedSceneIndex.h"
PXR_NAMESPACE_OPEN_SCOPE
class HdSceneDelegate;
TF_DECLARE_REF_PTRS(HdLegacyPrimSceneIndex);
/// \class HdLegacyPrimSceneIndex
///
/// Extends HdRetainedSceneIndex to instantiate and dirty HdDataSourceLegacyPrim
/// data sources.
///
/// During emulation of legacy HdSceneDelegates, HdRenderIndex forwards
/// prim insertion calls here to produce a comparable HdSceneIndex
/// representation
class HdLegacyPrimSceneIndex : public HdRetainedSceneIndex
{
public:
static HdLegacyPrimSceneIndexRefPtr New() {
return TfCreateRefPtr(new HdLegacyPrimSceneIndex);
}
/// custom insertion wrapper called by HdRenderIndex during population
/// of legacy HdSceneDelegates
void AddLegacyPrim(SdfPath const &id, TfToken const &type,
HdSceneDelegate *sceneDelegate);
/// extends to also call DirtyPrim on HdDataSourceLegacyPrim
void DirtyPrims(
const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+107
View File
@@ -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
+72
View File
@@ -0,0 +1,72 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_LIGHT_SCHEMA_H
#define PXR_IMAGING_HD_LIGHT_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDLIGHT_SCHEMA_TOKENS \
(light) \
TF_DECLARE_PUBLIC_TOKENS(HdLightSchemaTokens, HD_API,
HDLIGHT_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdLightSchema : public HdSchema
{
public:
HdLightSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
/// Retrieves a container data source with the schema's default name token
/// "light" from the parent container and constructs a
/// HdLightSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdLightSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+216
View File
@@ -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,83 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_MATERIAL_BINDING_SCHEMA_H
#define PXR_IMAGING_HD_MATERIAL_BINDING_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDMATERIALBINDING_SCHEMA_TOKENS \
(materialBinding) \
((allPurpose, "")) \
TF_DECLARE_PUBLIC_TOKENS(HdMaterialBindingSchemaTokens, HD_API,
HDMATERIALBINDING_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdMaterialBindingSchema : public HdSchema
{
public:
HdMaterialBindingSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
HD_API
static HdContainerDataSourceHandle
BuildRetained(
size_t count,
TfToken *names,
HdDataSourceBaseHandle *values);
HdPathDataSourceHandle GetMaterialBinding();
HdPathDataSourceHandle GetMaterialBinding(TfToken const &purpose);
/// Retrieves a container data source with the schema's default name token
/// "materialBinding" from the parent container and constructs a
/// HdMaterialBindingSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdMaterialBindingSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,104 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_MATERIAL_CONNECTION_SCHEMA_H
#define PXR_IMAGING_HD_MATERIAL_CONNECTION_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDMATERIALCONNECTION_SCHEMA_TOKENS \
(upstreamNodePath) \
(upstreamNodeOutputName) \
TF_DECLARE_PUBLIC_TOKENS(HdMaterialConnectionSchemaTokens, HD_API,
HDMATERIALCONNECTION_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdMaterialConnectionSchema : public HdSchema
{
public:
HdMaterialConnectionSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdTokenDataSourceHandle GetUpstreamNodePath();
HD_API
HdTokenDataSourceHandle GetUpstreamNodeOutputName();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdTokenDataSourceHandle &upstreamNodePath,
const HdTokenDataSourceHandle &upstreamNodeOutputName
);
/// \class HdMaterialConnectionSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetUpstreamNodePath(
const HdTokenDataSourceHandle &upstreamNodePath);
HD_API
Builder &SetUpstreamNodeOutputName(
const HdTokenDataSourceHandle &upstreamNodeOutputName);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdTokenDataSourceHandle _upstreamNodePath;
HdTokenDataSourceHandle _upstreamNodeOutputName;
};
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,104 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_MATERIAL_NETWORK_SCHEMA_H
#define PXR_IMAGING_HD_MATERIAL_NETWORK_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDMATERIALNETWORK_SCHEMA_TOKENS \
(nodes) \
(terminals) \
TF_DECLARE_PUBLIC_TOKENS(HdMaterialNetworkSchemaTokens, HD_API,
HDMATERIALNETWORK_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdMaterialNetworkSchema : public HdSchema
{
public:
HdMaterialNetworkSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdContainerDataSourceHandle GetNodes();
HD_API
HdContainerDataSourceHandle GetTerminals();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdContainerDataSourceHandle &nodes,
const HdContainerDataSourceHandle &terminals
);
/// \class HdMaterialNetworkSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetNodes(
const HdContainerDataSourceHandle &nodes);
HD_API
Builder &SetTerminals(
const HdContainerDataSourceHandle &terminals);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdContainerDataSourceHandle _nodes;
HdContainerDataSourceHandle _terminals;
};
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+112
View File
@@ -0,0 +1,112 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_MATERIAL_NODE_SCHEMA_H
#define PXR_IMAGING_HD_MATERIAL_NODE_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDMATERIALNODE_SCHEMA_TOKENS \
(parameters) \
(inputConnections) \
(nodeIdentifier) \
TF_DECLARE_PUBLIC_TOKENS(HdMaterialNodeSchemaTokens, HD_API,
HDMATERIALNODE_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdMaterialNodeSchema : public HdSchema
{
public:
HdMaterialNodeSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
//ACCESSORS
HD_API
HdContainerDataSourceHandle GetParameters();
HD_API
HdContainerDataSourceHandle GetInputConnections();
HD_API
HdTokenDataSourceHandle GetNodeIdentifier();
// RETRIEVING AND CONSTRUCTING
/// Builds a container data source which includes the provided child data
/// sources. Parameters with nullptr values are excluded. This is a
/// low-level interface. For cases in which it's desired to define
/// the container with a sparse set of child fields, the Builder class
/// is often more convenient and readable.
HD_API
static HdContainerDataSourceHandle
BuildRetained(
const HdContainerDataSourceHandle &parameters,
const HdContainerDataSourceHandle &inputConnections,
const HdTokenDataSourceHandle &nodeIdentifier
);
/// \class HdMaterialNodeSchema::Builder
///
/// Utility class for setting sparse sets of child data source fields to be
/// filled as arguments into BuildRetained. Because all setter methods
/// return a reference to the instance, this can be used in the "builder
/// pattern" form.
class Builder
{
public:
HD_API
Builder &SetParameters(
const HdContainerDataSourceHandle &parameters);
HD_API
Builder &SetInputConnections(
const HdContainerDataSourceHandle &inputConnections);
HD_API
Builder &SetNodeIdentifier(
const HdTokenDataSourceHandle &nodeIdentifier);
/// Returns a container data source containing the members set thus far.
HD_API
HdContainerDataSourceHandle Build();
private:
HdContainerDataSourceHandle _parameters;
HdContainerDataSourceHandle _inputConnections;
HdTokenDataSourceHandle _nodeIdentifier;
};
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+83
View File
@@ -0,0 +1,83 @@
//
// Copyright 2021 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.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// schema.template.h file to make changes.
#ifndef PXR_IMAGING_HD_MATERIAL_SCHEMA_H
#define PXR_IMAGING_HD_MATERIAL_SCHEMA_H
#include "pxr/imaging/hd/api.h"
#include "pxr/imaging/hd/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
//-----------------------------------------------------------------------------
#define HDMATERIAL_SCHEMA_TOKENS \
(material) \
((universalRenderContext, "")) \
TF_DECLARE_PUBLIC_TOKENS(HdMaterialSchemaTokens, HD_API,
HDMATERIAL_SCHEMA_TOKENS);
//-----------------------------------------------------------------------------
class HdMaterialSchema : public HdSchema
{
public:
HdMaterialSchema(HdContainerDataSourceHandle container)
: HdSchema(container) {}
HD_API
static HdContainerDataSourceHandle
BuildRetained(
size_t count,
TfToken *names,
HdDataSourceBaseHandle *values);
HdContainerDataSourceHandle GetMaterialNetwork();
HdContainerDataSourceHandle GetMaterialNetwork(TfToken const &context);
/// Retrieves a container data source with the schema's default name token
/// "material" from the parent container and constructs a
/// HdMaterialSchema instance.
/// Because the requested container data source may not exist, the result
/// should be checked with IsDefined() or a bool comparison before use.
HD_API
static HdMaterialSchema GetFromParent(
const HdContainerDataSourceHandle &fromParentContainer);
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
/// where the container representing this schema is found by default.
HD_API
static const HdDataSourceLocator &GetDefaultLocator();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+224
View File
@@ -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
Loaded 100 of 15684 files, more files were not shown because too many files have changed in this diff. Show more