Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit aa1bb8c

Browse files
authored
Fix sticking out border in curved resize mode (#980)
1 parent c5fb399 commit aa1bb8c

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

app/src/main/cpp/Cylinder.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,15 @@ Cylinder::GetCylinderTheta() const {
281281
return m.theta;
282282
}
283283

284+
vrb::RenderStatePtr
285+
Cylinder::GetRenderState() const {
286+
if (m.geometry) {
287+
return m.geometry->GetRenderState();
288+
}
289+
290+
return nullptr;
291+
}
292+
284293
void
285294
Cylinder::SetCylinderTheta(const float aAngleLength) {
286295
m.theta = aAngleLength;

app/src/main/cpp/Cylinder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Cylinder {
3838
float GetCylinderRadius() const;
3939
float GetCylinderHeight() const;
4040
float GetCylinderTheta() const;
41+
vrb::RenderStatePtr GetRenderState() const;
4142
void SetCylinderTheta(const float aAngleLength);
4243
void SetTintColor(const vrb::Color& aColor);
4344
vrb::NodePtr GetRoot() const;

app/src/main/cpp/WidgetResizer.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "vrb/Geometry.h"
1616
#include "vrb/RenderState.h"
1717
#include "vrb/SurfaceTextureFactory.h"
18+
#include "vrb/TextureGL.h"
1819
#include "vrb/TextureSurface.h"
1920
#include "vrb/Toggle.h"
2021
#include "vrb/Transform.h"
@@ -23,6 +24,23 @@
2324

2425
namespace crow {
2526

27+
static const char* sCylinderFragmentShader = R"SHADER(
28+
precision highp float;
29+
30+
uniform sampler2D u_texture0;
31+
varying vec4 v_color;
32+
varying vec2 v_uv;
33+
34+
void main() {
35+
vec4 color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
36+
if ((v_uv.x < 0.0f) || (v_uv.x > 1.0f)) {
37+
color.a = 0.0f;
38+
}
39+
gl_FragColor = color * v_color;
40+
}
41+
42+
)SHADER";
43+
2644
struct ResizeBar;
2745

2846
typedef std::shared_ptr<ResizeBar> ResizeBarPtr;
@@ -74,6 +92,12 @@ struct ResizeBar {
7492
if (aMode == ResizeBar::Mode::Cylinder) {
7593
result->cylinder = Cylinder::Create(aContext, 1.0f, kBarSize, vrb::Color(1.0f, 1.0f, 1.0f, 1.0f), kBorder, vrb::Color(1.0f, 1.0f, 1.0f, 0.0f));
7694
result->cylinder->SetLightsEnabled(false);
95+
if (aScale.x() == 1.0f) {
96+
// Fix sticking out border at the bottom of the resize bar (No handles to hide it...)
97+
vrb::TextureGLPtr defaultTexture = aContext->GetDefaultTexture();
98+
result->cylinder->SetTexture(defaultTexture, defaultTexture->GetWidth(), defaultTexture->GetHeight());
99+
result->cylinder->GetRenderState()->SetCustomFragmentShader(sCylinderFragmentShader);
100+
}
77101
result->transform->AddNode(result->cylinder->GetRoot());
78102
} else {
79103
result->geometry = CreateGeometry(aContext, -max, max, aBorder);

0 commit comments

Comments
 (0)