Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions include/Inventor/SoRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class COIN_DLL_API SoRenderManager {

void scheduleRedraw(void);
void setWindowSize(const SbVec2s & newsize);
void setDevicePixelRatio(float dpr);
float getDevicePixelRatio(void) const;
const SbVec2s & getWindowSize(void) const;
void setSize(const SbVec2s & newsize);
const SbVec2s & getSize(void) const;
Expand Down
2 changes: 2 additions & 0 deletions include/Inventor/SoSceneManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class COIN_DLL_API SoSceneManager {
virtual SoNode * getSceneGraph(void) const;
void setWindowSize(const SbVec2s & newsize);
const SbVec2s & getWindowSize(void) const;
void setDevicePixelRatio(float dpr);
float getDevicePixelRatio(void) const;
void setSize(const SbVec2s & newsize);
const SbVec2s & getSize(void) const;
void setOrigin(const SbVec2s & newOrigin);
Expand Down
1 change: 1 addition & 0 deletions include/Inventor/elements/Makefile.am

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions include/Inventor/elements/SoDevicePixelRatioElement.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef COIN_SODEVICEPIXELRATIOELEMENT_H
#define COIN_SODEVICEPIXELRATIOELEMENT_H

/**************************************************************************\
* Copyright (c) 2026 The Coin3D contributors *
* *
* This file is part of Coin. *
* *
* Coin is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free *
* Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/

#include <Inventor/elements/SoFloatElement.h>

class COIN_DLL_API SoDevicePixelRatioElement : public SoFloatElement {
typedef SoFloatElement inherited;

SO_ELEMENT_HEADER(SoDevicePixelRatioElement);

public:
static void initClass(void);

void init(SoState * state) override;

static void set(SoState * state, SoNode * node, float dpr);
static void set(SoState * state, float dpr);
static float get(SoState * state);

protected:
~SoDevicePixelRatioElement() override;
};

#endif // !COIN_SODEVICEPIXELRATIOELEMENT_H
1 change: 1 addition & 0 deletions include/Inventor/elements/SoElements.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#include <Inventor/elements/SoComplexityElement.h>
#include <Inventor/elements/SoCreaseAngleElement.h>
#include <Inventor/elements/SoDecimationPercentageElement.h>
#include <Inventor/elements/SoDevicePixelRatioElement.h>
#include <Inventor/elements/SoFocalDistanceElement.h>
#include <Inventor/elements/SoFontSizeElement.h>
#include <Inventor/elements/SoLineWidthElement.h>
Expand Down
2 changes: 2 additions & 0 deletions src/actions/SoGLRenderAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#include <Inventor/elements/SoCacheElement.h>
#include <Inventor/elements/SoDecimationPercentageElement.h>
#include <Inventor/elements/SoDecimationTypeElement.h>
#include <Inventor/elements/SoDevicePixelRatioElement.h>
#include <Inventor/elements/SoGLCacheContextElement.h>
#include <Inventor/elements/SoGLLazyElement.h>
#include <Inventor/elements/SoGLLightIdElement.h>
Expand Down Expand Up @@ -644,6 +645,7 @@ SoGLRenderAction::initClass(void)

SO_ENABLE(SoGLRenderAction, SoDecimationPercentageElement);
SO_ENABLE(SoGLRenderAction, SoDecimationTypeElement);
SO_ENABLE(SoGLRenderAction, SoDevicePixelRatioElement);
SO_ENABLE_LEGACY_GL(SoGLRenderAction, SoGLLightIdElement);
SO_ENABLE_LEGACY_GL(SoGLRenderAction, SoGLRenderPassElement);
SO_ENABLE_LEGACY_GL(SoGLRenderAction, SoGLUpdateAreaElement);
Expand Down
1 change: 1 addition & 0 deletions src/elements/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(COIN_ELEMENTS_FILES
SoCullElement.cpp
SoDecimationPercentageElement.cpp
SoDecimationTypeElement.cpp
SoDevicePixelRatioElement.cpp
SoDepthBufferElement.cpp
SoDiffuseColorElement.cpp
SoDrawStyleElement.cpp
Expand Down
1 change: 1 addition & 0 deletions src/elements/Makefile.am

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions src/elements/SoDevicePixelRatioElement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**************************************************************************\
* Copyright (c) 2026 The Coin3D contributors *
* *
* This file is part of Coin. *
* *
* Coin is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free *
* Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/

#include <Inventor/misc/SoState.h>

#include <Inventor/elements/SoDevicePixelRatioElement.h>

SO_ELEMENT_SOURCE(SoDevicePixelRatioElement);

void
SoDevicePixelRatioElement::initClass(void)
{
SO_ELEMENT_INIT_CLASS(SoDevicePixelRatioElement, inherited);
}

void
SoDevicePixelRatioElement::init(SoState * state)
{
inherited::init(state);
this->data = 1.0f;
}

void
SoDevicePixelRatioElement::set(SoState * state, SoNode * node, float dpr)
{
inherited::set(classStackIndex, state, node, dpr);
}

void
SoDevicePixelRatioElement::set(SoState * state, float dpr)
{
SoDevicePixelRatioElement::set(state, NULL, dpr);
}

float
SoDevicePixelRatioElement::get(SoState * state)
{
return inherited::get(classStackIndex, state);
}

SoDevicePixelRatioElement::~SoDevicePixelRatioElement(void)
{
}
1 change: 1 addition & 0 deletions src/elements/SoElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ SoElement::initElements(void)
SoComplexityElement::initClass();
SoCreaseAngleElement::initClass();
SoDecimationPercentageElement::initClass();
SoDevicePixelRatioElement::initClass();
SoFocalDistanceElement::initClass();
SoFontSizeElement::initClass();
SoLineWidthElement::initClass();
Expand Down
1 change: 1 addition & 0 deletions src/elements/all-elements-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "SoCullElement.cpp"
#include "SoDecimationPercentageElement.cpp"
#include "SoDecimationTypeElement.cpp"
#include "SoDevicePixelRatioElement.cpp"
#include "SoDepthBufferElement.cpp"
#include "SoDiffuseColorElement.cpp"
#include "SoDrawStyleElement.cpp"
Expand Down
12 changes: 12 additions & 0 deletions src/misc/SoSceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,18 @@ SoSceneManager::getWindowSize(void) const
return PRIVATE(this)->rendermanager->getWindowSize();
}

void
SoSceneManager::setDevicePixelRatio(float dpr)
{
PRIVATE(this)->rendermanager->setDevicePixelRatio(dpr);
}

float
SoSceneManager::getDevicePixelRatio(void) const
{
return PRIVATE(this)->rendermanager->getDevicePixelRatio();
}

/*!
Set size of rendering area for the viewport within the current
window.
Expand Down
29 changes: 29 additions & 0 deletions src/rendering/SoRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include <Inventor/elements/SoTextureQualityElement.h>
#include <Inventor/elements/SoTextureOverrideElement.h>
#include <Inventor/elements/SoComplexityTypeElement.h>
#include <Inventor/elements/SoDevicePixelRatioElement.h>
#include <Inventor/elements/SoLazyElement.h>

#include <algorithm>
Expand Down Expand Up @@ -264,6 +265,7 @@ SoRenderManager::SoRenderManager(void)
PRIVATE(this)->stereostencilmask = NULL;
PRIVATE(this)->superimpositions = NULL;
PRIVATE(this)->viewport = SbViewportRegion(SbVec2s(400, 400));
PRIVATE(this)->devicePixelRatio = 1.0f;

PRIVATE(this)->doublebuffer = TRUE;
PRIVATE(this)->deleteaudiorenderaction = TRUE;
Expand Down Expand Up @@ -698,7 +700,13 @@ SoRenderManager::render(SoGLRenderAction * action,
for (int i = 0; i < PRIVATE(this)->superimpositions->getLength(); i++) {
Superimposition * s = (Superimposition *) (*PRIVATE(this)->superimpositions)[i];
if (s->getStateFlags() & Superimposition::BACKGROUND) {
SoState * state = action->getState();
state->push();
SoDevicePixelRatioElement::set(state,
PRIVATE(this)->dummynode,
PRIVATE(this)->devicePixelRatio);
s->render(action, clearwindow_tmp);
state->pop();
clearwindow_tmp = FALSE;
}
}
Expand All @@ -712,7 +720,13 @@ SoRenderManager::render(SoGLRenderAction * action,
for (int i = 0; i < PRIVATE(this)->superimpositions->getLength(); i++) {
Superimposition * s = (Superimposition *) (*PRIVATE(this)->superimpositions)[i];
if (!(s->getStateFlags() & Superimposition::BACKGROUND)) {
SoState * state = action->getState();
state->push();
SoDevicePixelRatioElement::set(state,
PRIVATE(this)->dummynode,
PRIVATE(this)->devicePixelRatio);
s->render(action);
state->pop();
}
}
}
Expand Down Expand Up @@ -845,6 +859,7 @@ SoRenderManager::renderSingle(SoGLRenderAction * action,
state->push();

SoNode * node = PRIVATE(this)->dummynode;
SoDevicePixelRatioElement::set(state, node, PRIVATE(this)->devicePixelRatio);

if (!this->isTexturesEnabled()) {
SoTextureQualityElement::set(state, node, 0.0f);
Expand Down Expand Up @@ -1266,6 +1281,20 @@ SoRenderManager::getWindowSize(void) const
return PRIVATE(this)->viewport.getWindowSize();
}

void
SoRenderManager::setDevicePixelRatio(float dpr)
{
if (PRIVATE(this)->devicePixelRatio == dpr) return;
PRIVATE(this)->devicePixelRatio = dpr;
this->scheduleRedraw();
}

float
SoRenderManager::getDevicePixelRatio(void) const
{
return PRIVATE(this)->devicePixelRatio;
}

/*!
Set size of rendering area for the viewport within the current
window.
Expand Down
1 change: 1 addition & 0 deletions src/rendering/SoRenderManagerP.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class SoRenderManagerP {
SbBool deleteglaction;
#endif
SbViewportRegion viewport;
float devicePixelRatio;

SoRenderManager::StereoMode stereostenciltype;
SoRenderManager::RenderMode rendermode;
Expand Down
9 changes: 9 additions & 0 deletions testsuite/SceneManagerCoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Inventor/SoRenderManager.h>
#include <Inventor/SoSceneManager.h>
#include <Inventor/SbViewportRegion.h>
#include <Inventor/elements/SoDevicePixelRatioElement.h>
#include <Inventor/nodes/SoOrthographicCamera.h>
#include <Inventor/nodes/SoSeparator.h>

Expand All @@ -25,6 +26,10 @@ checkRenderManager(SoRenderManager & manager)
manager.setWindowSize(SbVec2s(800, 600));
if (manager.getWindowSize() != SbVec2s(800, 600)) return 1;

if (manager.getDevicePixelRatio() != 1.0f) return 1;
manager.setDevicePixelRatio(2.0f);
if (manager.getDevicePixelRatio() != 2.0f) return 1;

manager.setSize(SbVec2s(640, 480));
if (manager.getSize() != SbVec2s(640, 480)) return 1;

Expand Down Expand Up @@ -60,6 +65,10 @@ checkSceneManager(SoSceneManager & manager)
manager.setWindowSize(SbVec2s(800, 600));
if (manager.getWindowSize() != SbVec2s(800, 600)) return 1;

if (manager.getDevicePixelRatio() != 1.0f) return 1;
manager.setDevicePixelRatio(2.0f);
if (manager.getDevicePixelRatio() != 2.0f) return 1;

manager.setSize(SbVec2s(640, 480));
if (manager.getSize() != SbVec2s(640, 480)) return 1;

Expand Down