Add Chromium-only Blender WebEngine parity work
This commit is contained in:
48
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/CMakeLists.txt
vendored
Normal file
48
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
#
|
||||
# Copyright 2014 Pixar
|
||||
#
|
||||
# Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
# https://opensubdiv.org/license.
|
||||
#
|
||||
|
||||
# *** glShareTopology ***
|
||||
|
||||
set(SHADER_FILES
|
||||
shader.glsl
|
||||
)
|
||||
|
||||
include_directories(
|
||||
"${OPENSUBDIV_INCLUDE_DIR}"
|
||||
"${OPENGL_LOADER_INCLUDE_DIRS}"
|
||||
"${GLFW_INCLUDE_DIR}"
|
||||
)
|
||||
|
||||
list(APPEND PLATFORM_LIBRARIES
|
||||
"${OSD_LINK_TARGET}"
|
||||
"${OPENGL_LOADER_LIBRARIES}"
|
||||
"${GLFW_LIBRARIES}"
|
||||
)
|
||||
|
||||
if (OPENCL_FOUND)
|
||||
include_directories("${OPENCL_INCLUDE_DIRS}")
|
||||
list(APPEND PLATFORM_LIBRARIES OpenGL::GL)
|
||||
endif()
|
||||
|
||||
osd_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
osd_add_glfw_executable(glShareTopology "examples"
|
||||
glShareTopology.cpp
|
||||
sceneBase.cpp
|
||||
"${SHADER_FILES}"
|
||||
"${INC_FILES}"
|
||||
$<TARGET_OBJECTS:regression_common_obj>
|
||||
$<TARGET_OBJECTS:examples_common_gl_obj>
|
||||
)
|
||||
|
||||
target_link_libraries(glShareTopology
|
||||
${PLATFORM_LIBRARIES}
|
||||
)
|
||||
|
||||
install(TARGETS glShareTopology DESTINATION "${CMAKE_BINDIR_BASE}")
|
||||
1214
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/glShareTopology.cpp
vendored
Normal file
1214
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/glShareTopology.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
90
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/init_shapes.h
vendored
Normal file
90
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/init_shapes.h
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// Copyright 2013 Pixar
|
||||
//
|
||||
// Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
// https://opensubdiv.org/license.
|
||||
//
|
||||
|
||||
#include "../../regression/common/shape_utils.h"
|
||||
#include "../../regression/shapes/all.h"
|
||||
|
||||
|
||||
static std::vector<ShapeDesc> g_defaultShapes;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static void initShapes() {
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner0", catmark_cube_corner0, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner1", catmark_cube_corner1, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner2", catmark_cube_corner2, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner3", catmark_cube_corner3, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner4", catmark_cube_corner4, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases0", catmark_cube_creases0, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases1", catmark_cube_creases1, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases2", catmark_cube_creases2, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgecorner", catmark_dart_edgecorner, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgeonly", catmark_dart_edgeonly, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_edgecorner", catmark_edgecorner, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_edgeonly", catmark_edgeonly, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_edgenone", catmark_edgenone, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_quadstrips", catmark_quadstrips, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_chaikin0", catmark_chaikin0, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_chaikin1", catmark_chaikin1, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_chaikin2", catmark_chaikin2, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_fan", catmark_fan, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound0", catmark_fvar_bound0, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound1", catmark_fvar_bound1, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound2", catmark_fvar_bound2, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test0", catmark_gregory_test0, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test1", catmark_gregory_test1, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test2", catmark_gregory_test2, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test3", catmark_gregory_test3, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test4", catmark_gregory_test4, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test5", catmark_gregory_test5, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test6", catmark_gregory_test6, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test7", catmark_gregory_test7, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_hole_test1", catmark_hole_test1, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_hole_test2", catmark_hole_test2, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_hole_test3", catmark_hole_test3, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_hole_test4", catmark_hole_test4, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_lefthanded", catmark_lefthanded, kCatmark, true /*isLeftHanded*/ ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_righthanded", catmark_righthanded, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_pyramid_creases0", catmark_pyramid_creases0, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_pyramid_creases1", catmark_pyramid_creases1, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_pyramid", catmark_pyramid, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_tent_creases0", catmark_tent_creases0, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_tent_creases1", catmark_tent_creases1 , kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_tent", catmark_tent, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_torus", catmark_torus, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_torus_creases0", catmark_torus_creases0, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_smoothtris0", catmark_smoothtris0, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_smoothtris1", catmark_smoothtris1, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_bishop", catmark_bishop, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_car", catmark_car, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_helmet", catmark_helmet, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_pawn", catmark_pawn, kCatmark ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("catmark_rook", catmark_rook, kCatmark ) );
|
||||
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_cube", loop_cube, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_cubes_semisharp", loop_cubes_semisharp, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_cubes_infsharp", loop_cubes_infsharp, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_cube_asymmetric", loop_cube_asymmetric, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgecorner", loop_triangle_edgecorner, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgeonly", loop_triangle_edgeonly, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgenone", loop_triangle_edgenone, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_xord_interior", loop_xord_interior, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_xord_boundary", loop_xord_boundary, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_icos_semisharp", loop_icos_semisharp, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_icos_infsharp", loop_icos_infsharp, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_chaikin0", loop_chaikin0, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_chaikin1", loop_chaikin1, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_pole8", loop_pole8, kLoop ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("loop_pole64", loop_pole64, kLoop ) );
|
||||
|
||||
g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("bilinear_nonplanar", bilinear_nonplanar, kBilinear ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads0", bilinear_nonquads0, kBilinear ) );
|
||||
g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads1", bilinear_nonquads1, kBilinear ) );
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
130
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/meshRefiner.h
vendored
Normal file
130
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/meshRefiner.h
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// Copyright 2015 Pixar
|
||||
//
|
||||
// Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
// https://opensubdiv.org/license.
|
||||
//
|
||||
|
||||
#ifndef OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_MESH_REFINER_H
|
||||
#define OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_MESH_REFINER_H
|
||||
|
||||
#include <opensubdiv/osd/mesh.h> // for evaluator cache
|
||||
|
||||
template <class EVALUATOR,
|
||||
class VERTEX_BUFFER,
|
||||
class STENCIL_TABLE,
|
||||
class DEVICE_CONTEXT=void>
|
||||
class MeshRefiner {
|
||||
public:
|
||||
typedef EVALUATOR Evaluator;
|
||||
typedef STENCIL_TABLE StencilTable;
|
||||
typedef DEVICE_CONTEXT DeviceContext;
|
||||
typedef OpenSubdiv::Osd::EvaluatorCacheT<Evaluator> EvaluatorCache;
|
||||
|
||||
MeshRefiner(OpenSubdiv::Far::StencilTable const * vertexStencils, //XXX: takes ownership
|
||||
OpenSubdiv::Far::StencilTable const * varyingStencils,
|
||||
int numControlVertices,
|
||||
EvaluatorCache * evaluatorCache = NULL,
|
||||
DeviceContext * deviceContext = NULL)
|
||||
: _evaluatorCache(evaluatorCache),
|
||||
_deviceContext(deviceContext) {
|
||||
|
||||
_numControlVertices = numControlVertices;
|
||||
_numVertices = numControlVertices + vertexStencils->GetNumStencils();
|
||||
|
||||
_vertexStencils = OpenSubdiv::Osd::convertToCompatibleStencilTable<StencilTable>(
|
||||
vertexStencils, deviceContext);
|
||||
_varyingStencils = OpenSubdiv::Osd::convertToCompatibleStencilTable<StencilTable>(
|
||||
varyingStencils, deviceContext);
|
||||
}
|
||||
|
||||
~MeshRefiner() {
|
||||
delete _vertexStencils;
|
||||
delete _varyingStencils;
|
||||
}
|
||||
|
||||
template <typename VBO>
|
||||
void Refine(VBO *vbo, int vertsOffset) {
|
||||
OpenSubdiv::Osd::BufferDescriptor const &globalVertexDesc =
|
||||
vbo->GetVertexDesc();
|
||||
OpenSubdiv::Osd::BufferDescriptor const &globalVaryingDesc =
|
||||
vbo->GetVaryingDesc();
|
||||
|
||||
OpenSubdiv::Osd::BufferDescriptor vertexSrcDesc(
|
||||
globalVertexDesc.offset + vertsOffset * globalVertexDesc.stride,
|
||||
globalVertexDesc.length,
|
||||
globalVertexDesc.stride);
|
||||
OpenSubdiv::Osd::BufferDescriptor vertexDstDesc(
|
||||
vertexSrcDesc.offset + (_numControlVertices * vertexSrcDesc.stride),
|
||||
vertexSrcDesc.length,
|
||||
vertexSrcDesc.stride);
|
||||
|
||||
// vertex
|
||||
Evaluator const *evalInstance = OpenSubdiv::Osd::GetEvaluator<Evaluator>(
|
||||
_evaluatorCache, vertexSrcDesc, vertexDstDesc, _deviceContext);
|
||||
|
||||
Evaluator::EvalStencils(
|
||||
vbo->GetVertexBuffer(), vertexSrcDesc,
|
||||
vbo->GetVertexBuffer(), vertexDstDesc,
|
||||
_vertexStencils,
|
||||
evalInstance,
|
||||
_deviceContext);
|
||||
|
||||
// varying
|
||||
if (_varyingStencils) {
|
||||
OpenSubdiv::Osd::BufferDescriptor varyingSrcDesc(
|
||||
globalVaryingDesc.offset + vertsOffset * globalVaryingDesc.stride,
|
||||
globalVaryingDesc.length,
|
||||
globalVaryingDesc.stride);
|
||||
|
||||
OpenSubdiv::Osd::BufferDescriptor varyingDstDesc(
|
||||
varyingSrcDesc.offset + (_numControlVertices * varyingSrcDesc.stride),
|
||||
varyingSrcDesc.length,
|
||||
varyingSrcDesc.stride);
|
||||
|
||||
evalInstance = OpenSubdiv::Osd::GetEvaluator<Evaluator>(
|
||||
_evaluatorCache, varyingSrcDesc, varyingDstDesc, _deviceContext);
|
||||
|
||||
if (vbo->GetVaryingBuffer()) {
|
||||
// non interleaved
|
||||
Evaluator::EvalStencils(
|
||||
vbo->GetVaryingBuffer(), varyingSrcDesc,
|
||||
vbo->GetVaryingBuffer(), varyingDstDesc,
|
||||
_varyingStencils,
|
||||
evalInstance,
|
||||
_deviceContext);
|
||||
} else {
|
||||
// interleaved
|
||||
Evaluator::EvalStencils(
|
||||
vbo->GetVertexBuffer(), varyingSrcDesc,
|
||||
vbo->GetVertexBuffer(), varyingDstDesc,
|
||||
_varyingStencils,
|
||||
evalInstance,
|
||||
_deviceContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Synchronize() {
|
||||
Evaluator::Synchronize(_deviceContext);
|
||||
}
|
||||
|
||||
int GetNumVertices() const { // total (control + refined)
|
||||
return _numVertices;
|
||||
}
|
||||
int GetNumControlVertices() const {
|
||||
return _numControlVertices;
|
||||
}
|
||||
|
||||
private:
|
||||
int _numVertices;
|
||||
int _numControlVertices;
|
||||
|
||||
StencilTable const *_vertexStencils;
|
||||
StencilTable const *_varyingStencils;
|
||||
EvaluatorCache * _evaluatorCache;
|
||||
DeviceContext *_deviceContext;
|
||||
};
|
||||
|
||||
|
||||
#endif // OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_TOPOLOGY_H
|
||||
124
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/scene.h
vendored
Normal file
124
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/scene.h
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// Copyright 2015 Pixar
|
||||
//
|
||||
// Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
// https://opensubdiv.org/license.
|
||||
//
|
||||
|
||||
#ifndef OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_SCENE_H
|
||||
#define OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_SCENE_H
|
||||
|
||||
#include "meshRefiner.h"
|
||||
#include "vbo.h"
|
||||
#include "sceneBase.h"
|
||||
|
||||
template <class EVALUATOR,
|
||||
class VERTEX_BUFFER,
|
||||
class STENCIL_TABLES,
|
||||
class DEVICE_CONTEXT=void>
|
||||
class Scene : public SceneBase {
|
||||
public:
|
||||
typedef EVALUATOR Evaluator;
|
||||
typedef STENCIL_TABLES StencilTables;
|
||||
typedef DEVICE_CONTEXT DeviceContext;
|
||||
typedef OpenSubdiv::Osd::EvaluatorCacheT<Evaluator> EvaluatorCache;
|
||||
typedef MeshRefiner<EVALUATOR, VERTEX_BUFFER,
|
||||
STENCIL_TABLES, DEVICE_CONTEXT> MeshRefinerType;
|
||||
typedef VBO<VERTEX_BUFFER, DEVICE_CONTEXT> VBOType;
|
||||
|
||||
Scene(Options const &options,
|
||||
EvaluatorCache * evaluatorCache = NULL,
|
||||
DeviceContext * deviceContext = NULL)
|
||||
: SceneBase(options),
|
||||
_vbo(NULL),
|
||||
_evaluatorCache(evaluatorCache),
|
||||
_deviceContext(deviceContext) {
|
||||
}
|
||||
|
||||
virtual ~Scene() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
virtual void Refine(int object) {
|
||||
int vertsOffset = GetVertsOffset(object);
|
||||
_refiners[_objects[object].topologyIndex]->Refine(_vbo, vertsOffset);
|
||||
}
|
||||
|
||||
virtual void Synchronize() {
|
||||
Evaluator::Synchronize(_deviceContext);
|
||||
}
|
||||
|
||||
virtual void UpdateVertexBuffer(int vertsOffset, std::vector<float> const &src) {
|
||||
_vbo->UpdateVertexBuffer(vertsOffset, src);
|
||||
}
|
||||
virtual void UpdateVaryingBuffer(int vertsOffset, std::vector<float> const &src) {
|
||||
_vbo->UpdateVaryingBuffer(vertsOffset, src);
|
||||
}
|
||||
|
||||
virtual GLuint BindVertexBuffer() {
|
||||
return _vbo->BindVertexBuffer();
|
||||
}
|
||||
|
||||
virtual GLuint BindVaryingBuffer() {
|
||||
return _vbo->BindVaryingBuffer();
|
||||
}
|
||||
|
||||
virtual size_t AllocateVBO(int numVerts,
|
||||
OpenSubdiv::Osd::BufferDescriptor const &vertexDesc,
|
||||
OpenSubdiv::Osd::BufferDescriptor const &varyingDesc,
|
||||
bool interleaved) {
|
||||
|
||||
if (_vbo) delete _vbo;
|
||||
_vbo = new VBOType(vertexDesc, varyingDesc, interleaved, numVerts, _deviceContext);
|
||||
return _vbo->GetSize();
|
||||
}
|
||||
|
||||
virtual size_t createMeshRefiner(
|
||||
OpenSubdiv::Far::StencilTable const * vertexStencils,
|
||||
OpenSubdiv::Far::StencilTable const * varyingStencils,
|
||||
int numControlVertices) {
|
||||
|
||||
MeshRefinerType *meshRefiner =
|
||||
new MeshRefinerType(vertexStencils, varyingStencils,
|
||||
numControlVertices,
|
||||
_evaluatorCache,
|
||||
_deviceContext);
|
||||
_refiners.push_back(meshRefiner);
|
||||
|
||||
size_t size = 0;
|
||||
if (vertexStencils) {
|
||||
size += vertexStencils->GetSizes().size() * sizeof(vertexStencils->GetSizes()[0])
|
||||
+ vertexStencils->GetOffsets().size() * sizeof(vertexStencils->GetOffsets()[0])
|
||||
+ vertexStencils->GetControlIndices().size() * sizeof(vertexStencils->GetControlIndices()[0])
|
||||
+ vertexStencils->GetWeights().size() * sizeof(vertexStencils->GetWeights()[0]);
|
||||
}
|
||||
if (varyingStencils) {
|
||||
size += varyingStencils->GetSizes().size() * sizeof(varyingStencils->GetSizes()[0])
|
||||
+ varyingStencils->GetOffsets().size() * sizeof(varyingStencils->GetOffsets()[0])
|
||||
+ varyingStencils->GetControlIndices().size() * sizeof(varyingStencils->GetControlIndices()[0])
|
||||
+ varyingStencils->GetWeights().size() * sizeof(varyingStencils->GetWeights()[0]);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
for (typename std::vector<MeshRefinerType*>::iterator it = _refiners.begin();
|
||||
it != _refiners.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
_refiners.clear();
|
||||
_objects.clear();
|
||||
delete _vbo;
|
||||
_vbo = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<MeshRefinerType*> _refiners;
|
||||
VBOType *_vbo;
|
||||
EvaluatorCache * _evaluatorCache;
|
||||
DeviceContext *_deviceContext;
|
||||
|
||||
};
|
||||
|
||||
#endif // OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_SCENE_H
|
||||
342
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/sceneBase.cpp
vendored
Normal file
342
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/sceneBase.cpp
vendored
Normal file
@@ -0,0 +1,342 @@
|
||||
//
|
||||
// Copyright 2015 Pixar
|
||||
//
|
||||
// Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
// https://opensubdiv.org/license.
|
||||
//
|
||||
|
||||
#include "glLoader.h"
|
||||
|
||||
#include "sceneBase.h"
|
||||
|
||||
#include "../../regression/common/far_utils.h"
|
||||
|
||||
#include <opensubdiv/far/patchTableFactory.h>
|
||||
#include <opensubdiv/far/stencilTableFactory.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using namespace OpenSubdiv;
|
||||
|
||||
|
||||
SceneBase::SceneBase(Options const &options)
|
||||
: _options(options),
|
||||
_indexBuffer(0), _patchParamTexture(0) {
|
||||
}
|
||||
|
||||
SceneBase::~SceneBase() {
|
||||
if (_indexBuffer) glDeleteBuffers(1, &_indexBuffer);
|
||||
if (_patchParamTexture) glDeleteTextures(1, &_patchParamTexture);
|
||||
|
||||
for (int i = 0; i < (int)_patchTables.size(); ++i) {
|
||||
delete _patchTables[i];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SceneBase::AddTopology(Shape const *shape, int level, bool varying) {
|
||||
Far::PatchTable const * patchTable = NULL;
|
||||
int numVerts = createStencilTable(shape, level, varying, &patchTable);
|
||||
|
||||
// centering rest position
|
||||
float pmin[3] = { std::numeric_limits<float>::max(),
|
||||
std::numeric_limits<float>::max(),
|
||||
std::numeric_limits<float>::max() };
|
||||
float pmax[3] = { -std::numeric_limits<float>::max(),
|
||||
-std::numeric_limits<float>::max(),
|
||||
-std::numeric_limits<float>::max() };
|
||||
int nverts = shape->GetNumVertices();
|
||||
for (int i = 0; i < nverts; ++i) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
float v = shape->verts[i*3+j];
|
||||
pmin[j] = std::min(v, pmin[j]);
|
||||
pmax[j] = std::max(v, pmax[j]);
|
||||
}
|
||||
}
|
||||
float center[3] = { (pmax[0]+pmin[0])*0.5f,
|
||||
(pmax[1]+pmin[1])*0.5f,
|
||||
pmin[2] };
|
||||
float radius = sqrt((pmax[0]-pmin[0])*(pmax[0]-pmin[0]) +
|
||||
(pmax[1]-pmin[1])*(pmax[1]-pmin[1]) +
|
||||
(pmax[2]-pmin[2])*(pmax[2]-pmin[2]));
|
||||
|
||||
std::vector<float> restPosition(shape->verts);
|
||||
for (size_t i=0; i < restPosition.size()/3; ++i) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
restPosition[i*3+j] = (shape->verts[i*3+j] - center[j])/radius;
|
||||
}
|
||||
}
|
||||
|
||||
// store topology
|
||||
Topology topology;
|
||||
topology.numVerts = numVerts;
|
||||
topology.restPosition = restPosition;
|
||||
_topologies.push_back(topology);
|
||||
|
||||
// store patch.
|
||||
// PatchTables is used later to be spliced into the index buffer.
|
||||
_patchTables.push_back(patchTable);
|
||||
}
|
||||
|
||||
int
|
||||
SceneBase::createStencilTable(Shape const *shape, int level, bool varying,
|
||||
OpenSubdiv::Far::PatchTable const **patchTableOut) {
|
||||
|
||||
Far::TopologyRefiner * refiner = 0;
|
||||
{
|
||||
Sdc::SchemeType type = GetSdcType(*shape);
|
||||
Sdc::Options options = GetSdcOptions(*shape);
|
||||
|
||||
refiner = Far::TopologyRefinerFactory<Shape>::Create(
|
||||
*shape, Far::TopologyRefinerFactory<Shape>::Options(type, options));
|
||||
assert(refiner);
|
||||
}
|
||||
|
||||
// Adaptive refinement currently supported only for catmull-clark scheme
|
||||
|
||||
if (_options.adaptive) {
|
||||
Far::TopologyRefiner::AdaptiveOptions options(level);
|
||||
refiner->RefineAdaptive(options);
|
||||
} else {
|
||||
Far::TopologyRefiner::UniformOptions options(level);
|
||||
options.fullTopologyInLastLevel = true;
|
||||
refiner->RefineUniform(options);
|
||||
}
|
||||
|
||||
Far::StencilTable const * vertexStencils=0, * varyingStencils=0;
|
||||
{
|
||||
Far::StencilTableFactory::Options options;
|
||||
options.generateOffsets = true;
|
||||
options.generateIntermediateLevels = _options.adaptive;
|
||||
|
||||
vertexStencils = Far::StencilTableFactory::Create(*refiner, options);
|
||||
|
||||
if (varying) {
|
||||
varyingStencils = Far::StencilTableFactory::Create(*refiner, options);
|
||||
}
|
||||
|
||||
assert(vertexStencils);
|
||||
}
|
||||
|
||||
Far::PatchTable const * patchTable = NULL;
|
||||
{
|
||||
Far::PatchTableFactory::Options poptions(level);
|
||||
if (_options.endCap == kEndCapBSplineBasis) {
|
||||
poptions.SetEndCapType(
|
||||
Far::PatchTableFactory::Options::ENDCAP_BSPLINE_BASIS);
|
||||
} else {
|
||||
poptions.SetEndCapType(
|
||||
Far::PatchTableFactory::Options::ENDCAP_GREGORY_BASIS);
|
||||
}
|
||||
patchTable = Far::PatchTableFactory::Create(*refiner, poptions);
|
||||
}
|
||||
*patchTableOut = patchTable;
|
||||
|
||||
// append local points to stencils
|
||||
{
|
||||
if (Far::StencilTable const *vertexStencilsWithLocalPoints =
|
||||
Far::StencilTableFactory::AppendLocalPointStencilTable(
|
||||
*refiner,
|
||||
vertexStencils,
|
||||
patchTable->GetLocalPointStencilTable())) {
|
||||
delete vertexStencils;
|
||||
vertexStencils = vertexStencilsWithLocalPoints;
|
||||
}
|
||||
if (varyingStencils) {
|
||||
if (Far::StencilTable const *varyingStencilsWithLocalPoints =
|
||||
Far::StencilTableFactory::AppendLocalPointStencilTable(
|
||||
*refiner,
|
||||
varyingStencils,
|
||||
patchTable->GetLocalPointVaryingStencilTable())) {
|
||||
delete varyingStencils;
|
||||
varyingStencils = varyingStencilsWithLocalPoints;
|
||||
}
|
||||
}
|
||||
}
|
||||
int numControlVertices = refiner->GetLevel(0).GetNumVertices();
|
||||
|
||||
_stencilTableSize = createMeshRefiner(vertexStencils, varyingStencils,
|
||||
numControlVertices);
|
||||
// note: refiner takes ownership of vertexStencils, varyingStencils, patchTable
|
||||
|
||||
delete refiner;
|
||||
return numControlVertices + vertexStencils->GetNumStencils();
|
||||
}
|
||||
|
||||
int
|
||||
SceneBase::AddObjects(int numObjects) {
|
||||
|
||||
_objects.clear();
|
||||
|
||||
int numTopologies = (int)_topologies.size();
|
||||
int vertsOffset = 0;
|
||||
|
||||
for (int i = 0; i < numObjects; ++i) {
|
||||
|
||||
Object obj;
|
||||
obj.topologyIndex = i % numTopologies;
|
||||
obj.vertsOffset = vertsOffset;
|
||||
_objects.push_back(obj);
|
||||
|
||||
vertsOffset += _topologies[obj.topologyIndex].numVerts;
|
||||
}
|
||||
|
||||
// invalidate batch
|
||||
for (int i = 0; i < (int)_batches.size(); ++i) {
|
||||
glDeleteBuffers(1, &_batches[i].dispatchBuffer);
|
||||
}
|
||||
_batches.clear();
|
||||
|
||||
return vertsOffset;
|
||||
}
|
||||
|
||||
size_t
|
||||
SceneBase::CreateIndexBuffer() {
|
||||
if (_indexBuffer == 0) {
|
||||
glGenBuffers(1, &_indexBuffer);
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
|
||||
std::vector<int> buffer;
|
||||
std::vector<unsigned int> ppBuffer;
|
||||
|
||||
int numTopologies = (int)_topologies.size();
|
||||
for (int i = 0; i < numTopologies; ++i) {
|
||||
Far::PatchTable const *patchTable = _patchTables[i];
|
||||
|
||||
int nPatchArrays = patchTable->GetNumPatchArrays();
|
||||
|
||||
_topologies[i].patchArrays.clear();
|
||||
|
||||
// for each patchArray
|
||||
for (int j = 0; j < nPatchArrays; ++j) {
|
||||
|
||||
SceneBase::PatchArray patchArray;
|
||||
patchArray.desc = patchTable->GetPatchArrayDescriptor(j);
|
||||
patchArray.numPatches = patchTable->GetNumPatches(j);
|
||||
patchArray.indexOffset = (int)buffer.size();
|
||||
patchArray.primitiveIDOffset = (int)ppBuffer.size()/3;
|
||||
|
||||
_topologies[i].patchArrays.push_back(patchArray);
|
||||
|
||||
// indices
|
||||
Far::ConstIndexArray indices = patchTable->GetPatchArrayVertices(j);
|
||||
for (int k = 0; k < indices.size(); ++k) {
|
||||
buffer.push_back(indices[k]);
|
||||
}
|
||||
|
||||
// patchParams
|
||||
Far::ConstPatchParamArray patchParams = patchTable->GetPatchParams(j);
|
||||
// XXX: needs sharpness interface for patcharray or put sharpness into patchParam.
|
||||
for (int k = 0; k < patchParams.size(); ++k) {
|
||||
float sharpness = 0.0;
|
||||
ppBuffer.push_back(patchParams[k].field0);
|
||||
ppBuffer.push_back(patchParams[k].field1);
|
||||
ppBuffer.push_back(*((unsigned int *)&sharpness));
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
// XXX: we'll remove below APIs from Far::PatchTable.
|
||||
// use GetPatchParams(patchArray) instead as above.
|
||||
|
||||
// patch param (all in one)
|
||||
Far::PatchParamTable const &patchParamTable =
|
||||
patchTable->GetPatchParamTable();
|
||||
std::vector<int> const &sharpnessIndexTable =
|
||||
patchTable->GetSharpnessIndexTable();
|
||||
std::vector<float> const &sharpnessValues =
|
||||
patchTable->GetSharpnessValues();
|
||||
|
||||
int npatches = (int)patchParamTable.size();
|
||||
for (int i = 0; i < npatches; ++i) {
|
||||
float sharpness = 0.0;
|
||||
if (i < (int)sharpnessIndexTable.size()) {
|
||||
sharpness = sharpnessIndexTable[i] >= 0 ?
|
||||
sharpnessValues[sharpnessIndexTable[i]] : 0.0f;
|
||||
}
|
||||
ppBuffer.push_back(patchParamTable[i].faceIndex);
|
||||
ppBuffer.push_back(patchParamTable[i].bitField.field);
|
||||
ppBuffer.push_back(*((unsigned int *)&sharpness));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
|
||||
(int)buffer.size()*sizeof(int), &buffer[0], GL_STATIC_DRAW);
|
||||
|
||||
// patchParam is currently expected to be texture (it can be SSBO)
|
||||
GLuint texBuffer = 0;
|
||||
glGenBuffers(1, &texBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, texBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, ppBuffer.size()*sizeof(unsigned int),
|
||||
&ppBuffer[0], GL_STATIC_DRAW);
|
||||
|
||||
if (_patchParamTexture == 0) {
|
||||
glGenTextures(1, &_patchParamTexture);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_BUFFER, _patchParamTexture);
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32I, texBuffer);
|
||||
glBindTexture(GL_TEXTURE_BUFFER, 0);
|
||||
|
||||
glDeleteBuffers(1, &texBuffer);
|
||||
|
||||
return buffer.size()*sizeof(int) + ppBuffer.size()*sizeof(int);
|
||||
}
|
||||
|
||||
void
|
||||
SceneBase::buildBatches() {
|
||||
|
||||
int numObjects = (int)_objects.size();
|
||||
for (int i = 0; i < (int)_batches.size(); ++i) {
|
||||
glDeleteBuffers(1, &_batches[i].dispatchBuffer);
|
||||
}
|
||||
_batches.clear();
|
||||
|
||||
typedef std::map<Far::PatchDescriptor, std::vector<int> > StagingBatches;
|
||||
StagingBatches stagingBatches;
|
||||
|
||||
for (int i = 0; i < numObjects; ++i) {
|
||||
// get patchArrays from topology
|
||||
SceneBase::PatchArrayVector const &patchArrays =
|
||||
_topologies[_objects[i].topologyIndex].patchArrays;
|
||||
|
||||
// for each patchArray:
|
||||
for (int j = 0; j < (int)patchArrays.size(); ++j) {
|
||||
SceneBase::PatchArray const &patchArray = patchArrays[j];
|
||||
|
||||
// find batch for the descriptor
|
||||
std::vector<int> &command = stagingBatches[patchArray.desc];
|
||||
|
||||
int nPatch = patchArray.numPatches;
|
||||
int baseVertex = GetVertsOffset(i);
|
||||
|
||||
command.push_back(nPatch * patchArray.desc.GetNumControlVertices());
|
||||
command.push_back(1);
|
||||
command.push_back(patchArray.indexOffset);
|
||||
command.push_back(baseVertex);
|
||||
command.push_back(0);
|
||||
|
||||
command.push_back(patchArray.primitiveIDOffset);
|
||||
}
|
||||
}
|
||||
int stride = sizeof(int)*6; // not 5, since we interleave primitiveIDOffset
|
||||
|
||||
for (StagingBatches::iterator it = stagingBatches.begin();
|
||||
it != stagingBatches.end(); ++it) {
|
||||
|
||||
Batch batch;
|
||||
glGenBuffers(1, &batch.dispatchBuffer);
|
||||
|
||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, batch.dispatchBuffer);
|
||||
glBufferData(GL_DRAW_INDIRECT_BUFFER,
|
||||
it->second.size()*sizeof(int),
|
||||
&it->second[0], GL_STATIC_DRAW);
|
||||
|
||||
batch.desc = it->first;
|
||||
batch.count = (int)it->second.size()/6;
|
||||
batch.stride = stride;
|
||||
|
||||
_batches.push_back(batch);
|
||||
}
|
||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
|
||||
}
|
||||
143
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/sceneBase.h
vendored
Normal file
143
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/sceneBase.h
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
//
|
||||
// Copyright 2015 Pixar
|
||||
//
|
||||
// Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
// https://opensubdiv.org/license.
|
||||
//
|
||||
|
||||
#ifndef OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_SCENE_BASE_H
|
||||
#define OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_SCENE_BASE_H
|
||||
|
||||
#include "glLoader.h"
|
||||
|
||||
#include <opensubdiv/far/patchDescriptor.h>
|
||||
#include <opensubdiv/far/patchTable.h>
|
||||
#include <opensubdiv/osd/bufferDescriptor.h>
|
||||
|
||||
struct Shape;
|
||||
|
||||
class SceneBase {
|
||||
public:
|
||||
enum EndCap { kEndCapBSplineBasis,
|
||||
kEndCapGregoryBasis };
|
||||
|
||||
struct Options {
|
||||
Options() : adaptive(true), endCap(kEndCapGregoryBasis) { }
|
||||
|
||||
bool adaptive;
|
||||
int endCap;
|
||||
};
|
||||
|
||||
struct Object {
|
||||
int topologyIndex;
|
||||
int vertsOffset; // an offset within the VBO
|
||||
};
|
||||
|
||||
struct PatchArray {
|
||||
OpenSubdiv::Far::PatchDescriptor desc;
|
||||
int numPatches;
|
||||
int indexOffset; // an offset within the index buffer
|
||||
int primitiveIDOffset; // an offset within the patch param buffer
|
||||
};
|
||||
typedef std::vector<PatchArray> PatchArrayVector;
|
||||
|
||||
struct Topology {
|
||||
int numVerts;
|
||||
PatchArrayVector patchArrays;
|
||||
std::vector<float> restPosition;
|
||||
};
|
||||
|
||||
struct Batch {
|
||||
OpenSubdiv::Far::PatchDescriptor desc;
|
||||
int count;
|
||||
int stride;
|
||||
GLuint dispatchBuffer;
|
||||
};
|
||||
typedef std::vector<Batch> BatchVector;
|
||||
|
||||
/// Constructor.
|
||||
SceneBase(Options const &options);
|
||||
|
||||
/// Destructor.
|
||||
virtual ~SceneBase();
|
||||
|
||||
/// trivial accessors
|
||||
int GetNumObjects() const { return (int)_objects.size(); }
|
||||
|
||||
PatchArrayVector const &GetPatchArrays(int object) const {
|
||||
return _topologies[_objects[object].topologyIndex].patchArrays;
|
||||
}
|
||||
|
||||
BatchVector const &GetBatches() {
|
||||
if (_batches.empty()) buildBatches();
|
||||
return _batches;
|
||||
}
|
||||
|
||||
int GetVertsOffset(int object) const {
|
||||
return _objects[object].vertsOffset;
|
||||
}
|
||||
|
||||
std::vector<float> const &GetRestPosition(int object) const {
|
||||
return _topologies[_objects[object].topologyIndex].restPosition;
|
||||
}
|
||||
|
||||
GLuint GetPatchParamTexture() const {
|
||||
return _patchParamTexture;
|
||||
}
|
||||
|
||||
GLuint GetIndexBuffer() const {
|
||||
return _indexBuffer;
|
||||
}
|
||||
|
||||
// allocate batched vbo
|
||||
virtual size_t AllocateVBO(int numVerts,
|
||||
OpenSubdiv::Osd::BufferDescriptor const &vertexDesc,
|
||||
OpenSubdiv::Osd::BufferDescriptor const &varyingDesc,
|
||||
bool interleaved) = 0;
|
||||
|
||||
// refine an object
|
||||
virtual void Refine(int object) =0;
|
||||
|
||||
virtual void Synchronize() = 0;
|
||||
|
||||
virtual void UpdateVertexBuffer(int vertsOffset, std::vector<float> const &src)=0;
|
||||
|
||||
virtual void UpdateVaryingBuffer(int vertsOffset, std::vector<float> const &src)=0;
|
||||
|
||||
virtual GLuint BindVertexBuffer() = 0;
|
||||
|
||||
virtual GLuint BindVaryingBuffer() = 0;
|
||||
|
||||
// build batched index buffer and patchparam texture buffer
|
||||
size_t CreateIndexBuffer();
|
||||
|
||||
void AddTopology(Shape const *shape, int level, bool varying);
|
||||
|
||||
int AddObjects(int numObjects);
|
||||
|
||||
size_t GetStencilTableSize() const { return _stencilTableSize; }
|
||||
|
||||
protected:
|
||||
int createStencilTable(Shape const *shape, int level, bool varying,
|
||||
OpenSubdiv::Far::PatchTable const **patchTableOut);
|
||||
|
||||
void buildBatches();
|
||||
|
||||
virtual size_t createMeshRefiner(
|
||||
OpenSubdiv::Far::StencilTable const * vertexStencils,
|
||||
OpenSubdiv::Far::StencilTable const * varyingStencils,
|
||||
int numControlVertices) = 0;
|
||||
|
||||
Options _options;
|
||||
|
||||
std::vector<Object> _objects;
|
||||
std::vector<Topology> _topologies;
|
||||
std::vector<OpenSubdiv::Far::PatchTable const *> _patchTables;
|
||||
GLuint _indexBuffer;
|
||||
GLuint _patchParamTexture;
|
||||
BatchVector _batches;
|
||||
size_t _stencilTableSize;
|
||||
|
||||
};
|
||||
|
||||
#endif // OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_SCENE_BASE_H
|
||||
452
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/shader.glsl
vendored
Normal file
452
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/shader.glsl
vendored
Normal file
@@ -0,0 +1,452 @@
|
||||
//
|
||||
// Copyright 2014 Pixar
|
||||
//
|
||||
// Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
// https://opensubdiv.org/license.
|
||||
//
|
||||
#line 24
|
||||
#if defined(VARYING_COLOR) || defined(FACEVARYING_COLOR)
|
||||
#undef OSD_USER_VARYING_DECLARE
|
||||
#define OSD_USER_VARYING_DECLARE \
|
||||
vec3 color;
|
||||
|
||||
#undef OSD_USER_VARYING_ATTRIBUTE_DECLARE
|
||||
#define OSD_USER_VARYING_ATTRIBUTE_DECLARE \
|
||||
layout(location = 1) in vec3 color;
|
||||
|
||||
#undef OSD_USER_VARYING_PER_VERTEX
|
||||
#define OSD_USER_VARYING_PER_VERTEX() \
|
||||
outpt.color = color
|
||||
|
||||
#undef OSD_USER_VARYING_PER_CONTROL_POINT
|
||||
#define OSD_USER_VARYING_PER_CONTROL_POINT(ID_OUT, ID_IN) \
|
||||
outpt[ID_OUT].color = inpt[ID_IN].color
|
||||
|
||||
#undef OSD_USER_VARYING_PER_EVAL_POINT
|
||||
#define OSD_USER_VARYING_PER_EVAL_POINT(UV, a, b, c, d) \
|
||||
outpt.color = \
|
||||
mix(mix(inpt[a].color, inpt[b].color, UV.x), \
|
||||
mix(inpt[c].color, inpt[d].color, UV.x), UV.y)
|
||||
#else
|
||||
#define OSD_USER_VARYING_DECLARE
|
||||
#define OSD_USER_VARYING_ATTRIBUTE_DECLARE
|
||||
#define OSD_USER_VARYING_PER_CONTROL_POINT(ID_OUT, ID_IN)
|
||||
#define OSD_USER_VARYING_PER_EVAL_POINT(UV, a, b, c, d)
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Uniforms / Uniform Blocks
|
||||
//--------------------------------------------------------------
|
||||
|
||||
layout(std140) uniform Transform {
|
||||
mat4 ModelViewMatrix;
|
||||
mat4 ProjectionMatrix;
|
||||
mat4 ModelViewProjectionMatrix;
|
||||
};
|
||||
|
||||
layout(std140) uniform Tessellation {
|
||||
float TessLevel;
|
||||
};
|
||||
|
||||
uniform int GregoryQuadOffsetBase;
|
||||
uniform int BaseVertex;
|
||||
uniform int PrimitiveIdBase;
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Osd external functions
|
||||
//--------------------------------------------------------------
|
||||
|
||||
mat4 OsdModelViewMatrix()
|
||||
{
|
||||
return ModelViewMatrix;
|
||||
}
|
||||
mat4 OsdProjectionMatrix()
|
||||
{
|
||||
return ProjectionMatrix;
|
||||
}
|
||||
mat4 OsdModelViewProjectionMatrix()
|
||||
{
|
||||
return ModelViewProjectionMatrix;
|
||||
}
|
||||
float OsdTessLevel()
|
||||
{
|
||||
return TessLevel;
|
||||
}
|
||||
int OsdGregoryQuadOffsetBase()
|
||||
{
|
||||
return GregoryQuadOffsetBase;
|
||||
}
|
||||
int OsdPrimitiveIdBase()
|
||||
{
|
||||
// return inpt[0].primitiveIDOffset;
|
||||
return PrimitiveIdBase;
|
||||
}
|
||||
int OsdBaseVertex()
|
||||
{
|
||||
|
||||
#ifdef GL_ARB_shader_draw_parameters
|
||||
// return gl_BaseVertexARB;
|
||||
return BaseVertex;
|
||||
#else
|
||||
return BaseVertex;
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Vertex Shader
|
||||
//--------------------------------------------------------------
|
||||
#ifdef VERTEX_SHADER
|
||||
|
||||
layout (location=0) in vec4 position;
|
||||
OSD_USER_VARYING_ATTRIBUTE_DECLARE
|
||||
|
||||
out block {
|
||||
OutputVertex v;
|
||||
OSD_USER_VARYING_DECLARE
|
||||
} outpt;
|
||||
|
||||
void main()
|
||||
{
|
||||
outpt.v.position = ModelViewMatrix * position;
|
||||
OSD_USER_VARYING_PER_VERTEX();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Geometry Shader
|
||||
//--------------------------------------------------------------
|
||||
#ifdef GEOMETRY_SHADER
|
||||
|
||||
#ifdef PRIM_QUAD
|
||||
|
||||
layout(lines_adjacency) in;
|
||||
|
||||
#define EDGE_VERTS 4
|
||||
|
||||
#endif // PRIM_QUAD
|
||||
|
||||
#ifdef PRIM_TRI
|
||||
|
||||
layout(triangles) in;
|
||||
|
||||
#define EDGE_VERTS 3
|
||||
|
||||
#endif // PRIM_TRI
|
||||
|
||||
|
||||
layout(triangle_strip, max_vertices = EDGE_VERTS) out;
|
||||
in block {
|
||||
OutputVertex v;
|
||||
OSD_USER_VARYING_DECLARE
|
||||
} inpt[EDGE_VERTS];
|
||||
|
||||
out block {
|
||||
OutputVertex v;
|
||||
noperspective out vec4 edgeDistance;
|
||||
OSD_USER_VARYING_DECLARE
|
||||
} outpt;
|
||||
|
||||
void emit(int index, vec3 normal)
|
||||
{
|
||||
outpt.v.position = inpt[index].v.position;
|
||||
#ifdef SMOOTH_NORMALS
|
||||
outpt.v.normal = inpt[index].v.normal;
|
||||
#else
|
||||
outpt.v.normal = normal;
|
||||
#endif
|
||||
|
||||
#ifdef VARYING_COLOR
|
||||
outpt.color = inpt[index].color;
|
||||
#endif
|
||||
outpt.v.patchCoord = inpt[index].v.patchCoord;
|
||||
|
||||
gl_Position = ProjectionMatrix * inpt[index].v.position;
|
||||
EmitVertex();
|
||||
}
|
||||
|
||||
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
|
||||
const float VIEWPORT_SCALE = 1024.0; // XXXdyu
|
||||
|
||||
float edgeDistance(vec4 p, vec4 p0, vec4 p1)
|
||||
{
|
||||
return VIEWPORT_SCALE *
|
||||
abs((p.x - p0.x) * (p1.y - p0.y) -
|
||||
(p.y - p0.y) * (p1.x - p0.x)) / length(p1.xy - p0.xy);
|
||||
}
|
||||
|
||||
void emit(int index, vec3 normal, vec4 edgeVerts[EDGE_VERTS])
|
||||
{
|
||||
outpt.edgeDistance[0] =
|
||||
edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]);
|
||||
outpt.edgeDistance[1] =
|
||||
edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]);
|
||||
#ifdef PRIM_TRI
|
||||
outpt.edgeDistance[2] =
|
||||
edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]);
|
||||
#endif
|
||||
#ifdef PRIM_QUAD
|
||||
outpt.edgeDistance[2] =
|
||||
edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[3]);
|
||||
outpt.edgeDistance[3] =
|
||||
edgeDistance(edgeVerts[index], edgeVerts[3], edgeVerts[0]);
|
||||
#endif
|
||||
|
||||
emit(index, normal);
|
||||
}
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_PrimitiveID = gl_PrimitiveIDIn;
|
||||
|
||||
#ifdef PRIM_QUAD
|
||||
vec3 A = (inpt[0].v.position - inpt[1].v.position).xyz;
|
||||
vec3 B = (inpt[3].v.position - inpt[1].v.position).xyz;
|
||||
vec3 C = (inpt[2].v.position - inpt[1].v.position).xyz;
|
||||
vec3 n0 = normalize(cross(B, A));
|
||||
|
||||
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
|
||||
vec4 edgeVerts[EDGE_VERTS];
|
||||
edgeVerts[0] = ProjectionMatrix * inpt[0].v.position;
|
||||
edgeVerts[1] = ProjectionMatrix * inpt[1].v.position;
|
||||
edgeVerts[2] = ProjectionMatrix * inpt[2].v.position;
|
||||
edgeVerts[3] = ProjectionMatrix * inpt[3].v.position;
|
||||
|
||||
edgeVerts[0].xy /= edgeVerts[0].w;
|
||||
edgeVerts[1].xy /= edgeVerts[1].w;
|
||||
edgeVerts[2].xy /= edgeVerts[2].w;
|
||||
edgeVerts[3].xy /= edgeVerts[3].w;
|
||||
|
||||
emit(0, n0, edgeVerts);
|
||||
emit(1, n0, edgeVerts);
|
||||
emit(3, n0, edgeVerts);
|
||||
emit(2, n0, edgeVerts);
|
||||
#else
|
||||
emit(0, n0);
|
||||
emit(1, n0);
|
||||
emit(3, n0);
|
||||
emit(2, n0);
|
||||
#endif
|
||||
#endif // PRIM_QUAD
|
||||
|
||||
#ifdef PRIM_TRI
|
||||
vec3 A = (inpt[1].v.position - inpt[0].v.position).xyz;
|
||||
vec3 B = (inpt[2].v.position - inpt[0].v.position).xyz;
|
||||
vec3 n0 = normalize(cross(B, A));
|
||||
|
||||
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
|
||||
vec4 edgeVerts[EDGE_VERTS];
|
||||
edgeVerts[0] = ProjectionMatrix * inpt[0].v.position;
|
||||
edgeVerts[1] = ProjectionMatrix * inpt[1].v.position;
|
||||
edgeVerts[2] = ProjectionMatrix * inpt[2].v.position;
|
||||
|
||||
edgeVerts[0].xy /= edgeVerts[0].w;
|
||||
edgeVerts[1].xy /= edgeVerts[1].w;
|
||||
edgeVerts[2].xy /= edgeVerts[2].w;
|
||||
|
||||
emit(0, n0, edgeVerts);
|
||||
emit(1, n0, edgeVerts);
|
||||
emit(2, n0, edgeVerts);
|
||||
#else
|
||||
emit(0, n0);
|
||||
emit(1, n0);
|
||||
emit(2, n0);
|
||||
#endif
|
||||
#endif // PRIM_TRI
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Fragment Shader
|
||||
//--------------------------------------------------------------
|
||||
#ifdef FRAGMENT_SHADER
|
||||
|
||||
in block {
|
||||
OutputVertex v;
|
||||
noperspective in vec4 edgeDistance;
|
||||
OSD_USER_VARYING_DECLARE
|
||||
} inpt;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
#define NUM_LIGHTS 2
|
||||
|
||||
struct LightSource {
|
||||
vec4 position;
|
||||
vec4 ambient;
|
||||
vec4 diffuse;
|
||||
vec4 specular;
|
||||
};
|
||||
|
||||
layout(std140) uniform Lighting {
|
||||
LightSource lightSource[NUM_LIGHTS];
|
||||
};
|
||||
|
||||
uniform vec4 diffuseColor = vec4(1);
|
||||
uniform vec4 ambientColor = vec4(1);
|
||||
|
||||
vec4
|
||||
lighting(vec4 diffuse, vec3 Peye, vec3 Neye)
|
||||
{
|
||||
vec4 color = vec4(0);
|
||||
|
||||
for (int i = 0; i < NUM_LIGHTS; ++i) {
|
||||
|
||||
vec4 Plight = lightSource[i].position;
|
||||
|
||||
vec3 l = (Plight.w == 0.0)
|
||||
? normalize(Plight.xyz) : normalize(Plight.xyz - Peye);
|
||||
|
||||
vec3 n = normalize(Neye);
|
||||
vec3 h = normalize(l + vec3(0,0,1)); // directional viewer
|
||||
|
||||
float d = max(0.0, dot(n, l));
|
||||
float s = pow(max(0.0, dot(n, h)), 500.0f);
|
||||
|
||||
color += lightSource[i].ambient * ambientColor
|
||||
+ d * lightSource[i].diffuse * diffuse
|
||||
+ s * lightSource[i].specular;
|
||||
}
|
||||
|
||||
color.a = 1;
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4
|
||||
edgeColor(vec4 Cfill, vec4 edgeDistance)
|
||||
{
|
||||
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
|
||||
#ifdef PRIM_TRI
|
||||
float d =
|
||||
min(inpt.edgeDistance[0], min(inpt.edgeDistance[1], inpt.edgeDistance[2]));
|
||||
#endif
|
||||
#ifdef PRIM_QUAD
|
||||
float d =
|
||||
min(min(inpt.edgeDistance[0], inpt.edgeDistance[1]),
|
||||
min(inpt.edgeDistance[2], inpt.edgeDistance[3]));
|
||||
#endif
|
||||
float v = 0.8;
|
||||
vec4 Cedge = vec4(Cfill.r*v, Cfill.g*v, Cfill.b*v, 1);
|
||||
float p = exp2(-2 * d * d);
|
||||
|
||||
#if defined(GEOMETRY_OUT_WIRE)
|
||||
if (p < 0.25) discard;
|
||||
#endif
|
||||
|
||||
Cfill.rgb = mix(Cfill.rgb, Cedge.rgb, p);
|
||||
#endif
|
||||
return Cfill;
|
||||
}
|
||||
|
||||
vec4
|
||||
getAdaptivePatchColor(ivec3 patchParam)
|
||||
{
|
||||
const vec4 patchColors[7*6] = vec4[7*6](
|
||||
vec4(1.0f, 1.0f, 1.0f, 1.0f), // regular
|
||||
vec4(0.0f, 1.0f, 1.0f, 1.0f), // regular pattern 0
|
||||
vec4(0.0f, 0.5f, 1.0f, 1.0f), // regular pattern 1
|
||||
vec4(0.0f, 0.5f, 0.5f, 1.0f), // regular pattern 2
|
||||
vec4(0.5f, 0.0f, 1.0f, 1.0f), // regular pattern 3
|
||||
vec4(1.0f, 0.5f, 1.0f, 1.0f), // regular pattern 4
|
||||
|
||||
vec4(1.0f, 0.5f, 0.5f, 1.0f), // single crease
|
||||
vec4(1.0f, 0.70f, 0.6f, 1.0f), // single crease pattern 0
|
||||
vec4(1.0f, 0.65f, 0.6f, 1.0f), // single crease pattern 1
|
||||
vec4(1.0f, 0.60f, 0.6f, 1.0f), // single crease pattern 2
|
||||
vec4(1.0f, 0.55f, 0.6f, 1.0f), // single crease pattern 3
|
||||
vec4(1.0f, 0.50f, 0.6f, 1.0f), // single crease pattern 4
|
||||
|
||||
vec4(0.8f, 0.0f, 0.0f, 1.0f), // boundary
|
||||
vec4(0.0f, 0.0f, 0.75f, 1.0f), // boundary pattern 0
|
||||
vec4(0.0f, 0.2f, 0.75f, 1.0f), // boundary pattern 1
|
||||
vec4(0.0f, 0.4f, 0.75f, 1.0f), // boundary pattern 2
|
||||
vec4(0.0f, 0.6f, 0.75f, 1.0f), // boundary pattern 3
|
||||
vec4(0.0f, 0.8f, 0.75f, 1.0f), // boundary pattern 4
|
||||
|
||||
vec4(0.0f, 1.0f, 0.0f, 1.0f), // corner
|
||||
vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 0
|
||||
vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 1
|
||||
vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 2
|
||||
vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 3
|
||||
vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 4
|
||||
|
||||
vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
|
||||
vec4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
vec4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
vec4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
vec4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
vec4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
vec4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
|
||||
vec4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
|
||||
vec4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
|
||||
vec4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
|
||||
vec4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
|
||||
vec4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
|
||||
vec4(1.0f, 0.7f, 0.3f, 1.0f) // gregory basis
|
||||
);
|
||||
|
||||
int patchType = 0;
|
||||
|
||||
int edgeCount = bitCount(OsdGetPatchBoundaryMask(patchParam));
|
||||
if (edgeCount == 1) {
|
||||
patchType = 2; // BOUNDARY
|
||||
}
|
||||
if (edgeCount > 1) {
|
||||
patchType = 3; // CORNER (not correct for patches that are not isolated)
|
||||
}
|
||||
|
||||
#if defined OSD_PATCH_ENABLE_SINGLE_CREASE
|
||||
// check this after boundary/corner since single crease patch also has edgeCount.
|
||||
if (inpt.vSegments.y > 0) {
|
||||
patchType = 1;
|
||||
}
|
||||
#elif defined OSD_PATCH_GREGORY
|
||||
patchType = 4;
|
||||
#elif defined OSD_PATCH_GREGORY_BOUNDARY
|
||||
patchType = 5;
|
||||
#elif defined OSD_PATCH_GREGORY_BASIS
|
||||
patchType = 6;
|
||||
#elif defined OSD_PATCH_GREGORY_TRIANGLE
|
||||
patchType = 6;
|
||||
#endif
|
||||
|
||||
int pattern = bitCount(OsdGetPatchTransitionMask(patchParam));
|
||||
|
||||
return patchColors[6*patchType + pattern];
|
||||
}
|
||||
|
||||
#if defined(PRIM_QUAD) || defined(PRIM_TRI)
|
||||
void
|
||||
main()
|
||||
{
|
||||
vec3 N = (gl_FrontFacing ? inpt.v.normal : -inpt.v.normal);
|
||||
|
||||
#if defined(VARYING_COLOR)
|
||||
vec4 color = vec4(inpt.color, 1);
|
||||
#else
|
||||
vec4 color = getAdaptivePatchColor(OsdGetPatchParam(OsdGetPatchIndex(gl_PrimitiveID)));
|
||||
#endif
|
||||
|
||||
vec4 Cf = lighting(color, inpt.v.position.xyz, N);
|
||||
|
||||
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
|
||||
Cf = edgeColor(Cf, inpt.edgeDistance);
|
||||
#endif
|
||||
|
||||
outColor = Cf;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
111
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/vbo.h
vendored
Normal file
111
blender-5.2.0/extern/opensubdiv-source/examples/glShareTopology/vbo.h
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// Copyright 2015 Pixar
|
||||
//
|
||||
// Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
// https://opensubdiv.org/license.
|
||||
//
|
||||
|
||||
#ifndef OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_VBO_H
|
||||
#define OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_VBO_H
|
||||
|
||||
#include "glLoader.h"
|
||||
|
||||
#include <opensubdiv/osd/bufferDescriptor.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
template <class VERTEX_BUFFER, class DEVICE_CONTEXT>
|
||||
class VBO {
|
||||
public:
|
||||
VBO(OpenSubdiv::Osd::BufferDescriptor const &vertexDesc,
|
||||
OpenSubdiv::Osd::BufferDescriptor const &varyingDesc,
|
||||
bool interleaved, int numVertices, DEVICE_CONTEXT *deviceContext) :
|
||||
_vertexDesc(vertexDesc),
|
||||
_varyingDesc(varyingDesc),
|
||||
_numVertices(numVertices),
|
||||
_vertexBuffer(NULL), _varyingBuffer(NULL), _interleaved(interleaved),
|
||||
_deviceContext(deviceContext) {
|
||||
|
||||
if (interleaved) {
|
||||
assert(vertexDesc.stride == varyingDesc.stride);
|
||||
_vertexBuffer = createVertexBuffer(
|
||||
vertexDesc.stride, numVertices);
|
||||
} else {
|
||||
if (vertexDesc.stride > 0) {
|
||||
_vertexBuffer = createVertexBuffer(
|
||||
vertexDesc.stride, numVertices);
|
||||
}
|
||||
if (varyingDesc.stride > 0) {
|
||||
_varyingBuffer = createVertexBuffer(
|
||||
varyingDesc.stride, numVertices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~VBO() {
|
||||
delete _vertexBuffer;
|
||||
delete _varyingBuffer;
|
||||
}
|
||||
|
||||
OpenSubdiv::Osd::BufferDescriptor const &GetVertexDesc() const {
|
||||
return _vertexDesc;
|
||||
}
|
||||
OpenSubdiv::Osd::BufferDescriptor const &GetVaryingDesc() const {
|
||||
return _varyingDesc;
|
||||
}
|
||||
|
||||
void UpdateVertexBuffer(int vertsOffset, std::vector<float> const &src) {
|
||||
updateVertexBuffer(_vertexBuffer, &src[0], vertsOffset,
|
||||
(int)src.size()/_vertexBuffer->GetNumElements());
|
||||
}
|
||||
void UpdateVaryingBuffer(int vertsOffset, std::vector<float> const &src) {
|
||||
updateVertexBuffer(_varyingBuffer, &src[0], vertsOffset,
|
||||
(int)src.size()/_varyingBuffer->GetNumElements());
|
||||
}
|
||||
|
||||
GLuint BindVertexBuffer() {
|
||||
return _vertexBuffer->BindVBO();
|
||||
}
|
||||
|
||||
GLuint BindVaryingBuffer() {
|
||||
return _varyingBuffer->BindVBO();
|
||||
}
|
||||
|
||||
VERTEX_BUFFER *GetVertexBuffer() const {
|
||||
return _vertexBuffer;
|
||||
}
|
||||
|
||||
VERTEX_BUFFER *GetVaryingBuffer() const {
|
||||
return _interleaved ? _vertexBuffer : _varyingBuffer;
|
||||
}
|
||||
|
||||
size_t GetSize() const {
|
||||
size_t size = _numVertices * _vertexDesc.stride;
|
||||
if (_varyingBuffer) size += _numVertices * _varyingDesc.stride;
|
||||
return size * sizeof(float);
|
||||
}
|
||||
|
||||
private:
|
||||
VERTEX_BUFFER *createVertexBuffer(int numElements, int numVertices) {
|
||||
return VERTEX_BUFFER::Create(numElements, numVertices, _deviceContext);
|
||||
}
|
||||
|
||||
void updateVertexBuffer(VERTEX_BUFFER *vertexBuffer,
|
||||
const float *src, int startVertex,
|
||||
int numVertices) {
|
||||
vertexBuffer->UpdateData(src, startVertex, numVertices, _deviceContext);
|
||||
}
|
||||
|
||||
OpenSubdiv::Osd::BufferDescriptor _vertexDesc;
|
||||
OpenSubdiv::Osd::BufferDescriptor _varyingDesc;
|
||||
|
||||
// # of vertices total, including both control verts and refined verts.
|
||||
int _numVertices;
|
||||
|
||||
VERTEX_BUFFER *_vertexBuffer;
|
||||
VERTEX_BUFFER *_varyingBuffer;
|
||||
bool _interleaved;
|
||||
DEVICE_CONTEXT *_deviceContext;
|
||||
};
|
||||
|
||||
#endif // OPENSUBDIV_EXAMPLES_GL_SHARE_TOPOLOGY_VBO_H
|
||||
Reference in New Issue
Block a user