Browse Source

Adjustments for Cairo, and general cleanup

Signed-off-by: falkTX <falktx@gmail.com>
pull/99/head
falkTX 4 years ago
parent
commit
204fbeb807
Signed by: falkTX <falktx@gmail.com> GPG Key ID: 2D3445A829213837
40 changed files with 1153 additions and 675 deletions
  1. +5
    -2
      Makefile
  2. +71
    -30
      Makefile.base.mk
  3. +50
    -12
      Makefile.plugins.mk
  4. +5
    -108
      dgl/Base.hpp
  5. +40
    -0
      dgl/Cairo.hpp
  6. +1
    -5
      dgl/Color.hpp
  7. +13
    -24
      dgl/Geometry.hpp
  8. +30
    -52
      dgl/Image.hpp
  9. +125
    -0
      dgl/ImageBase.hpp
  10. +87
    -19
      dgl/Makefile
  11. +2
    -1
      dgl/NanoVG.hpp
  12. +121
    -0
      dgl/OpenGL.hpp
  13. +1
    -3
      dgl/Widget.hpp
  14. +2
    -2
      dgl/Window.hpp
  15. +27
    -0
      dgl/src/Cairo.cpp
  16. +13
    -39
      dgl/src/Color.cpp
  17. +13
    -103
      dgl/src/Geometry.cpp
  18. +29
    -73
      dgl/src/Image.cpp
  19. +106
    -0
      dgl/src/ImageBase.cpp
  20. +5
    -1
      dgl/src/ImageWidgets.cpp
  21. +20
    -1
      dgl/src/NanoVG.cpp
  22. +157
    -0
      dgl/src/OpenGL.cpp
  23. +1
    -6
      dgl/src/Widget.cpp
  24. +92
    -0
      dgl/src/WidgetPrivateData.cpp
  25. +3
    -60
      dgl/src/WidgetPrivateData.hpp
  26. +16
    -18
      dgl/src/Window.cpp
  27. +35
    -41
      dgl/src/pugl/pugl.h
  28. +2
    -2
      dgl/src/pugl/pugl_internal.h
  29. +11
    -11
      dgl/src/pugl/pugl_osx.m
  30. +20
    -20
      dgl/src/pugl/pugl_win.cpp
  31. +23
    -23
      dgl/src/pugl/pugl_x11.c
  32. +8
    -1
      distrho/DistrhoUI.hpp
  33. +3
    -3
      distrho/src/DistrhoPluginChecks.h
  34. +2
    -2
      distrho/src/DistrhoUI.cpp
  35. +2
    -1
      dpf.doxygen
  36. +2
    -2
      examples/Info/Makefile
  37. +3
    -3
      examples/Meters/Makefile
  38. +3
    -3
      examples/Parameters/Makefile
  39. +3
    -3
      examples/States/Makefile
  40. +1
    -1
      utils/lv2-ttl-generator/GNUmakefile

+ 5
- 2
Makefile View File

@@ -11,9 +11,7 @@ all: dgl examples gen
# --------------------------------------------------------------

dgl:
ifeq ($(HAVE_DGL),true)
$(MAKE) -C dgl
endif

examples: dgl
$(MAKE) all -C examples/Info
@@ -23,6 +21,10 @@ examples: dgl
$(MAKE) all -C examples/Parameters
$(MAKE) all -C examples/States

ifeq ($(HAVE_CAIRO),true)
$(MAKE) all -C examples/CairoUI
endif

ifneq ($(MACOS_OR_WIN32),true)
# ExternalUI is WIP
$(MAKE) all -C examples/ExternalUI
@@ -50,6 +52,7 @@ endif

clean:
$(MAKE) clean -C dgl
$(MAKE) clean -C examples/CairoUI
$(MAKE) clean -C examples/ExternalUI
$(MAKE) clean -C examples/Info
$(MAKE) clean -C examples/Latency


+ 71
- 30
Makefile.base.mk View File

@@ -16,7 +16,7 @@ ifneq ($(HAIKU),true)
ifneq ($(HURD),true)
ifneq ($(LINUX),true)
ifneq ($(MACOS),true)
ifneq ($(WIN32),true)
ifneq ($(WINDOWS),true)

TARGET_MACHINE := $(shell $(CC) -dumpmachine)
ifneq (,$(findstring bsd,$(TARGET_MACHINE)))
@@ -35,7 +35,7 @@ ifneq (,$(findstring apple,$(TARGET_MACHINE)))
MACOS=true
endif
ifneq (,$(findstring mingw,$(TARGET_MACHINE)))
WIN32=true
WINDOWS=true
endif

endif
@@ -57,14 +57,20 @@ LINUX_OR_MACOS=true
endif

# ---------------------------------------------------------------------------------------------------------------------
# Set MACOS_OR_WIN32
# Set MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WINDOWS

ifeq ($(HAIKU),true)
HAIKU_OR_MACOS_OR_WINDOWS=true
endif

ifeq ($(MACOS),true)
MACOS_OR_WIN32=true
MACOS_OR_WINDOWS=true
HAIKU_OR_MACOS_OR_WINDOWS=true
endif

ifeq ($(WIN32),true)
MACOS_OR_WIN32=true
ifeq ($(WINDOWS),true)
MACOS_OR_WINDOWS=true
HAIKU_OR_MACOS_OR_WINDOWS=true
endif

# ---------------------------------------------------------------------------------------------------------------------
@@ -108,7 +114,7 @@ ifeq ($(NOOPT),true)
BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections
endif

ifeq ($(WIN32),true)
ifeq ($(WINDOWS),true)
# mingw has issues with this specific optimization
# See https://github.com/falkTX/Carla/issues/696
BASE_OPTS += -fno-rerun-cse-after-loop
@@ -141,7 +147,7 @@ ifeq ($(MACOS_OLD),true)
BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
endif

ifeq ($(WIN32),true)
ifeq ($(WINDOWS),true)
# Always build statically on windows
LINK_FLAGS += -static
endif
@@ -170,46 +176,81 @@ CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
endif

# ---------------------------------------------------------------------------------------------------------------------
# Check for optional libs
# Check for required libraries

ifeq ($(MACOS_OR_WIN32),true)
HAVE_DGL = true
HAVE_CAIRO = $(shell pkg-config --exists cairo && echo true)

ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
HAVE_OPENGL = true
else
HAVE_DGL = $(shell pkg-config --exists gl x11 && echo true)
HAVE_JACK = $(shell pkg-config --exists jack && echo true)
HAVE_LIBLO = $(shell pkg-config --exists liblo && echo true)
HAVE_OPENGL = $(shell pkg-config --exists gl && echo true)
HAVE_X11 = $(shell pkg-config --exists x11 && echo true)
endif

# ---------------------------------------------------------------------------------------------------------------------
# Check for optional libraries

HAVE_JACK = $(shell pkg-config --exists jack && echo true)
HAVE_LIBLO = $(shell pkg-config --exists liblo && echo true)

# ---------------------------------------------------------------------------------------------------------------------
# Set Generic DGL stuff

ifeq ($(MACOS),true)
DGL_LIBS += -framework Cocoa
endif

ifneq ($(HAVE_DGL),true)
$(error DGL missing 22)
ifeq ($(WINDOWS),true)
DGL_LIBS += -lgdi32
endif

ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
DGL_FLAGS += $(shell pkg-config --cflags x11)
DGL_LIBS += $(shell pkg-config --libs x11)
endif

# ---------------------------------------------------------------------------------------------------------------------
# Set libs stuff
# Set Cairo specific stuff

ifeq ($(HAVE_CAIRO),true)

ifeq ($(HAVE_DGL),true)
DGL_FLAGS += -DHAVE_CAIRO

DGL_FLAGS += -DHAVE_DGL
CAIRO_FLAGS = $(shell pkg-config --cflags cairo)
CAIRO_LIBS = $(shell pkg-config --libs cairo)

HAVE_CAIRO_OR_OPENGL = true

endif

# ---------------------------------------------------------------------------------------------------------------------
# Set OpenGL specific stuff

ifeq ($(HAVE_OPENGL),true)

DGL_FLAGS += -DHAVE_OPENGL

ifeq ($(MACOS),true)
DGL_LIBS = -framework OpenGL -framework Cocoa
OPENGL_LIBS = -framework OpenGL
endif

ifeq ($(WIN32),true)
DGL_LIBS = -lopengl32 -lgdi32
ifeq ($(WINDOWS),true)
OPENGL_LIBS = -lopengl32
endif

ifneq ($(MACOS_OR_WIN32),true)
DGL_FLAGS += $(shell pkg-config --cflags gl x11)
DGL_LIBS += $(shell pkg-config --libs gl x11)
ifneq ($(MACOS_OR_WINDOWS),true)
OPENGL_FLAGS = $(shell pkg-config --cflags gl x11)
OPENGL_LIBS = $(shell pkg-config --libs gl x11)
endif

endif # HAVE_DGL
HAVE_CAIRO_OR_OPENGL = true

endif

# ---------------------------------------------------------------------------------------------------------------------
# Set app extension

ifeq ($(WIN32),true)
ifeq ($(WINDOWS),true)
APP_EXT = .exe
endif

@@ -222,17 +263,17 @@ ifeq ($(MACOS),true)
LIB_EXT = .dylib
endif

ifeq ($(WIN32),true)
ifeq ($(WINDOWS),true)
LIB_EXT = .dll
endif

# ---------------------------------------------------------------------------------------------------------------------
# Set shared library CLI arg

SHARED = -shared

ifeq ($(MACOS),true)
SHARED = -dynamiclib
else
SHARED = -shared
endif

# ---------------------------------------------------------------------------------------------------------------------

+ 50
- 12
Makefile.plugins.mk View File

@@ -15,10 +15,6 @@ endif

include $(DPF_PATH)/Makefile.base.mk

ifeq ($(FILES_UI),)
HAVE_DGL = false
endif

# ---------------------------------------------------------------------------------------------------------------------
# Basic setup

@@ -28,8 +24,12 @@ BUILD_DIR = ../../build/$(NAME)
BUILD_C_FLAGS += -I.
BUILD_CXX_FLAGS += -I. -I$(DPF_PATH)/distrho -I$(DPF_PATH)/dgl

ifeq ($(HAVE_DGL),true)
BASE_FLAGS += -DHAVE_DGL
ifeq ($(HAVE_CAIRO),true)
DGL_FLAGS += -DHAVE_CAIRO
endif

ifeq ($(HAVE_OPENGL),true)
DGL_FLAGS += -DHAVE_OPENGL
endif

ifeq ($(HAVE_JACK),true)
@@ -59,7 +59,37 @@ lv2_ui = $(TARGET_DIR)/$(NAME).lv2/$(NAME)_ui$(LIB_EXT)
vst = $(TARGET_DIR)/$(NAME)-vst$(LIB_EXT)

# ---------------------------------------------------------------------------------------------------------------------
# Handle plugins without UI
# Handle UI stuff, disable UI support automatically

ifeq ($(FILES_UI),)
UI_TYPE = none
endif

ifeq ($(UI_TYPE),)
UI_TYPE = opengl
endif

ifeq ($(UI_TYPE),cairo)
ifeq ($(HAVE_CAIRO),true)
DGL_FLAGS += $(CAIRO_FLAGS) -DDGL_CAIRO
DGL_LIBS += $(CAIRO_LIBS)
DGL_LIB = $(DPF_PATH)/build/libdgl-cairo.a
HAVE_DGL = true
else
HAVE_DGL = false
endif
endif

ifeq ($(UI_TYPE),opengl)
ifeq ($(HAVE_OPENGL),true)
DGL_FLAGS += $(OPENGL_FLAGS) -DDGL_OPENGL
DGL_LIBS += $(OPENGL_LIBS)
DGL_LIB = $(DPF_PATH)/build/libdgl-opengl.a
HAVE_DGL = true
else
HAVE_DGL = false
endif
endif

ifneq ($(HAVE_DGL),true)
dssi_ui =
@@ -68,6 +98,9 @@ DGL_LIBS =
OBJS_UI =
endif

# TODO split dsp and ui object build flags
BASE_FLAGS += $(DGL_FLAGS)

# ---------------------------------------------------------------------------------------------------------------------
# all needs to be first

@@ -81,6 +114,11 @@ $(BUILD_DIR)/%.c.o: %.c
@echo "Compiling $<"
@$(CC) $< $(BUILD_C_FLAGS) -c -o $@

$(BUILD_DIR)/%.cc.o: %.cc
-@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)"
@echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@

$(BUILD_DIR)/%.cpp.o: %.cpp
-@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)"
@echo "Compiling $<"
@@ -118,7 +156,7 @@ $(BUILD_DIR)/DistrhoUIMain_DSSI.cpp.o: $(DPF_PATH)/distrho/DistrhoUIMain.cpp
jack: $(jack)

ifeq ($(HAVE_DGL),true)
$(jack): $(OBJS_DSP) $(OBJS_UI) $(BUILD_DIR)/DistrhoPluginMain_JACK.cpp.o $(BUILD_DIR)/DistrhoUIMain_JACK.cpp.o $(DPF_PATH)/build/libdgl.a
$(jack): $(OBJS_DSP) $(OBJS_UI) $(BUILD_DIR)/DistrhoPluginMain_JACK.cpp.o $(BUILD_DIR)/DistrhoUIMain_JACK.cpp.o $(DGL_LIB)
else
$(jack): $(OBJS_DSP) $(BUILD_DIR)/DistrhoPluginMain_JACK.cpp.o
endif
@@ -148,7 +186,7 @@ $(dssi_dsp): $(OBJS_DSP) $(BUILD_DIR)/DistrhoPluginMain_DSSI.cpp.o
@echo "Creating DSSI plugin library for $(NAME)"
@$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) $(SHARED) -o $@

$(dssi_ui): $(OBJS_UI) $(BUILD_DIR)/DistrhoUIMain_DSSI.cpp.o $(DPF_PATH)/build/libdgl.a
$(dssi_ui): $(OBJS_UI) $(BUILD_DIR)/DistrhoUIMain_DSSI.cpp.o $(DGL_LIB)
-@mkdir -p $(shell dirname $@)
@echo "Creating DSSI UI for $(NAME)"
@$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) $(DGL_LIBS) $(shell pkg-config --libs liblo) -o $@
@@ -160,7 +198,7 @@ lv2: $(lv2)
lv2_dsp: $(lv2_dsp)
lv2_sep: $(lv2_dsp) $(lv2_ui)

$(lv2): $(OBJS_DSP) $(OBJS_UI) $(BUILD_DIR)/DistrhoPluginMain_LV2.cpp.o $(BUILD_DIR)/DistrhoUIMain_LV2.cpp.o $(DPF_PATH)/build/libdgl.a
$(lv2): $(OBJS_DSP) $(OBJS_UI) $(BUILD_DIR)/DistrhoPluginMain_LV2.cpp.o $(BUILD_DIR)/DistrhoUIMain_LV2.cpp.o $(DGL_LIB)
-@mkdir -p $(shell dirname $@)
@echo "Creating LV2 plugin for $(NAME)"
@$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) $(DGL_LIBS) $(SHARED) -o $@
@@ -170,7 +208,7 @@ $(lv2_dsp): $(OBJS_DSP) $(BUILD_DIR)/DistrhoPluginMain_LV2.cpp.o
@echo "Creating LV2 plugin library for $(NAME)"
@$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) $(SHARED) -o $@

$(lv2_ui): $(OBJS_UI) $(BUILD_DIR)/DistrhoUIMain_LV2.cpp.o $(DPF_PATH)/build/libdgl.a
$(lv2_ui): $(OBJS_UI) $(BUILD_DIR)/DistrhoUIMain_LV2.cpp.o $(DGL_LIB)
-@mkdir -p $(shell dirname $@)
@echo "Creating LV2 plugin UI for $(NAME)"
@$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) $(DGL_LIBS) $(SHARED) -o $@
@@ -181,7 +219,7 @@ $(lv2_ui): $(OBJS_UI) $(BUILD_DIR)/DistrhoUIMain_LV2.cpp.o $(DPF_PATH)/build/lib
vst: $(vst)

ifeq ($(HAVE_DGL),true)
$(vst): $(OBJS_DSP) $(OBJS_UI) $(BUILD_DIR)/DistrhoPluginMain_VST.cpp.o $(BUILD_DIR)/DistrhoUIMain_VST.cpp.o $(DPF_PATH)/build/libdgl.a
$(vst): $(OBJS_DSP) $(OBJS_UI) $(BUILD_DIR)/DistrhoPluginMain_VST.cpp.o $(BUILD_DIR)/DistrhoUIMain_VST.cpp.o $(DGL_LIB)
else
$(vst): $(OBJS_DSP) $(BUILD_DIR)/DistrhoPluginMain_VST.cpp.o
endif


+ 5
- 108
dgl/Base.hpp View File

@@ -31,104 +31,6 @@
#define END_NAMESPACE_DGL }
#define USE_NAMESPACE_DGL using namespace DGL_NAMESPACE;

#ifdef DISTRHO_OS_WINDOWS
// -----------------------------------------------------------------------
// Fix OpenGL includes for Windows, based on glfw code

#ifndef APIENTRY
# define APIENTRY __stdcall
#endif // APIENTRY

/* We need WINGDIAPI defined */
#ifndef WINGDIAPI
# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__POCC__)
# define WINGDIAPI __declspec(dllimport)
# elif defined(__LCC__)
# define WINGDIAPI __stdcall
# else
# define WINGDIAPI extern
# endif
# define DGL_WINGDIAPI_DEFINED
#endif // WINGDIAPI

/* Some <GL/glu.h> files also need CALLBACK defined */
#ifndef CALLBACK
# if defined(_MSC_VER)
# if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS)
# define CALLBACK __stdcall
# else
# define CALLBACK
# endif
# else
# define CALLBACK __stdcall
# endif
# define DGL_CALLBACK_DEFINED
#endif // CALLBACK

/* Most GL/glu.h variants on Windows need wchar_t */
#include <cstddef>

#endif // DISTRHO_OS_WINDOWS

// -----------------------------------------------------------------------
// OpenGL includes

#ifdef HAVE_DGL

#ifdef DISTRHO_OS_MAC
# include <OpenGL/gl.h>
#else
# ifndef DISTRHO_OS_WINDOWS
# define GL_GLEXT_PROTOTYPES
# endif
# include <GL/gl.h>
# include <GL/glext.h>
#endif

#endif

// -----------------------------------------------------------------------
// Cairo includes

#ifdef HAVE_DCAIRO
# include <cairo/cairo.h>
#endif

// -----------------------------------------------------------------------
// Missing OpenGL defines

#ifdef HAVE_DGL

#if defined(GL_BGR_EXT) && ! defined(GL_BGR)
# define GL_BGR GL_BGR_EXT
#endif

#if defined(GL_BGRA_EXT) && ! defined(GL_BGRA)
# define GL_BGRA GL_BGRA_EXT
#endif

#ifndef GL_CLAMP_TO_BORDER
# define GL_CLAMP_TO_BORDER 0x812D
#endif

#endif

#ifdef DISTRHO_OS_WINDOWS
// -----------------------------------------------------------------------
// Fix OpenGL includes for Windows, based on glfw code

#ifdef DGL_WINGDIAPI_DEFINED
# undef WINGDIAPI
# undef DGL_WINGDIAPI_DEFINED
#endif

#ifdef DGL_CALLBACK_DEFINED
# undef CALLBACK
# undef DGL_CALLBACK_DEFINED
#endif

#endif // DISTRHO_OS_WINDOWS

START_NAMESPACE_DGL

// -----------------------------------------------------------------------
@@ -187,6 +89,11 @@ enum Key {
// -----------------------------------------------------------------------
// Base DGL classes

/**
Graphics context, definition depends on build type.
*/
struct GraphicsContext;

/**
Idle callback.
*/
@@ -197,16 +104,6 @@ public:
virtual void idleCallback() = 0;
};

/**
Graphics context.
*/
struct Context
{
#ifdef HAVE_DCAIRO
cairo_t* cairo;
#endif
};

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

END_NAMESPACE_DGL


+ 40
- 0
dgl/Cairo.hpp View File

@@ -0,0 +1,40 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef DGL_CAIRO_HPP_INCLUDED
#define DGL_CAIRO_HPP_INCLUDED

#include "Base.hpp"

#include <cairo/cairo.h>

START_NAMESPACE_DGL

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

/**
Graphics context.
*/
struct GraphicsContext
{
cairo_t* cairo; // FIXME proper name..
};

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

END_NAMESPACE_DGL

#endif

+ 1
- 5
dgl/Color.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -19,9 +19,7 @@

#include "Base.hpp"

#ifndef HAVE_DCAIRO
struct NVGcolor;
#endif

START_NAMESPACE_DGL

@@ -97,14 +95,12 @@ struct Color {
*/
void fixBounds() noexcept;

#ifndef HAVE_DCAIRO
/**
@internal
Needed for NanoVG compatibility.
*/
Color(const NVGcolor&) noexcept;
operator NVGcolor() const noexcept;
#endif
};

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


+ 13
- 24
dgl/Geometry.hpp View File

@@ -346,12 +346,10 @@ public:
*/
void moveBy(const Point<T>& pos) noexcept;

#ifdef HAVE_DGL
/**
Draw this line using the current OpenGL state.
*/
void draw();
#endif

/**
Return true if line is null (start and end pos are equal).
@@ -462,7 +460,6 @@ public:
*/
void setNumSegments(const uint num);

#ifdef HAVE_DGL
/**
Draw this circle using the current OpenGL state.
*/
@@ -472,7 +469,6 @@ public:
Draw lines (outline of this circle) using the current OpenGL state.
*/
void drawOutline();
#endif

Circle<T>& operator=(const Circle<T>& cir) noexcept;
bool operator==(const Circle<T>& cir) const noexcept;
@@ -486,9 +482,8 @@ private:
// cached values
float fTheta, fCos, fSin;

#ifdef HAVE_DGL
/** @internal */
void _draw(const bool outline);
#endif
};

// -----------------------------------------------------------------------
@@ -522,18 +517,6 @@ public:
*/
Triangle(const Triangle<T>& tri) noexcept;

#ifdef HAVE_DGL
/**
Draw this triangle using the current OpenGL state.
*/
void draw();

/**
Draw lines (outline of this triangle) using the current OpenGL state.
*/
void drawOutline();
#endif

/**
Return true if triangle is null (all its points are equal).
An null triangle is also invalid.
@@ -557,6 +540,16 @@ public:
*/
bool isInvalid() const noexcept;

/**
Draw this triangle using the current OpenGL state.
*/
void draw();

/**
Draw lines (outline of this triangle) using the current OpenGL state.
*/
void drawOutline();

Triangle<T>& operator=(const Triangle<T>& tri) noexcept;
bool operator==(const Triangle<T>& tri) const noexcept;
bool operator!=(const Triangle<T>& tri) const noexcept;
@@ -564,9 +557,8 @@ public:
private:
Point<T> fPos1, fPos2, fPos3;

#ifdef HAVE_DGL
/** @internal */
void _draw(const bool outline);
#endif
};

// -----------------------------------------------------------------------
@@ -730,7 +722,6 @@ public:
*/
bool containsY(const T& y) const noexcept;

#ifdef HAVE_DGL
/**
Draw this rectangle using the current OpenGL state.
*/
@@ -740,7 +731,6 @@ public:
Draw lines (outline of this rectangle) using the current OpenGL state.
*/
void drawOutline();
#endif

Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept;
Rectangle<T>& operator*=(double m) noexcept;
@@ -752,9 +742,8 @@ private:
Point<T> fPos;
Size<T> fSize;

#ifdef HAVE_DGL
/** @internal */
void _draw(const bool outline);
#endif
};

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


+ 30
- 52
dgl/Image.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -17,14 +17,15 @@
#ifndef DGL_IMAGE_HPP_INCLUDED
#define DGL_IMAGE_HPP_INCLUDED

#include "Geometry.hpp"
#include "ImageBase.hpp"
#include "OpenGL.hpp"

START_NAMESPACE_DGL

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

/**
Base DGL Image class.
OpenGL Image class.

This is an Image class that handles raw image data in pixels.
You can init the image data on the contructor or later on by calling loadFromMemory().
@@ -35,7 +36,7 @@ START_NAMESPACE_DGL

Images are drawn on screen via 2D textures.
*/
class Image
class Image : public ImageBase
{
public:
/**
@@ -47,13 +48,20 @@ public:
Constructor using raw image data.
@note @a rawData must remain valid for the lifetime of this Image.
*/
Image(const char* const rawData, const uint width, const uint height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE);
Image(const char* const rawData,
const uint width,
const uint height,
const GLenum format = GL_BGRA,
const GLenum type = GL_UNSIGNED_BYTE);

/**
Constructor using raw image data.
@note @a rawData must remain valid for the lifetime of this Image.
*/
Image(const char* const rawData, const Size<uint>& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE);
Image(const char* const rawData,
const Size<uint>& size,
const GLenum format = GL_BGRA,
const GLenum type = GL_UNSIGNED_BYTE);

/**
Constructor using another image data.
@@ -63,44 +71,26 @@ public:
/**
Destructor.
*/
~Image();
~Image() override;

/**
Load image data from memory.
@note @a rawData must remain valid for the lifetime of this Image.
*/
void loadFromMemory(const char* const rawData, const uint width, const uint height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept;
void loadFromMemory(const char* const rawData,
const uint width,
const uint height,
const GLenum format = GL_BGRA,
const GLenum type = GL_UNSIGNED_BYTE) noexcept;

/**
Load image data from memory.
@note @a rawData must remain valid for the lifetime of this Image.
*/
void loadFromMemory(const char* const rawData, const Size<uint>& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept;

/**
Check if this image is valid.
*/
bool isValid() const noexcept;

/**
Get width.
*/
uint getWidth() const noexcept;

/**
Get height.
*/
uint getHeight() const noexcept;

/**
Get size.
*/
const Size<uint>& getSize() const noexcept;

/**
Get the raw image data.
*/
const char* getRawData() const noexcept;
void loadFromMemory(const char* const rawData,
const Size<uint>& size,
const GLenum format = GL_BGRA,
const GLenum type = GL_UNSIGNED_BYTE) noexcept;

/**
Get the image format.
@@ -113,27 +103,15 @@ public:
GLenum getType() const noexcept;

/**
Draw this image at (0, 0) point.
*/
void draw();

/**
Draw this image at (x, y) point.
TODO document this.
*/
void drawAt(const int x, const int y);

/**
Draw this image at position @a pos.
*/
void drawAt(const Point<int>& pos);

Image& operator=(const Image& image) noexcept;
bool operator==(const Image& image) const noexcept;
bool operator!=(const Image& image) const noexcept;

protected:
/** @internal */
void _drawAt(const Point<int>& pos) override;

private:
const char* fRawData;
Size<uint> fSize;
GLenum fFormat;
GLenum fType;
GLuint fTextureId;
@@ -144,4 +122,4 @@ private:

END_NAMESPACE_DGL

#endif // DGL_IMAGE_HPP_INCLUDED
#endif

+ 125
- 0
dgl/ImageBase.hpp View File

@@ -0,0 +1,125 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef DGL_IMAGE_BASE_HPP_INCLUDED
#define DGL_IMAGE_BASE_HPP_INCLUDED

#include "Geometry.hpp"

START_NAMESPACE_DGL

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

/**
Base DGL Image class.

This is an Image class that handles raw image data in pixels.
It is an abstract class that provides the common methods to build on top.
Cairo and OpenGL Image classes are based upon this one.

@see Image
*/
class ImageBase
{
protected:
/**
Constructor for a null Image.
*/
ImageBase();

/**
Constructor using raw image data.
@note @a rawData must remain valid for the lifetime of this Image.
*/
ImageBase(const char* const rawData, const uint width, const uint height);

/**
Constructor using raw image data.
@note @a rawData must remain valid for the lifetime of this Image.
*/
ImageBase(const char* const rawData, const Size<uint>& size);

/**
Constructor using another image data.
*/
ImageBase(const ImageBase& image);

public:
/**
Destructor.
*/
virtual ~ImageBase();

/**
Check if this image is valid.
*/
bool isValid() const noexcept;

/**
Get width.
*/
uint getWidth() const noexcept;

/**
Get height.
*/
uint getHeight() const noexcept;

/**
Get size.
*/
const Size<uint>& getSize() const noexcept;

/**
Get the raw image data.
*/
const char* getRawData() const noexcept;

/**
Draw this image at (0, 0) point.
*/
void draw();

/**
Draw this image at (x, y) point.
*/
void drawAt(const int x, const int y);

/**
Draw this image at position @a pos.
*/
void drawAt(const Point<int>& pos);

/**
TODO document this.
*/
ImageBase& operator=(const ImageBase& image) noexcept;
bool operator==(const ImageBase& image) const noexcept;
bool operator!=(const ImageBase& image) const noexcept;

protected:
/** @internal */
virtual void _drawAt(const Point<int>& pos) = 0;

const char* fRawData;
Size<uint> fSize;
};

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

END_NAMESPACE_DGL

#endif // DGL_IMAGE_HPP_INCLUDED

+ 87
- 19
dgl/Makefile View File

@@ -9,7 +9,7 @@ include ../Makefile.base.mk
# ---------------------------------------------------------------------------------------------------------------------

BUILD_C_FLAGS += $(DGL_FLAGS) -I. -Isrc
BUILD_CXX_FLAGS += $(DGL_FLAGS) -I. -Isrc
BUILD_CXX_FLAGS += $(DGL_FLAGS) -I. -Isrc -Wno-unused-parameter
LINK_FLAGS += $(DGL_LIBS)

# ifneq ($(MACOS_OLD),true)
@@ -19,36 +19,78 @@ LINK_FLAGS += $(DGL_LIBS)

# ---------------------------------------------------------------------------------------------------------------------

OBJS = \
OBJS_common = \
../build/dgl/Application.cpp.o \
../build/dgl/Color.cpp.o \
../build/dgl/Geometry.cpp.o \
../build/dgl/Image.cpp.o \
../build/dgl/ImageWidgets.cpp.o \
../build/dgl/NanoVG.cpp.o \
../build/dgl/ImageBase.cpp.o \
../build/dgl/Resources.cpp.o \
../build/dgl/Widget.cpp.o

# TODO: ImageWidgets.cpp

# ---------------------------------------------------------------------------------------------------------------------

OBJS_cairo = $(OBJS_common) \
../build/dgl/Cairo.cpp.cairo.o \
../build/dgl/WidgetPrivateData.cpp.cairo.o

ifeq ($(MACOS),true)
OBJS_cairo += ../build/dgl/Window.mm.cairo.o
else
OBJS_cairo += ../build/dgl/Window.cpp.cairo.o
endif

# ---------------------------------------------------------------------------------------------------------------------

OBJS_opengl = $(OBJS_common) \
../build/dgl/OpenGL.cpp.opengl.o \
../build/dgl/Image.cpp.opengl.o \
../build/dgl/ImageWidgets.cpp.opengl.o \
../build/dgl/NanoVG.cpp.opengl.o \
../build/dgl/WidgetPrivateData.cpp.opengl.o

ifeq ($(MACOS),true)
OBJS += ../build/dgl/Window.mm.o
OBJS_opengl += ../build/dgl/Window.mm.opengl.o
else
OBJS += ../build/dgl/Window.cpp.o
OBJS_opengl += ../build/dgl/Window.cpp.opengl.o
endif

TARGET = ../build/libdgl.a
# ---------------------------------------------------------------------------------------------------------------------

ifeq ($(HAVE_CAIRO),true)
TARGETS += ../build/libdgl-cairo.a
endif

ifeq ($(HAVE_OPENGL),true)
TARGETS += ../build/libdgl-opengl.a
# Compat name, to be removed soon
TARGETS += ../build/libdgl.a
endif

# ---------------------------------------------------------------------------------------------------------------------

all: $(TARGET)
all: $(TARGETS)

# ---------------------------------------------------------------------------------------------------------------------

../build/libdgl.a: $(OBJS)
../build/libdgl-cairo.a: $(OBJS_cairo)
-@mkdir -p ../build
@echo "Creating libdgl-cairo.a"
@rm -f $@
@$(AR) crs $@ $^

../build/libdgl-opengl.a: $(OBJS_opengl)
-@mkdir -p ../build
@echo "Creating libdgl.a"
@echo "Creating libdgl-opengl.a"
@rm -f $@
@$(AR) crs $@ $^

# Compat name, to be removed soon
../build/libdgl.a: ../build/libdgl-opengl.a
@echo "Symlinking libdgl.a"
@ln -s $< $@

# ---------------------------------------------------------------------------------------------------------------------

../build/dgl/%.c.o: src/%.c
@@ -61,26 +103,52 @@ all: $(TARGET)
@echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@

../build/dgl/Window.cpp.o: src/Window.cpp src/sofd/* src/pugl/*
# ---------------------------------------------------------------------------------------------------------------------

../build/dgl/%.cpp.cairo.o: src/%.cpp
-@mkdir -p ../build/dgl
@echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@
@echo "Compiling $< (Cairo variant)"
@$(CXX) $< $(BUILD_CXX_FLAGS) -DDGL_CAIRO -c -o $@

../build/dgl/Window.mm.o: src/Window.cpp src/sofd/* src/pugl/*
../build/dgl/Window.cpp.cairo.o: src/Window.cpp src/sofd/* src/pugl/*
-@mkdir -p ../build/dgl
@echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) -ObjC++ -c -o $@
@echo "Compiling $< (Cairo variant)"
@$(CXX) $< $(BUILD_CXX_FLAGS) -DDGL_CAIRO -c -o $@

../build/dgl/Window.mm.cairo.o: src/Window.cpp src/sofd/* src/pugl/*
-@mkdir -p ../build/dgl
@echo "Compiling $< (Cairo variant)"
@$(CXX) $< $(BUILD_CXX_FLAGS) -DDGL_CAIRO -ObjC++ -c -o $@

# ---------------------------------------------------------------------------------------------------------------------

../build/dgl/%.cpp.opengl.o: src/%.cpp
-@mkdir -p ../build/dgl
@echo "Compiling $< (OpenGL variant)"
@$(CXX) $< $(BUILD_CXX_FLAGS) -DDGL_OPENGL -c -o $@

../build/dgl/Window.cpp.opengl.o: src/Window.cpp src/sofd/* src/pugl/*
-@mkdir -p ../build/dgl
@echo "Compiling $< (OpenGL variant)"
@$(CXX) $< $(BUILD_CXX_FLAGS) -DDGL_OPENGL -c -o $@

../build/dgl/Window.mm.opengl.o: src/Window.cpp src/sofd/* src/pugl/*
-@mkdir -p ../build/dgl
@echo "Compiling $< (OpenGL variant)"
@$(CXX) $< $(BUILD_CXX_FLAGS) -DDGL_OPENGL -ObjC++ -c -o $@

# ---------------------------------------------------------------------------------------------------------------------

clean:
rm -rf ../build/dgl ../build/libdgl.*
rm -rf ../build/dgl ../build/libdgl*.*

debug:
$(MAKE) DEBUG=true

# ---------------------------------------------------------------------------------------------------------------------

-include $(OBJS:%.o=%.d)
-include $(OBJS_common:%.o=%.d)
-include $(OBJS_cairo:%.o=%.d)
-include $(OBJS_opengl:%.o=%.d)

# ---------------------------------------------------------------------------------------------------------------------

+ 2
- 1
dgl/NanoVG.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -18,6 +18,7 @@
#define DGL_NANO_WIDGET_HPP_INCLUDED

#include "Color.hpp"
#include "OpenGL.hpp"
#include "Widget.hpp"

#ifndef DGL_NO_SHARED_RESOURCES


+ 121
- 0
dgl/OpenGL.hpp View File

@@ -0,0 +1,121 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef DGL_OPENGL_HPP_INCLUDED
#define DGL_OPENGL_HPP_INCLUDED

#include "ImageBase.hpp"

// -----------------------------------------------------------------------
// Fix OpenGL includes for Windows, based on glfw code (part 1)

#undef DGL_CALLBACK_DEFINED
#undef DGL_WINGDIAPI_DEFINED

#ifdef DISTRHO_OS_WINDOWS

#ifndef APIENTRY
# define APIENTRY __stdcall
#endif // APIENTRY

/* We need WINGDIAPI defined */
#ifndef WINGDIAPI
# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__POCC__)
# define WINGDIAPI __declspec(dllimport)
# elif defined(__LCC__)
# define WINGDIAPI __stdcall
# else
# define WINGDIAPI extern
# endif
# define DGL_WINGDIAPI_DEFINED
#endif // WINGDIAPI

/* Some <GL/glu.h> files also need CALLBACK defined */
#ifndef CALLBACK
# if defined(_MSC_VER)
# if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS)
# define CALLBACK __stdcall
# else
# define CALLBACK
# endif
# else
# define CALLBACK __stdcall
# endif
# define DGL_CALLBACK_DEFINED
#endif // CALLBACK

/* Most GL/glu.h variants on Windows need wchar_t */
#include <cstddef>

#endif // DISTRHO_OS_WINDOWS

// -----------------------------------------------------------------------
// OpenGL includes

#ifdef DISTRHO_OS_MAC
# include <OpenGL/gl.h>
#else
# ifndef DISTRHO_OS_WINDOWS
# define GL_GLEXT_PROTOTYPES
# endif
# include <GL/gl.h>
# include <GL/glext.h>
#endif

// -----------------------------------------------------------------------
// Missing OpenGL defines

#if defined(GL_BGR_EXT) && !defined(GL_BGR)
# define GL_BGR GL_BGR_EXT
#endif

#if defined(GL_BGRA_EXT) && !defined(GL_BGRA)
# define GL_BGRA GL_BGRA_EXT
#endif

#ifndef GL_CLAMP_TO_BORDER
# define GL_CLAMP_TO_BORDER 0x812D
#endif

// -----------------------------------------------------------------------
// Fix OpenGL includes for Windows, based on glfw code (part 2)

#ifdef DGL_CALLBACK_DEFINED
# undef CALLBACK
# undef DGL_CALLBACK_DEFINED
#endif

#ifdef DGL_WINGDIAPI_DEFINED
# undef WINGDIAPI
# undef DGL_WINGDIAPI_DEFINED
#endif

START_NAMESPACE_DGL

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

/**
Graphics context.
*/
struct GraphicsContext
{
};

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

END_NAMESPACE_DGL

#endif

+ 1
- 3
dgl/Widget.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -312,8 +312,6 @@ public:
*/
Window& getParentWindow() const noexcept;

const Context& getContext() const noexcept;

/**
Check if this widget contains the point defined by @a x and @a y.
*/


+ 2
- 2
dgl/Window.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -119,7 +119,7 @@ public:
Application& getApp() const noexcept;
intptr_t getWindowId() const noexcept;

const Context& getContext() const noexcept;
const GraphicsContext& getGraphicsContext() const noexcept;

void addIdleCallback(IdleCallback* const callback);
void removeIdleCallback(IdleCallback* const callback);


+ 27
- 0
dgl/src/Cairo.cpp View File

@@ -0,0 +1,27 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "../Base.hpp"

START_NAMESPACE_DGL

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

// nothing here yet

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

END_NAMESPACE_DGL

+ 13
- 39
dgl/src/Color.cpp View File

@@ -24,6 +24,19 @@ START_NAMESPACE_DGL

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

static float computeHue(float h, float m1, float m2)
{
if (h < 0) h += 1;
if (h > 1) h -= 1;
if (h < 1.0f/6.0f)
return m1 + (m2 - m1) * h * 6.0f;
if (h < 3.0f/6.0f)
return m2;
if (h < 4.0f/6.0f)
return m1 + (m2 - m1) * (2.0f/3.0f - h) * 6.0f;
return m1;
}

static void fixRange(float& value)
{
/**/ if (value < 0.0f)
@@ -105,26 +118,8 @@ Color::Color(const Color& color1, const Color& color2, float u) noexcept
interpolate(color2, u);
}

#ifndef HAVE_DGL
static float computeHue(float h, float m1, float m2)
{
if (h < 0) h += 1;
if (h > 1) h -= 1;
if (h < 1.0f/6.0f)
return m1 + (m2 - m1) * h * 6.0f;
else if (h < 3.0f/6.0f)
return m2;
else if (h < 4.0f/6.0f)
return m1 + (m2 - m1) * (2.0f/3.0f - h) * 6.0f;
return m1;
}
#endif

Color Color::fromHSL(float hue, float saturation, float lightness, float alpha)
{
#ifdef HAVE_DGL
return nvgHSLA(hue, saturation, lightness, static_cast<uchar>(getFixedRange(alpha)*255.0f));
#else
float m1, m2;
Color col;
hue = fmodf(hue, 1.0f);
@@ -139,7 +134,6 @@ Color Color::fromHSL(float hue, float saturation, float lightness, float alpha)
col.alpha = alpha;
col.fixBounds();
return col;
#endif
}

Color Color::fromHTML(const char* rgb, float alpha)
@@ -258,24 +252,4 @@ void Color::fixBounds() noexcept

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

#ifndef HAVE_DCAIRO
Color::Color(const NVGcolor& c) noexcept
: red(c.r), green(c.g), blue(c.b), alpha(c.a)
{
fixBounds();
}

Color::operator NVGcolor() const noexcept
{
NVGcolor nc;
nc.r = red;
nc.g = green;
nc.b = blue;
nc.a = alpha;
return nc;
}
#endif

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

END_NAMESPACE_DGL

+ 13
- 103
dgl/src/Geometry.cpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -441,23 +441,6 @@ void Line<T>::moveBy(const Point<T>& pos) noexcept
fPosEnd.moveBy(pos);
}

#ifdef HAVE_DGL
template<typename T>
void Line<T>::draw()
{
DISTRHO_SAFE_ASSERT_RETURN(fPosStart != fPosEnd,);

glBegin(GL_LINES);

{
glVertex2d(fPosStart.fX, fPosStart.fY);
glVertex2d(fPosEnd.fX, fPosEnd.fY);
}

glEnd();
}
#endif

template<typename T>
bool Line<T>::isNull() const noexcept
{
@@ -616,7 +599,6 @@ void Circle<T>::setNumSegments(const uint num)
fSin = std::sin(fTheta);
}

#ifdef HAVE_DGL
template<typename T>
void Circle<T>::draw()
{
@@ -628,7 +610,6 @@ void Circle<T>::drawOutline()
{
_draw(true);
}
#endif

template<typename T>
Circle<T>& Circle<T>::operator=(const Circle<T>& cir) noexcept
@@ -654,29 +635,6 @@ bool Circle<T>::operator!=(const Circle<T>& cir) const noexcept
return (fPos != cir.fPos || d_isNotEqual(fSize, cir.fSize) || fNumSegments != cir.fNumSegments);
}

#ifdef HAVE_DGL
template<typename T>
void Circle<T>::_draw(const bool outline)
{
DISTRHO_SAFE_ASSERT_RETURN(fNumSegments >= 3 && fSize > 0.0f,);

double t, x = fSize, y = 0.0;

glBegin(outline ? GL_LINE_LOOP : GL_POLYGON);

for (uint i=0; i<fNumSegments; ++i)
{
glVertex2d(x + fPos.fX, y + fPos.fY);

t = x;
x = fCos * x - fSin * y;
y = fSin * t + fCos * y;
}

glEnd();
}
#endif

// -----------------------------------------------------------------------
// Triangle

@@ -704,20 +662,6 @@ Triangle<T>::Triangle(const Triangle<T>& tri) noexcept
fPos2(tri.fPos2),
fPos3(tri.fPos3) {}

#ifdef HAVE_DGL
template<typename T>
void Triangle<T>::draw()
{
_draw(false);
}

template<typename T>
void Triangle<T>::drawOutline()
{
_draw(true);
}
#endif

template<typename T>
bool Triangle<T>::isNull() const noexcept
{
@@ -742,6 +686,18 @@ bool Triangle<T>::isInvalid() const noexcept
return fPos1 == fPos2 || fPos1 == fPos3;
}

template<typename T>
void Triangle<T>::draw()
{
_draw(false);
}

template<typename T>
void Triangle<T>::drawOutline()
{
_draw(true);
}

template<typename T>
Triangle<T>& Triangle<T>::operator=(const Triangle<T>& tri) noexcept
{
@@ -763,24 +719,6 @@ bool Triangle<T>::operator!=(const Triangle<T>& tri) const noexcept
return (fPos1 != tri.fPos1 || fPos2 != tri.fPos2 || fPos3 != tri.fPos3);
}

#ifdef HAVE_DGL
template<typename T>
void Triangle<T>::_draw(const bool outline)
{
DISTRHO_SAFE_ASSERT_RETURN(fPos1 != fPos2 && fPos1 != fPos3,);

glBegin(outline ? GL_LINE_LOOP : GL_TRIANGLES);

{
glVertex2d(fPos1.fX, fPos1.fY);
glVertex2d(fPos2.fX, fPos2.fY);
glVertex2d(fPos3.fX, fPos3.fY);
}

glEnd();
}
#endif

// -----------------------------------------------------------------------
// Rectangle

@@ -962,7 +900,6 @@ bool Rectangle<T>::containsY(const T& y) const noexcept
return (y >= fPos.fY && y <= fPos.fY + fSize.fHeight);
}

#ifdef HAVE_DGL
template<typename T>
void Rectangle<T>::draw()
{
@@ -974,7 +911,6 @@ void Rectangle<T>::drawOutline()
{
_draw(true);
}
#endif

template<typename T>
Rectangle<T>& Rectangle<T>::operator=(const Rectangle<T>& rect) noexcept
@@ -1010,32 +946,6 @@ bool Rectangle<T>::operator!=(const Rectangle<T>& rect) const noexcept
return (fPos != rect.fPos || fSize != rect.fSize);
}

#ifdef HAVE_DGL
template<typename T>
void Rectangle<T>::_draw(const bool outline)
{
DISTRHO_SAFE_ASSERT_RETURN(fSize.isValid(),);

glBegin(outline ? GL_LINE_LOOP : GL_QUADS);

{
glTexCoord2f(0.0f, 0.0f);
glVertex2d(fPos.fX, fPos.fY);

glTexCoord2f(1.0f, 0.0f);
glVertex2d(fPos.fX+fSize.fWidth, fPos.fY);

glTexCoord2f(1.0f, 1.0f);
glVertex2d(fPos.fX+fSize.fWidth, fPos.fY+fSize.fHeight);

glTexCoord2f(0.0f, 1.0f);
glVertex2d(fPos.fX, fPos.fY+fSize.fHeight);
}

glEnd();
}
#endif

// -----------------------------------------------------------------------
// Possible template data types



+ 29
- 73
dgl/src/Image.cpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -21,8 +21,7 @@ START_NAMESPACE_DGL
// -----------------------------------------------------------------------

Image::Image()
: fRawData(nullptr),
fSize(0, 0),
: ImageBase(),
fFormat(0),
fType(0),
fTextureId(0),
@@ -31,20 +30,18 @@ Image::Image()
glGenTextures(1, &fTextureId);
}

Image::Image(const char* const rawData, const uint width, const uint height, const GLenum format, const GLenum type)
: fRawData(rawData),
fSize(width, height),
fFormat(format),
fType(type),
Image::Image(const Image& image)
: ImageBase(image),
fFormat(image.fFormat),
fType(image.fType),
fTextureId(0),
fIsReady(false)
{
glGenTextures(1, &fTextureId);
}

Image::Image(const char* const rawData, const Size<uint>& size, const GLenum format, const GLenum type)
: fRawData(rawData),
fSize(size),
Image::Image(const char* const rawData, const uint width, const uint height, const GLenum format, const GLenum type)
: ImageBase(rawData, width, height),
fFormat(format),
fType(type),
fTextureId(0),
@@ -53,11 +50,10 @@ Image::Image(const char* const rawData, const Size<uint>& size, const GLenum for
glGenTextures(1, &fTextureId);
}

Image::Image(const Image& image)
: fRawData(image.fRawData),
fSize(image.fSize),
fFormat(image.fFormat),
fType(image.fType),
Image::Image(const char* const rawData, const Size<uint>& size, const GLenum format, const GLenum type)
: ImageBase(rawData, size),
fFormat(format),
fType(type),
fTextureId(0),
fIsReady(false)
{
@@ -75,12 +71,19 @@ Image::~Image()
}
}

void Image::loadFromMemory(const char* const rawData, const uint width, const uint height, const GLenum format, const GLenum type) noexcept
void Image::loadFromMemory(const char* const rawData,
const uint width,
const uint height,
const GLenum format,
const GLenum type) noexcept
{
loadFromMemory(rawData, Size<uint>(width, height), format, type);
}

void Image::loadFromMemory(const char* const rawData, const Size<uint>& size, const GLenum format, const GLenum type) noexcept
void Image::loadFromMemory(const char* const rawData,
const Size<uint>& size,
const GLenum format,
const GLenum type) noexcept
{
fRawData = rawData;
fSize = size;
@@ -89,31 +92,6 @@ void Image::loadFromMemory(const char* const rawData, const Size<uint>& size, co
fIsReady = false;
}

bool Image::isValid() const noexcept
{
return (fRawData != nullptr && fSize.getWidth() > 0 && fSize.getHeight() > 0);
}

uint Image::getWidth() const noexcept
{
return fSize.getWidth();
}

uint Image::getHeight() const noexcept
{
return fSize.getHeight();
}

const Size<uint>& Image::getSize() const noexcept
{
return fSize;
}

const char* Image::getRawData() const noexcept
{
return fRawData;
}

GLenum Image::getFormat() const noexcept
{
return fFormat;
@@ -124,17 +102,17 @@ GLenum Image::getType() const noexcept
return fType;
}

void Image::draw()
{
drawAt(0, 0);
}

void Image::drawAt(const int x, const int y)
Image& Image::operator=(const Image& image) noexcept
{
drawAt(Point<int>(x, y));
fRawData = image.fRawData;
fSize = image.fSize;
fFormat = image.fFormat;
fType = image.fType;
fIsReady = false;
return *this;
}

void Image::drawAt(const Point<int>& pos)
void Image::_drawAt(const Point<int>& pos)
{
if (fTextureId == 0 || ! isValid())
return;
@@ -169,26 +147,4 @@ void Image::drawAt(const Point<int>& pos)

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

Image& Image::operator=(const Image& image) noexcept
{
fRawData = image.fRawData;
fSize = image.fSize;
fFormat = image.fFormat;
fType = image.fType;
fIsReady = false;
return *this;
}

bool Image::operator==(const Image& image) const noexcept
{
return (fRawData == image.fRawData && fSize == image.fSize);
}

bool Image::operator!=(const Image& image) const noexcept
{
return !operator==(image);
}

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

END_NAMESPACE_DGL

+ 106
- 0
dgl/src/ImageBase.cpp View File

@@ -0,0 +1,106 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "../ImageBase.hpp"

START_NAMESPACE_DGL

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

ImageBase::ImageBase()
: fRawData(nullptr),
fSize(0, 0) {}

ImageBase::ImageBase(const char* const rawData, const uint width, const uint height)
: fRawData(rawData),
fSize(width, height) {}

ImageBase::ImageBase(const char* const rawData, const Size<uint>& size)
: fRawData(rawData),
fSize(size) {}

ImageBase::ImageBase(const ImageBase& image)
: fRawData(image.fRawData),
fSize(image.fSize) {}

ImageBase::~ImageBase() {}

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

bool ImageBase::isValid() const noexcept
{
return (fRawData != nullptr && fSize.isValid());
}

uint ImageBase::getWidth() const noexcept
{
return fSize.getWidth();
}

uint ImageBase::getHeight() const noexcept
{
return fSize.getHeight();
}

const Size<uint>& ImageBase::getSize() const noexcept
{
return fSize;
}

const char* ImageBase::getRawData() const noexcept
{
return fRawData;
}

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

void ImageBase::draw()
{
_drawAt(Point<int>());
}

void ImageBase::drawAt(const int x, const int y)
{
_drawAt(Point<int>(x, y));
}

void ImageBase::drawAt(const Point<int>& pos)
{
_drawAt(pos);
}

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

ImageBase& ImageBase::operator=(const ImageBase& image) noexcept
{
fRawData = image.fRawData;
fSize = image.fSize;
return *this;
}

bool ImageBase::operator==(const ImageBase& image) const noexcept
{
return (fRawData == image.fRawData && fSize == image.fSize);
}

bool ImageBase::operator!=(const ImageBase& image) const noexcept
{
return !operator==(image);
}

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

END_NAMESPACE_DGL

+ 5
- 1
dgl/src/ImageWidgets.cpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -14,9 +14,13 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "../Image.hpp"
#include "Common.hpp"
#include "WidgetPrivateData.hpp"

// FIXME make this code more generic and move GL specific bits to OpenGL.cpp
#include "../OpenGL.hpp"

START_NAMESPACE_DGL

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


+ 20
- 1
dgl/src/NanoVG.cpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2018 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -124,6 +124,25 @@ DGL_EXT(PFNGLVERTEXATTRIBPOINTERPROC, glVertexAttribPointer)

START_NAMESPACE_DGL

// -----------------------------------------------------------------------
// DGL Color class conversion

Color::Color(const NVGcolor& c) noexcept
: red(c.r), green(c.g), blue(c.b), alpha(c.a)
{
fixBounds();
}

Color::operator NVGcolor() const noexcept
{
NVGcolor nc;
nc.r = red;
nc.g = green;
nc.b = blue;
nc.a = alpha;
return nc;
}

// -----------------------------------------------------------------------
// NanoImage



+ 157
- 0
dgl/src/OpenGL.cpp View File

@@ -0,0 +1,157 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "../Geometry.hpp"
#include "../OpenGL.hpp"

START_NAMESPACE_DGL

// -----------------------------------------------------------------------
// Line

template<typename T>
void Line<T>::draw()
{
DISTRHO_SAFE_ASSERT_RETURN(fPosStart != fPosEnd,);

glBegin(GL_LINES);

{
glVertex2d(fPosStart.fX, fPosStart.fY);
glVertex2d(fPosEnd.fX, fPosEnd.fY);
}

glEnd();
}

// -----------------------------------------------------------------------
// Circle

template<typename T>
void Circle<T>::_draw(const bool outline)
{
DISTRHO_SAFE_ASSERT_RETURN(fNumSegments >= 3 && fSize > 0.0f,);

double t, x = fSize, y = 0.0;

glBegin(outline ? GL_LINE_LOOP : GL_POLYGON);

for (uint i=0; i<fNumSegments; ++i)
{
glVertex2d(x + fPos.fX, y + fPos.fY);

t = x;
x = fCos * x - fSin * y;
y = fSin * t + fCos * y;
}

glEnd();
}

// -----------------------------------------------------------------------
// Triangle

template<typename T>
void Triangle<T>::_draw(const bool outline)
{
DISTRHO_SAFE_ASSERT_RETURN(fPos1 != fPos2 && fPos1 != fPos3,);

glBegin(outline ? GL_LINE_LOOP : GL_TRIANGLES);

{
glVertex2d(fPos1.fX, fPos1.fY);
glVertex2d(fPos2.fX, fPos2.fY);
glVertex2d(fPos3.fX, fPos3.fY);
}

glEnd();
}

// -----------------------------------------------------------------------
// Rectangle

template<