2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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:
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifndef OSD_GLSL_COMPUTE_CONTEXT_H
|
|
|
|
#define OSD_GLSL_COMPUTE_CONTEXT_H
|
|
|
|
|
|
|
|
#include "../version.h"
|
|
|
|
|
2014-03-19 18:44:51 +00:00
|
|
|
#include "../far/mesh.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "../far/vertexEditTables.h"
|
2013-03-08 01:50:15 +00:00
|
|
|
#include "../osd/vertex.h"
|
2013-05-17 02:53:49 +00:00
|
|
|
#include "../osd/vertexDescriptor.h"
|
2013-03-08 01:50:15 +00:00
|
|
|
#include "../osd/nonCopyable.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-10 22:54:40 +00:00
|
|
|
#include "../osd/opengl.h"
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
class OsdGLSLComputeKernelBundle;
|
|
|
|
|
|
|
|
|
|
|
|
class OsdGLSLComputeTable : OsdNonCopyable<OsdGLSLComputeTable> {
|
|
|
|
public:
|
2013-03-08 01:50:15 +00:00
|
|
|
template<typename T>
|
|
|
|
explicit OsdGLSLComputeTable(const std::vector<T> &table) {
|
2013-06-28 20:53:14 +00:00
|
|
|
createBuffer(table.size() * sizeof(unsigned int), table.empty() ? NULL : &table[0]);
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
virtual ~OsdGLSLComputeTable();
|
|
|
|
|
|
|
|
GLuint GetBuffer() const;
|
|
|
|
|
|
|
|
private:
|
2013-03-08 01:50:15 +00:00
|
|
|
void createBuffer(size_t size, const void *ptr);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-07 22:25:49 +00:00
|
|
|
GLuint _devicePtr;
|
2012-12-11 01:15:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class OsdGLSLComputeHEditTable : OsdNonCopyable<OsdGLSLComputeHEditTable> {
|
|
|
|
public:
|
2014-03-19 18:44:51 +00:00
|
|
|
OsdGLSLComputeHEditTable(const FarVertexEditTables::
|
2012-12-11 01:15:13 +00:00
|
|
|
VertexEditBatch &batch);
|
|
|
|
|
|
|
|
virtual ~OsdGLSLComputeHEditTable();
|
|
|
|
|
|
|
|
const OsdGLSLComputeTable * GetPrimvarIndices() const;
|
|
|
|
|
|
|
|
const OsdGLSLComputeTable * GetEditValues() const;
|
|
|
|
|
|
|
|
int GetOperation() const;
|
|
|
|
|
|
|
|
int GetPrimvarOffset() const;
|
|
|
|
|
|
|
|
int GetPrimvarWidth() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
OsdGLSLComputeTable *_primvarIndicesTable;
|
|
|
|
OsdGLSLComputeTable *_editValuesTable;
|
|
|
|
|
|
|
|
int _operation;
|
|
|
|
int _primvarOffset;
|
|
|
|
int _primvarWidth;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
///
|
|
|
|
/// \brief GLSL-Compute Refine Context
|
|
|
|
///
|
|
|
|
/// The GLSL-Compute implementation of the Refine module contextual functionality.
|
|
|
|
///
|
|
|
|
/// Contexts interface the serialized topological data pertaining to the
|
|
|
|
/// geometric primitives with the capabilities of the selected discrete
|
|
|
|
/// compute device.
|
|
|
|
///
|
2013-03-08 01:50:15 +00:00
|
|
|
class OsdGLSLComputeContext {
|
2013-05-17 02:53:49 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
public:
|
2013-05-07 02:05:50 +00:00
|
|
|
/// Creates an OsdGLSLComputeContext instance
|
|
|
|
///
|
|
|
|
/// @param farmesh the FarMesh used for this Context.
|
|
|
|
///
|
2013-05-11 02:35:25 +00:00
|
|
|
static OsdGLSLComputeContext * Create(FarMesh<OsdVertex> const *farmesh);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
/// Destructor
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual ~OsdGLSLComputeContext();
|
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
/// Binds a vertex and a varying data buffers to the context. Binding ensures
|
|
|
|
/// that data buffers are properly inter-operated between Contexts and
|
|
|
|
/// Controllers operating across multiple devices.
|
|
|
|
///
|
2013-05-17 21:07:53 +00:00
|
|
|
/// @param vertex a buffer containing vertex-interpolated primvar data
|
2013-05-07 02:05:50 +00:00
|
|
|
///
|
2013-05-17 21:07:53 +00:00
|
|
|
/// @param varying a buffer containing varying-interpolated primvar data
|
2013-05-07 02:05:50 +00:00
|
|
|
///
|
2012-12-11 01:15:13 +00:00
|
|
|
template<class VERTEX_BUFFER, class VARYING_BUFFER>
|
|
|
|
void Bind(VERTEX_BUFFER *vertex, VARYING_BUFFER *varying) {
|
|
|
|
|
|
|
|
_currentVertexBuffer = vertex ? vertex->BindVBO() : 0;
|
|
|
|
_currentVaryingBuffer = varying ? varying->BindVBO() : 0;
|
|
|
|
|
2013-05-17 02:53:49 +00:00
|
|
|
_vdesc.numVertexElements = vertex ? vertex->GetNumElements() : 0;
|
|
|
|
_vdesc.numVaryingElements = varying ? varying->GetNumElements() : 0;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
bindShaderStorageBuffers();
|
|
|
|
}
|
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
/// Unbinds any previously bound vertex and varying data buffers.
|
2012-12-11 01:15:13 +00:00
|
|
|
void Unbind() {
|
|
|
|
_currentVertexBuffer = 0;
|
|
|
|
_currentVaryingBuffer = 0;
|
|
|
|
|
|
|
|
unbindShaderStorageBuffers();
|
|
|
|
}
|
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
/// Returns one of the vertex refinement tables.
|
|
|
|
///
|
|
|
|
/// @param tableIndex the type of table
|
|
|
|
///
|
2012-12-11 01:15:13 +00:00
|
|
|
const OsdGLSLComputeTable * GetTable(int tableIndex) const;
|
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
/// Returns the number of hierarchical edit tables
|
2012-12-11 01:15:13 +00:00
|
|
|
int GetNumEditTables() const;
|
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
/// Returns a specific hierarchical edit table
|
|
|
|
///
|
|
|
|
/// @param tableIndex the index of the table
|
|
|
|
///
|
2012-12-11 01:15:13 +00:00
|
|
|
const OsdGLSLComputeHEditTable * GetEditTable(int tableIndex) const;
|
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
/// Returns a handle to the vertex-interpolated buffer
|
2012-12-11 01:15:13 +00:00
|
|
|
GLuint GetCurrentVertexBuffer() const;
|
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
/// Returns a handle to the varying-interpolated buffer
|
2012-12-11 01:15:13 +00:00
|
|
|
GLuint GetCurrentVaryingBuffer() const;
|
|
|
|
|
2013-05-17 02:53:49 +00:00
|
|
|
/// Returns an OsdVertexDescriptor if vertex buffers have been bound.
|
|
|
|
///
|
|
|
|
/// @return a descriptor for the format of the vertex data currently bound
|
|
|
|
///
|
|
|
|
OsdVertexDescriptor const & GetVertexDescriptor() const {
|
|
|
|
return _vdesc;
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * GetKernelBundle() const;
|
|
|
|
|
|
|
|
void SetKernelBundle(OsdGLSLComputeKernelBundle *kernelBundle);
|
|
|
|
|
|
|
|
void BindUniformBlockBilinearFace(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindUniformBlockBilinearEdge(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindUniformBlockBilinearVertex(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindUniformBlockCatmarkFace(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindUniformBlockCatmarkEdge(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindUniformBlockCatmarkVertexA0(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindUniformBlockCatmarkVertexA1(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindUniformBlockCatmarkVertexB(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindUniformBlockLoopEdge(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindUniformBlockLoopVertexA(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindUniformBlockLoopVertexB(GLuint program, int level);
|
|
|
|
|
|
|
|
void BindEditShaderStorageBuffers(int editIndex);
|
|
|
|
|
|
|
|
void UnbindEditShaderStorageBuffers();
|
|
|
|
|
|
|
|
protected:
|
2013-05-11 02:35:25 +00:00
|
|
|
explicit OsdGLSLComputeContext(FarMesh<OsdVertex> const *farMesh);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
void bindShaderStorageBuffers();
|
|
|
|
|
|
|
|
void unbindShaderStorageBuffers();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<OsdGLSLComputeTable*> _tables;
|
|
|
|
std::vector<OsdGLSLComputeHEditTable*> _editTables;
|
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
GLuint _vertexTexture,
|
|
|
|
_varyingTexture;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-17 02:53:49 +00:00
|
|
|
OsdVertexDescriptor _vdesc;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-07 02:05:50 +00:00
|
|
|
GLuint _currentVertexBuffer,
|
|
|
|
_currentVaryingBuffer;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * _kernelBundle;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
|
|
|
#endif // OSD_GLSL_COMPUTE_CONTEXT_H
|