2014-01-10 01:36:35 +00:00
|
|
|
//
|
|
|
|
// Copyright 2013 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.
|
|
|
|
//
|
|
|
|
|
2015-05-19 18:22:37 +00:00
|
|
|
#pragma once
|
|
|
|
#ifndef OPENSUBDIV3_OSD_CPU_SMOOTHNORMAL_CONTEXT_H
|
|
|
|
#define OPENSUBDIV3_OSD_CPU_SMOOTHNORMAL_CONTEXT_H
|
2014-01-10 01:36:35 +00:00
|
|
|
|
|
|
|
#include "../version.h"
|
|
|
|
|
|
|
|
#include "../osd/nonCopyable.h"
|
|
|
|
#include "../osd/vertexDescriptor.h"
|
2014-11-25 20:41:19 +00:00
|
|
|
#include "../far/types.h"
|
2014-01-10 01:36:35 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
#include <vector>
|
2014-01-10 01:36:35 +00:00
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
namespace Far {
|
|
|
|
class TopologyRefiner;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
namespace Osd {
|
|
|
|
|
|
|
|
class CpuSmoothNormalContext : private NonCopyable<CpuSmoothNormalContext> {
|
2014-01-10 01:36:35 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// Creates an CpuComputeContext instance
|
2014-01-10 01:36:35 +00:00
|
|
|
///
|
2014-11-25 20:41:19 +00:00
|
|
|
/// @param refiner The uniformly refined Far::TopologyRefiner
|
|
|
|
///
|
|
|
|
/// @param level Refinement level used to generate normals
|
2014-01-10 01:36:35 +00:00
|
|
|
///
|
2014-01-10 22:56:59 +00:00
|
|
|
/// @param resetMemory Set to true if the target vertex buffer needs its
|
|
|
|
/// memory reset before accumulating the averaged normals.
|
|
|
|
/// If the SmoothNormal Controller runs after a Computer
|
|
|
|
/// Controller, then the vertex buffer will already have
|
|
|
|
/// been reset and this step can be skipped to save time.
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
static CpuSmoothNormalContext * Create(
|
2014-11-25 20:41:19 +00:00
|
|
|
Far::TopologyRefiner const & refiner, int level, bool resetMemory=false);
|
2014-01-10 01:36:35 +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.
|
|
|
|
///
|
|
|
|
/// @param in a buffer containing input vertex-interpolated primvar data
|
|
|
|
///
|
|
|
|
/// @param iOfs offset to the buffer element describing the vertex position
|
|
|
|
///
|
|
|
|
/// @param out a buffer where the smooth normals will be output
|
|
|
|
///
|
|
|
|
/// @param oOfs offset to the buffer element describing the normal position
|
|
|
|
///
|
|
|
|
template<class VERTEX_BUFFER>
|
|
|
|
void Bind(VERTEX_BUFFER * in, int iOfs,
|
|
|
|
VERTEX_BUFFER * out, int oOfs) {
|
|
|
|
|
|
|
|
assert( ((iOfs+3)<=in->GetNumElements()) and
|
2014-01-10 22:56:59 +00:00
|
|
|
((oOfs+3)<=out->GetNumElements()) and
|
|
|
|
out->GetNumVertices()>=in->GetNumVertices());
|
2014-01-10 01:36:35 +00:00
|
|
|
|
|
|
|
_iBuffer = in ? in->BindCpuBuffer() : 0;
|
|
|
|
_oBuffer = out ? out->BindCpuBuffer() : 0;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
_iDesc = VertexBufferDescriptor( iOfs, 3, in->GetNumElements() );
|
|
|
|
_oDesc = VertexBufferDescriptor( oOfs, 3, out->GetNumElements() );
|
2014-01-10 22:56:59 +00:00
|
|
|
|
|
|
|
_numVertices = out->GetNumVertices();
|
2014-01-10 01:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Unbinds any previously bound vertex and varying data buffers.
|
|
|
|
void Unbind() {
|
|
|
|
|
|
|
|
_iBuffer = _oBuffer = 0;
|
|
|
|
_iDesc.Reset();
|
|
|
|
_oDesc.Reset();
|
2014-01-10 22:56:59 +00:00
|
|
|
_numVertices = 0;
|
2014-01-10 01:36:35 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
Far::Index const * GetFaceVertices() const {
|
|
|
|
return &_faceVerts[0];
|
2014-01-10 01:36:35 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
|
|
|
|
int GetNumFaces() const {
|
|
|
|
return (int)_faceVerts.size()/4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the number of vertices in output vertex buffer
|
|
|
|
int GetNumVertices() const {
|
|
|
|
return _numVertices;
|
2014-01-10 01:36:35 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
|
2014-01-10 01:36:35 +00:00
|
|
|
/// Returns a pointer to the data of the input buffer
|
|
|
|
float const * GetCurrentInputVertexBuffer() const {
|
|
|
|
return _iBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a pointer to the data of the output buffer
|
|
|
|
float * GetCurrentOutputVertexBuffer() {
|
|
|
|
return _oBuffer;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// Returns an VertexDescriptor for the input vertex data
|
|
|
|
VertexBufferDescriptor const & GetInputVertexDescriptor() const {
|
2014-01-10 01:36:35 +00:00
|
|
|
return _iDesc;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// Returns an VertexDescriptor for the buffer where the normals data
|
2014-01-10 01:36:35 +00:00
|
|
|
/// will be stored
|
2014-09-05 22:07:46 +00:00
|
|
|
VertexBufferDescriptor const & GetOutputVertexDescriptor() const {
|
2014-01-10 01:36:35 +00:00
|
|
|
return _oDesc;
|
|
|
|
}
|
|
|
|
|
2014-01-10 22:56:59 +00:00
|
|
|
/// Returns whether the controller needs to reset the vertex buffer before
|
|
|
|
/// accumulating smooth normals
|
|
|
|
bool GetResetMemory() const {
|
|
|
|
return _resetMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set to true if the controller needs to reset the vertex buffer before
|
|
|
|
/// accumulating smooth normals
|
|
|
|
void SetResetMemory(bool resetMemory) {
|
|
|
|
_resetMemory = resetMemory;
|
|
|
|
}
|
|
|
|
|
2014-01-10 01:36:35 +00:00
|
|
|
protected:
|
|
|
|
// Constructor
|
2014-11-25 20:41:19 +00:00
|
|
|
explicit CpuSmoothNormalContext(Far::TopologyRefiner const & refiner,
|
|
|
|
int level, bool resetMemory);
|
2014-01-10 01:36:35 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// Topology data for a mesh
|
2014-11-25 20:41:19 +00:00
|
|
|
std::vector<Far::Index> _faceVerts; // patch control vertices
|
2014-01-10 01:36:35 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
VertexBufferDescriptor _iDesc,
|
2014-10-09 21:48:50 +00:00
|
|
|
_oDesc;
|
2014-01-10 01:36:35 +00:00
|
|
|
|
2014-01-10 22:56:59 +00:00
|
|
|
int _numVertices;
|
|
|
|
|
2014-01-10 01:36:35 +00:00
|
|
|
float * _iBuffer,
|
|
|
|
* _oBuffer;
|
|
|
|
|
2014-01-10 22:56:59 +00:00
|
|
|
bool _resetMemory; // set to true if the output buffer needs to be reset to 0
|
2014-01-10 01:36:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
} // end namespace Osd
|
|
|
|
|
2014-01-10 01:36:35 +00:00
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
2015-05-19 18:22:37 +00:00
|
|
|
#endif // OPENSUBDIV3_OSD_CPU_SMOOTHNORMAL_CONTEXT_H
|