mirror of
https://github.com/PixarAnimationStudios/OpenSubdiv
synced 2024-11-09 13:50:05 +00:00
first pass at osd module - no GLSL / CUDA / CL kernels yet
This commit is contained in:
parent
d7ef589ebb
commit
a055967056
@ -168,3 +168,5 @@ endif(MSVC)
|
||||
add_subdirectory(opensubdiv)
|
||||
|
||||
add_subdirectory(regression)
|
||||
|
||||
add_subdirectory(examples)
|
||||
|
118
cmake/FindGLEW.cmake
Normal file
118
cmake/FindGLEW.cmake
Normal file
@ -0,0 +1,118 @@
|
||||
#
|
||||
# Copyright (C) Pixar. All rights reserved.
|
||||
#
|
||||
# This license governs use of the accompanying software. If you
|
||||
# use the software, you accept this license. If you do not accept
|
||||
# the license, do not use the software.
|
||||
#
|
||||
# 1. Definitions
|
||||
# The terms "reproduce," "reproduction," "derivative works," and
|
||||
# "distribution" have the same meaning here as under U.S.
|
||||
# copyright law. A "contribution" is the original software, or
|
||||
# any additions or changes to the software.
|
||||
# A "contributor" is any person or entity that distributes its
|
||||
# contribution under this license.
|
||||
# "Licensed patents" are a contributor's patent claims that read
|
||||
# directly on its contribution.
|
||||
#
|
||||
# 2. Grant of Rights
|
||||
# (A) Copyright Grant- Subject to the terms of this license,
|
||||
# including the license conditions and limitations in section 3,
|
||||
# each contributor grants you a non-exclusive, worldwide,
|
||||
# royalty-free copyright license to reproduce its contribution,
|
||||
# prepare derivative works of its contribution, and distribute
|
||||
# its contribution or any derivative works that you create.
|
||||
# (B) Patent Grant- Subject to the terms of this license,
|
||||
# including the license conditions and limitations in section 3,
|
||||
# each contributor grants you a non-exclusive, worldwide,
|
||||
# royalty-free license under its licensed patents to make, have
|
||||
# made, use, sell, offer for sale, import, and/or otherwise
|
||||
# dispose of its contribution in the software or derivative works
|
||||
# of the contribution in the software.
|
||||
#
|
||||
# 3. Conditions and Limitations
|
||||
# (A) No Trademark License- This license does not grant you
|
||||
# rights to use any contributor's name, logo, or trademarks.
|
||||
# (B) If you bring a patent claim against any contributor over
|
||||
# patents that you claim are infringed by the software, your
|
||||
# patent license from such contributor to the software ends
|
||||
# automatically.
|
||||
# (C) If you distribute any portion of the software, you must
|
||||
# retain all copyright, patent, trademark, and attribution
|
||||
# notices that are present in the software.
|
||||
# (D) If you distribute any portion of the software in source
|
||||
# code form, you may do so only under this license by including a
|
||||
# complete copy of this license with your distribution. If you
|
||||
# distribute any portion of the software in compiled or object
|
||||
# code form, you may only do so under a license that complies
|
||||
# with this license.
|
||||
# (E) The software is licensed "as-is." You bear the risk of
|
||||
# using it. The contributors give no express warranties,
|
||||
# guarantees or conditions. You may have additional consumer
|
||||
# rights under your local laws which this license cannot change.
|
||||
# To the extent permitted under your local laws, the contributors
|
||||
# exclude the implied warranties of merchantability, fitness for
|
||||
# a particular purpose and non-infringement.
|
||||
#
|
||||
#
|
||||
|
||||
# Try to find GLEW library and include path.
|
||||
# Once done this will define
|
||||
#
|
||||
# GLEW_FOUND
|
||||
# GLEW_INCLUDE_DIR
|
||||
# GLEW_LIBRARIES
|
||||
#
|
||||
|
||||
IF (WIN32)
|
||||
FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h
|
||||
$ENV{PROGRAMFILES}/GLEW/include
|
||||
${PROJECT_SOURCE_DIR}/extern/glew/include
|
||||
DOC "The directory where GL/glew.h resides")
|
||||
FIND_LIBRARY( GLEW_LIBRARIES
|
||||
NAMES glew GLEW glew32 glew32s
|
||||
PATHS
|
||||
$ENV{PROGRAMFILES}/GLEW/lib
|
||||
${PROJECT_SOURCE_DIR}/extern/glew/bin
|
||||
${PROJECT_SOURCE_DIR}/extern/glew/lib
|
||||
DOC "The GLEW library")
|
||||
ENDIF (WIN32)
|
||||
|
||||
IF (${CMAKE_HOST_UNIX})
|
||||
FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h
|
||||
${GLEW_LOCATION}/include
|
||||
${PROJECT_SOURCE_DIR}/extern/glew/include
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/sw/include
|
||||
/opt/local/include
|
||||
DOC "The directory where GL/glew.h resides")
|
||||
FIND_LIBRARY( GLEW_LIBRARIES
|
||||
NAMES GLEW glew
|
||||
PATHS
|
||||
${GLEW_LOCATION}/lib
|
||||
${PROJECT_SOURCE_DIR}/extern/glew/bin
|
||||
/usr/lib64
|
||||
/usr/lib
|
||||
/usr/local/lib64
|
||||
/usr/local/lib
|
||||
/sw/lib
|
||||
/opt/local/lib
|
||||
DOC "The GLEW library")
|
||||
ENDIF ()
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLEW DEFAULT_MSG
|
||||
GLEW_INCLUDE_DIR
|
||||
GLEW_LIBRARIES
|
||||
)
|
||||
|
||||
IF (GLEW_INCLUDE_DIR)
|
||||
SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
|
||||
SET( ILMBASE_FOUND TRUE )
|
||||
ELSE (GLEW_INCLUDE_DIR)
|
||||
SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
|
||||
SET( ILMBASE_FOUND FALSE )
|
||||
ENDIF (GLEW_INCLUDE_DIR)
|
||||
|
||||
MARK_AS_ADVANCED( GLEW_FOUND )
|
185
cmake/FindGLUT.cmake
Normal file
185
cmake/FindGLUT.cmake
Normal file
@ -0,0 +1,185 @@
|
||||
#
|
||||
# Copyright (C) Pixar. All rights reserved.
|
||||
#
|
||||
# This license governs use of the accompanying software. If you
|
||||
# use the software, you accept this license. If you do not accept
|
||||
# the license, do not use the software.
|
||||
#
|
||||
# 1. Definitions
|
||||
# The terms "reproduce," "reproduction," "derivative works," and
|
||||
# "distribution" have the same meaning here as under U.S.
|
||||
# copyright law. A "contribution" is the original software, or
|
||||
# any additions or changes to the software.
|
||||
# A "contributor" is any person or entity that distributes its
|
||||
# contribution under this license.
|
||||
# "Licensed patents" are a contributor's patent claims that read
|
||||
# directly on its contribution.
|
||||
#
|
||||
# 2. Grant of Rights
|
||||
# (A) Copyright Grant- Subject to the terms of this license,
|
||||
# including the license conditions and limitations in section 3,
|
||||
# each contributor grants you a non-exclusive, worldwide,
|
||||
# royalty-free copyright license to reproduce its contribution,
|
||||
# prepare derivative works of its contribution, and distribute
|
||||
# its contribution or any derivative works that you create.
|
||||
# (B) Patent Grant- Subject to the terms of this license,
|
||||
# including the license conditions and limitations in section 3,
|
||||
# each contributor grants you a non-exclusive, worldwide,
|
||||
# royalty-free license under its licensed patents to make, have
|
||||
# made, use, sell, offer for sale, import, and/or otherwise
|
||||
# dispose of its contribution in the software or derivative works
|
||||
# of the contribution in the software.
|
||||
#
|
||||
# 3. Conditions and Limitations
|
||||
# (A) No Trademark License- This license does not grant you
|
||||
# rights to use any contributor's name, logo, or trademarks.
|
||||
# (B) If you bring a patent claim against any contributor over
|
||||
# patents that you claim are infringed by the software, your
|
||||
# patent license from such contributor to the software ends
|
||||
# automatically.
|
||||
# (C) If you distribute any portion of the software, you must
|
||||
# retain all copyright, patent, trademark, and attribution
|
||||
# notices that are present in the software.
|
||||
# (D) If you distribute any portion of the software in source
|
||||
# code form, you may do so only under this license by including a
|
||||
# complete copy of this license with your distribution. If you
|
||||
# distribute any portion of the software in compiled or object
|
||||
# code form, you may only do so under a license that complies
|
||||
# with this license.
|
||||
# (E) The software is licensed "as-is." You bear the risk of
|
||||
# using it. The contributors give no express warranties,
|
||||
# guarantees or conditions. You may have additional consumer
|
||||
# rights under your local laws which this license cannot change.
|
||||
# To the extent permitted under your local laws, the contributors
|
||||
# exclude the implied warranties of merchantability, fitness for
|
||||
# a particular purpose and non-infringement.
|
||||
#
|
||||
#
|
||||
|
||||
# Try to find GLUT library and include path.
|
||||
# Once done this will define
|
||||
#
|
||||
# GLUT_FOUND
|
||||
# GLUT_INCLUDE_DIR
|
||||
# GLUT_LIBRARIES
|
||||
#
|
||||
|
||||
IF (WIN32)
|
||||
|
||||
IF(CYGWIN)
|
||||
|
||||
FIND_PATH( GLUT_INCLUDE_DIR GL/glut.h
|
||||
${GLUT_LOCATION}/include
|
||||
/usr/include
|
||||
)
|
||||
|
||||
FIND_LIBRARY( GLUT_glut_LIBRARY glut32
|
||||
${GLUT_LOCATION}/lib
|
||||
${OPENGL_LIBRARY_DIR}
|
||||
/usr/lib
|
||||
/usr/lib/w32api
|
||||
/usr/local/lib
|
||||
/usr/X11R6/lib
|
||||
)
|
||||
|
||||
|
||||
ELSE(CYGWIN)
|
||||
|
||||
FIND_PATH( GLUT_INCLUDE_DIR GL/glut.h
|
||||
${GLUT_LOCATION}/include
|
||||
${PROJECT_SOURCE_DIR}/extern/glut/include
|
||||
DOC "The directory where GL/glut.h resides")
|
||||
FIND_LIBRARY( GLUT_glut_LIBRARY
|
||||
NAMES glut GLUT glut32 glut32s
|
||||
PATHS
|
||||
${GLUT_LOCATION}/lib
|
||||
${PROJECT_SOURCE_DIR}/extern/glut/bin
|
||||
${PROJECT_SOURCE_DIR}/extern/glut/lib
|
||||
${OPENGL_LIBRARY_DIR}
|
||||
DOC "The GLUT library")
|
||||
|
||||
ENDIF(CYGWIN)
|
||||
ELSE (WIN32)
|
||||
|
||||
IF (APPLE)
|
||||
# These values for Apple could probably do with improvement.
|
||||
FIND_PATH( GLUT_INCLUDE_DIR glut.h
|
||||
/System/Library/Frameworks/GLUT.framework/Versions/A/Headers
|
||||
${OPENGL_LIBRARY_DIR}
|
||||
)
|
||||
SET(GLUT_glut_LIBRARY "-framework Glut" CACHE STRING "GLUT library for OSX")
|
||||
SET(GLUT_cocoa_LIBRARY "-framework Cocoa" CACHE STRING "Cocoa framework for OSX")
|
||||
ELSE (APPLE)
|
||||
|
||||
FIND_PATH( GLUT_INCLUDE_DIR GL/glut.h
|
||||
${GLUT_LOCATION}/include
|
||||
/usr/include
|
||||
/usr/include/GL
|
||||
/usr/local/include
|
||||
/usr/openwin/share/include
|
||||
/usr/openwin/include
|
||||
/usr/X11R6/include
|
||||
/usr/include/X11
|
||||
/opt/graphics/OpenGL/include
|
||||
/opt/graphics/OpenGL/contrib/libglut
|
||||
)
|
||||
|
||||
FIND_LIBRARY( GLUT_glut_LIBRARY glut
|
||||
${GLUT_LOCATION}/lib
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/usr/openwin/lib
|
||||
/usr/X11R6/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY( GLUT_Xi_LIBRARY Xi
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/usr/openwin/lib
|
||||
/usr/X11R6/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY( GLUT_Xmu_LIBRARY Xmu
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/usr/openwin/lib
|
||||
/usr/X11R6/lib
|
||||
)
|
||||
|
||||
ENDIF (APPLE)
|
||||
|
||||
ENDIF (WIN32)
|
||||
|
||||
SET( GLUT_FOUND "NO" )
|
||||
IF(GLUT_INCLUDE_DIR)
|
||||
IF(GLUT_glut_LIBRARY)
|
||||
# Is -lXi and -lXmu required on all platforms that have it?
|
||||
# If not, we need some way to figure out what platform we are on.
|
||||
SET( GLUT_LIBRARIES
|
||||
${GLUT_glut_LIBRARY}
|
||||
${GLUT_Xmu_LIBRARY}
|
||||
${GLUT_Xi_LIBRARY}
|
||||
${GLUT_cocoa_LIBRARY}
|
||||
)
|
||||
SET( GLUT_FOUND "YES" )
|
||||
|
||||
SET (GLUT_LIBRARY ${GLUT_LIBRARIES})
|
||||
SET (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
|
||||
|
||||
ENDIF(GLUT_glut_LIBRARY)
|
||||
ENDIF(GLUT_INCLUDE_DIR)
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT DEFAULT_MSG
|
||||
GLUT_INCLUDE_DIR
|
||||
GLUT_LIBRARIES
|
||||
)
|
||||
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
GLUT_INCLUDE_DIR
|
||||
GLUT_glut_LIBRARY
|
||||
GLUT_Xmu_LIBRARY
|
||||
GLUT_Xi_LIBRARY
|
||||
)
|
||||
|
@ -59,7 +59,7 @@
|
||||
# Once done this will define
|
||||
#
|
||||
# ILMBASE_FOUND - System has OPENCL
|
||||
# ILMBASE_INCLUDE_DIRECTORY - The include directory
|
||||
# ILMBASE_INCLUDE_DIR - The include directory
|
||||
# ILMBASE_LIBS_DIRECTORY - The libraries needed
|
||||
|
||||
IF(NOT DEFINED ILMBASE_LOCATION)
|
||||
@ -118,7 +118,7 @@ SET(INCLUDE_PATHS
|
||||
)
|
||||
|
||||
|
||||
FIND_PATH( ILMBASE_INCLUDE_DIRECTORY ImathMath.h
|
||||
FIND_PATH( ILMBASE_INCLUDE_DIR ImathMath.h
|
||||
PATHS
|
||||
${INCLUDE_PATHS}
|
||||
NO_DEFAULT_PATH
|
||||
@ -178,7 +178,7 @@ IF ( ${ILMBASE_IMATH_LIB} STREQUAL "ILMBASE_IMATH_LIB-NOTFOUND" )
|
||||
MESSAGE( FATAL_ERROR "ilmbase libraries (Imath) not found, required" )
|
||||
ENDIF()
|
||||
|
||||
IF ( ${ILMBASE_INCLUDE_DIRECTORY} STREQUAL "ILMBASE_INCLUDE_DIRECTORY-NOTFOUND" )
|
||||
IF ( ${ILMBASE_INCLUDE_DIR} STREQUAL "ILMBASE_INCLUDE_DIR-NOTFOUND" )
|
||||
MESSAGE( FATAL_ERROR "ilmbase header files not found, required: ILMBASE_LOCATION: ${ILMBASE_LOCATION}" )
|
||||
ENDIF()
|
||||
|
||||
@ -191,14 +191,9 @@ SET( ILMBASE_LIBS_DIRECTORY
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(IlmBase DEFAULT_MSG
|
||||
ILMBASE_LOCATION
|
||||
ILMBASE_INCLUDE_DIRECTORY
|
||||
ILMBASE_INCLUDE_DIR
|
||||
ILMBASE_LIBS_DIRECTORY
|
||||
)
|
||||
|
||||
|
||||
#MESSAGE( STATUS "ILMBASE INCLUDE PATH: ${ILMBASE_INCLUDE_DIRECTORY}" )
|
||||
#MESSAGE( STATUS "IEX LIB: ${ILMBASE_IEX_LIB}" )
|
||||
#MESSAGE( STATUS "IMATH LIB: ${ILMBASE_IMATH_LIB}" )
|
||||
|
||||
SET( ILMBASE_FOUND TRUE )
|
||||
|
||||
|
@ -57,6 +57,7 @@
|
||||
|
||||
add_subdirectory(hbr)
|
||||
add_subdirectory(far)
|
||||
add_subdirectory(osd)
|
||||
|
||||
install( FILES version.h
|
||||
DESTINATION include/
|
||||
|
81
opensubdiv/osd/CMakeLists.txt
Normal file
81
opensubdiv/osd/CMakeLists.txt
Normal file
@ -0,0 +1,81 @@
|
||||
find_package(IlmBase REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
|
||||
include_directories(
|
||||
${ILMBASE_INCLUDE_DIR}
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${GLEW_INCLUDE_DIR}
|
||||
${GLUT_INCLUDE_DIR}
|
||||
${PROJECT_SOURCE_DIR}/opensubdiv
|
||||
)
|
||||
|
||||
|
||||
set(SOURCE_FILES
|
||||
cpuDispatcher.cpp
|
||||
cpuKernel.cpp
|
||||
kernelDispatcher.cpp
|
||||
mesh.cpp
|
||||
)
|
||||
|
||||
set(HEADER_FILES
|
||||
cpuDispatcher.h
|
||||
cpuKernel.h
|
||||
kernelDispatcher.h
|
||||
local.h
|
||||
mesh.h
|
||||
vertex.h
|
||||
)
|
||||
|
||||
if(APPLE)
|
||||
set(PLATFORM_COMPILE_FLAGS
|
||||
-fopenmp
|
||||
)
|
||||
set(PLATFORM_LIBRARIES
|
||||
#XXX:cleanup Remove opengl, glut, and OpenCL from this list.
|
||||
/System/Library/Frameworks/OpenGL.framework
|
||||
/System/Library/Frameworks/OpenCL.framework
|
||||
/System/Library/Frameworks/GLUT.framework
|
||||
gomp
|
||||
)
|
||||
endif(APPLE)
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
set(PLATFORM_COMPILE_FLAGS
|
||||
-fopenmp
|
||||
-fPIC
|
||||
)
|
||||
set(PLATFORM_LIBRARIES
|
||||
GLU
|
||||
glut
|
||||
gomp
|
||||
)
|
||||
endif(UNIX AND NOT APPLE)
|
||||
|
||||
if(WIN32)
|
||||
set(PLATFORM_COMPILE_FLAGS
|
||||
/openmp
|
||||
)
|
||||
set(PLATFORM_LIBRARIES
|
||||
)
|
||||
endif(WIN32)
|
||||
|
||||
macro(_add_library target)
|
||||
if(CUDA_FOUND)
|
||||
cuda_add_library(${target} ${ARGN})
|
||||
else()
|
||||
add_library(${target} ${ARGN})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
_add_library(osd STATIC
|
||||
${SOURCE_FILES}
|
||||
${HEADER_FILES}
|
||||
)
|
||||
|
||||
target_link_libraries(osd
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLUT_LIBRARIES}
|
||||
${PLATFORM_LIBRARIES}
|
||||
glew
|
||||
)
|
301
opensubdiv/osd/cpuDispatcher.cpp
Normal file
301
opensubdiv/osd/cpuDispatcher.cpp
Normal file
@ -0,0 +1,301 @@
|
||||
//
|
||||
// Copyright (C) Pixar. All rights reserved.
|
||||
//
|
||||
// This license governs use of the accompanying software. If you
|
||||
// use the software, you accept this license. If you do not accept
|
||||
// the license, do not use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S.
|
||||
// copyright law. A "contribution" is the original software, or
|
||||
// any additions or changes to the software.
|
||||
// A "contributor" is any person or entity that distributes its
|
||||
// contribution under this license.
|
||||
// "Licensed patents" are a contributor's patent claims that read
|
||||
// directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
// (A) Copyright Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free copyright license to reproduce its contribution,
|
||||
// prepare derivative works of its contribution, and distribute
|
||||
// its contribution or any derivative works that you create.
|
||||
// (B) Patent Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free license under its licensed patents to make, have
|
||||
// made, use, sell, offer for sale, import, and/or otherwise
|
||||
// dispose of its contribution in the software or derivative works
|
||||
// of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
// (A) No Trademark License- This license does not grant you
|
||||
// rights to use any contributor's name, logo, or trademarks.
|
||||
// (B) If you bring a patent claim against any contributor over
|
||||
// patents that you claim are infringed by the software, your
|
||||
// patent license from such contributor to the software ends
|
||||
// automatically.
|
||||
// (C) If you distribute any portion of the software, you must
|
||||
// retain all copyright, patent, trademark, and attribution
|
||||
// notices that are present in the software.
|
||||
// (D) If you distribute any portion of the software in source
|
||||
// code form, you may do so only under this license by including a
|
||||
// complete copy of this license with your distribution. If you
|
||||
// distribute any portion of the software in compiled or object
|
||||
// code form, you may only do so under a license that complies
|
||||
// with this license.
|
||||
// (E) The software is licensed "as-is." You bear the risk of
|
||||
// using it. The contributors give no express warranties,
|
||||
// guarantees or conditions. You may have additional consumer
|
||||
// rights under your local laws which this license cannot change.
|
||||
// To the extent permitted under your local laws, the contributors
|
||||
// exclude the implied warranties of merchantability, fitness for
|
||||
// a particular purpose and non-infringement.
|
||||
//
|
||||
#include "../osd/cpuDispatcher.h"
|
||||
#include "../osd/cpuKernel.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace OpenSubdiv {
|
||||
namespace OPENSUBDIV_VERSION {
|
||||
|
||||
OsdCpuKernelDispatcher::DeviceTable::~DeviceTable()
|
||||
{
|
||||
if(devicePtr) free(devicePtr);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::DeviceTable::Copy(int size, const void *table)
|
||||
{
|
||||
if(size > 0){
|
||||
if(devicePtr) free(devicePtr);
|
||||
devicePtr = malloc(size);
|
||||
memcpy(devicePtr, table, size);
|
||||
}
|
||||
}
|
||||
|
||||
OsdCpuKernelDispatcher::OsdCpuKernelDispatcher(int levels, int numVertexElements, int numVaryingElements) :
|
||||
OsdKernelDispatcher(levels),
|
||||
_vertexBuffer(0),
|
||||
_varyingBuffer(0),
|
||||
_vbo(NULL),
|
||||
_varyingVbo(NULL),
|
||||
_numVertexElements(numVertexElements),
|
||||
_numVaryingElements(numVaryingElements)
|
||||
{
|
||||
_tables.resize(TABLE_MAX);
|
||||
}
|
||||
|
||||
OsdCpuKernelDispatcher::~OsdCpuKernelDispatcher()
|
||||
{
|
||||
if(_vbo) delete[] _vbo;
|
||||
if(_varyingVbo) delete[] _varyingVbo;
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::CopyTable(int tableIndex, size_t size, const void *ptr)
|
||||
{
|
||||
_tables[tableIndex].Copy(size, ptr);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::BeginLaunchKernel()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::EndLaunchKernel()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::BindVertexBuffer(GLuint vertexBuffer, GLuint varyingBuffer)
|
||||
{
|
||||
_vertexBuffer = vertexBuffer;
|
||||
_varyingBuffer = varyingBuffer;
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::UpdateVertexBuffer(size_t size, void *ptr)
|
||||
{
|
||||
memcpy(_vbo, ptr, size);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::UpdateVaryingBuffer(size_t size, void *ptr)
|
||||
{
|
||||
memcpy(_varyingVbo, ptr, size);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::MapVertexBuffer()
|
||||
{
|
||||
// XXX not efficient for CPU
|
||||
// copy vbo content to kernel-buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
|
||||
glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &_vboSize);
|
||||
|
||||
if(_vbo) delete[] _vbo;
|
||||
_vbo = new float[_vboSize/sizeof(float)];
|
||||
|
||||
// too slow...
|
||||
float *buffer = (float*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
|
||||
if(buffer){
|
||||
memcpy(_vbo, buffer, _vboSize);
|
||||
}
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::MapVaryingBuffer()
|
||||
{
|
||||
if(_varyingBuffer){
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _varyingBuffer);
|
||||
glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &_varyingVboSize);
|
||||
|
||||
if(_varyingVbo) delete[] _varyingVbo;
|
||||
_varyingVbo = new float[_varyingVboSize/sizeof(float)];
|
||||
|
||||
float *buffer = (float*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
|
||||
if(buffer){
|
||||
memcpy(_varyingVbo, buffer, _varyingVboSize);
|
||||
}
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::UnmapVertexBuffer()
|
||||
{
|
||||
// write back kernel-buffer to vbo
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
|
||||
float *buffer = (float*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
if(buffer){
|
||||
memcpy(buffer, _vbo, _vboSize);
|
||||
}
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::UnmapVaryingBuffer()
|
||||
{
|
||||
if(_varyingBuffer){
|
||||
// write back kernel-buffer to vbo
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _varyingBuffer);
|
||||
float *buffer = (float*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
if(buffer){
|
||||
memcpy(buffer, _varyingVbo, _varyingVboSize);
|
||||
}
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::Synchronize()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::ApplyCatmarkFaceVerticesKernel(FarMesh<OsdVertex> * mesh, int offset,
|
||||
int level, int start, int end, void * data) const
|
||||
{
|
||||
VertexDescriptor vd(_numVertexElements, _numVaryingElements);
|
||||
|
||||
computeFace(&vd, _vbo, _varyingVbo,
|
||||
(int*)_tables[F_IT].devicePtr + _tableOffsets[F_IT][level-1],
|
||||
(int*)_tables[F_ITa].devicePtr + _tableOffsets[F_ITa][level-1],
|
||||
offset, start, end);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::ApplyCatmarkEdgeVerticesKernel(FarMesh<OsdVertex> * mesh, int offset,
|
||||
int level, int start, int end, void * data) const
|
||||
{
|
||||
VertexDescriptor vd(_numVertexElements, _numVaryingElements);
|
||||
|
||||
computeEdge(&vd, _vbo, _varyingVbo,
|
||||
(int*)_tables[E_IT].devicePtr + _tableOffsets[E_IT][level-1],
|
||||
(float*)_tables[E_W].devicePtr + _tableOffsets[E_W][level-1],
|
||||
offset,
|
||||
start, end);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::ApplyCatmarkVertexVerticesKernelB(FarMesh<OsdVertex> * mesh, int offset,
|
||||
int level, int start, int end, void * data) const
|
||||
{
|
||||
VertexDescriptor vd(_numVertexElements, _numVaryingElements);
|
||||
|
||||
computeVertexB(&vd, _vbo, _varyingVbo,
|
||||
(int*)_tables[V_ITa].devicePtr + _tableOffsets[V_ITa][level-1],
|
||||
(int*)_tables[V_IT].devicePtr + _tableOffsets[V_IT][level-1],
|
||||
(float*)_tables[V_W].devicePtr + _tableOffsets[V_W][level-1],
|
||||
offset, start, end);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::ApplyCatmarkVertexVerticesKernelA(FarMesh<OsdVertex> * mesh, int offset,
|
||||
bool pass, int level, int start, int end, void * data) const
|
||||
{
|
||||
VertexDescriptor vd(_numVertexElements, _numVaryingElements);
|
||||
|
||||
computeVertexA(&vd, _vbo, _varyingVbo,
|
||||
(int*)_tables[V_ITa].devicePtr + _tableOffsets[V_ITa][level-1],
|
||||
(float*)_tables[V_W].devicePtr + _tableOffsets[V_W][level-1],
|
||||
offset, start, end, pass);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::ApplyLoopEdgeVerticesKernel(FarMesh<OsdVertex> * mesh, int offset,
|
||||
int level, int start, int end, void * data) const
|
||||
{
|
||||
VertexDescriptor vd(_numVertexElements, _numVaryingElements);
|
||||
|
||||
computeEdge(&vd, _vbo, _varyingVbo,
|
||||
(int*)_tables[E_IT].devicePtr + _tableOffsets[E_IT][level-1],
|
||||
(float*)_tables[E_W].devicePtr + _tableOffsets[E_W][level-1],
|
||||
offset,
|
||||
start, end);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::ApplyLoopVertexVerticesKernelB(FarMesh<OsdVertex> * mesh, int offset,
|
||||
int level, int start, int end, void * data) const
|
||||
{
|
||||
VertexDescriptor vd(_numVertexElements, _numVaryingElements);
|
||||
|
||||
computeLoopVertexB(&vd, _vbo, _varyingVbo,
|
||||
(int*)_tables[V_ITa].devicePtr + _tableOffsets[V_ITa][level-1],
|
||||
(int*)_tables[V_IT].devicePtr + _tableOffsets[V_IT][level-1],
|
||||
(float*)_tables[V_W].devicePtr + _tableOffsets[V_W][level-1],
|
||||
offset, start, end);
|
||||
}
|
||||
|
||||
void
|
||||
OsdCpuKernelDispatcher::ApplyLoopVertexVerticesKernelA(FarMesh<OsdVertex> * mesh, int offset,
|
||||
bool pass, int level, int start, int end, void * data) const
|
||||
{
|
||||
VertexDescriptor vd(_numVertexElements, _numVaryingElements);
|
||||
|
||||
computeVertexA(&vd, _vbo, _varyingVbo,
|
||||
(int*)_tables[V_ITa].devicePtr + _tableOffsets[V_ITa][level-1],
|
||||
(float*)_tables[V_W].devicePtr + _tableOffsets[V_W][level-1],
|
||||
offset, start, end, pass);
|
||||
}
|
||||
|
||||
} // end namespace OPENSUBDIV_VERSION
|
||||
using namespace OPENSUBDIV_VERSION;
|
||||
|
||||
} // end namespace OpenSubdiv
|
||||
|
141
opensubdiv/osd/cpuDispatcher.h
Normal file
141
opensubdiv/osd/cpuDispatcher.h
Normal file
@ -0,0 +1,141 @@
|
||||
//
|
||||
// Copyright (C) Pixar. All rights reserved.
|
||||
//
|
||||
// This license governs use of the accompanying software. If you
|
||||
// use the software, you accept this license. If you do not accept
|
||||
// the license, do not use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S.
|
||||
// copyright law. A "contribution" is the original software, or
|
||||
// any additions or changes to the software.
|
||||
// A "contributor" is any person or entity that distributes its
|
||||
// contribution under this license.
|
||||
// "Licensed patents" are a contributor's patent claims that read
|
||||
// directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
// (A) Copyright Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free copyright license to reproduce its contribution,
|
||||
// prepare derivative works of its contribution, and distribute
|
||||
// its contribution or any derivative works that you create.
|
||||
// (B) Patent Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free license under its licensed patents to make, have
|
||||
// made, use, sell, offer for sale, import, and/or otherwise
|
||||
// dispose of its contribution in the software or derivative works
|
||||
// of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
// (A) No Trademark License- This license does not grant you
|
||||
// rights to use any contributor's name, logo, or trademarks.
|
||||
// (B) If you bring a patent claim against any contributor over
|
||||
// patents that you claim are infringed by the software, your
|
||||
// patent license from such contributor to the software ends
|
||||
// automatically.
|
||||
// (C) If you distribute any portion of the software, you must
|
||||
// retain all copyright, patent, trademark, and attribution
|
||||
// notices that are present in the software.
|
||||
// (D) If you distribute any portion of the software in source
|
||||
// code form, you may do so only under this license by including a
|
||||
// complete copy of this license with your distribution. If you
|
||||
// distribute any portion of the software in compiled or object
|
||||
// code form, you may only do so under a license that complies
|
||||
// with this license.
|
||||
// (E) The software is licensed "as-is." You bear the risk of
|
||||
// using it. The contributors give no express warranties,
|
||||
// guarantees or conditions. You may have additional consumer
|
||||
// rights under your local laws which this license cannot change.
|
||||
// To the extent permitted under your local laws, the contributors
|
||||
// exclude the implied warranties of merchantability, fitness for
|
||||
// a particular purpose and non-infringement.
|
||||
//
|
||||
#ifndef OSD_CPU_DISPATCHER_H
|
||||
#define OSD_CPU_DISPATCHER_H
|
||||
|
||||
#include "../osd/kernelDispatcher.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
// Including omp.h makes sure we link against the correct OpenMP run-time
|
||||
// library. This is Windows specific, but we want a given header file to
|
||||
// include the same set of files across all platforms if possible.
|
||||
#include <omp.h>
|
||||
|
||||
namespace OpenSubdiv {
|
||||
namespace OPENSUBDIV_VERSION {
|
||||
|
||||
class OsdCpuKernelDispatcher : public OsdKernelDispatcher
|
||||
{
|
||||
public:
|
||||
OsdCpuKernelDispatcher(int levels, int numVertexElements, int numVaryingElements);
|
||||
virtual ~OsdCpuKernelDispatcher();
|
||||
|
||||
virtual void ApplyCatmarkFaceVerticesKernel(FarMesh<OsdVertex> * mesh, int offset,
|
||||
int level, int start, int end, void * data) const;
|
||||
virtual void ApplyCatmarkEdgeVerticesKernel(FarMesh<OsdVertex> * mesh, int offset,
|
||||
int level, int start, int end, void * data) const;
|
||||
virtual void ApplyCatmarkVertexVerticesKernelB(FarMesh<OsdVertex> * mesh, int offset,
|
||||
int level, int start, int end, void * data) const;
|
||||
virtual void ApplyCatmarkVertexVerticesKernelA(FarMesh<OsdVertex> * mesh, int offset,
|
||||
bool pass, int level, int start, int end, void * data) const;
|
||||
|
||||
virtual void ApplyLoopEdgeVerticesKernel(FarMesh<OsdVertex> * mesh, int offset,
|
||||
int level, int start, int end, void * data) const;
|
||||
virtual void ApplyLoopVertexVerticesKernelB(FarMesh<OsdVertex> * mesh, int offset,
|
||||
int level, int start, int end, void * data) const;
|
||||
virtual void ApplyLoopVertexVerticesKernelA(FarMesh<OsdVertex> * mesh, int offset,
|
||||
bool pass, int level, int start, int end, void * data) const;
|
||||
|
||||
|
||||
virtual void CopyTable(int tableIndex, size_t size, const void *ptr);
|
||||
|
||||
virtual void BeginLaunchKernel();
|
||||
virtual void EndLaunchKernel();
|
||||
|
||||
virtual void BindVertexBuffer(GLuint vertexBuffer, GLuint varyingBuffer);
|
||||
virtual void UpdateVertexBuffer(size_t size, void *ptr);
|
||||
virtual void UpdateVaryingBuffer(size_t size, void *ptr);
|
||||
virtual void MapVertexBuffer();
|
||||
virtual void MapVaryingBuffer();
|
||||
virtual void UnmapVertexBuffer();
|
||||
virtual void UnmapVaryingBuffer();
|
||||
|
||||
virtual void Synchronize();
|
||||
|
||||
static OsdKernelDispatcher * Create(int levels, int numVertexElements, int numVaryingElements){
|
||||
return new OsdCpuKernelDispatcher(levels, numVertexElements, numVaryingElements);
|
||||
}
|
||||
static void Register() {
|
||||
Factory::GetInstance().Register("omp", Create);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
struct DeviceTable
|
||||
{
|
||||
DeviceTable() : devicePtr(NULL) {}
|
||||
~DeviceTable();
|
||||
|
||||
void Copy(int size, const void *ptr);
|
||||
void *devicePtr;
|
||||
};
|
||||
|
||||
std::vector<DeviceTable> _tables;
|
||||
|
||||
GLuint _vertexBuffer, _varyingBuffer;
|
||||
float *_vbo, *_varyingVbo;
|
||||
int _vboSize, _varyingVboSize;
|
||||
int _numVertexElements, _numVaryingElements;
|
||||
};
|
||||
|
||||
} // end namespace OPENSUBDIV_VERSION
|
||||
using namespace OPENSUBDIV_VERSION;
|
||||
|
||||
} // end namespace OpenSubdiv
|
||||
|
||||
#endif /* OSD_CPU_DISPATCHER_H */
|
240
opensubdiv/osd/cpuKernel.cpp
Normal file
240
opensubdiv/osd/cpuKernel.cpp
Normal file
@ -0,0 +1,240 @@
|
||||
//
|
||||
// Copyright (C) Pixar. All rights reserved.
|
||||
//
|
||||
// This license governs use of the accompanying software. If you
|
||||
// use the software, you accept this license. If you do not accept
|
||||
// the license, do not use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S.
|
||||
// copyright law. A "contribution" is the original software, or
|
||||
// any additions or changes to the software.
|
||||
// A "contributor" is any person or entity that distributes its
|
||||
// contribution under this license.
|
||||
// "Licensed patents" are a contributor's patent claims that read
|
||||
// directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
// (A) Copyright Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free copyright license to reproduce its contribution,
|
||||
// prepare derivative works of its contribution, and distribute
|
||||
// its contribution or any derivative works that you create.
|
||||
// (B) Patent Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free license under its licensed patents to make, have
|
||||
// made, use, sell, offer for sale, import, and/or otherwise
|
||||
// dispose of its contribution in the software or derivative works
|
||||
// of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
// (A) No Trademark License- This license does not grant you
|
||||
// rights to use any contributor's name, logo, or trademarks.
|
||||
// (B) If you bring a patent claim against any contributor over
|
||||
// patents that you claim are infringed by the software, your
|
||||
// patent license from such contributor to the software ends
|
||||
// automatically.
|
||||
// (C) If you distribute any portion of the software, you must
|
||||
// retain all copyright, patent, trademark, and attribution
|
||||
// notices that are present in the software.
|
||||
// (D) If you distribute any portion of the software in source
|
||||
// code form, you may do so only under this license by including a
|
||||
// complete copy of this license with your distribution. If you
|
||||
// distribute any portion of the software in compiled or object
|
||||
// code form, you may only do so under a license that complies
|
||||
// with this license.
|
||||
// (E) The software is licensed "as-is." You bear the risk of
|
||||
// using it. The contributors give no express warranties,
|
||||
// guarantees or conditions. You may have additional consumer
|
||||
// rights under your local laws which this license cannot change.
|
||||
// To the extent permitted under your local laws, the contributors
|
||||
// exclude the implied warranties of merchantability, fitness for
|
||||
// a particular purpose and non-infringement.
|
||||
//
|
||||
#include <math.h>
|
||||
|
||||
#include "../osd/cpuKernel.h"
|
||||
|
||||
namespace OpenSubdiv {
|
||||
namespace OPENSUBDIV_VERSION {
|
||||
|
||||
extern void computeFace(const VertexDescriptor *vdesc, float * vertex, float * varying,
|
||||
const int *F_IT, const int *F_ITa, int offset, int start, int end)
|
||||
{
|
||||
int ve = vdesc->numVertexElements;
|
||||
int vev = vdesc->numVaryingElements;
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for(int i = start; i < end; i++){
|
||||
int h = F_ITa[2*i];
|
||||
int n = F_ITa[2*i+1];
|
||||
|
||||
float weight = 1.0f/n;
|
||||
|
||||
// XXX: should use local vertex struct variable instead of accumulating directly into global memory.
|
||||
float *dst = &vertex[(offset + i)*ve];
|
||||
float *dstVarying = &varying[(offset + i)*vev];
|
||||
vdesc->clear(dst, dstVarying);
|
||||
|
||||
for(int j=0; j<n; ++j){
|
||||
int index = F_IT[h+j];
|
||||
vdesc->addWithWeight(dst, &vertex[index*ve], weight);
|
||||
vdesc->addVaryingWithWeight(dstVarying, &varying[index*vev], weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern void computeEdge(const VertexDescriptor *vdesc, float *vertex, float *varying,
|
||||
const int *E_IT, const float *E_W, int offset, int start, int end)
|
||||
{
|
||||
int ve = vdesc->numVertexElements;
|
||||
int vev = vdesc->numVaryingElements;
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for(int i = start; i < end; i++){
|
||||
int eidx0 = E_IT[4*i+0];
|
||||
int eidx1 = E_IT[4*i+1];
|
||||
int eidx2 = E_IT[4*i+2];
|
||||
int eidx3 = E_IT[4*i+3];
|
||||
|
||||
float vertWeight = E_W[i*2+0];
|
||||
|
||||
float *dst = &vertex[(offset+i)*ve];
|
||||
float *dstVarying = &varying[(offset+i)*vev];
|
||||
vdesc->clear(dst, dstVarying);
|
||||
|
||||
vdesc->addWithWeight(dst, &vertex[eidx0*ve], vertWeight);
|
||||
vdesc->addWithWeight(dst, &vertex[eidx1*ve], vertWeight);
|
||||
|
||||
if(eidx2 != -1){
|
||||
float faceWeight = E_W[i*2+1];
|
||||
|
||||
vdesc->addWithWeight(dst, &vertex[eidx2*ve], faceWeight);
|
||||
vdesc->addWithWeight(dst, &vertex[eidx3*ve], faceWeight);
|
||||
}
|
||||
|
||||
vdesc->addVaryingWithWeight(dstVarying, &varying[eidx0*vev], 0.5f);
|
||||
vdesc->addVaryingWithWeight(dstVarying, &varying[eidx1*vev], 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
extern void computeVertexA(const VertexDescriptor *vdesc, float *vertex, float *varying,
|
||||
const int *V_ITa, const float *V_W,
|
||||
int offset, int start, int end, int pass)
|
||||
{
|
||||
int ve = vdesc->numVertexElements;
|
||||
int vev = vdesc->numVaryingElements;
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for(int i = start; i < end; i++){
|
||||
int n = V_ITa[5*i+1];
|
||||
int p = V_ITa[5*i+2];
|
||||
int eidx0 = V_ITa[5*i+3];
|
||||
int eidx1 = V_ITa[5*i+4];
|
||||
|
||||
float weight = (pass==1) ? V_W[i] : 1.0f - V_W[i];
|
||||
|
||||
// In the case of fractional weight, the weight must be inverted since
|
||||
// the value is shared with the k_Smooth kernel (statistically the
|
||||
// k_Smooth kernel runs much more often than this one)
|
||||
if (weight>0.0f && weight<1.0f && n > 0)
|
||||
weight=1.0f-weight;
|
||||
|
||||
float *dst = &vertex[(offset+i)*ve];
|
||||
float *dstVarying = &varying[(offset+i)*vev];
|
||||
if(not pass)
|
||||
vdesc->clear(dst, dstVarying);
|
||||
|
||||
if (eidx0==-1 || (pass==0 && (n==-1)) ) {
|
||||
vdesc->addWithWeight(dst, &vertex[p*ve], weight);
|
||||
} else {
|
||||
vdesc->addWithWeight(dst, &vertex[p*ve], weight * 0.75f);
|
||||
vdesc->addWithWeight(dst, &vertex[eidx0*ve], weight * 0.125f);
|
||||
vdesc->addWithWeight(dst, &vertex[eidx1*ve], weight * 0.125f);
|
||||
}
|
||||
|
||||
if(not pass)
|
||||
vdesc->addVaryingWithWeight(dstVarying, &varying[p*vev], 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
extern void computeVertexB(const VertexDescriptor *vdesc, float *vertex, float *varying,
|
||||
const int *V_ITa, const int *V_IT, const float *V_W,
|
||||
int offset, int start, int end)
|
||||
{
|
||||
int ve = vdesc->numVertexElements;
|
||||
int vev = vdesc->numVaryingElements;
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for(int i = start; i < end; i++){
|
||||
int h = V_ITa[5*i];
|
||||
int n = V_ITa[5*i+1];
|
||||
int p = V_ITa[5*i+2];
|
||||
|
||||
float weight = V_W[i];
|
||||
float wp = 1.0f/float(n*n);
|
||||
float wv = (n-2.0f) * n * wp;
|
||||
|
||||
float *dst = &vertex[(offset+i)*ve];
|
||||
float *dstVarying = &varying[(offset+i)*vev];
|
||||
vdesc->clear(dst, dstVarying);
|
||||
|
||||
vdesc->addWithWeight(dst, &vertex[p*ve], weight * wv);
|
||||
|
||||
for(int j = 0; j < n; ++j){
|
||||
vdesc->addWithWeight(dst, &vertex[V_IT[h+j*2]*ve], weight * wp);
|
||||
vdesc->addWithWeight(dst, &vertex[V_IT[h+j*2+1]*ve], weight * wp);
|
||||
}
|
||||
vdesc->addVaryingWithWeight(dstVarying, &varying[p*vev], 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
extern void computeLoopVertexB(const VertexDescriptor *vdesc, float *vertex, float *varying,
|
||||
const int *V_ITa, const int *V_IT, const float *V_W,
|
||||
int offset, int start, int end)
|
||||
{
|
||||
int ve = vdesc->numVertexElements;
|
||||
int vev = vdesc->numVaryingElements;
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for(int i = start; i < end; i++){
|
||||
int h = V_ITa[5*i];
|
||||
int n = V_ITa[5*i+1];
|
||||
int p = V_ITa[5*i+2];
|
||||
|
||||
float weight = V_W[i];
|
||||
float wp = 1.0f/float(n);
|
||||
float beta = 0.25f * cosf(float(M_PI) * 2.0f * wp) + 0.375f;
|
||||
beta = beta * beta;
|
||||
beta = (0.625f - beta) * wp;
|
||||
|
||||
float *dst = &vertex[(offset+i)*ve];
|
||||
float *dstVarying = &varying[(offset+i)*vev];
|
||||
vdesc->clear(dst, dstVarying);
|
||||
|
||||
vdesc->addWithWeight(dst, &vertex[p*ve], weight * (1.0f - (beta * n)));
|
||||
|
||||
for(int j = 0; j < n; ++j){
|
||||
vdesc->addWithWeight(dst, &vertex[V_IT[h+j]*ve], weight * beta);
|
||||
}
|
||||
|
||||
vdesc->addVaryingWithWeight(dstVarying, &varying[p*vev], 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace OPENSUBDIV_VERSION
|
||||
using namespace OPENSUBDIV_VERSION;
|
||||
|
||||
} // end namespace OpenSubdiv
|
109
opensubdiv/osd/cpuKernel.h
Normal file
109
opensubdiv/osd/cpuKernel.h
Normal file
@ -0,0 +1,109 @@
|
||||
//
|
||||
// Copyright (C) Pixar. All rights reserved.
|
||||
//
|
||||
// This license governs use of the accompanying software. If you
|
||||
// use the software, you accept this license. If you do not accept
|
||||
// the license, do not use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S.
|
||||
// copyright law. A "contribution" is the original software, or
|
||||
// any additions or changes to the software.
|
||||
// A "contributor" is any person or entity that distributes its
|
||||
// contribution under this license.
|
||||
// "Licensed patents" are a contributor's patent claims that read
|
||||
// directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
// (A) Copyright Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free copyright license to reproduce its contribution,
|
||||
// prepare derivative works of its contribution, and distribute
|
||||
// its contribution or any derivative works that you create.
|
||||
// (B) Patent Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free license under its licensed patents to make, have
|
||||
// made, use, sell, offer for sale, import, and/or otherwise
|
||||
// dispose of its contribution in the software or derivative works
|
||||
// of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
// (A) No Trademark License- This license does not grant you
|
||||
// rights to use any contributor's name, logo, or trademarks.
|
||||
// (B) If you bring a patent claim against any contributor over
|
||||
// patents that you claim are infringed by the software, your
|
||||
// patent license from such contributor to the software ends
|
||||
// automatically.
|
||||
// (C) If you distribute any portion of the software, you must
|
||||
// retain all copyright, patent, trademark, and attribution
|
||||
// notices that are present in the software.
|
||||
// (D) If you distribute any portion of the software in source
|
||||
// code form, you may do so only under this license by including a
|
||||
// complete copy of this license with your distribution. If you
|
||||
// distribute any portion of the software in compiled or object
|
||||
// code form, you may only do so under a license that complies
|
||||
// with this license.
|
||||
// (E) The software is licensed "as-is." You bear the risk of
|
||||
// using it. The contributors give no express warranties,
|
||||
// guarantees or conditions. You may have additional consumer
|
||||
// rights under your local laws which this license cannot change.
|
||||
// To the extent permitted under your local laws, the contributors
|
||||
// exclude the implied warranties of merchantability, fitness for
|
||||
// a particular purpose and non-infringement.
|
||||
//
|
||||
#ifndef OSD_CPU_KERNEL_H
|
||||
#define OSD_CPU_KERNEL_H
|
||||
|
||||
namespace OpenSubdiv {
|
||||
namespace OPENSUBDIV_VERSION {
|
||||
|
||||
struct VertexDescriptor
|
||||
{
|
||||
VertexDescriptor(int numVertexElem, int numVaryingElem) :
|
||||
numVertexElements(numVertexElem), numVaryingElements(numVaryingElem) {}
|
||||
|
||||
void clear(float *vertex, float *varying) const{
|
||||
for(int i = 0; i < numVertexElements; ++i){
|
||||
vertex[i] = 0.0f;
|
||||
}
|
||||
for(int i = 0; i < numVaryingElements; ++i){
|
||||
varying[i] = 0.0f;
|
||||
}
|
||||
}
|
||||
void addWithWeight(float *vertex, const float *src, float weight) const {
|
||||
for(int i = 0; i < numVertexElements; ++i){
|
||||
vertex[i] += src[i] * weight;
|
||||
}
|
||||
}
|
||||
void addVaryingWithWeight(float *varying, const float *src, float weight) const {
|
||||
for(int i = 0; i < numVaryingElements; ++i){
|
||||
varying[i] += src[i] * weight;
|
||||
}
|
||||
}
|
||||
int numVertexElements;
|
||||
int numVaryingElements;
|
||||
};
|
||||
|
||||
extern void computeFace(const VertexDescriptor *vdesc, float * vertex, float * varying,
|
||||
const int *F_IT, const int *F_ITa, int offset, int start, int end);
|
||||
extern void computeEdge(const VertexDescriptor *vdesc, float *vertex, float * varying,
|
||||
const int *E_IT, const float *E_W, int offset, int start, int end);
|
||||
extern void computeVertexA(const VertexDescriptor *vdesc, float *vertex, float * varying,
|
||||
const int *V_ITa, const float *V_W,
|
||||
int offset, int start, int end, int pass);
|
||||
extern void computeVertexB(const VertexDescriptor *vdesc, float *vertex, float * varying,
|
||||
const int *V_ITa, const int *V_IT, const float *V_W,
|
||||
int offset, int start, int end);
|
||||
extern void computeLoopVertexB(const VertexDescriptor *vdesc, float *vertex, float * varying,
|
||||
const int *V_ITa, const int *V_IT, const float *V_W,
|
||||
int offset, int start, int end);
|
||||
|
||||
} // end namespace OPENSUBDIV_VERSION
|
||||
using namespace OPENSUBDIV_VERSION;
|
||||
|
||||
} // end namespace OpenSubdiv
|
||||
|
||||
#endif /* OSD_CPU_KERNEL_H */
|
77
opensubdiv/osd/dump.cpp
Normal file
77
opensubdiv/osd/dump.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include <GL/glew.h>
|
||||
|
||||
static void
|
||||
DumpBuffer(GLuint buffer)
|
||||
{
|
||||
printf("----------------------------------------------------\n");
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
int size = 0;
|
||||
glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
|
||||
float *p = (float*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
|
||||
if(p){
|
||||
for(int i = 0; i < size/16; i++){
|
||||
printf("%d: %f %f %f %f\n", i, p[0], p[1], p[2], p[3]);
|
||||
p += 4;
|
||||
}
|
||||
}
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
static void
|
||||
DumpBufferInt(GLuint buffer)
|
||||
{
|
||||
if(buffer == 0) return;
|
||||
|
||||
printf("---------------------------------------------------\n");
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
int size = 0;
|
||||
glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
|
||||
unsigned int *p = (unsigned int*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
|
||||
if(p){
|
||||
for(int i = 0; i < size/4; i++){
|
||||
printf("%04x ", *p++);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
DebugAttribs(GLuint program)
|
||||
{
|
||||
GLint numAttributes = 0;
|
||||
glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &numAttributes);
|
||||
if (numAttributes == 0) {
|
||||
printf("No attributes\n");
|
||||
return;
|
||||
}
|
||||
|
||||
GLint maxNameLength = 0;
|
||||
glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNameLength);
|
||||
|
||||
char * name = new char[maxNameLength];
|
||||
|
||||
for (int i=0; i<numAttributes; ++i) {
|
||||
GLint size;
|
||||
GLenum type;
|
||||
glGetActiveAttrib(program, i,
|
||||
maxNameLength, NULL,
|
||||
&size, &type, name);
|
||||
printf("Attrib %s, size=%d, type=%x\n", name, size, type);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
DebugProgram(GLuint program)
|
||||
{
|
||||
unsigned char buffer[1*1024*1024];
|
||||
GLsizei length = 0;
|
||||
GLenum format;
|
||||
glGetProgramBinary(program, 10*1024*1024, &length, &format, buffer);
|
||||
FILE *fp =fopen ("out.bin", "wb");
|
||||
if(fp){
|
||||
fwrite(buffer, 1, length, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
71
opensubdiv/osd/kernelDispatcher.cpp
Normal file
71
opensubdiv/osd/kernelDispatcher.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
//
|
||||
// Copyright (C) Pixar. All rights reserved.
|
||||
//
|
||||
// This license governs use of the accompanying software. If you
|
||||
// use the software, you accept this license. If you do not accept
|
||||
// the license, do not use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S.
|
||||
// copyright law. A "contribution" is the original software, or
|
||||
// any additions or changes to the software.
|
||||
// A "contributor" is any person or entity that distributes its
|
||||
// contribution under this license.
|
||||
// "Licensed patents" are a contributor's patent claims that read
|
||||
// directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
// (A) Copyright Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free copyright license to reproduce its contribution,
|
||||
// prepare derivative works of its contribution, and distribute
|
||||
// its contribution or any derivative works that you create.
|
||||
// (B) Patent Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free license under its licensed patents to make, have
|
||||
// made, use, sell, offer for sale, import, and/or otherwise
|
||||
// dispose of its contribution in the software or derivative works
|
||||
// of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
// (A) No Trademark License- This license does not grant you
|
||||
// rights to use any contributor's name, logo, or trademarks.
|
||||
// (B) If you bring a patent claim against any contributor over
|
||||
// patents that you claim are infringed by the software, your
|
||||
// patent license from such contributor to the software ends
|
||||
// automatically.
|
||||
// (C) If you distribute any portion of the software, you must
|
||||
// retain all copyright, patent, trademark, and attribution
|
||||
// notices that are present in the software.
|
||||
// (D) If you distribute any portion of the software in source
|
||||
// code form, you may do so only under this license by including a
|
||||
// complete copy of this license with your distribution. If you
|
||||
// distribute any portion of the software in compiled or object
|
||||
// code form, you may only do so under a license that complies
|
||||
// with this license.
|
||||
// (E) The software is licensed "as-is." You bear the risk of
|
||||
// using it. The contributors give no express warranties,
|
||||
// guarantees or conditions. You may have additional consumer
|
||||
// rights under your local laws which this license cannot change.
|
||||
// To the extent permitted under your local laws, the contributors
|
||||
// exclude the implied warranties of merchantability, fitness for
|
||||
// a particular purpose and non-infringement.
|
||||
//
|
||||
|
||||
#include "../osd/kernelDispatcher.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
namespace OpenSubdiv {
|
||||
namespace OPENSUBDIV_VERSION {
|
||||
|
||||
OsdKernelDispatcher::Factory OsdKernelDispatcher::Factory::_instance;
|
||||
|
||||
} // end namespace OPENSUBDIV_VERSION
|
||||
using namespace OPENSUBDIV_VERSION;
|
||||
|
||||
} // end namespace OpenSubdiv
|
||||
|
162
opensubdiv/osd/kernelDispatcher.h
Normal file
162
opensubdiv/osd/kernelDispatcher.h
Normal file
@ -0,0 +1,162 @@
|
||||
//
|
||||
// Copyright (C) Pixar. All rights reserved.
|
||||
//
|
||||
// This license governs use of the accompanying software. If you
|
||||
// use the software, you accept this license. If you do not accept
|
||||
// the license, do not use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S.
|
||||
// copyright law. A "contribution" is the original software, or
|
||||
// any additions or changes to the software.
|
||||
// A "contributor" is any person or entity that distributes its
|
||||
// contribution under this license.
|
||||
// "Licensed patents" are a contributor's patent claims that read
|
||||
// directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
// (A) Copyright Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free copyright license to reproduce its contribution,
|
||||
// prepare derivative works of its contribution, and distribute
|
||||
// its contribution or any derivative works that you create.
|
||||
// (B) Patent Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free license under its licensed patents to make, have
|
||||
// made, use, sell, offer for sale, import, and/or otherwise
|
||||
// dispose of its contribution in the software or derivative works
|
||||
// of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
// (A) No Trademark License- This license does not grant you
|
||||
// rights to use any contributor's name, logo, or trademarks.
|
||||
// (B) If you bring a patent claim against any contributor over
|
||||
// patents that you claim are infringed by the software, your
|
||||
// patent license from such contributor to the software ends
|
||||
// automatically.
|
||||
// (C) If you distribute any portion of the software, you must
|
||||
// retain all copyright, patent, trademark, and attribution
|
||||
// notices that are present in the software.
|
||||
// (D) If you distribute any portion of the software in source
|
||||
// code form, you may do so only under this license by including a
|
||||
// complete copy of this license with your distribution. If you
|
||||
// distribute any portion of the software in compiled or object
|
||||
// code form, you may only do so under a license that complies
|
||||
// with this license.
|
||||
// (E) The software is licensed "as-is." You bear the risk of
|
||||
// using it. The contributors give no express warranties,
|
||||
// guarantees or conditions. You may have additional consumer
|
||||
// rights under your local laws which this license cannot change.
|
||||
// To the extent permitted under your local laws, the contributors
|
||||
// exclude the implied warranties of merchantability, fitness for
|
||||
// a particular purpose and non-infringement.
|
||||
//
|
||||
#ifndef OSD_KERNEL_DISPATCHER_H
|
||||
#define OSD_KERNEL_DISPATCHER_H
|
||||
|
||||
#include "vertex.h"
|
||||
|
||||
#include "../far/dispatcher.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OpenSubdiv {
|
||||
namespace OPENSUBDIV_VERSION {
|
||||
|
||||
class OsdKernelDispatcher : public FarDispatcher<OsdVertex>
|
||||
{
|
||||
public:
|
||||
OsdKernelDispatcher (int maxLevel) : _maxLevel(maxLevel) {}
|
||||
virtual ~OsdKernelDispatcher() {}
|
||||
|
||||
virtual void CopyTable(int tableIndex, size_t size, const void *ptr) = 0;
|
||||
|
||||
virtual void BeginLaunchKernel() = 0;
|
||||
virtual void EndLaunchKernel() = 0;
|
||||
|
||||
virtual void BindVertexBuffer(GLuint vertexBuffer, GLuint varyingBuffer) = 0;
|
||||
virtual void UpdateVertexBuffer(size_t size, void *ptr) = 0;
|
||||
virtual void UpdateVaryingBuffer(size_t size, void *ptr) = 0;
|
||||
virtual void MapVertexBuffer() = 0;
|
||||
virtual void MapVaryingBuffer() = 0;
|
||||
virtual void UnmapVertexBuffer() = 0;
|
||||
virtual void UnmapVaryingBuffer() = 0;
|
||||
|
||||
virtual void Synchronize() = 0;
|
||||
|
||||
template<class T> void UpdateTable(int tableIndex, const T & table)
|
||||
{
|
||||
CopyTable(tableIndex, table.GetMemoryUsed(), table[0]);
|
||||
|
||||
_tableOffsets[tableIndex].resize(_maxLevel);
|
||||
for(int i = 0; i < _maxLevel; ++i){
|
||||
_tableOffsets[tableIndex][i] = table[i] - table[0];
|
||||
}
|
||||
}
|
||||
|
||||
static OsdKernelDispatcher *CreateKernelDispatcher(
|
||||
const std::string &kernel,
|
||||
int levels,
|
||||
int numVertexElements,
|
||||
int numVaryingElements) {
|
||||
return Factory::GetInstance().Create(
|
||||
kernel, levels, numVertexElements, numVaryingElements);
|
||||
}
|
||||
|
||||
enum { E_IT,
|
||||
E_W,
|
||||
V_ITa,
|
||||
V_IT,
|
||||
V_W,
|
||||
F_IT,
|
||||
F_ITa,
|
||||
TABLE_MAX
|
||||
};
|
||||
|
||||
protected:
|
||||
class Factory {
|
||||
private:
|
||||
typedef OsdKernelDispatcher *(*Creator)(
|
||||
int levels, int numVertexElements, int numVaryingElements);
|
||||
typedef std::map<const std::string, Creator> CreatorMap;
|
||||
CreatorMap _creators;
|
||||
public:
|
||||
bool Register(const std::string &kernel, Creator creator) {
|
||||
return _creators.insert(CreatorMap::value_type(kernel, creator)).second;
|
||||
}
|
||||
bool Unregister(const std::string &kernel) {
|
||||
return _creators.erase(kernel) == 1;
|
||||
}
|
||||
OsdKernelDispatcher *Create(
|
||||
const std::string &kernel,
|
||||
int levels,
|
||||
int numVertexElements,
|
||||
int numVaryingElements) {
|
||||
CreatorMap::const_iterator it = _creators.find(kernel);
|
||||
if (it != _creators.end())
|
||||
return (it->second)(levels, numVertexElements, numVaryingElements);
|
||||
return NULL;
|
||||
}
|
||||
static Factory &GetInstance() {
|
||||
return _instance;
|
||||
}
|
||||
static Factory _instance;
|
||||
};
|
||||
|
||||
protected:
|
||||
int _maxLevel;
|
||||
std::vector<int> _tableOffsets[TABLE_MAX];
|
||||
};
|
||||
|
||||
} // end namespace OPENSUBDIV_VERSION
|
||||
using namespace OPENSUBDIV_VERSION;
|
||||
|
||||
} // end namespace OpenSubdiv
|
||||
|
||||
#endif /* OSD_KERNEL_DISPATCHER_H */
|
18
opensubdiv/osd/local.h
Normal file
18
opensubdiv/osd/local.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef OSD_LOCAL_H
|
||||
#define OSD_LOCAL_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define CHECK_GL_ERROR(...) \
|
||||
if(GLuint err = glGetError()) { \
|
||||
printf("GL error %x :", err); \
|
||||
printf(__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define OSD_ERROR(...) printf(__VA_ARGS__);
|
||||
|
||||
//#define OSD_DEBUG(...) printf(__VA_ARGS__);
|
||||
#define OSD_DEBUG(...)
|
||||
|
||||
|
||||
#endif // OSD_LOCAL_H
|
254
opensubdiv/osd/mesh.cpp
Normal file
254
opensubdiv/osd/mesh.cpp
Normal file
@ -0,0 +1,254 @@
|
||||
//
|
||||
// Copyright (C) Pixar. All rights reserved.
|
||||
//
|
||||
// This license governs use of the accompanying software. If you
|
||||
// use the software, you accept this license. If you do not accept
|
||||
// the license, do not use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S.
|
||||
// copyright law. A "contribution" is the original software, or
|
||||
// any additions or changes to the software.
|
||||
// A "contributor" is any person or entity that distributes its
|
||||
// contribution under this license.
|
||||
// "Licensed patents" are a contributor's patent claims that read
|
||||
// directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
// (A) Copyright Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free copyright license to reproduce its contribution,
|
||||
// prepare derivative works of its contribution, and distribute
|
||||
// its contribution or any derivative works that you create.
|
||||
// (B) Patent Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free license under its licensed patents to make, have
|
||||
// made, use, sell, offer for sale, import, and/or otherwise
|
||||
// dispose of its contribution in the software or derivative works
|
||||
// of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
// (A) No Trademark License- This license does not grant you
|
||||
// rights to use any contributor's name, logo, or trademarks.
|
||||
// (B) If you bring a patent claim against any contributor over
|
||||
// patents that you claim are infringed by the software, your
|
||||
// patent license from such contributor to the software ends
|
||||
// automatically.
|
||||
// (C) If you distribute any portion of the software, you must
|
||||
// retain all copyright, patent, trademark, and attribution
|
||||
// notices that are present in the software.
|
||||
// (D) If you distribute any portion of the software in source
|
||||
// code form, you may do so only under this license by including a
|
||||
// complete copy of this license with your distribution. If you
|
||||
// distribute any portion of the software in compiled or object
|
||||
// code form, you may only do so under a license that complies
|
||||
// with this license.
|
||||
// (E) The software is licensed "as-is." You bear the risk of
|
||||
// using it. The contributors give no express warranties,
|
||||
// guarantees or conditions. You may have additional consumer
|
||||
// rights under your local laws which this license cannot change.
|
||||
// To the extent permitted under your local laws, the contributors
|
||||
// exclude the implied warranties of merchantability, fitness for
|
||||
// a particular purpose and non-infringement.
|
||||
//
|
||||
#include <string.h>
|
||||
|
||||
#include "../osd/mesh.h"
|
||||
#include "../osd/local.h"
|
||||
#include "../osd/dump.cpp"
|
||||
#include "../osd/kernelDispatcher.h"
|
||||
#include "../osd/cpuDispatcher.h"
|
||||
|
||||
#include "../far/meshFactory.h"
|
||||
|
||||
namespace OpenSubdiv {
|
||||
namespace OPENSUBDIV_VERSION {
|
||||
|
||||
OsdMesh::OsdMesh(int numVertexElements, int numVaryingElements) :
|
||||
_numVertexElements(numVertexElements),
|
||||
_numVaryingElements(numVaryingElements),
|
||||
_mMesh(NULL),
|
||||
_dispatcher(NULL)
|
||||
{
|
||||
glGenBuffers(1, &_vertexBuffer);
|
||||
glGenBuffers(1, &_varyingBuffer);
|
||||
}
|
||||
|
||||
OsdMesh::~OsdMesh()
|
||||
{
|
||||
if(_dispatcher) delete _dispatcher;
|
||||
if(_mMesh) delete _mMesh;
|
||||
|
||||
glDeleteBuffers(1, &_vertexBuffer);
|
||||
glDeleteBuffers(1, &_varyingBuffer);
|
||||
}
|
||||
|
||||
bool
|
||||
OsdMesh::Create(OsdHbrMesh *hbrMesh, int level, const std::string &kernel)
|
||||
{
|
||||
if(_dispatcher) delete _dispatcher;
|
||||
_dispatcher = OsdKernelDispatcher::CreateKernelDispatcher(kernel, level,
|
||||
_numVertexElements, _numVaryingElements);
|
||||
if(_dispatcher == NULL){
|
||||
OSD_ERROR("Unknown kernel %s\n", kernel.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
_level = level;
|
||||
|
||||
// create cctable
|
||||
OSD_DEBUG("Create MeshFactory\n");
|
||||
FarMeshFactory<OsdVertex> meshFactory(hbrMesh, _level);
|
||||
OSD_DEBUG("Create Mesh\n");
|
||||
|
||||
_mMesh = meshFactory.Create(_dispatcher);
|
||||
|
||||
OSD_DEBUG("PREP: NumCoarseVertex = %d\n", _mMesh->GetNumCoarseVertices());
|
||||
OSD_DEBUG("PREP: NumVertex = %d\n", _mMesh->GetNumVertices());
|
||||
OSD_DEBUG("PREP: NumTables = %d\n", _mMesh->GetNumSubdivisionTables());
|
||||
|
||||
const FarSubdivisionTables<OsdVertex>* table = _mMesh->GetSubdivision();
|
||||
|
||||
_dispatcher->UpdateTable(OsdKernelDispatcher::E_IT, table->Get_E_IT());
|
||||
_dispatcher->UpdateTable(OsdKernelDispatcher::V_IT, table->Get_V_IT());
|
||||
_dispatcher->UpdateTable(OsdKernelDispatcher::V_ITa, table->Get_V_ITa());
|
||||
_dispatcher->UpdateTable(OsdKernelDispatcher::E_W, table->Get_E_W());
|
||||
_dispatcher->UpdateTable(OsdKernelDispatcher::V_W, table->Get_V_W());
|
||||
|
||||
if(const FarCatmarkSubdivisionTables<OsdVertex>* cctable =
|
||||
dynamic_cast<const FarCatmarkSubdivisionTables<OsdVertex>*>(table)){
|
||||
// catmark
|
||||
_dispatcher->UpdateTable(OsdKernelDispatcher::F_IT, cctable->Get_F_IT());
|
||||
_dispatcher->UpdateTable(OsdKernelDispatcher::F_ITa, cctable->Get_F_ITa());
|
||||
}else{
|
||||
// XXX for glsl shader...
|
||||
_dispatcher->CopyTable(OsdKernelDispatcher::F_IT, 0, NULL);
|
||||
_dispatcher->CopyTable(OsdKernelDispatcher::F_ITa, 0, NULL);
|
||||
}
|
||||
|
||||
CHECK_GL_ERROR("Mesh, update tables\n");
|
||||
|
||||
// vbo prep
|
||||
int vertexSize = _mMesh->GetNumVertices() * _numVertexElements * sizeof(float);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertexSize, 0, GL_STREAM_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
CHECK_GL_ERROR("Mesh, vertex buffer %d\n", _vertexBuffer);
|
||||
|
||||
int varyingSize = _mMesh->GetNumVertices() * _numVaryingElements * sizeof(float);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _varyingBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, varyingSize, 0, GL_STREAM_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
CHECK_GL_ERROR("Mesh, varying buffer %d\n", _varyingBuffer);
|
||||
|
||||
_dispatcher->BindVertexBuffer(_vertexBuffer, varyingSize ? _varyingBuffer : 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
OsdMesh::UpdatePoints(const std::vector<float> &points)
|
||||
{
|
||||
int numCoarseVertices = _mMesh->GetNumCoarseVertices();
|
||||
if(numCoarseVertices * _numVertexElements != points.size()) {
|
||||
OSD_ERROR("UpdatePoints points size mismatch %d != %d\n", numCoarseVertices, (int)points.size());
|
||||
return;
|
||||
}
|
||||
|
||||
float * updateVertexBuffer = new float[GetNumCoarseVertices() * _numVertexElements];
|
||||
float *p = updateVertexBuffer;
|
||||
for(int i = 0; i < numCoarseVertices; ++i){
|
||||
for(int j = 0; j < _numVertexElements; ++j){
|
||||
*p++ = points[i*_numVertexElements+j];
|
||||
}
|
||||
}
|
||||
|
||||
// send to gpu
|
||||
_dispatcher->MapVertexBuffer();
|
||||
|
||||
// copy _updateVertexBuffer to each kernel's local memory
|
||||
int size = numCoarseVertices * _numVertexElements * sizeof(float);
|
||||
_dispatcher->UpdateVertexBuffer(size, updateVertexBuffer);
|
||||
|
||||
_dispatcher->UnmapVertexBuffer();
|
||||
|
||||
delete[] updateVertexBuffer;
|
||||
}
|
||||
|
||||
void
|
||||
OsdMesh::UpdateVaryings(const std::vector<float> &varyings)
|
||||
{
|
||||
int numCoarseVertices = _mMesh->GetNumCoarseVertices();
|
||||
if(numCoarseVertices * _numVaryingElements != varyings.size()) {
|
||||
OSD_ERROR("UpdateVaryings array size mismatch %d != %d\n", numCoarseVertices, (int)varyings.size());
|
||||
return;
|
||||
}
|
||||
|
||||
// send to gpu
|
||||
_dispatcher->MapVaryingBuffer();
|
||||
|
||||
int size = numCoarseVertices * _numVaryingElements * sizeof(float);
|
||||
_dispatcher->UpdateVaryingBuffer(size, (void*)&varyings[0]);
|
||||
|
||||
_dispatcher->UnmapVaryingBuffer();
|
||||
}
|
||||
|
||||
void
|
||||
OsdMesh::Subdivide()
|
||||
{
|
||||
_dispatcher->MapVertexBuffer();
|
||||
_dispatcher->MapVaryingBuffer();
|
||||
_dispatcher->BeginLaunchKernel();
|
||||
|
||||
_mMesh->Subdivide(_level+1);
|
||||
|
||||
_dispatcher->EndLaunchKernel();
|
||||
_dispatcher->UnmapVertexBuffer();
|
||||
_dispatcher->UnmapVaryingBuffer();
|
||||
|
||||
//DumpBuffer(_varyingBuffer);
|
||||
}
|
||||
|
||||
void
|
||||
OsdMesh::Synchronize()
|
||||
{
|
||||
_dispatcher->Synchronize();
|
||||
}
|
||||
|
||||
void
|
||||
OsdMesh::GetRefinedPoints(std::vector<float> &refinedPoints)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
|
||||
int size = 0;
|
||||
glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
|
||||
int numTotalVertices = _mMesh->GetNumVertices();
|
||||
if(size != numTotalVertices*_numVertexElements*sizeof(float)){
|
||||
OSD_ERROR("vertex count mismatch %d != %d\n", (int)(size/_numVertexElements/sizeof(float)), numTotalVertices);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
refinedPoints.resize(numTotalVertices*_numVertexElements);
|
||||
float *p = (float*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
|
||||
if(p){
|
||||
for(int i = 0; i < numTotalVertices; ++i){
|
||||
for(int j = 0; j < _numVertexElements; ++j){
|
||||
refinedPoints[i*_numVertexElements+j] = *p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
}
|
||||
|
||||
} // end namespace OPENSUBDIV_VERSION
|
||||
using namespace OPENSUBDIV_VERSION;
|
||||
|
||||
} // end namespace OpenSubdiv
|
||||
|
123
opensubdiv/osd/mesh.h
Normal file
123
opensubdiv/osd/mesh.h
Normal file
@ -0,0 +1,123 @@
|
||||
//
|
||||
// Copyright (C) Pixar. All rights reserved.
|
||||
//
|
||||
// This license governs use of the accompanying software. If you
|
||||
// use the software, you accept this license. If you do not accept
|
||||
// the license, do not use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S.
|
||||
// copyright law. A "contribution" is the original software, or
|
||||
// any additions or changes to the software.
|
||||
// A "contributor" is any person or entity that distributes its
|
||||
// contribution under this license.
|
||||
// "Licensed patents" are a contributor's patent claims that read
|
||||
// directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
// (A) Copyright Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free copyright license to reproduce its contribution,
|
||||
// prepare derivative works of its contribution, and distribute
|
||||
// its contribution or any derivative works that you create.
|
||||
// (B) Patent Grant- Subject to the terms of this license,
|
||||
// including the license conditions and limitations in section 3,
|
||||
// each contributor grants you a non-exclusive, worldwide,
|
||||
// royalty-free license under its licensed patents to make, have
|
||||
// made, use, sell, offer for sale, import, and/or otherwise
|
||||
// dispose of its contribution in the software or derivative works
|
||||
// of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
// (A) No Trademark License- This license does not grant you
|
||||
// rights to use any contributor's name, logo, or trademarks.
|
||||
// (B) If you bring a patent claim against any contributor over
|
||||
// patents that you claim are infringed by the software, your
|
||||
// patent license from such contributor to the software ends
|
||||
// automatically.
|
||||
// (C) If you distribute any portion of the software, you must
|
||||
// retain all copyright, patent, trademark, and attribution
|
||||
// notices that are present in the software.
|
||||
// (D) If you distribute any portion of the software in source
|
||||
// code form, you may do so only under this license by including a
|
||||
// complete copy of this license with your distribution. If you
|
||||
// distribute any portion of the software in compiled or object
|
||||
// code form, you may only do so under a license that complies
|
||||
// with this license.
|
||||
// (E) The software is licensed "as-is." You bear the risk of
|
||||
// using it. The contributors give no express warranties,
|
||||
// guarantees or conditions. You may have additional consumer
|
||||
// rights under your local laws which this license cannot change.
|
||||
// To the extent permitted under your local laws, the contributors
|
||||
// exclude the implied warranties of merchantability, fitness for
|
||||
// a particular purpose and non-infringement.
|
||||
//
|
||||
#ifndef OSD_MESH_H
|
||||
#define OSD_MESH_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "../osd/vertex.h"
|
||||
|
||||
#include "../far/mesh.h"
|
||||
#include "../hbr/mesh.h"
|
||||
#include "../hbr/vertex.h"
|
||||
#include "../hbr/face.h"
|
||||
#include "../hbr/halfedge.h"
|
||||
|
||||
namespace OpenSubdiv {
|
||||
namespace OPENSUBDIV_VERSION {
|
||||
|
||||
class OsdKernelDispatcher;
|
||||
|
||||
typedef HbrMesh<OsdVertex> OsdHbrMesh;
|
||||
typedef HbrVertex<OsdVertex> OsdHbrVertex;
|
||||
typedef HbrHalfedge<OsdVertex> OsdHbrHalfedge;
|
||||
typedef HbrFace<OsdVertex> OsdHbrFace;
|
||||
|
||||
class OsdMesh
|
||||
{
|
||||
public:
|
||||
OsdMesh(int numVertexElements, int numVaryingElements);
|
||||
virtual ~OsdMesh();
|
||||
|
||||
bool Create(OsdHbrMesh *hbrMesh, int level, const std::string &kernel);
|
||||
|
||||
void UpdatePoints(const std::vector<float> &points);
|
||||
void GetRefinedPoints(std::vector<float> &refinedPoints);
|
||||
void UpdateVaryings(const std::vector<float> &varyings);
|
||||
void GetRefinedVaryings(std::vector<float> &refinedVaryings);
|
||||
|
||||
FarMesh<OsdVertex> *GetFarMesh() { return _mMesh; }
|
||||
|
||||
void Subdivide();
|
||||
void Synchronize();
|
||||
|
||||
int GetNumVertexElements() const { return _numVertexElements; }
|
||||
int GetNumVaryingElements() const { return _numVaryingElements; }
|
||||
GLuint GetVertexBuffer() const { return _vertexBuffer; }
|
||||
GLuint GetVaryingBuffer() const { return _varyingBuffer; }
|
||||
|
||||
protected:
|
||||
|
||||
int GetTotalVertices() const { return _mMesh->GetNumVertices(); }
|
||||
int GetNumCoarseVertices() const { return _mMesh->GetNumCoarseVertices(); }
|
||||
|
||||
FarMesh<OsdVertex> *_mMesh;
|
||||
int _numVertexElements, _numVaryingElements;
|
||||
int _level;
|
||||
|
||||
GLuint _vertexBuffer, _varyingBuffer;
|
||||
OsdKernelDispatcher * _dispatcher;
|
||||
};
|
||||
|
||||
} // end namespace OPENSUBDIV_VERSION
|
||||
using namespace OPENSUBDIV_VERSION;
|
||||
|
||||
} // end namespace OpenSubdiv
|
||||
|
||||
#endif /* OSD_MESH_H */
|
15
opensubdiv/osd/vertex.h
Normal file
15
opensubdiv/osd/vertex.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef GSD_VERTEX_H
|
||||
#define GSD_VERTEX_H
|
||||
|
||||
class OsdVertex {
|
||||
public:
|
||||
OsdVertex() {}
|
||||
OsdVertex(int index) {}
|
||||
OsdVertex(const OsdVertex &src) {}
|
||||
|
||||
void AddWithWeight(const OsdVertex & i, float weight, void * = 0) {}
|
||||
void AddVaryingWithWeight(const OsdVertex & i, float weight, void * = 0) {}
|
||||
void Clear(void * = 0) {}
|
||||
};
|
||||
|
||||
#endif // GSD_VERTEX_H
|
@ -55,7 +55,7 @@
|
||||
# a particular purpose and non-infringement.
|
||||
#
|
||||
|
||||
find_package(IlmBase)
|
||||
find_package(IlmBase REQUIRED)
|
||||
|
||||
if(NOT ILMBASE_FOUND)
|
||||
message(WARNING
|
||||
@ -68,7 +68,7 @@ if(NOT ILMBASE_FOUND)
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${ILMBASE_INCLUDE_DIRECTORY}
|
||||
${ILMBASE_INCLUDE_DIR}
|
||||
${PROJECT_SOURCE_DIR}/opensubdiv
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user