Skip to content
2 changes: 0 additions & 2 deletions include/polyscope/color_image_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class ColorImageQuantity : public ImageQuantity {


protected:
std::vector<glm::vec4> colorsData;

PersistentValue<bool> isPremultiplied;

// rendering internals
Expand Down
2 changes: 0 additions & 2 deletions include/polyscope/color_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class ColorQuantity {
// === ~DANGER~ experimental/unsupported functions

protected:
std::vector<glm::vec3> colorsData;

// === Visualization parameters

// Parameters
Expand Down
6 changes: 4 additions & 2 deletions include/polyscope/color_quantity.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace polyscope {

template <typename QuantityT>
ColorQuantity<QuantityT>::ColorQuantity(QuantityT& quantity_, const std::vector<glm::vec3>& colors_)
: quantity(quantity_), colors(&quantity, quantity.uniquePrefix() + "colors", colorsData), colorsData(colors_) {
: quantity(quantity_), colors(&quantity, quantity.uniquePrefix() + "colors", std::vector<glm::vec3>(colors_)) {
colors.checkInvalidValues();
}

Expand All @@ -27,7 +27,9 @@ template <typename QuantityT>
template <class V>
void ColorQuantity<QuantityT>::updateData(const V& newColors) {
validateSize(newColors, colors.size(), "color quantity");
colors.data = standardizeVectorArray<glm::vec3, 3>(newColors);
auto d = standardizeVectorArray<glm::vec3, 3>(newColors);
colors.resize(d.size());
colors.setDataHost(d);
colors.markHostBufferUpdated();
}

Expand Down
5 changes: 1 addition & 4 deletions include/polyscope/color_render_image_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class ColorRenderImageQuantity : public RenderImageQuantityBase {
protected:
// === Visualization parameters

// Store the raw data
std::vector<glm::vec3> colorsData;

// === Render data
std::shared_ptr<render::ShaderProgram> program;

Expand All @@ -60,7 +57,7 @@ void ColorRenderImageQuantity::updateBuffers(const T1& depthData, const T2& norm
std::vector<glm::vec3> standardNormal(standardizeVectorArray<glm::vec3, 3>(normalData));
std::vector<glm::vec3> standardColor(standardizeVectorArray<glm::vec3, 3>(colorsData));

colors.data = standardColor;
colors.setDataHost(standardColor);
colors.markHostBufferUpdated();

updateBaseBuffers(standardDepth, standardNormal);
Expand Down
7 changes: 0 additions & 7 deletions include/polyscope/curve_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ class CurveNetwork : public Structure {


private:
// Storage for the managed buffers above. You should generally interact with these through the managed buffers, not
// these members.
std::vector<glm::vec3> nodePositionsData;
std::vector<uint32_t> edgeTailIndsData;
std::vector<uint32_t> edgeTipIndsData;
std::vector<glm::vec3> edgeCentersData;

void computeEdgeCenters();

// === Visualization parameters
Expand Down
4 changes: 3 additions & 1 deletion include/polyscope/curve_network.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ CurveNetwork* registerCurveNetworkLoop2D(std::string name, const P& nodes) {
template <class V>
void CurveNetwork::updateNodePositions(const V& newPositions) {
validateSize(newPositions, nNodes(), "newPositions");
nodePositions.data = standardizeVectorArray<glm::vec3, 3>(newPositions);
auto d = standardizeVectorArray<glm::vec3, 3>(newPositions);
nodePositions.resize(d.size());
nodePositions.setDataHost(d);
nodePositions.markHostBufferUpdated();
recomputeGeometryIfPopulated();
}
Expand Down
3 changes: 0 additions & 3 deletions include/polyscope/curve_network_color_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class CurveNetworkEdgeColorQuantity : public CurveNetworkColorQuantity {

render::ManagedBuffer<glm::vec3> nodeAverageColors;
void updateNodeAverageColors();

private:
std::vector<glm::vec3> nodeAverageColorsData;
};

} // namespace polyscope
3 changes: 0 additions & 3 deletions include/polyscope/curve_network_scalar_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ class CurveNetworkEdgeScalarQuantity : public CurveNetworkScalarQuantity {

render::ManagedBuffer<float> nodeAverageValues;
void updateNodeAverageValues();

private:
std::vector<float> nodeAverageValuesData;
};


Expand Down
3 changes: 0 additions & 3 deletions include/polyscope/parameterization_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ class ParameterizationQuantity {
void setParameterizationUniforms(render::ShaderProgram& p);

protected:
// Raw storage for the data. You should only interact with this via the managed buffer above
std::vector<glm::vec2> coordsData;
std::vector<float> islandLabelsData;
bool islandLabelsPopulated = false;

// === Visualization parameters
Expand Down
9 changes: 5 additions & 4 deletions include/polyscope/parameterization_quantity.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ ParameterizationQuantity<QuantityT>::ParameterizationQuantity(QuantityT& quantit
: quantity(quantity_),

// buffers
coords(&quantity, quantity.uniquePrefix() + "#coords", coordsData),
islandLabels(&quantity, quantity.uniquePrefix() + "#islandLabels", islandLabelsData), coordsType(type_),
coordsData(coords_),
coords(&quantity, quantity.uniquePrefix() + "#coords", std::vector<glm::vec2>(coords_)),
islandLabels(&quantity, quantity.uniquePrefix() + "#islandLabels", std::vector<float>{}), coordsType(type_),

// options
checkerSize(quantity.uniquePrefix() + "#checkerSize", 0.02),
Expand Down Expand Up @@ -227,7 +226,9 @@ template <typename QuantityT>
template <class V>
void ParameterizationQuantity<QuantityT>::updateCoords(const V& newCoords) {
validateSize(newCoords, coords.size(), "parameterization quantity " + quantity.name);
coords.data = standardizeVectorArray<glm::vec2, 2>(newCoords);
auto d = standardizeVectorArray<glm::vec2, 2>(newCoords);
coords.resize(d.size());
coords.setDataHost(d);
coords.markHostBufferUpdated();
}

Expand Down
2 changes: 0 additions & 2 deletions include/polyscope/point_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ class PointCloud : public Structure {


private:
// Storage for the managed buffers above. You should generally interact with this directly through them.
std::vector<glm::vec3> pointsData;

// === Visualization parameters
PersistentValue<std::string> pointRenderMode;
Expand Down
4 changes: 3 additions & 1 deletion include/polyscope/point_cloud.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ PointCloud* registerPointCloud2D(std::string name, const T& points) {
template <class V>
void PointCloud::updatePointPositions(const V& newPositions) {
validateSize(newPositions, nPoints(), "point cloud updated positions " + name);
points.data = standardizeVectorArray<glm::vec3, 3>(newPositions);
auto d = standardizeVectorArray<glm::vec3, 3>(newPositions);
points.resize(d.size());
points.setDataHost(d);
points.markHostBufferUpdated();
}

Expand Down
5 changes: 1 addition & 4 deletions include/polyscope/raw_color_alpha_render_image_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class RawColorAlphaRenderImageQuantity : public RenderImageQuantityBase {
bool getIsPremultiplied();

protected:
// Store the raw data
std::vector<glm::vec4> colorsData;

// === Visualization parameters
PersistentValue<bool> isPremultiplied;

Expand All @@ -59,7 +56,7 @@ void RawColorAlphaRenderImageQuantity::updateBuffers(const T1& depthData, const
std::vector<glm::vec3> standardNormal;
std::vector<glm::vec4> standardColor(standardizeVectorArray<glm::vec4, 4>(colorsData));

colors.data = standardColor;
colors.setDataHost(standardColor);
colors.markHostBufferUpdated();

updateBaseBuffers(standardDepth, standardNormal);
Expand Down
5 changes: 1 addition & 4 deletions include/polyscope/raw_color_render_image_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class RawColorRenderImageQuantity : public RenderImageQuantityBase {
protected:
// === Visualization parameters

// Store the raw data
std::vector<glm::vec3> colorsData;

// === Render data
std::shared_ptr<render::ShaderProgram> program;

Expand All @@ -56,7 +53,7 @@ void RawColorRenderImageQuantity::updateBuffers(const T1& depthData, const T2& c
std::vector<glm::vec3> standardNormal;
std::vector<glm::vec3> standardColor(standardizeVectorArray<glm::vec3, 3>(colorsData));

colors.data = standardColor;
colors.setDataHost(standardColor);
colors.markHostBufferUpdated();

updateBaseBuffers(standardDepth, standardNormal);
Expand Down
39 changes: 30 additions & 9 deletions include/polyscope/render/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

namespace polyscope {

// Forward declarations for ManagedBuffer integration
namespace render {
class ManagedBufferBase;
template <typename T> class ManagedBuffer;
} // namespace render

// == A few enums that control behavior
// public enums are in the outer namespace to keep the typing burden down

Expand Down Expand Up @@ -96,13 +102,16 @@ class AttributeBuffer {
virtual void setData(const std::vector<std::array<glm::vec3, 3>>& data) = 0;
virtual void setData(const std::vector<std::array<glm::vec3, 4>>& data) = 0;

// Pre-allocate GPU memory for n elements without uploading any data. Subsequent setData()
// calls with size <= n will not need to reallocate the underlying buffer.
virtual void reserveCapacity(size_t n) = 0;

virtual uint32_t getNativeBufferID() = 0; // used to interop with external things, e.g. ImGui

// == Getters
RenderDataType getType() const { return dataType; }
int getArrayCount() const { return arrayCount; }
int64_t getDataSize() const { return dataSize; }
int64_t getDataSizeInBytes() const { return dataSize * sizeInBytes(dataType) * getArrayCount(); }
uint64_t getBufferSize() const { return bufferSize; }
uint64_t getUniqueID() const { return uniqueID; }
bool isSet() const { return setFlag; }

Expand Down Expand Up @@ -140,9 +149,7 @@ class AttributeBuffer {
RenderDataType dataType;
int arrayCount;
bool setFlag = false;
int64_t dataSize = -1; // the size of the data currently stored in this attribute (-1 if nothing)
// this counts # elements of the specified type, s.t. array'd mulitpliers are still just one
uint64_t bufferSize = 0; // the size of the allocated buffer (which might be larger than the data sixze)
uint64_t bufferSize = 0; // size of the allocated GPU buffer in elements of this buffer's type
uint64_t uniqueID;
};

Expand Down Expand Up @@ -391,7 +398,7 @@ class ShaderProgram {
virtual bool hasAttribute(std::string name) = 0;
virtual bool attributeIsSet(std::string name) = 0;
virtual std::shared_ptr<AttributeBuffer> getAttributeBuffer(std::string name) = 0;
virtual void setAttribute(std::string name, std::shared_ptr<AttributeBuffer> externalBuffer) = 0;
virtual void setAttribute(std::string name, std::shared_ptr<AttributeBuffer> externalBuffer, ManagedBufferBase* source = nullptr) = 0;
virtual void setAttribute(std::string name, const std::vector<glm::vec2>& data) = 0;
virtual void setAttribute(std::string name, const std::vector<glm::vec3>& data) = 0;
virtual void setAttribute(std::string name, const std::vector<glm::vec4>& data) = 0;
Expand All @@ -414,13 +421,26 @@ class ShaderProgram {
bool withAlpha = true, bool useMipMap = false, bool repeat = false) = 0;
virtual void setTextureFromColormap(std::string name, const std::string& colorMap, bool allowUpdate = false) = 0;
// TODO make this one take a shared pointer and have the same semantics as the attribute version
virtual void setTextureFromBuffer(std::string name, TextureBuffer* textureBuffer) = 0;
virtual void setTextureFromBuffer(std::string name, TextureBuffer* textureBuffer, ManagedBufferBase* source = nullptr) = 0;


// Convenience overloads for ManagedBuffer — set the buffer AND record the source for lazy sync.
// Defined in managed_buffer.h after ManagedBuffer<T> is fully declared.
template <typename T> void setAttribute(std::string name, ManagedBuffer<T>& buf);
template <typename T> void setTextureFromBuffer(std::string name, ManagedBuffer<T>& buf);
template <typename T> void setIndex(ManagedBuffer<T>& buf);

// Indices
virtual void setIndex(std::shared_ptr<AttributeBuffer> externalBuffer) = 0;
virtual void setPrimitiveRestartIndex(unsigned int restartIndex) = 0;

// Set the number of primitives to draw in the draw call. Must be called before drawing.
// For non-indexed modes: number of vertices (e.g. points, line endpoints, triangle corners).
// For indexed modes: number of index-buffer entries (e.g. uvec3 faces for IndexedTriangles),
// the engine multiplies by indexSizeMult internally to get the total index count passed to GL.
// For instanced modes: number of vertices per instance (instanceCount sets the instance count separately).
void setDrawCount(uint32_t count) { drawCount = count; }

// Indices
virtual void setInstanceCount(uint32_t instanceCount) = 0;

Expand All @@ -438,8 +458,6 @@ class ShaderProgram {
// What mode does this program draw in?
DrawMode drawMode;

// How much data is there to draw
uint32_t drawDataLength;

// Indexed drawing
bool useIndex = false;
Expand All @@ -451,6 +469,9 @@ class ShaderProgram {
uint64_t uniqueID;

std::shared_ptr<AttributeBuffer> indexBuffer;
ManagedBufferBase* indexSourceManagedBuffer = nullptr;

uint32_t drawCount = INVALID_IND_32;

// instancing
uint32_t instanceCount = INVALID_IND_32;
Expand Down
Loading
Loading