Skip to content

Commit

Permalink
Merge pull request #148 from vsg-dev/master
Browse files Browse the repository at this point in the history
Merge vsgXchange master into 1.0 branch in prep for next stable release
  • Loading branch information
robertosfield authored Mar 1, 2023
2 parents 9e5d678 + dbe7648 commit c3527a1
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 63 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.7)

project(vsgXchange
VERSION 1.0.1
VERSION 1.0.2
DESCRIPTION "VulkanSceneGraph 3rd party data integration library"
LANGUAGES CXX C
)
set(VSGXCHANGE_SOVERSION 0)
SET(VSGXCHANGE_RELEASE_CANDIDATE 0)
SET(VSGXCHANGE_RELEASE_CANDIDATE 1)

set(VSGXCHANGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Root source directory of vsgXchange.")
set(VSGXCHANGE_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "Root binary directory of vsgXchange.")
Expand All @@ -20,7 +20,7 @@ if (VULKAN_SDK)
set(ENV{VULKAN_SDK} ${VULKAN_SDK})
endif()

set(VSG_MIN_VERSION 1.0.0)
set(VSG_MIN_VERSION 1.0.3)
find_package(vsg ${VSG_MIN_VERSION})

vsg_setup_dir_vars()
Expand Down
6 changes: 6 additions & 0 deletions include/vsgXchange/freetype.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ namespace vsgXchange

bool getFeatures(Features& features) const override;

// vsg::Options::setValue(str, value) suppoorted options:
static constexpr const char* texel_margin_ratio = "texel_margin_ratio";
static constexpr const char* quad_margin_ratio = "quad_margin_ratio";

bool readOptions(vsg::Options& options, vsg::CommandLine& arguments) const override;

protected:
~freetype();

Expand Down
1 change: 1 addition & 0 deletions include/vsgXchange/models.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace vsgXchange
static constexpr const char* generate_sharp_normals = "generate_sharp_normals";
static constexpr const char* crease_angle = "crease_angle"; /// float
static constexpr const char* two_sided = "two_sided"; /// bool
static constexpr const char* discard_empty_nodes = "discard_empty_nodes"; /// bool

bool readOptions(vsg::Options& options, vsg::CommandLine& arguments) const override;

Expand Down
2 changes: 2 additions & 0 deletions src/all/all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/io/spirv.h>
#include <vsg/io/tile.h>
#include <vsg/io/glsl.h>
#include <vsg/io/txt.h>
#include <vsg/io/Logger.h>

#ifdef vsgXchange_OSG
Expand Down Expand Up @@ -66,6 +67,7 @@ all::all()
add(vsg::VSG::create());
add(vsg::spirv::create());
add(vsg::glsl::create());
add(vsg::txt::create());

add(cpp::create());

Expand Down
15 changes: 10 additions & 5 deletions src/assimp/assimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ bool assimp::getFeatures(Features& features) const
features.optionNameTypeMap[assimp::generate_sharp_normals] = vsg::type_name<bool>();
features.optionNameTypeMap[assimp::crease_angle] = vsg::type_name<float>();
features.optionNameTypeMap[assimp::two_sided] = vsg::type_name<bool>();
features.optionNameTypeMap[assimp::discard_empty_nodes] = vsg::type_name<bool>();

return true;
}
Expand All @@ -126,6 +127,7 @@ bool assimp::readOptions(vsg::Options& options, vsg::CommandLine& arguments) con
result = arguments.readAndAssign<bool>(assimp::generate_sharp_normals, &options) || result;
result = arguments.readAndAssign<float>(assimp::crease_angle, &options) || result;
result = arguments.readAndAssign<bool>(assimp::two_sided, &options) || result;
result = arguments.readAndAssign<bool>(assimp::discard_empty_nodes, &options) || result;
return result;
}

Expand All @@ -144,6 +146,7 @@ struct SceneConverter
LightMap lightMap;

bool useViewDependentState = true;
bool discardEmptyNodes = true;

// TODO flatShadedShaderSet?
vsg::ref_ptr<vsg::ShaderSet> pbrShaderSet;
Expand Down Expand Up @@ -724,6 +727,7 @@ vsg::ref_ptr<vsg::Node> SceneConverter::visit(const aiScene* in_scene, vsg::ref_
{
scene = in_scene;
options = in_options;
discardEmptyNodes = vsg::value<bool>(true, assimp::discard_empty_nodes, options);

std::string name = scene->mName.C_Str();

Expand Down Expand Up @@ -822,9 +826,9 @@ vsg::ref_ptr<vsg::Node> SceneConverter::visit(const aiNode* node, int depth)
}
}

if (children.empty()) return {};
if (children.empty() && discardEmptyNodes) return {};

if (node->mTransformation.IsIdentity())
if (discardEmptyNodes && node->mTransformation.IsIdentity())
{
if (children.size() == 1 && name.empty()) return children[0];

Expand Down Expand Up @@ -990,8 +994,9 @@ assimp::Implementation::Implementation() :
vsg::ref_ptr<vsg::Object> assimp::Implementation::read(const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options) const
{
Assimp::Importer importer;
vsg::Path ext = (options && options->extensionHint) ? options->extensionHint : vsg::lowerCaseFileExtension(filename);

if (const auto ext = vsg::lowerCaseFileExtension(filename); importer.IsExtensionSupported(ext.string()))
if (importer.IsExtensionSupported(ext.string()))
{
vsg::Path filenameToUse = vsg::findFile(filename, options);
if (!filenameToUse) return {};
Expand Down Expand Up @@ -1036,7 +1041,7 @@ vsg::ref_ptr<vsg::Object> assimp::Implementation::read(const vsg::Path& filename

vsg::ref_ptr<vsg::Object> assimp::Implementation::read(std::istream& fin, vsg::ref_ptr<const vsg::Options> options) const
{
if (!options) return {};
if (!options || !options->extensionHint) return {};

Assimp::Importer importer;
if (importer.IsExtensionSupported(options->extensionHint.string()))
Expand Down Expand Up @@ -1067,7 +1072,7 @@ vsg::ref_ptr<vsg::Object> assimp::Implementation::read(std::istream& fin, vsg::r

vsg::ref_ptr<vsg::Object> assimp::Implementation::read(const uint8_t* ptr, size_t size, vsg::ref_ptr<const vsg::Options> options) const
{
if (!options) return {};
if (!options || !options->extensionHint) return {};

Assimp::Importer importer;
if (importer.IsExtensionSupported(options->extensionHint.string()))
Expand Down
13 changes: 8 additions & 5 deletions src/cpp/cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ bool cpp::write(const vsg::Object* object, const vsg::Path& filename, vsg::ref_p

bool binary = options ? (options->extensionHint == ".vsgb") : false;

auto local_options = vsg::Options::create();
local_options->extensionHint = binary ? ".vsgb" : ".vsgt";

// serialize object(s) to string
std::ostringstream str;
vsg::VSG io;
io.write(object, str, options);
io.write(object, str, local_options);
std::string s = str.str();

std::ofstream fout(filename);
Expand All @@ -49,7 +52,7 @@ bool cpp::write(const vsg::Object* object, const vsg::Path& filename, vsg::ref_p
if (binary || s.size() > 65535)
{
// long string has to be handled as a byte array as VisualStudio can't handle long strings.
fout << "uint8_t data[] = {\n";
fout << "static const uint8_t data[] = {\n";
fout << uint32_t(uint8_t(s[0]));
for(size_t i = 1; i < s.size(); ++i)
{
Expand All @@ -64,11 +67,11 @@ bool cpp::write(const vsg::Object* object, const vsg::Path& filename, vsg::ref_p
}
else
{
fout << "std::istringstream str(\n";
fout << "static const char str[] = \n";
write(fout, str.str());
fout << ");\n";
fout << ";\n";
fout << "vsg::VSG io;\n";
fout << "return io.read_cast<" << object->className() << ">(str);\n";
fout << "return io.read_cast<" << object->className() << ">(reinterpret_cast<const uint8_t*>(str), sizeof(str));\n";
}

fout << "};\n";
Expand Down
5 changes: 4 additions & 1 deletion src/curl/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ vsg::ref_ptr<vsg::Object> curl::Implementation::read(const vsg::Path& filename,
// success
auto local_options = vsg::Options::create(*options);
local_options->paths.insert(local_options->paths.begin(), vsg::filePath(filename));
local_options->extensionHint = vsg::fileExtension(filename);
if (!local_options->extensionHint)
{
local_options->extensionHint = vsg::lowerCaseFileExtension(filename);
}

object = vsg::read(sstr, local_options);

Expand Down
9 changes: 3 additions & 6 deletions src/dds/dds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ dds::dds() :

vsg::ref_ptr<vsg::Object> dds::read(const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options) const
{
if (const auto ext = vsg::lowerCaseFileExtension(filename); _supportedExtensions.count(ext) == 0)
return {};
if (!vsg::compatibleExtension(filename, options, _supportedExtensions)) return {};

vsg::Path filenameToUse = findFile(filename, options);
if (!filenameToUse) return {};
Expand Down Expand Up @@ -272,8 +271,7 @@ vsg::ref_ptr<vsg::Object> dds::read(const vsg::Path& filename, vsg::ref_ptr<cons

vsg::ref_ptr<vsg::Object> dds::read(std::istream& fin, vsg::ref_ptr<const vsg::Options> options) const
{
if (!options || _supportedExtensions.count(options->extensionHint) == 0)
return {};
if (!vsg::compatibleExtension(options, _supportedExtensions)) return {};

tinyddsloader::DDSFile ddsFile;
if (const auto result = ddsFile.Load(fin); result == tinyddsloader::Success)
Expand All @@ -298,8 +296,7 @@ vsg::ref_ptr<vsg::Object> dds::read(std::istream& fin, vsg::ref_ptr<const vsg::O

vsg::ref_ptr<vsg::Object> dds::read(const uint8_t* ptr, size_t size, vsg::ref_ptr<const vsg::Options> options) const
{
if (!options || _supportedExtensions.count(options->extensionHint) == 0)
return {};
if (!vsg::compatibleExtension(options, _supportedExtensions)) return {};

tinyddsloader::DDSFile ddsFile;
if (const auto result = ddsFile.Load(ptr, size); result == tinyddsloader::Success)
Expand Down
34 changes: 24 additions & 10 deletions src/freetype/freetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/nodes/Group.h>
#include <vsg/state/ShaderStage.h>
#include <vsg/text/Font.h>
#include <vsg/utils/CommandLine.h>
#include <vsg/io/Logger.h>

#include <ft2build.h>
#include FT_FREETYPE_H
Expand All @@ -37,7 +39,7 @@ namespace vsgXchange
return (c <= b) && (b <= a);
}

inline bool betwern_not_equal(float a, float b, float c)
inline bool between_not_equal(float a, float b, float c)
{
if (a < c)
return (a <= b) && (b < c);
Expand Down Expand Up @@ -103,9 +105,21 @@ bool freetype::getFeatures(Features& features) const
{
features.extensionFeatureMap[ext.first] = static_cast<vsg::ReaderWriter::FeatureMask>(vsg::ReaderWriter::READ_FILENAME);
}

// enumerate the supported vsg::Options::setValue(str, value) options
features.optionNameTypeMap[freetype::texel_margin_ratio] = vsg::type_name<float>();
features.optionNameTypeMap[freetype::quad_margin_ratio] = vsg::type_name<float>();

return true;
}

bool freetype::readOptions(vsg::Options& options, vsg::CommandLine& arguments) const
{
bool result = arguments.readAndAssign<float>(freetype::texel_margin_ratio, &options);
result = arguments.readAndAssign<float>(freetype::quad_margin_ratio, &options) || result;
return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// freetype ReaderWriter Implementation
Expand Down Expand Up @@ -483,7 +497,7 @@ bool freetype::Implementation::outside_contours(const Contours& local_contours,
}
else if (p0.x == p1.x) // vertical
{
if (betwern_not_equal(p0.y, v.y, p1.y))
if (between_not_equal(p0.y, v.y, p1.y))
{
if (v.x == p0.x)
{
Expand All @@ -498,7 +512,7 @@ bool freetype::Implementation::outside_contours(const Contours& local_contours,
}
else // diagonal
{
if (betwern_not_equal(p0.y, v.y, p1.y))
if (between_not_equal(p0.y, v.y, p1.y))
{
if (v.x > p0.x && v.x > p1.x)
{
Expand All @@ -522,11 +536,8 @@ bool freetype::Implementation::outside_contours(const Contours& local_contours,

vsg::ref_ptr<vsg::Object> freetype::Implementation::read(const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options) const
{
auto ext = vsg::lowerCaseFileExtension(filename);
if (_supportedFormats.find(ext) == _supportedFormats.end())
{
return {};
}
vsg::Path ext = (options && options->extensionHint) ? options->extensionHint : vsg::lowerCaseFileExtension(filename);
if (_supportedFormats.find(ext) == _supportedFormats.end()) return {};

vsg::Path filenameToUse = findFile(filename, options);
if (!filenameToUse) return {};
Expand Down Expand Up @@ -639,8 +650,11 @@ vsg::ref_ptr<vsg::Object> freetype::Implementation::read(const vsg::Path& filena

unsigned int average_width = static_cast<unsigned int>(ceil(total_width / double(sortedGlyphQuads.size())));

unsigned int texel_margin = pixel_size / 4;
int quad_margin = texel_margin / 2;
auto texel_margin = static_cast<unsigned int>(static_cast<float>(pixel_size) * vsg::value<float>(0.25f, freetype::texel_margin_ratio, options));
auto quad_margin = static_cast<unsigned int>(static_cast<float>(pixel_size) * vsg::value<float>(0.125f, freetype::quad_margin_ratio, options));

vsg::info("texel_margin = ", texel_margin);
vsg::info("quad_margin = ", quad_margin);

unsigned int provisional_cells_across = static_cast<unsigned int>(ceil(sqrt(double(face->num_glyphs))));
unsigned int provisional_width = provisional_cells_across * (average_width + texel_margin);
Expand Down
4 changes: 4 additions & 0 deletions src/freetype/freetype_fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ bool freetype::getFeatures(Features&) const
{
return false;
}
bool freetype::readOptions(vsg::Options&, vsg::CommandLine&) const
{
return false;
}
9 changes: 3 additions & 6 deletions src/ktx/ktx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ ktx::ktx() :

vsg::ref_ptr<vsg::Object> ktx::read(const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options) const
{
if (const auto ext = vsg::lowerCaseFileExtension(filename); _supportedExtensions.count(ext) == 0)
return {};
if (!vsg::compatibleExtension(filename, options, _supportedExtensions)) return {};

vsg::Path filenameToUse = vsg::findFile(filename, options);
if (!filenameToUse) return {};
Expand Down Expand Up @@ -277,8 +276,7 @@ vsg::ref_ptr<vsg::Object> ktx::read(const vsg::Path& filename, vsg::ref_ptr<cons

vsg::ref_ptr<vsg::Object> ktx::read(std::istream& fin, vsg::ref_ptr<const vsg::Options> options) const
{
if (!options || _supportedExtensions.count(options->extensionHint) == 0)
return {};
if (!vsg::compatibleExtension(options, _supportedExtensions)) return {};

std::string buffer(1 << 16, 0); // 64kB
std::string input;
Expand Down Expand Up @@ -312,8 +310,7 @@ vsg::ref_ptr<vsg::Object> ktx::read(std::istream& fin, vsg::ref_ptr<const vsg::O

vsg::ref_ptr<vsg::Object> ktx::read(const uint8_t* ptr, size_t size, vsg::ref_ptr<const vsg::Options> options) const
{
if (!options || _supportedExtensions.count(options->extensionHint) == 0)
return {};
if (!vsg::compatibleExtension(options, _supportedExtensions)) return {};

ktxTexture* texture = nullptr;
if (ktxTexture_CreateFromMemory(ptr, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &texture) == KTX_SUCCESS)
Expand Down
4 changes: 2 additions & 2 deletions src/ktx/libktx/texture2.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

#include <stdlib.h>
#include <string.h>
#include <zstd.h>
#include <zstd_errors.h>
#include "zstd.h"
#include "zstd_errors.h"
#include <KHR/khr_df.h>

#include "dfdutils/dfd.h"
Expand Down
Loading

0 comments on commit c3527a1

Please sign in to comment.