Skip to content

Commit

Permalink
ProM and GL3 fixes
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Oct 31, 2022
1 parent cbb6c04 commit dd46b54
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 63 deletions.
11 changes: 0 additions & 11 deletions dpf/dgl/src/WindowPrivateData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,6 @@ void Window::PrivateData::initPre(const uint width, const uint height, const boo
#endif
puglSetViewHint(view, PUGL_STENCIL_BITS, 8);

#if defined(DGL_USE_OPENGL3) || defined(DGL_USE_GLES3)
puglSetViewHint(view, PUGL_USE_COMPAT_PROFILE, PUGL_FALSE);
puglSetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR, 3);
#elif defined(DGL_USE_GLES2)
puglSetViewHint(view, PUGL_USE_COMPAT_PROFILE, PUGL_FALSE);
puglSetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR, 2);
#else
puglSetViewHint(view, PUGL_USE_COMPAT_PROFILE, PUGL_TRUE);
puglSetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR, 2);
#endif

// PUGL_SAMPLES ??
puglSetEventFunc(view, puglEventCallback);

Expand Down
31 changes: 31 additions & 0 deletions dpf/dgl/src/nanovg/nanovg.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,37 @@

#ifndef NVG_NO_STB
#define STB_IMAGE_IMPLEMENTATION
#define stbi_convert_iphone_png_to_rgb dpf_stbi_convert_iphone_png_to_rgb
#define stbi_failure_reason dpf_stbi_failure_reason
#define stbi_hdr_to_ldr_gamma dpf_stbi_hdr_to_ldr_gamma
#define stbi_hdr_to_ldr_scale dpf_stbi_hdr_to_ldr_scale
#define stbi_image_free dpf_stbi_image_free
#define stbi_info dpf_stbi_info
#define stbi_info_from_callbacks dpf_stbi_info_from_callbacks
#define stbi_info_from_file dpf_stbi_info_from_file
#define stbi_info_from_memory dpf_stbi_info_from_memory
#define stbi_is_hdr dpf_stbi_is_hdr
#define stbi_is_hdr_from_callbacks dpf_stbi_is_hdr_from_callbacks
#define stbi_is_hdr_from_file dpf_stbi_is_hdr_from_file
#define stbi_is_hdr_from_memory dpf_stbi_is_hdr_from_memory
#define stbi_ldr_to_hdr_gamma dpf_stbi_ldr_to_hdr_gamma
#define stbi_ldr_to_hdr_scale dpf_stbi_ldr_to_hdr_scale
#define stbi_load dpf_stbi_load
#define stbi_load_from_callbacks dpf_stbi_load_from_callbacks
#define stbi_load_from_file dpf_stbi_load_from_file
#define stbi_load_from_memory dpf_stbi_load_from_memory
#define stbi_loadf dpf_stbi_loadf
#define stbi_loadf_from_callbacks dpf_stbi_loadf_from_callbacks
#define stbi_loadf_from_file dpf_stbi_loadf_from_file
#define stbi_loadf_from_memory dpf_stbi_loadf_from_memory
#define stbi_set_flip_vertically_on_load dpf_stbi_set_flip_vertically_on_load
#define stbi_set_unpremultiply_on_load dpf_stbi_set_unpremultiply_on_load
#define stbi_zlib_decode_buffer dpf_stbi_zlib_decode_buffer
#define stbi_zlib_decode_malloc dpf_stbi_zlib_decode_malloc
#define stbi_zlib_decode_malloc_guesssize dpf_stbi_zlib_decode_malloc_guesssize
#define stbi_zlib_decode_malloc_guesssize_headerflag dpf_stbi_zlib_decode_malloc_guesssize_headerflag
#define stbi_zlib_decode_noheader_buffer dpf_stbi_zlib_decode_noheader_buffer
#define stbi_zlib_decode_noheader_malloc dpf_stbi_zlib_decode_noheader_malloc
#include "stb_image.h"
#endif

Expand Down
57 changes: 36 additions & 21 deletions dpf/dgl/src/pugl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
# ifdef DGL_CAIRO
# include <cairo-quartz.h>
# endif
# ifdef DGL_OPENGL
# include <OpenGL/gl.h>
# endif
# ifdef DGL_VULKAN
# import <QuartzCore/CAMetalLayer.h>
# include <vulkan/vulkan_macos.h>
Expand Down Expand Up @@ -204,17 +201,35 @@ bool puglBackendLeave(PuglView* const view)

void puglSetMatchingBackendForCurrentBuild(PuglView* const view)
{
#ifdef DGL_CAIRO
#ifdef DGL_CAIRO
puglSetBackend(view, puglCairoBackend());
#endif
#ifdef DGL_OPENGL
#endif
#ifdef DGL_OPENGL
puglSetBackend(view, puglGlBackend());
#endif
#ifdef DGL_VULKAN
#endif
#ifdef DGL_VULKAN
puglSetBackend(view, puglVulkanBackend());
#endif
if (view->backend == nullptr)
#endif

if (view->backend != nullptr)
{
#ifdef DGL_OPENGL
#if defined(DGL_USE_OPENGL3) || defined(DGL_USE_GLES3)
puglSetViewHint(view, PUGL_USE_COMPAT_PROFILE, PUGL_FALSE);
puglSetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR, 3);
#elif defined(DGL_USE_GLES2)
puglSetViewHint(view, PUGL_USE_COMPAT_PROFILE, PUGL_FALSE);
puglSetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR, 2);
#else
puglSetViewHint(view, PUGL_USE_COMPAT_PROFILE, PUGL_TRUE);
puglSetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR, 2);
#endif
#endif
}
else
{
puglSetBackend(view, puglStubBackend());
}
}

// --------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -406,37 +421,37 @@ PuglStatus puglSetSizeAndDefault(PuglView* view, uint width, uint height)

void puglOnDisplayPrepare(PuglView*)
{
#ifdef DGL_OPENGL
#ifdef DGL_OPENGL
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
# ifndef DGL_USE_GLES
#ifndef DGL_USE_OPENGL3
glLoadIdentity();
# endif
#endif
#endif
#endif
}

// --------------------------------------------------------------------------------------------------------------------
// DGL specific, build-specific fallback resize

void puglFallbackOnResize(PuglView* const view)
{
#ifdef DGL_OPENGL
#ifdef DGL_OPENGL
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
# ifndef DGL_USE_GLES
#ifdef DGL_USE_OPENGL3
glViewport(0, 0, static_cast<GLsizei>(view->frame.width), static_cast<GLsizei>(view->frame.height));
#else
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, static_cast<GLdouble>(view->frame.width), static_cast<GLdouble>(view->frame.height), 0.0, 0.0, 1.0);
glViewport(0, 0, static_cast<GLsizei>(view->frame.width), static_cast<GLsizei>(view->frame.height));
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
# else
glViewport(0, 0, static_cast<GLsizei>(view->frame.width), static_cast<GLsizei>(view->frame.height));
# endif
#else
#endif
#else
return;
// unused
(void)view;
#endif
#endif
}

// --------------------------------------------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions plugins/ProM/DistrhoUIProM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ bool DistrhoUIProM::onKeyboard(const KeyboardEvent& ev)
return true;
}

bool DistrhoUIProM::onMouse(const MouseEvent& ev)
{
if (ev.press)
getWindow().focus();

return false;
}

// -----------------------------------------------------------------------

UI* createUI()
Expand Down
1 change: 1 addition & 0 deletions plugins/ProM/DistrhoUIProM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class DistrhoUIProM : public UI

void onDisplay() override;
bool onKeyboard(const KeyboardEvent&) override;
bool onMouse(const MouseEvent& ev) override;

private:
ScopedPointer<projectM> fPM;
Expand Down
47 changes: 16 additions & 31 deletions plugins/ProM/ResizeHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@

#pragma once

#include "TopLevelWidget.hpp"
#include "Color.hpp"
#include "NanoVG.hpp"

START_NAMESPACE_DGL

/** Resize handle for DPF windows, will sit on bottom-right. */
class ResizeHandle : public TopLevelWidget
class ResizeHandle : public NanoTopLevelWidget
{
public:
/** Overloaded constructor, will fetch the window from an existing top-level widget. */
explicit ResizeHandle(TopLevelWidget* const tlw)
: TopLevelWidget(tlw->getWindow()),
: NanoTopLevelWidget(tlw->getWindow()),
handleSize(16),
hasCursor(false),
isResizing(false)
Expand All @@ -44,22 +43,19 @@ class ResizeHandle : public TopLevelWidget
}

protected:
void onDisplay() override
void onNanoDisplay() override
{
const GraphicsContext& context(getGraphicsContext());
const double lineWidth = 1.0 * getScaleFactor();

glMatrixMode(GL_MODELVIEW);
glLineWidth(lineWidth);
strokeWidth(lineWidth);

// draw white lines, 1px wide
glColor3f(1.0f, 1.0f, 1.0f);
strokeColor(Color(1.0f, 1.0f, 1.0f));
drawLine(l1);
drawLine(l2);
drawLine(l3);

// draw black lines, offset by 1px and 1px wide
glColor3f(0.0f, 0.0f, 0.0f);
strokeColor(Color(0.0f, 0.0f, 0.0f));
Line<double> l1b(l1), l2b(l2), l3b(l3);
l1b.moveBy(lineWidth, lineWidth);
l2b.moveBy(lineWidth, lineWidth);
Expand All @@ -69,6 +65,14 @@ class ResizeHandle : public TopLevelWidget
drawLine(l3b);
}

void drawLine(const Line<double>& line)
{
beginPath();
moveTo(line.getStartPos().getX(), line.getStartPos().getY());
lineTo(line.getEndPos().getX(), line.getEndPos().getY());
stroke();
}

bool onMouse(const MouseEvent& ev) override
{
if (ev.button != 1)
Expand Down Expand Up @@ -155,7 +159,7 @@ class ResizeHandle : public TopLevelWidget
void resetArea()
{
const double scaleFactor = getScaleFactor();
const uint margin = 0.0 * scaleFactor;
const uint margin = 1.5 * scaleFactor;
const uint size = handleSize * scaleFactor;

area = Rectangle<uint>(getWidth() - size - margin,
Expand Down Expand Up @@ -187,25 +191,6 @@ class ResizeHandle : public TopLevelWidget
l3.setEndPos(x + offset, y + linesize + offset);
}

void drawLine(const Line<double>& line)
{
drawLine(line.getStartPos(), line.getEndPos());
}

void drawLine(const Point<double>& posStart, const Point<double>& posEnd)
{
DISTRHO_SAFE_ASSERT_RETURN(posStart != posEnd,);

glBegin(GL_LINES);

{
glVertex2d(posStart.getX(), posStart.getY());
glVertex2d(posEnd.getX(), posEnd.getY());
}

glEnd();
}

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ResizeHandle)
};

Expand Down

0 comments on commit dd46b54

Please sign in to comment.