-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move implementation source into separate files. Minor clang-tidy chan…
…ges.
- Loading branch information
Showing
7 changed files
with
105 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Copyright (c) 2017 Big Ladder Software LLC. All rights reserved. | ||
* See the LICENSE file for additional terms and conditions. */ | ||
|
||
// Standard | ||
#include <memory> | ||
|
||
#ifndef NDEBUG | ||
#ifdef __unix__ | ||
#include <cfenv> | ||
#endif | ||
#endif | ||
|
||
// Penumbra | ||
#include "penumbra-implementation.h" | ||
|
||
namespace Penumbra { | ||
|
||
PenumbraImplementation::PenumbraImplementation(int size, | ||
const std::shared_ptr<Courierr::Courierr> &logger_in) | ||
: context(size, logger_in.get()), logger(logger_in) {} | ||
|
||
void PenumbraImplementation::add_surface(const Surface &surface) { | ||
surface.surface->logger = logger; | ||
if (surface.surface->name.empty()) { | ||
surface.surface->name = fmt::format("Surface {}", surfaces.size()); | ||
} | ||
surfaces.push_back(*surface.surface); | ||
} | ||
|
||
bool PenumbraImplementation::check_surface(const unsigned index) const { | ||
return index < surfaces.size(); | ||
} | ||
|
||
} // namespace Penumbra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* Copyright (c) 2017 Big Ladder Software LLC. All rights reserved. | ||
* See the LICENSE file for additional terms and conditions. */ | ||
|
||
// Standard | ||
#include <vector> | ||
#include <array> | ||
|
||
// Penumbra | ||
#include <penumbra/surface.h> | ||
#include "surface-implementation.h" | ||
#include <penumbra/logging.h> | ||
|
||
namespace Penumbra { | ||
|
||
TessData::TessData(const float *array, unsigned number_of_vertices) | ||
: number_of_vertices(number_of_vertices) { | ||
vertices.insert(vertices.end(), (const float *)array, (const float *)array + number_of_vertices); | ||
} | ||
|
||
SurfaceImplementation::SurfaceImplementation(Polygon polygon) : polygon(std::move(polygon)) {} | ||
|
||
TessData SurfaceImplementation::tessellate() { | ||
TESStesselator *tess = tessNewTess(nullptr); | ||
|
||
if (!tess) { | ||
throw PenumbraException(fmt::format("Unable to create tessellator for surface, \"{}\".", name), | ||
*logger); | ||
} | ||
|
||
// Add primary polygon | ||
tessAddContour(tess, TessData::polygon_size, &polygon[0], sizeof(float) * TessData::vertex_size, | ||
(int)polygon.size() / TessData::vertex_size); | ||
|
||
// Add holes | ||
for (auto &hole : holes) { | ||
tessAddContour(tess, TessData::polygon_size, &hole[0], sizeof(float) * TessData::vertex_size, | ||
(int)hole.size() / TessData::vertex_size); | ||
} | ||
|
||
if (!tessTesselate(tess, TESS_WINDING_ODD, TESS_POLYGONS, TessData::polygon_size, | ||
TessData::vertex_size, nullptr)) { | ||
throw PenumbraException(fmt::format("Unable to tessellate surface, \"{}\".", name), *logger); | ||
} | ||
|
||
// For now convert to glDrawArrays() style of vertices, sometime may change to glDrawElements | ||
// (with element buffers) | ||
std::vector<float> vertex_array; | ||
const TESSreal *vertices = tessGetVertices(tess); | ||
const int number_of_elements = tessGetElementCount(tess); | ||
const TESSindex *elements = tessGetElements(tess); | ||
for (int i = 0; i < number_of_elements * TessData::polygon_size; ++i) { | ||
const int vertex = *(elements + i); | ||
for (int j = 0; j < TessData::vertex_size; ++j) { | ||
vertex_array.push_back(vertices[vertex * TessData::vertex_size + j]); | ||
} | ||
} | ||
|
||
TessData data(&vertex_array[0], static_cast<unsigned int>(vertex_array.size())); | ||
|
||
tessDeleteTess(tess); | ||
|
||
return data; | ||
} | ||
|
||
} // namespace Penumbra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters