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_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