1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00
Commit graph

131 commits

Author SHA1 Message Date
reuk
a3f81eb2fb
OpenGL: Correctly restore blend mode when nested context goes out-of-scope
Fixes an issue where primitives such as text could end up with sharp
edges when creating temporary contexts:

    void paint (Graphics& g)
    {
        g.fillAll (Colours::white);
        const auto preferredType = g.getInternalContext().getPreferredImageTypeForTemporaryImages();
        Image img (Image::ARGB, getWidth(), getHeight(), false, *preferredType);
        {
            Graphics g2 (img);
        }
        g.setColour (Colours::black);
        g.setFont (32);
        g.drawText ("test", getLocalBounds(), Justification::centred);
    }
2025-11-14 13:36:03 +00:00
reuk
5eba9a6434
OpenGL: Clear bound texture after rendering transparency layer
A change introduced in 00836d1e94 meant
that GL renderers could sometimes assert in
StateHelpers::ActiveTextures::bindTexture() when ending a transparency
layer.

Specifically, the issue was provoked by adding the ScopedTextureBinding
in the constructor of OpenGLFrameBuffer. This reset the bound texture
after creating a new transparency layer.

I think the previous implementation worked by accident, not by design.
It so happens that when rendering multiple transparency layers within
the same frame (i.e. calling begin/end several times in that order,
*not* nesting the calls), the same texture ID will generally get reused.

From the graphics context's (GC's) perspective, we create a texture with
ID "2", then call bindTexture() to bind it, and the GC remembers that
this ID is bound. We draw the frame, and the texture gets destroyed. The
call to glDeleteTextures() will cause the default texture, "0", to be
bound if the texture being destroyed is bound at the point of
destruction. So, after the texture is destroyed, the GC's stored binding
no longer reflects reality, since texture "0" is now bound.

The next time we create a texture, that texture also gets created with
ID "2". Previously, we would leave this texture bound after
construction, but now we re-bind the previously-bound texture, "0". This
causes the assertion in bindTexture() to fire when we next attempt to
bind texture "2", since the actual bound texture is "0".

The solution added in this patch will bind texture "0" when the
transparency layer image is destroyed, in order to keep the GC's view of
the GL context consistent with the real state.
2025-08-14 14:13:09 +01:00
reuk
2712f63628
Graphics: Use unique_ptr instead of raw pointers in RenderingHelpers 2025-08-14 14:13:09 +01:00
reuk
fb4159c436
OpenGL: Fix state restoration when drawing into a temporary nested context
Fixes a regression introduced in
bd26d79b17

The issue was observed in the DemoRunner when enabling the OpenGL
renderer and then switching to the LookAndFeel V1.

The cause of the problem was the creation of a secondary OpenGL-backed
Graphics instance in the DropShadowEffect. This temporary context could
modify the OpenGL context state without restoring the state
appropriately on destruction. As a result, when the outer long-lived
OpenGL context resumed drawing, properties such as the viewport, bound
shader, shader uniform values, and bound framebuffer could all be
incorrect.
2025-05-19 13:30:27 +01:00
Oli
250abe9cf4 LowLevelGraphicsContext: Add preferred image type for temporary images
Co-authored-by: Matt Gonzalez <matt@echoaudio.com>
2025-04-24 13:58:23 +01:00
reuk
dcca72484f Image: Update return type of getPixelData to avoid dangling pointers 2024-12-13 14:42:26 +00:00
reuk
4f2c287f9b
Font: Deprecate old Font constructors 2024-04-18 14:16:00 +01:00
reuk
72819437e7
RenderingHelpers: Move drawGlyph to a common location 2024-04-18 14:15:59 +01:00
reuk
bc654f8007
RenderingHelpers: Reduce templating of GlyphCache 2024-04-18 14:15:58 +01:00
Tom Poole
94d98a2b10 Update licensing information 2024-04-16 11:39:35 +01:00
Tom Poole
6bf9bb9a2e Add final specifiers in implementation files 2023-10-10 16:12:38 +01:00
Tom Poole
4153d59e39 Formatting 2023-10-02 15:42:20 +01:00
reuk
f012f8c280
OpenGL: Keep track of previously-attached VAOs and buffers when creating additional GL-backed Graphics contexts
Previously, code such as the following (where MyGLComponent is rendering
using an OpenGLContext) could result in GL errors, as the destruction of
the inner context unbound the array buffer and element array buffer
after use, instead of setting them to the previous values set up by the
outer context.

Additionally, a VAO was only set up in the OpenGLContext, so rendering
into a GL-backed LowLevel graphics context could fail if no VAO was
bound.

    void MyGLComponent::paint (juce::Graphics& g)
    {
        juce::Image image { juce::Image::PixelFormat::ARGB, width, height, false, juce::OpenGLImageType() };

        {
            juce::Graphics innerContext { image };
            // draw into innerContext
        }

        g.drawImage (image, juce::Rectangle<float> { width, height });
    }
2023-06-08 15:26:24 +01:00
reuk
af2a4a7e2a
OpenGL: Avoid enabling GL_TEXTURE_2D in core profile contexts 2023-03-06 12:35:26 +00:00
reuk
a59cba010b
ColourGradient: Create lookup tables using non-premultiplied colours
The OpenGL renderer uses ColourGradient::createLookupTable to generate
gradient textures. However, the tweening method used was different to
the tweening used by CoreGraphics gradients, and by the software
renderer.

Gradient tweening is now computed using non-premultiplied colours, to
ensure consistency between gradients rendered using OpenGL, and with
other renderers.
2023-02-09 17:54:19 +00:00
reuk
02b5ab748a OpenGL: Add support for a few more OpenGL profiles
- 4.1 and 4.3 contexts can now be requested
- The requested context version is no longer ignored on Linux
- Debugging contexts are now enabled in Debug builds with GL 4.3
- Fixes a bug where glEnable(GL_TEXTURE_2D) was called in core profiles
2022-08-31 17:42:47 +01:00
Tom Poole
2ec861d99e Update licensing banners to JUCE 7 2022-05-16 17:55:48 +01:00
Tom Poole
dea3fe60e4 Update copyright banners 2022-04-04 12:36:32 +01:00
reuk
3768349a05
Font: Make Font and TypefaceCache threadsafe
Previously, it wasn't safe to access Font instances from multiple
threads because there was a chance that they might reference the same
shared internal state. In this case, calling getTypeface() or getAscent from
two threads simultaneously would cause a race on the typeface and ascent
data members, even though the Font instances appeared to be disjoint.

With this change in place, it is now safe to use Font instances from
multiple threads simultaneously.

It is still an error to modify the same Font instance from multiple
threads without synchronization!

    // Fine:
    Font a;
    Font b = a;

    auto futureA = std::async (std::launch::async, [&a] { /* do something with a */ });
    auto futureB = std::async (std::launch::async, [&b] { /* do something with b */ });

    // Bad idea:
    Font f;

    auto futureA = std::async (std::launch::async, [&f] { /* do something with f */ });
    auto futureB = std::async (std::launch::async, [&f] { /* do something with f */ });
2021-09-23 10:28:47 +01:00
reuk
7ac6911ccc
Windows: Fix clang/gnu compiler warnings 2021-06-03 17:30:44 +01:00
reuk
31a7c62baf
Windows: Fix and suppress some analysis warnings
This fixes warnings that are emitted when building with the `-analyze`
flag enabled.
2021-05-26 15:34:26 +01:00
reuk
54423f6583
OpenGL: Add GLEW-inspired dynamic function loading 2021-05-26 11:23:49 +01:00
reuk
394c4fd475 Clang: Fix warnings when building with clang 10 2020-07-01 10:00:43 +01:00
ed
009d685179 Updated all license headers 2020-06-29 08:30:22 +01:00
ed
d510b73cdf Normalised all whitespace before args in std::function 2020-06-05 09:37:49 +01:00
Tom Poole
894e7d2bd2 Updated all license headers 2020-04-23 17:30:39 +01:00
reuk
327f817b9b Copyrights: Update commercial/gpl headers to be gpl-only 2020-04-09 15:22:56 +01:00
jules
f58eacc135 Added more unique_ptr use, for functions that create LowLevelGraphicsContext or ImageType objects. 2019-05-15 12:08:38 +01:00
jules
359132ed55 More zero -> nullptr fixes 2018-10-09 11:42:55 +01:00
jules
95a3f0b039 Whitespace 2018-07-03 11:51:36 +01:00
jules
1e6bbb8da9 Added some methods to allow ReferenceCountedObjectPtrs to be constructed or copied from references as well as pointers - as well as increasing safety, this actually makes things a bit more efficient as it skips a nullptr check. Updated lots of places in the code that could take advantage of this 2018-07-03 11:51:13 +01:00
jules
49aa9c9db4 Added flag JUCE_STRICT_REFCOUNTEDPOINTER which is recommended to avoid accidental leaks when using ref-counted pointers. Enabled this flag in the demo projects, and used it to help tidy up some dubious smart-pointer use 2018-06-26 14:06:52 +01:00
jules
49ddaddbae Added a lambda callback to OpenGLGraphicsContextCustomShader to allow custom set-up when the shader is activated 2018-05-08 11:15:17 +01:00
jules
38295f332b Converted some old typedefs to using declarations 2018-05-03 09:59:05 +01:00
Tom Poole
ab863a6dc2 Replaced all usage of ScopedPointer with std::unique_ptr 2018-04-19 20:27:47 +01:00
jules
1a60fa9765 More ScopedPointer/unique_ptr compatibility work 2018-01-10 17:35:08 +00:00
jules
a9eafbc90f Some tidying up in AffineTransform, and added a new fromTargetPoints method 2017-12-20 12:58:20 +00:00
jules
a9bc970ff8 Made the openGL 2D renderer limit the size of its vertex buffers to avoid problems on systems with limited GPUs 2017-11-24 13:33:11 +00:00
jules
9d56e2990d Optimised the GL renderer to avoid splitting large rectangles into horizontal strips unnecessarily 2017-11-03 13:51:37 +00:00
jules
2dc9316420 Misc ScopedPointer changes to start using reset() and get() rather than assignments and casts (part of an ongoing drift towards more std::unique_ptr compatibility) 2017-11-01 17:41:06 +00:00
jules
369d59f656 Added a template to allow the HeapBlock class to be given signed ints or other types that are not size_t for its size parameters 2017-10-11 12:10:58 +01:00
jules
eda613c6db Moved all "namespace juce" declarations from module headers to the individual .h and .cpp source files. This makes life a lot easier for Intellisense and other IDE autocompletion tools 2017-09-08 08:59:55 +01:00
hogliux
b5afccc37c Updated file headers and the README with the JUCE 5 license 2017-04-27 14:43:04 +01:00
jules
38d49a5ee7 Modernised a few RectangleList iterators 2017-04-03 16:08:07 +01:00
hogliux
9f3fb1c0a6 Added a compiler error if your compiler is too old and removed numerous code checks for old compilers which are now deprecated 2017-02-01 17:18:06 +00:00
hogliux
082b15969f Fix OpenGL 2D custom shader crash on newer Android devices 2016-01-28 17:04:16 +00:00
jules
2a1234b6ac Simplified some inter-module dependencies and exception-catching fallbacks 2015-12-23 11:47:18 +00:00
jules
9f7eb07ce5 OpenGL: changed image invalidation to allow non-GL threads that draw into images to correctly invalidate the GPU-cached version 2015-11-24 11:31:26 +00:00
hogliux
c7b8e77031 Update copyright notice 2015-07-22 15:59:34 +01:00
Timur Doumler
be9a2ff1bb Implemented support for Android OpenGL native ARGB pixel format. 2015-05-05 17:44:10 +01:00