Skip to content

Commit

Permalink
Finish most of the APIs for implement test (PixarAnimationStudios#79)
Browse files Browse the repository at this point in the history
(cherry picked from commit 33226577edfd040e79626e895491354c0ff5179b)
  • Loading branch information
PierreWang committed Jan 17, 2023
1 parent 754b450 commit 6e88839
Show file tree
Hide file tree
Showing 19 changed files with 804 additions and 189 deletions.
24 changes: 24 additions & 0 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,29 @@ def InstallOpenSubdiv(context, force, buildArgs):
OPENSUBDIV = Dependency("OpenSubdiv", InstallOpenSubdiv,
"include/opensubdiv/version.h")

############################################################
# TextSystem

def InstallTextSystem(context, force, buildArgs):
extraArgs = buildArgs

oldGenerator = context.cmakeGenerator
if oldGenerator == "Ninja" and Windows():
context.cmakeGenerator = None

oldNumJobs = context.numJobs
if MacOS():
context.numJobs = 1

try:
RunCMake(context, force, extraArgs)
finally:
context.cmakeGenerator = oldGenerator
context.numJobs = oldNumJobs

TEXTSYSTEM = Dependency("TextSystem", InstallTextSystem,
"include/TextSystem/TextSystem.h")

############################################################
# PyOpenGL

Expand Down Expand Up @@ -2302,6 +2325,7 @@ def ForceBuildDependency(self, dep):
requiredDependencies += [PTEX]

requiredDependencies += [OPENSUBDIV]
requiredDependencies += [TEXTSYSTEM]

if context.enableOpenVDB:
requiredDependencies += [BLOSC, BOOST, OPENEXR, OPENVDB, TBB]
Expand Down
86 changes: 86 additions & 0 deletions cmake/modules/FindTextSystem.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# - Find TextSystem library
# Find the native TextSystem includes and library
# This module defines
# TEXTSYSTEM_INCLUDE_DIRS, where to find TextSystem headers, Set when
# TEXTSYSTEM_INCLUDE_DIR is found.
# TEXTSYSTEM_LIBRARIES, libraries to link against to use TextSystem.
# TEXTSYSTEM_ROOT_DIR, the base directory to search for TextSystem.
# This can also be an environment variable.
# TEXTSYSTEM_FOUND, if false, do not try to use TextSystem.
#
# also defined, but not for general use are
# TEXTSYSTEM_LIBRARY, where to find the TextSystem library.

#=============================================================================
# Copyright 2021 Blender Foundation.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================

# If TEXTSYSTEM_ROOT_DIR was defined in the environment, use it.
IF(NOT TEXTSYSTEM_ROOT_DIR AND NOT $ENV{TEXTSYSTEM_ROOT_DIR} STREQUAL "")
SET(TEXTSYSTEM_ROOT_DIR $ENV{TEXTSYSTEM_ROOT_DIR})
ENDIF()

SET(TEXTSYSTEM_FIND_COMPONENTS
text_system
)

SET(TEXTSYSTEM_SEARCH_DIRS
${TEXTSYSTEM_ROOT_DIR}
)

FIND_PATH(TEXTSYSTEM_INCLUDE_DIR
NAMES
TextSystem/TextSystem.h
HINTS
${TEXTSYSTEM_SEARCH_DIRS}
PATH_SUFFIXES
include
)

SET(TEXTSYSTEM_LIBRARIES)
FOREACH(COMPONENT ${TEXTSYSTEM_FIND_COMPONENTS})
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
FIND_LIBRARY(TEXTSYSTEM_${UPPERCOMPONENT}_LIBRARY
NAMES
${COMPONENT}
HINTS
${TEXTSYSTEM_SEARCH_DIRS}
PATH_SUFFIXES
lib64 lib
)
if(DEFINED TEXTSYSTEM_${UPPERCOMPONENT}_LIBRARY)
LIST(APPEND
TEXTSYSTEM_LIBRARIES
"${TEXTSYSTEM_${UPPERCOMPONENT}_LIBRARY}")
set(TEXTSYSTEM_FOUND TRUE)
endif()
ENDFOREACH()

IF(TEXTSYSTEM_FOUND)
SET(TEXTSYSTEM_LIBRARIES ${TEXTSYSTEM_LIBRARIES})
SET(TEXTSYSTEM_INCLUDE_DIRS ${TEXTSYSTEM_INCLUDE_DIR})
ENDIF(TEXTSYSTEM_FOUND)

MARK_AS_ADVANCED(
TEXTSYSTEM_INCLUDE_DIR
)
FOREACH(COMPONENT ${TEXTSYSTEM_FIND_COMPONENTS})
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
MARK_AS_ADVANCED(TEXTSYSTEM_${UPPERCOMPONENT}_LIBRARY)
ENDFOREACH()

# handle the QUIETLY and REQUIRED arguments and set TEXTSYSTEM_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(TEXTSYSTEM
REQUIRED_VARS
TEXTSYSTEM_INCLUDE_DIR
TEXTSYSTEM_LIBRARIES
)
3 changes: 1 addition & 2 deletions pxr/imaging/hd/simpleText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ HdSimpleText::GetBuiltinPrimvarNames() const
{
static const TfTokenVector primvarNames = {
HdTokens->points,
HdTokens->normals,
HdTokens->widths
HdTokens->textTextureUV
};
return primvarNames;
}
Expand Down
41 changes: 33 additions & 8 deletions pxr/imaging/hd/simpleTextTopology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,51 @@

PXR_NAMESPACE_OPEN_SCOPE


HdSimpleTextTopology::HdSimpleTextTopology()
: HdTopology()
: HdTopology()
, _textData("")
, _textEncoding(TfToken())
, _textHeight(22)
, _textWidthFactor(1.0f)
, _bold(false)
, _italic(false)
{
HD_PERF_COUNTER_INCR(HdPerfTokens->simpleTextTopology);
}
HdSimpleTextTopology::HdSimpleTextTopology(const std::string& textData,
const TfToken& textEncoding, int textHeight, float textWidthFactor,
bool bold, bool italic)
: HdTopology(), _textData(textData), _textEncoding(textEncoding),
_textHeight(textHeight), _textWidthFactor(textWidthFactor),
_bold(bold), _italic(italic)
{
HD_PERF_COUNTER_INCR(HdPerfTokens->singleTextTopology);
HD_PERF_COUNTER_INCR(HdPerfTokens->simpleTextTopology);
}

HdSimpleTextTopology::HdSimpleTextTopology(const HdSimpleTextTopology& src)
: HdTopology(src)
{
HD_PERF_COUNTER_INCR(HdPerfTokens->singleTextTopology);
HD_PERF_COUNTER_INCR(HdPerfTokens->simpleTextTopology);
}


HdSimpleTextTopology::~HdSimpleTextTopology()
{
HD_PERF_COUNTER_DECR(HdPerfTokens->singleTextTopology);
HD_PERF_COUNTER_DECR(HdPerfTokens->simpleTextTopology);
}

bool
HdSimpleTextTopology::operator==(HdSimpleTextTopology const &/*other*/) const
HdSimpleTextTopology::operator==(HdSimpleTextTopology const &other) const
{
HD_TRACE_FUNCTION();

// no need to compare _adajency and _quadInfo
return true;
return (_textData == other._textData &&
_textEncoding == other._textEncoding &&
_textHeight == other._textHeight &&
_textWidthFactor == other._textWidthFactor &&
_bold == other._bold &&
_italic == other._italic);
}

bool
Expand All @@ -69,7 +88,13 @@ HdSimpleTextTopology::ComputeHash() const
HD_TRACE_FUNCTION();

HdTopology::ID hash = 0;

hash = ArchHash64((const char*)_textData.data(), _textData.length(), hash);
hash = ArchHash64((const char*)&_textEncoding, sizeof(TfToken), hash);
hash = ArchHash64((const char*)&_textHeight, sizeof(int), hash);
hash = ArchHash64((const char*)&_textWidthFactor, sizeof(float), hash);
hash = ArchHash64((const char*)&_bold, sizeof(bool), hash);
hash = ArchHash64((const char*)&_italic, sizeof(bool), hash);

// Note: We don't hash topological visibility, because it is treated as a
// per-prim opinion, and hence, shouldn't break topology sharing.
return hash;
Expand Down
69 changes: 32 additions & 37 deletions pxr/imaging/hd/simpleTextTopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,46 +37,14 @@

PXR_NAMESPACE_OPEN_SCOPE

/// \class HdBasisCurvesTopology
///
/// Topology data for basisCurves.
///
/// HdBasisCurvesTopology holds the raw input topology data for basisCurves
///
/// The Type, Basis and Wrap mode combined describe the curve and it's
/// segments.
///
/// If Type == linear, the curve is a bunch of line segments and basis is
/// ignored.
///
/// The wrap mode defines how the curve segments are specified:
///
/// If Wrap == segmented, this is equivalent to GL_LINES and curve vertex
/// counts is 2 * number of segments (multiple entries in curve vertex
/// array is optional).
///
/// If Wrap == nonperiodic, this is equivalent to GL_LINE_STRIP and curve
/// counts is an array where each entry is the number of vertices in that
/// line segment. The first and last vertex in the segment are not joined.
///
/// If Wrap == periodic, this is equivalent to GL_LINE_LOOP and curve counts
/// is an array where each entry is the number of vertices in that line
/// segment. An additional line is place between the first and last vertex
/// in each segment.
///
/// If Type == cubic, the type of curve is specified by basis:
/// The Basis can be bezier, bspline or catmullRom.
///
/// Wrap can be either periodic or nonperiodic (segmented is unsupported).
///
/// For each type of line, the generated vertex indices can pass through an
/// optional index buffer to map the generated indices to actual indices in
/// the vertex buffer.
///
class HdSimpleTextTopology : public HdTopology {
public:
HD_API
HdSimpleTextTopology();
HD_API
HdSimpleTextTopology(const std::string& textData,
const TfToken& textEncoding, int textHeight, float textWidthFactor,
bool bold, bool italic);
HD_API
HdSimpleTextTopology(const HdSimpleTextTopology& src);
HD_API
Expand All @@ -86,12 +54,39 @@ class HdSimpleTextTopology : public HdTopology {
HD_API
virtual ID ComputeHash() const;

/// Returns segment vertex counts.
std::string GetTextData() const {
return _textData;
}

/// Returns indices.
TfToken GetTextEncoding() const {
return _textEncoding;
}

/// Returns the number of curves
int GetTextHeight() const {
return _textHeight;
}

/// See class documentation for valid combination of values
float GetTextWidthFactor() const { return _textWidthFactor; }
bool GetBold() const { return _bold; }
bool GetItalic() const { return _italic; }


/// Equality check between two basisCurves topologies.
HD_API
bool operator==(HdSimpleTextTopology const &other) const;
HD_API
bool operator!=(HdSimpleTextTopology const &other) const;

private:
std::string _textData;
TfToken _textEncoding;
int _textHeight;
float _textWidthFactor;
bool _bold;
bool _italic;
};

HD_API
Expand Down
7 changes: 4 additions & 3 deletions pxr/imaging/hd/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ PXR_NAMESPACE_OPEN_SCOPE
(subdivTags) \
(taskState) \
(taskParams) \
(textData) \
(textTextureUV) \
(topology) \
(topologyVisibility) \
(totalItemCount) \
(transform) \
(transformInverse) \
(typeface) \
(velocities) \
(visibility) \
(widths) \
Expand Down Expand Up @@ -168,6 +167,8 @@ PXR_NAMESPACE_OPEN_SCOPE
(instMeshTopology) \
(instMeshTopologyRange) \
(instPrimvarRange) \
(instSimpleTextTopology) \
(instSimpleTextTopologyRange) \
(instVertexAdjacency) \
(meshTopology) \
(nonUniformSize) \
Expand All @@ -177,7 +178,7 @@ PXR_NAMESPACE_OPEN_SCOPE
(quadrangulateFaceVarying) \
(quadrangulatedVerts) \
(rebuildBatches) \
(singleTextTopology) \
(simpleTextTopology) \
(singleBufferSize) \
(ssboSize) \
(skipInvisibleRprimSync) \
Expand Down
2 changes: 2 additions & 0 deletions pxr/imaging/hdSt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ pxr_library(hdSt
tf
trace
${OPENSUBDIV_LIBRARIES}
${TEXTSYSTEM_LIBRARIES}
${optionalLibs}

INCLUDE_DIRS
${OPENSUBDIV_INCLUDE_DIR}
${TEXTSYSTEM_INCLUDE_DIRS}
${optionalIncludeDirs}

PUBLIC_CLASSES
Expand Down
Loading

0 comments on commit 6e88839

Please sign in to comment.