Skip to content

Commit 2c6ffe2

Browse files
committed
Reworked rendering backend selection
1 parent 475ccf4 commit 2c6ffe2

13 files changed

+179
-46
lines changed

cmake/yup.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ function (_yup_module_setup_plugin_client_clap target_name plugin_client_target
444444

445445
_yup_glob_recurse ("${module_path}/clap/*" all_module_files_clap)
446446
target_sources (${custom_target_name} PRIVATE ${all_module_files_clap})
447+
source_group (TREE ${module_path}/clap/ FILES ${all_module_files_clap})
447448
set_source_files_properties (${all_module_files_clap} PROPERTIES HEADER_FILE_ONLY TRUE)
448449

449450
endfunction()
@@ -622,6 +623,7 @@ function (yup_add_module module_path)
622623

623624
_yup_glob_recurse ("${module_path}/*" all_module_files)
624625
target_sources (${module_name} PRIVATE ${all_module_files})
626+
source_group (TREE ${module_path}/ FILES ${all_module_files})
625627
set_source_files_properties (${all_module_files} PROPERTIES HEADER_FILE_ONLY TRUE)
626628

627629
# ==== Setup parent scope variables

modules/yup_graphics/native/yup_GraphicsContext_d3d.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
==============================================================================
2020
*/
2121

22+
#if YUP_RIVE_USE_D3D
2223
#include "rive/renderer/rive_renderer.hpp"
2324
#include "rive/renderer/d3d/render_context_d3d_impl.hpp"
2425
#include "rive/renderer/d3d/d3d11.hpp"
@@ -171,3 +172,4 @@ std::unique_ptr<GraphicsContext> juce_constructDirect3DGraphicsContext (Graphics
171172
}
172173

173174
} // namespace yup
175+
#endif

modules/yup_graphics/native/yup_GraphicsContext_dawn.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,4 @@ std::unique_ptr<GraphicsContext> juce_constructDawnGraphicsContext (GraphicsCont
280280
}
281281

282282
} // namespace yup
283-
284-
#else
285-
286-
namespace yup
287-
{
288-
289-
std::unique_ptr<GraphicsContext> juce_constructDawnGraphicsContext (GraphicsContext::Options options)
290-
{
291-
return nullptr;
292-
}
293-
294-
} // namespace yup
295-
296283
#endif

modules/yup_graphics/native/yup_GraphicsContext_gl.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
==============================================================================
2020
*/
2121

22+
#if YUP_RIVE_USE_OPENGL || JUCE_LINUX || JUCE_WASM || JUCE_ANDROID
2223
#include "rive/renderer/rive_renderer.hpp"
2324
#include "rive/renderer/gl/gles3.hpp"
2425
#include "rive/renderer/gl/render_buffer_gl_impl.hpp"
@@ -75,12 +76,6 @@ class LowLevelRenderContextGL : public GraphicsContext
7576
public:
7677
LowLevelRenderContextGL()
7778
{
78-
if (! m_plsContext)
79-
{
80-
fprintf (stderr, "Failed to create a renderer.\n");
81-
exit (-1);
82-
}
83-
8479
#if RIVE_DESKTOP_GL
8580
// Load the OpenGL API using glad.
8681
if (! gladLoadCustomLoader ((GLADloadproc) glfwGetProcAddress))
@@ -90,6 +85,13 @@ class LowLevelRenderContextGL : public GraphicsContext
9085
}
9186
#endif
9287

88+
m_plsContext = rive::gpu::RenderContextGLImpl::MakeContext (rive::gpu::RenderContextGLImpl::ContextOptions());
89+
if (! m_plsContext)
90+
{
91+
fprintf (stderr, "Failed to create a renderer.\n");
92+
exit (-1);
93+
}
94+
9395
printf ("GL_VENDOR: %s\n", glGetString (GL_VENDOR));
9496
printf ("GL_RENDERER: %s\n", glGetString (GL_RENDERER));
9597
printf ("GL_VERSION: %s\n", glGetString (GL_VERSION));
@@ -148,15 +150,13 @@ class LowLevelRenderContextGL : public GraphicsContext
148150

149151
void end (void*) override
150152
{
151-
m_plsContext->flush ({ .renderTarget = m_renderTarget.get() });
153+
m_plsContext->flush ({ m_renderTarget.get() });
152154

153155
m_plsContext->static_impl_cast<rive::gpu::RenderContextGLImpl>()->unbindGLInternalResources();
154156
}
155157

156158
private:
157-
std::unique_ptr<rive::gpu::RenderContext> m_plsContext =
158-
rive::gpu::RenderContextGLImpl::MakeContext (rive::gpu::RenderContextGLImpl::ContextOptions());
159-
159+
std::unique_ptr<rive::gpu::RenderContext> m_plsContext;
160160
rive::rcp<rive::gpu::RenderTargetGL> m_renderTarget;
161161
};
162162

@@ -166,3 +166,4 @@ std::unique_ptr<GraphicsContext> juce_constructOpenGLGraphicsContext (GraphicsCo
166166
}
167167

168168
} // namespace yup
169+
#endif

modules/yup_graphics/native/yup_GraphicsContext_impl.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,29 @@ std::unique_ptr<GraphicsContext> GraphicsContext::createContext (Api graphicsApi
3939
{
4040
switch (graphicsApi)
4141
{
42-
#if JUCE_MAC || JUCE_IOS
43-
case Api::Metal:
44-
return juce_constructMetalGraphicsContext (options);
45-
#elif JUCE_WINDOWS
46-
case Api::Direct3D:
47-
return juce_constructDirect3DGraphicsContext (options);
48-
#elif JUCE_LINUX || JUCE_WASM || JUCE_ANDROID
49-
case Api::OpenGL:
50-
return juce_constructOpenGLGraphicsContext (options);
42+
#if YUP_RIVE_USE_METAL && (JUCE_MAC || JUCE_IOS)
43+
case Api::Metal:
44+
return juce_constructMetalGraphicsContext (options);
45+
#endif
46+
47+
#if YUP_RIVE_USE_D3D && JUCE_WINDOWS
48+
case Api::Direct3D:
49+
return juce_constructDirect3DGraphicsContext (options);
50+
#endif
51+
52+
#if YUP_RIVE_USE_OPENGL || JUCE_LINUX || JUCE_WASM || JUCE_ANDROID
53+
case Api::OpenGL:
54+
return juce_constructOpenGLGraphicsContext (options);
55+
#endif
56+
57+
#if YUP_RIVE_USE_DAWN
58+
case Api::Dawn:
59+
return juce_constructDawnGraphicsContext (options);
5160
#endif
52-
case Api::Dawn:
53-
return juce_constructDawnGraphicsContext (options);
5461

55-
default:
56-
Logger::outputDebugString ("Invalid API requested for current platform");
57-
return nullptr;
62+
default:
63+
Logger::outputDebugString ("Invalid API requested for current platform");
64+
return nullptr;
5865
}
5966

6067
Logger::outputDebugString ("Failed to create the graphics context");

modules/yup_graphics/native/yup_GraphicsContext_metal.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
==============================================================================
2020
*/
2121

22+
#if YUP_RIVE_USE_METAL
2223
#include "rive/renderer/rive_renderer.hpp"
2324
#include "rive/renderer/metal/render_context_metal_impl.h"
2425

@@ -122,3 +123,4 @@ std::unique_ptr<GraphicsContext> juce_constructMetalGraphicsContext (GraphicsCon
122123
}
123124

124125
} // namespace yup
126+
#endif

modules/yup_graphics/yup_graphics.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,38 @@
3333
//==============================================================================
3434

3535
#if JUCE_WINDOWS
36+
37+
#if YUP_RIVE_USE_D3D
3638
#include <array>
3739
#include <dxgi1_2.h>
3840

3941
#include "native/yup_GraphicsContext_d3d.cpp"
42+
#endif
43+
44+
#if YUP_RIVE_USE_OPENGL
45+
#include "native/yup_GraphicsContext_gl.cpp"
46+
#endif
47+
48+
//==============================================================================
4049

4150
#elif JUCE_MAC || JUCE_IOS
51+
52+
#if YUP_RIVE_USE_METAL
4253
#import <Metal/Metal.h>
4354
#import <Cocoa/Cocoa.h>
4455
#import <QuartzCore/CAMetalLayer.h>
4556

4657
#include "native/yup_GraphicsContext_metal.cpp"
58+
#endif
59+
60+
#if YUP_RIVE_USE_OPENGL
61+
#include "native/yup_GraphicsContext_gl.cpp"
62+
#endif
63+
64+
//==============================================================================
4765

4866
#elif JUCE_LINUX || JUCE_WASM || JUCE_ANDROID
67+
4968
#if JUCE_EMSCRIPTEN && RIVE_WEBGL
5069
#include <emscripten/emscripten.h>
5170
#include <emscripten/html5.h>
@@ -55,8 +74,15 @@
5574

5675
#endif
5776

77+
//==============================================================================
78+
79+
#if YUP_RIVE_USE_DAWN
5880
#include "native/yup_GraphicsContext_dawn.cpp"
5981
#include "native/yup_GraphicsContext_dawn_helper.cpp"
82+
#endif
83+
84+
//==============================================================================
85+
6086
#include "native/yup_GraphicsContext_impl.cpp"
6187

6288
//==============================================================================

modules/yup_graphics/yup_graphics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949

5050
#include <juce_core/juce_core.h>
5151

52+
#include <rive_renderer/rive_renderer.h>
53+
5254
//==============================================================================
5355

5456
#include <rive/rive.h>

modules/yup_gui/native/yup_Windowing_glfw.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,15 @@ GLFWComponentNative::GLFWComponentNative (Component& component, const Flags& fla
468468
nswindow.contentView.wantsLayer = YES;
469469
#endif
470470

471-
context = GraphicsContext::createContext (GraphicsContext::Options {});
472-
if (context == nullptr)
473-
return;
474-
475-
#if JUCE_EMSCRIPTEN && RIVE_WEBGL
471+
#if RIVE_DESKTOP_GL || (JUCE_EMSCRIPTEN && RIVE_WEBGL)
476472
glfwMakeContextCurrent (window);
477473
//glfwSwapInterval (0);
478474
#endif
479475

476+
context = GraphicsContext::createContext (GraphicsContext::Options {});
477+
if (context == nullptr)
478+
return;
479+
480480
glfwSetWindowUserPointer (window, this);
481481

482482
glfwSetWindowCloseCallback (window, glfwWindowClose);
@@ -1316,9 +1316,11 @@ void initialiseYup_Windowing()
13161316

13171317
glfwInit();
13181318

1319-
#if JUCE_MAC || JUCE_WINDOWS
1319+
#if (JUCE_MAC && !YUP_RIVE_USE_OPENGL)
13201320
glfwWindowHint (GLFW_CLIENT_API, GLFW_NO_API);
13211321
glfwWindowHint (GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE);
1322+
#elif (JUCE_WINDOWS && !YUP_RIVE_USE_OPENGL)
1323+
glfwWindowHint (GLFW_CLIENT_API, GLFW_NO_API);
13221324
#elif defined(ANGLE)
13231325
glfwWindowHint (GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
13241326
glfwWindowHint (GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
@@ -1327,8 +1329,8 @@ void initialiseYup_Windowing()
13271329
glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
13281330
#else
13291331
glfwWindowHint (GLFW_CLIENT_API, GLFW_OPENGL_API);
1330-
glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 4);
1331-
glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 6);
1332+
glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, YUP_RIVE_OPENGL_MAJOR);
1333+
glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, YUP_RIVE_OPENGL_MINOR);
13321334
#endif
13331335

13341336
Desktop::getInstance()->updateDisplays();

thirdparty/rive_renderer/rive_renderer.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,70 @@
4747

4848
#pragma once
4949

50-
// TODO - Other deps: rive-decoders rive-dependencies
50+
//==============================================================================
51+
/** Config: YUP_RIVE_USE_METAL
52+
Enables the use of the Metal renderer on macOS (the default is enabled).
53+
*/
54+
#ifndef YUP_RIVE_USE_METAL
55+
#define YUP_RIVE_USE_METAL 1
56+
#endif
57+
58+
/** Config: YUP_RIVE_USE_D3D
59+
Enables the use of the Direct3D renderer on Windows (the default is enabled).
60+
*/
61+
#ifndef YUP_RIVE_USE_D3D
62+
#define YUP_RIVE_USE_D3D 1
63+
#endif
64+
65+
/** Config: YUP_RIVE_USE_OPENGL
66+
Enables the use of the OpenGL renderer on platform that support it but where it is not used by default (in
67+
the specific case macOS and Windows).
68+
69+
You will need to link to the specific OpenGL framework on macOS when building your application with this
70+
flag set: add "-framework OpenGL" to link flags.
71+
*/
72+
#ifndef YUP_RIVE_USE_OPENGL
73+
#define YUP_RIVE_USE_OPENGL 0
74+
#endif
75+
76+
/** Config: YUP_RIVE_USE_DAWN
77+
Enables the use of the Dawn renderer on platform that support it.
78+
*/
79+
#ifndef YUP_RIVE_USE_DAWN
80+
#define YUP_RIVE_USE_DAWN 0
81+
#endif
82+
83+
//==============================================================================
84+
/** Config: YUP_RIVE_OPENGL_MAJOR
85+
Enables a speficic OpenGL major version. Must be at least 4.
86+
*/
87+
#ifndef YUP_RIVE_OPENGL_MAJOR
88+
#define YUP_RIVE_OPENGL_MAJOR 4
89+
#endif
90+
91+
/** Config: YUP_RIVE_OPENGL_MINOR
92+
Enables a speficic OpenGL minor version. Must be at least 2.
93+
*/
94+
#ifndef YUP_RIVE_OPENGL_MINOR
95+
#define YUP_RIVE_OPENGL_MINOR 2
96+
#endif
97+
98+
//==============================================================================
99+
100+
#if YUP_RIVE_USE_OPENGL
101+
#if __APPLE__ && !YUP_RIVE_USE_METAL && !YUP_RIVE_USE_DAWN
102+
#error Must select at least one between YUP_RIVE_USE_METAL, YUP_RIVE_USE_OPENGL or YUP_RIVE_USE_DAWN
103+
#elif _WIN32 && !YUP_RIVE_USE_D3D && !YUP_RIVE_USE_DAWN
104+
#error Must select at least one between YUP_RIVE_USE_D3D, YUP_RIVE_USE_OPENGL or YUP_RIVE_USE_DAWN
105+
#endif
106+
107+
#if !defined(RIVE_DESKTOP_GL) && !defined(RIVE_WEBGL)
108+
#define RIVE_DESKTOP_GL 1
109+
#endif
110+
#endif
111+
112+
#if YUP_RIVE_USE_DAWN
113+
#if !defined(RIVE_DAWN)
114+
#define RIVE_DAWN 1
115+
#endif
116+
#endif

0 commit comments

Comments
 (0)