Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d8d56b1
initial structure for multi viewport
nmwsharp Jun 15, 2026
7e47777
shared view updates to subviews
nmwsharp Jun 15, 2026
e6f38b9
subview support for core picking and view helpers
nmwsharp Nov 22, 2026
a7a30bf
add some subview tests
nmwsharp Nov 22, 2026
777280f
clean up render buffer allocation, fix transparency with subviews
nmwsharp Nov 22, 2026
ddc3bb0
fix interaction behavior for subviews
nmwsharp Nov 22, 2026
b241db6
fix buggy ssaa with subviews
nmwsharp Nov 22, 2026
137a81c
fixes to subview widget scaling, active logic, and comments
nmwsharp Nov 22, 2026
9e6fa13
add a unit64_t persistent value
nmwsharp Nov 22, 2026
60a18ea
implement structure subview visibility masking
nmwsharp Nov 23, 2026
38e9d3f
handle perspective vs ortho cameras dynamically
nmwsharp Nov 23, 2026
b39a7b8
clean up projection mode, improve naming and comments
nmwsharp Nov 23, 2026
465aa90
make view_parameters comments more pedantic
nmwsharp Nov 23, 2026
6fc605d
add TODO
nmwsharp Nov 23, 2026
579d034
update blit signature
nmwsharp Nov 25, 2026
ac6bdf5
clean up subview coordinate helpers
nmwsharp Nov 25, 2026
fc5d65d
rename subview --> viewport
nmwsharp Nov 25, 2026
4e7dde9
more renaming for consistency
nmwsharp Nov 25, 2026
09b127d
subview picking basic test
nmwsharp Nov 25, 2026
79203a7
clean up bufferInd and viewport coordinate conventions
nmwsharp Nov 25, 2026
bd338c6
clean up loose ends for viewports
nmwsharp Nov 25, 2026
7d67df6
run formatter
nmwsharp Nov 26, 2026
daacbe0
run formatter
nmwsharp Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/polyscope/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <polyscope/pick.h>
#include <polyscope/types.h>
#include <polyscope/view_parameters.h>
#include <polyscope/weak_handle.h>

#include <glm/glm.hpp>
Expand Down Expand Up @@ -101,6 +102,11 @@ struct Context {
glm::vec3 flightTargetViewT, flightInitialViewT;
float flightTargetFov, flightInitialFov;

// Viewports
std::vector<view::ViewParameters> viewportParameters;
int activeViewportIndex = -1;
bool viewportsShareNavigation = true;

// ======================================================
// === Picking globals from pick.h / pick.cpp
// ======================================================
Expand Down
1 change: 0 additions & 1 deletion include/polyscope/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ extern float rightWindowsWidth;
// Cached versions of lazy properties used for updates
namespace lazy {
extern TransparencyMode transparencyMode;
extern ProjectionMode projectionMode;
extern int transparencyRenderPasses;
extern int ssaaFactor;
extern float uiScale;
Expand Down
2 changes: 2 additions & 0 deletions include/polyscope/persistent_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class PersistentValue {
namespace detail {

extern PersistentCache<int32_t> persistentCache_int32_t;
extern PersistentCache<uint64_t> persistentCache_uint64_t;
extern PersistentCache<double> persistentCache_double;
extern PersistentCache<float> persistentCache_float;
extern PersistentCache<bool> persistentCache_bool;
Expand All @@ -151,6 +152,7 @@ extern PersistentCache<MeshSelectionMode> persistentCache_MeshSelectionMode;
extern PersistentCache<SparseVolumeGridRenderMode> persistentCache_SparseVolumeGridRenderMode;

template<> inline PersistentCache<int32_t>& getPersistentCacheRef<int32_t>() { return persistentCache_int32_t; }
template<> inline PersistentCache<uint64_t>& getPersistentCacheRef<uint64_t>() { return persistentCache_uint64_t; }
template<> inline PersistentCache<double>& getPersistentCacheRef<double>() { return persistentCache_double; }
template<> inline PersistentCache<float>& getPersistentCacheRef<float>() { return persistentCache_float; }
template<> inline PersistentCache<bool>& getPersistentCacheRef<bool>() { return persistentCache_bool; }
Expand Down
36 changes: 31 additions & 5 deletions include/polyscope/pick.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,38 @@ struct PickResult {
std::string structureType = "";
std::string structureName = "";
std::string quantityName = "";

// Where the pick was evaluated, in two coordinate frames. See the notes in view.h on screen coords vs. buffer inds.
//
// `screenCoords` and `bufferInds` are GLOBAL: they are positions in the whole window, regardless of viewport.
// When using a single viewport, these are all you need.
glm::vec2 screenCoords;
glm::ivec2 bufferInds;
//
// The `viewport*` members are LOCAL to the viewport that the pick landed in, which is `viewportInd`: the origin is
// the top-left of that viewport. These are the coordinates to use with pickViewportAtScreenCoords() and
// pickViewportAtBufferInds(), so that pickViewportAtBufferInds(r.viewportBufferInds, r.viewportInd) round-trips.
// With a single viewport (viewportInd == 0, covering the whole window), these equal the global values above.
int32_t viewportInd = 0;
glm::vec2 viewportScreenCoords;
glm::ivec2 viewportBufferInds;

glm::vec3 position;
float depth;
uint64_t localIndex = INVALID_IND_64;
};

// Query functions to evaluate a pick.
// Internally, these do a render pass to populate relevant information, then query the resulting buffers.
// If using viewports, these assume inputs are GLOBAL coordinates on the whole window, and internally route to the
// appropriate viewport.
PickResult pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
PickResult pickAtBufferInds(glm::ivec2 bufferInds); // takes indices into render buffer

// Viewport-explicit pick variants: coordinates are LOCAL to the given viewport (origin at viewport top-left).
// Pass viewportInd=-1 to use the current active viewport.
PickResult pickViewportAtScreenCoords(glm::vec2 screenCoords, int32_t viewportInd = -1);
PickResult pickViewportAtBufferInds(glm::ivec2 bufferInds, int32_t viewportInd = -1);

// == Stateful picking: track and update a current selection

Expand All @@ -61,11 +81,17 @@ namespace pick {
// Old, deprecated picking API. Use the above functions instead.
// Get the structure which was clicked on (nullptr if none), and the pick ID in local indices for that structure (such
// that 0 is the first index as returned from requestPickBufferRange())
std::pair<Structure*, uint64_t> pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
std::pair<Structure*, uint64_t> pickAtBufferCoords(int xPos, int yPos); // takes indices into the buffer
std::pair<Structure*, uint64_t> evaluatePickQuery(int xPos, int yPos); // old, badly named. takes buffer coordinates.
std::tuple<Structure*, Quantity*, uint64_t> evaluatePickQueryFull(int xPos,
int yPos); // badly named. takes buffer coordinates.
//
// When using multiple viewports, the coordinates are LOCAL to the viewport iView, where iView<0 means the active
// viewport, as with other viewport-aware functions. With a single viewport, these all behave as they always did. To
// pick using global window coordinates and have the viewport found automatically, use the functions above.
std::pair<Structure*, uint64_t> pickAtScreenCoords(glm::vec2 screenCoords,
int32_t iView = -1); // takes screen coordinates
std::pair<Structure*, uint64_t> pickAtBufferCoords(int xPos, int yPos,
int32_t iView = -1); // takes indices into the buffer
std::pair<Structure*, uint64_t> evaluatePickQuery(int xPos, int yPos, int32_t iView = -1);
std::tuple<Structure*, Quantity*, uint64_t>
evaluatePickQueryFull(int xPos, int yPos, int32_t iView = -1); // badly named. takes buffer coordinates.


// == Helpers
Expand Down
64 changes: 41 additions & 23 deletions include/polyscope/render/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ namespace polyscope {

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

// == A few enums that control behavior
Expand Down Expand Up @@ -262,7 +263,7 @@ class RenderBuffer {
public:
// abstract class: use the factory methods from the Engine class
RenderBuffer(RenderBufferType type_, unsigned int sizeX_, unsigned int sizeY_);
virtual ~RenderBuffer() {};
virtual ~RenderBuffer(){};

virtual void resize(unsigned int newX, unsigned int newY);

Expand All @@ -283,7 +284,7 @@ class FrameBuffer {
public:
// abstract class: use the factory methods from the Engine class
FrameBuffer();
virtual ~FrameBuffer() {};
virtual ~FrameBuffer(){};

virtual void bind() = 0;
// Bind to this framebuffer so subsequent draw calls will go to it
Expand Down Expand Up @@ -319,7 +320,7 @@ class FrameBuffer {
// Query pixel
virtual std::array<float, 4> readFloat4(int xPos, int yPos) = 0;
virtual float readDepth(int xPos, int yPos) = 0;
virtual void blitTo(FrameBuffer* other) = 0;
virtual void blitTo(FrameBuffer* other, int targetPosX = 0, int targetPosY = 0) = 0;
virtual std::vector<unsigned char> readBuffer() = 0;

virtual uint32_t getNativeBufferID() = 0;
Expand Down Expand Up @@ -402,7 +403,7 @@ class ShaderProgram {

public:
ShaderProgram(DrawMode dm);
virtual ~ShaderProgram() {};
virtual ~ShaderProgram(){};


// === Store data
Expand Down Expand Up @@ -455,23 +456,30 @@ 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, ManagedBufferBase* source = nullptr) = 0;
// Bind an AttributeBuffer (VBO) as a buffer texture (samplerBuffer / GL_TEXTURE_BUFFER, ShaderTextureType::TextureBuffer).
// Note: the buffer is always exposed to shaders as a flattened 1-component scalar stream (GL_R32F / GL_R32I / GL_R32UI),
// even for vector/matrix types (e.g., fetch a vec3 at index i via texelFetch at 3*i + {0, 1, 2}). This is done because
// OpenGL 3.3 core does not support 3-component buffer texture formats (GL_RGB32F requires GL 4.0).
virtual void setTextureFromBuffer(std::string name, TextureBuffer* textureBuffer,
ManagedBufferBase* source = nullptr) = 0;
// Bind an AttributeBuffer (VBO) as a buffer texture (samplerBuffer / GL_TEXTURE_BUFFER,
// ShaderTextureType::TextureBuffer). Note: the buffer is always exposed to shaders as a flattened 1-component scalar
// stream (GL_R32F / GL_R32I / GL_R32UI), even for vector/matrix types (e.g., fetch a vec3 at index i via texelFetch
// at 3*i + {0, 1, 2}). This is done because OpenGL 3.3 core does not support 3-component buffer texture formats
// (GL_RGB32F requires GL 4.0).
virtual void setTextureFromAttributeBuffer(std::string name, std::shared_ptr<AttributeBuffer> externalBuffer,
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 setAttribute(std::string name, ManagedBuffer<T>& buf);
// Binds a texture-backed ManagedBuffer (DeviceBufferType::Texture1d/2d/3d) to a sampler1D/2D/3D.
template <typename T> void setTextureFromBuffer(std::string name, ManagedBuffer<T>& buf);
// Binds an attribute-backed ManagedBuffer (DeviceBufferType::Attribute) as a buffer texture (samplerBuffer / TextureBuffer).
template <typename T> void setTextureFromAttributeBuffer(std::string name, ManagedBuffer<T>& buf);
template <typename T> void setIndex(ManagedBuffer<T>& buf);
template <typename T>
void setTextureFromBuffer(std::string name, ManagedBuffer<T>& buf);
// Binds an attribute-backed ManagedBuffer (DeviceBufferType::Attribute) as a buffer texture (samplerBuffer /
// TextureBuffer).
template <typename T>
void setTextureFromAttributeBuffer(std::string name, ManagedBuffer<T>& buf);
template <typename T>
void setIndex(ManagedBuffer<T>& buf);

// Indices
virtual void setIndex(std::shared_ptr<AttributeBuffer> externalBuffer) = 0;
Expand Down Expand Up @@ -545,8 +553,7 @@ class Engine {

virtual void clearSceneBuffer();
virtual bool bindSceneBuffer();
virtual void resizeScreenBuffers(); // applies to all buffers tied to display size
virtual void setScreenBufferViewports();
virtual void resizeScreenBuffersAndSetViewports(); // applies to all buffers tied to display size
virtual void
applyLightingTransform(std::shared_ptr<TextureBuffer>& texture); // tonemap and gamma correct, render to active buffer
void updateMinDepthTexture();
Expand Down Expand Up @@ -650,18 +657,25 @@ class Engine {
// === The frame buffers used in the rendering pipeline
// The size of these buffers is always kept in sync with the screen size
std::shared_ptr<FrameBuffer> displayBuffer, displayBufferAlt;
std::shared_ptr<FrameBuffer> sceneBuffer, sceneBufferFinal;
std::shared_ptr<FrameBuffer> sceneBuffer, sceneBufferFinal; // TODO rename the 'final' one
std::vector<std::shared_ptr<FrameBuffer>> sceneBufferTargets;
std::shared_ptr<FrameBuffer> pickFramebuffer;
std::shared_ptr<FrameBuffer> sceneDepthMinFrame;
std::shared_ptr<FrameBuffer> sceneDepthMinFrame; // per-viewport; set by setActiveSceneTarget
std::vector<std::shared_ptr<FrameBuffer>> sceneDepthMinFrameTargets;
FrameBuffer& getDisplayBuffer();

// Main buffers for rendering
// sceneDepthMin is an optional texture copy of the depth buffe used for some effects
std::shared_ptr<TextureBuffer> sceneColor, sceneColorFinal, sceneDepth, sceneDepthMin;
// Main buffers for rendering.
// sceneColor, sceneDepth, sceneDepthMin, and their corresponding framebuffers are per-viewport;
// the active viewport's versions are exposed as the non-vector members, set by setActiveSceneTarget.
// sceneColorFinal holds the composited result and remains a single texture.
std::shared_ptr<TextureBuffer> sceneColorFinal;
std::shared_ptr<TextureBuffer> sceneColor, sceneDepth, sceneDepthMin;
std::vector<std::shared_ptr<TextureBuffer>> sceneColorTargets, sceneDepthTargets, sceneDepthMinTargets;
std::shared_ptr<RenderBuffer> pickColorBuffer, pickDepthBuffer;
TextureBuffer& getFinalSceneColorTexture();

// General-use programs used by the engine
// TODO some of these seem to be unused; remove them
std::shared_ptr<ShaderProgram> renderTexturePlain, renderTextureDot3, renderTextureMap3, renderTextureSphereBG;
std::shared_ptr<ShaderProgram> compositePeel, mapLight, copyDepth;

Expand All @@ -676,6 +690,10 @@ class Engine {
virtual void setFrontFaceCCW(bool newVal) = 0; // true if CCW triangles are considered front-facing; false otherwise
bool getFrontFaceCCW();

// A few viewport related helpers
void setActiveSceneTarget(int activeSceneTargets);
void ensureSceneTargetsAllocated(int sceneTargetsCount);

// == Options
BackgroundView background = BackgroundView::None;

Expand Down
14 changes: 9 additions & 5 deletions include/polyscope/render/mock_opengl/mock_gl_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class GLFrameBuffer : public FrameBuffer {
std::vector<unsigned char> readBuffer() override;
std::array<float, 4> readFloat4(int xPos, int yPos) override;
float readDepth(int xPos, int yPos) override;
void blitTo(FrameBuffer* other) override;
void blitTo(FrameBuffer* other, int targetPosX = 0, int targetPosY = 0) override;

// Getters
uint32_t getNativeBufferID() override;
Expand All @@ -244,17 +244,20 @@ struct GLShaderAttribute {
RenderDataType type;
int arrayCount;
std::shared_ptr<GLAttributeBuffer> buff; // the buffer that we will actually use
ManagedBufferBase* sourceManagedBuffer; // might be empty if not from a managed buffer. for indexed views, it's the original data source
ManagedBufferBase* sourceManagedBuffer; // might be empty if not from a managed buffer. for indexed views, it's the
// original data source
};

struct GLShaderTexture {
std::string name;
ShaderTextureType type;
uint32_t index;
bool isSet;
GLTextureBuffer* textureBuffer; // NOTE: very confusing name, unrelated to the OpenGL "TextureBuffer" concept as used below
GLTextureBuffer*
textureBuffer; // NOTE: very confusing name, unrelated to the OpenGL "TextureBuffer" concept as used below
std::shared_ptr<GLTextureBuffer> textureBufferOwned; // might be empty, if texture isn't owned
ManagedBufferBase* sourceManagedBuffer; // might be empty if not from a managed buffer. for indexed views, it's the original data source
ManagedBufferBase* sourceManagedBuffer; // might be empty if not from a managed buffer. for indexed views, it's the
// original data source

// used only for ShaderTextureType::TextureBuffer
std::shared_ptr<GLAttributeBuffer> attrBuffer;
Expand Down Expand Up @@ -347,7 +350,8 @@ class GLShaderProgram : public ShaderProgram {
void setTexture2D(std::string name, unsigned char* texData, unsigned int width, unsigned int height,
bool withAlpha = true, bool useMipMap = false, bool repeat = false) override;
void setTextureFromColormap(std::string name, const std::string& colorMap, bool allowUpdate = false) override;
void setTextureFromBuffer(std::string name, TextureBuffer* textureBuffer, ManagedBufferBase* source = nullptr) override;
void setTextureFromBuffer(std::string name, TextureBuffer* textureBuffer,
ManagedBufferBase* source = nullptr) override;
void setTextureFromAttributeBuffer(std::string name, std::shared_ptr<AttributeBuffer> externalBuffer,
ManagedBufferBase* source = nullptr) override;

Expand Down
18 changes: 11 additions & 7 deletions include/polyscope/render/opengl/gl_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class GLAttributeBuffer : public AttributeBuffer {
};

class GLTextureBuffer : public TextureBuffer {
// NOTE: very confusing name, this is unrelated to the openGL "TextureBuffer" concept as used in ShaderTextureType::TextureBuffer
// this is just a texture that happens to hold buffer data
// NOTE: very confusing name, this is unrelated to the openGL "TextureBuffer" concept as used in
// ShaderTextureType::TextureBuffer this is just a texture that happens to hold buffer data

public:
// create a 1D texture from data
Expand Down Expand Up @@ -264,7 +264,7 @@ class GLFrameBuffer : public FrameBuffer {
std::vector<unsigned char> readBuffer() override;
std::array<float, 4> readFloat4(int xPos, int yPos) override;
float readDepth(int xPos, int yPos) override;
void blitTo(FrameBuffer* other) override;
void blitTo(FrameBuffer* other, int targetPosX = 0, int targetPosY = 0) override;

// Getters
FrameBufferHandle getHandle() const { return handle; }
Expand All @@ -287,18 +287,21 @@ struct GLShaderAttribute {
int arrayCount;
AttributeLocation location; // -1 means "no location", usually because it was optimized out
std::shared_ptr<GLAttributeBuffer> buff; // the buffer that we will actually use
ManagedBufferBase* sourceManagedBuffer; // might be empty if not from a managed buffer. for indexed views, it's the original data source
ManagedBufferBase* sourceManagedBuffer; // might be empty if not from a managed buffer. for indexed views, it's the
// original data source
};

struct GLShaderTexture {
std::string name;
ShaderTextureType type;
uint32_t index;
bool isSet;
GLTextureBuffer* textureBuffer; // NOTE: very confusing name, unrelated to the openGL "TextureBuffer" concept as used below
GLTextureBuffer*
textureBuffer; // NOTE: very confusing name, unrelated to the openGL "TextureBuffer" concept as used below
std::shared_ptr<GLTextureBuffer> textureBufferOwned; // might be empty, if texture isn't owned
TextureLocation location; // -1 means "no location", usually because it was optimized out
ManagedBufferBase* sourceManagedBuffer; // might be empty if not from a managed buffer. for indexed views, it's the original data source
ManagedBufferBase* sourceManagedBuffer; // might be empty if not from a managed buffer. for indexed views, it's the
// original data source

// these are used only for ShaderTextureType::TextureBuffer
std::shared_ptr<GLAttributeBuffer> attrBuffer;
Expand Down Expand Up @@ -397,7 +400,8 @@ class GLShaderProgram : public ShaderProgram {
void setTexture2D(std::string name, unsigned char* texData, unsigned int width, unsigned int height,
bool withAlpha = true, bool useMipMap = false, bool repeat = false) override;
void setTextureFromColormap(std::string name, const std::string& colorMap, bool allowUpdate = false) override;
void setTextureFromBuffer(std::string name, TextureBuffer* textureBuffer, ManagedBufferBase* source = nullptr) override;
void setTextureFromBuffer(std::string name, TextureBuffer* textureBuffer,
ManagedBufferBase* source = nullptr) override;
void setTextureFromAttributeBuffer(std::string name, std::shared_ptr<AttributeBuffer> externalBuffer,
ManagedBufferBase* source = nullptr) override;

Expand Down
3 changes: 1 addition & 2 deletions include/polyscope/render/opengl/shaders/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ extern const ShaderReplacementRule PROJ_AND_INV_PROJ_MAT;
extern const ShaderReplacementRule COMPUTE_SHADE_NORMAL_FROM_POSITION;
extern const ShaderReplacementRule PREMULTIPLY_LIT_COLOR;
extern const ShaderReplacementRule CULL_POS_FROM_VIEW;
extern const ShaderReplacementRule BUILD_RAY_FOR_FRAGMENT_PERSPECTIVE;
extern const ShaderReplacementRule BUILD_RAY_FOR_FRAGMENT_ORTHOGRAPHIC;
extern const ShaderReplacementRule BUILD_RAY_FOR_FRAGMENT_DYNAMIC;

ShaderReplacementRule generateSlicePlaneRule(std::string uniquePostfix);
ShaderReplacementRule generateVolumeGridSlicePlaneRule(std::string uniquePostfix);
Expand Down
Loading
Loading