Browse Source

Add opengl3 as a possible build type

Signed-off-by: falkTX <falktx@falktx.com>
pull/365/head
falkTX 3 years ago
parent
commit
9236640093
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 134 additions and 14 deletions
  1. +15
    -0
      Makefile.plugins.mk
  2. +36
    -4
      dgl/Makefile
  3. +83
    -10
      dgl/src/OpenGL.cpp

+ 15
- 0
Makefile.plugins.mk View File

@@ -213,6 +213,18 @@ HAVE_DGL = false
endif endif
endif endif


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

ifeq ($(UI_TYPE),vulkan) ifeq ($(UI_TYPE),vulkan)
ifeq ($(HAVE_VULKAN),true) ifeq ($(HAVE_VULKAN),true)
DGL_FLAGS += -DDGL_VULKAN -DHAVE_DGL DGL_FLAGS += -DDGL_VULKAN -DHAVE_DGL
@@ -313,6 +325,9 @@ $(DPF_PATH)/build/libdgl-cairo.a:
$(DPF_PATH)/build/libdgl-opengl.a: $(DPF_PATH)/build/libdgl-opengl.a:
$(MAKE) -C $(DPF_PATH)/dgl opengl $(MAKE) -C $(DPF_PATH)/dgl opengl


$(DPF_PATH)/build/libdgl-opengl3.a:
$(MAKE) -C $(DPF_PATH)/dgl opengl3

$(DPF_PATH)/build/libdgl-stub.a: $(DPF_PATH)/build/libdgl-stub.a:
$(MAKE) -C $(DPF_PATH)/dgl stub $(MAKE) -C $(DPF_PATH)/dgl stub




+ 36
- 4
dgl/Makefile View File

@@ -69,6 +69,18 @@ endif


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


OBJS_opengl3 = $(OBJS_common) \
../build/dgl/OpenGL.cpp.opengl3.o \
../build/dgl/NanoVG.cpp.opengl3.o

ifeq ($(MACOS),true)
OBJS_opengl3 += ../build/dgl/pugl.mm.opengl3.o
else
OBJS_opengl3 += ../build/dgl/pugl.cpp.opengl3.o
endif

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

OBJS_stub = $(OBJS_common) OBJS_stub = $(OBJS_common)


ifeq ($(MACOS),true) ifeq ($(MACOS),true)
@@ -112,10 +124,11 @@ endif


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


cairo: ../build/libdgl-cairo.a
opengl: ../build/libdgl-opengl.a
stub: ../build/libdgl-stub.a
vulkan: ../build/libdgl-vulkan.a
cairo: ../build/libdgl-cairo.a
opengl: ../build/libdgl-opengl.a
opengl3: ../build/libdgl-opengl3.a
stub: ../build/libdgl-stub.a
vulkan: ../build/libdgl-vulkan.a


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


@@ -131,6 +144,12 @@ vulkan: ../build/libdgl-vulkan.a
$(SILENT)rm -f $@ $(SILENT)rm -f $@
$(SILENT)$(AR) crs $@ $^ $(SILENT)$(AR) crs $@ $^


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

../build/libdgl-stub.a: $(OBJS_stub) ../build/libdgl-stub.a: $(OBJS_stub)
-@mkdir -p ../build -@mkdir -p ../build
@echo "Creating libdgl-stub.a" @echo "Creating libdgl-stub.a"
@@ -191,6 +210,18 @@ vulkan: ../build/libdgl-vulkan.a


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


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

../build/dgl/%.mm.opengl3.o: src/%.mm
-@mkdir -p ../build/dgl
@echo "Compiling $< (OpenGL variant)"
$(SILENT)$(CXX) $< $(BUILD_CXX_FLAGS) $(OPENGL_FLAGS) -DDGL_OPENGL -DDGL_USE_OPENGL3 -c -ObjC++ -o $@

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

../build/dgl/%.cpp.vulkan.o: src/%.cpp ../build/dgl/%.cpp.vulkan.o: src/%.cpp
-@mkdir -p ../build/dgl -@mkdir -p ../build/dgl
@echo "Compiling $< (Vulkan variant)" @echo "Compiling $< (Vulkan variant)"
@@ -214,6 +245,7 @@ debug:
-include $(OBJS_common:%.o=%.d) -include $(OBJS_common:%.o=%.d)
-include $(OBJS_cairo:%.o=%.d) -include $(OBJS_cairo:%.o=%.d)
-include $(OBJS_opengl:%.o=%.d) -include $(OBJS_opengl:%.o=%.d)
-include $(OBJS_opengl3:%.o=%.d)
-include $(OBJS_stub:%.o=%.d) -include $(OBJS_stub:%.o=%.d)
-include $(OBJS_vulkan:%.o=%.d) -include $(OBJS_vulkan:%.o=%.d)




+ 83
- 10
dgl/src/OpenGL.cpp View File

@@ -33,6 +33,15 @@


START_NAMESPACE_DGL START_NAMESPACE_DGL


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

#ifdef DGL_USE_OPENGL3
static void notImplemented(const char* const name)
{
d_stderr2("OpenGL3 function not implemented: %s", name);
}
#endif

// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// Color // Color


@@ -43,18 +52,22 @@ void Color::setFor(const GraphicsContext&, const bool includeAlpha)
glColor4f(red, green, blue, alpha); glColor4f(red, green, blue, alpha);
else else
glColor3f(red, green, blue); glColor3f(red, green, blue);
#else
notImplemented("Color::setFor");
// unused
(void)includeAlpha;
#endif #endif
} }


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


#ifndef DGL_USE_OPENGL3
template<typename T> template<typename T>
static void drawLine(const Point<T>& posStart, const Point<T>& posEnd) static void drawLine(const Point<T>& posStart, const Point<T>& posEnd)
{ {
DISTRHO_SAFE_ASSERT_RETURN(posStart != posEnd,); DISTRHO_SAFE_ASSERT_RETURN(posStart != posEnd,);


#ifndef DGL_USE_OPENGL3
glBegin(GL_LINES); glBegin(GL_LINES);


{ {
@@ -63,23 +76,31 @@ static void drawLine(const Point<T>& posStart, const Point<T>& posEnd)
} }


glEnd(); glEnd();
#endif
} }
#endif


template<typename T> template<typename T>
void Line<T>::draw(const GraphicsContext&, const T width) void Line<T>::draw(const GraphicsContext&, const T width)
{ {
#ifndef DGL_USE_OPENGL3
DISTRHO_SAFE_ASSERT_RETURN(width != 0,); DISTRHO_SAFE_ASSERT_RETURN(width != 0,);


glLineWidth(static_cast<GLfloat>(width)); glLineWidth(static_cast<GLfloat>(width));
drawLine<T>(posStart, posEnd); drawLine<T>(posStart, posEnd);
#else
notImplemented("Line::draw");
#endif
} }


// deprecated calls // deprecated calls
template<typename T> template<typename T>
void Line<T>::draw() void Line<T>::draw()
{ {
#ifndef DGL_USE_OPENGL3
drawLine<T>(posStart, posEnd); drawLine<T>(posStart, posEnd);
#else
notImplemented("Line::draw");
#endif
} }


template class Line<double>; template class Line<double>;
@@ -92,6 +113,7 @@ template class Line<ushort>;
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// Circle // Circle


#ifndef DGL_USE_OPENGL3
template<typename T> template<typename T>
static void drawCircle(const Point<T>& pos, static void drawCircle(const Point<T>& pos,
const uint numSegments, const uint numSegments,
@@ -106,7 +128,6 @@ static void drawCircle(const Point<T>& pos,
const T origy = pos.getY(); const T origy = pos.getY();
double t, x = size, y = 0.0; double t, x = size, y = 0.0;


#ifndef DGL_USE_OPENGL3
glBegin(outline ? GL_LINE_LOOP : GL_POLYGON); glBegin(outline ? GL_LINE_LOOP : GL_POLYGON);


for (uint i=0; i<numSegments; ++i) for (uint i=0; i<numSegments; ++i)
@@ -119,13 +140,17 @@ static void drawCircle(const Point<T>& pos,
} }


glEnd(); glEnd();
#endif
} }
#endif


template<typename T> template<typename T>
void Circle<T>::draw(const GraphicsContext&) void Circle<T>::draw(const GraphicsContext&)
{ {
#ifndef DGL_USE_OPENGL3
drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, false); drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, false);
#else
notImplemented("Circle::draw");
#endif
} }


template<typename T> template<typename T>
@@ -134,20 +159,32 @@ void Circle<T>::drawOutline(const GraphicsContext&, const T lineWidth)
DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,);


glLineWidth(static_cast<GLfloat>(lineWidth)); glLineWidth(static_cast<GLfloat>(lineWidth));
#ifndef DGL_USE_OPENGL3
drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, true); drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, true);
#else
notImplemented("Circle::drawOutline");
#endif
} }


// deprecated calls // deprecated calls
template<typename T> template<typename T>
void Circle<T>::draw() void Circle<T>::draw()
{ {
#ifndef DGL_USE_OPENGL3
drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, false); drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, false);
#else
notImplemented("Circle::draw");
#endif
} }


template<typename T> template<typename T>
void Circle<T>::drawOutline() void Circle<T>::drawOutline()
{ {
#ifndef DGL_USE_OPENGL3
drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, true); drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, true);
#else
notImplemented("Circle::drawOutline");
#endif
} }


template class Circle<double>; template class Circle<double>;
@@ -160,6 +197,7 @@ template class Circle<ushort>;
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// Triangle // Triangle


#ifndef DGL_USE_OPENGL3
template<typename T> template<typename T>
static void drawTriangle(const Point<T>& pos1, static void drawTriangle(const Point<T>& pos1,
const Point<T>& pos2, const Point<T>& pos2,
@@ -168,7 +206,6 @@ static void drawTriangle(const Point<T>& pos1,
{ {
DISTRHO_SAFE_ASSERT_RETURN(pos1 != pos2 && pos1 != pos3,); DISTRHO_SAFE_ASSERT_RETURN(pos1 != pos2 && pos1 != pos3,);


#ifndef DGL_USE_OPENGL3
glBegin(outline ? GL_LINE_LOOP : GL_TRIANGLES); glBegin(outline ? GL_LINE_LOOP : GL_TRIANGLES);


{ {
@@ -178,13 +215,17 @@ static void drawTriangle(const Point<T>& pos1,
} }


glEnd(); glEnd();
#endif
} }
#endif


template<typename T> template<typename T>
void Triangle<T>::draw(const GraphicsContext&) void Triangle<T>::draw(const GraphicsContext&)
{ {
#ifndef DGL_USE_OPENGL3
drawTriangle<T>(pos1, pos2, pos3, false); drawTriangle<T>(pos1, pos2, pos3, false);
#else
notImplemented("Triangle::draw");
#endif
} }


template<typename T> template<typename T>
@@ -193,20 +234,32 @@ void Triangle<T>::drawOutline(const GraphicsContext&, const T lineWidth)
DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,);


glLineWidth(static_cast<GLfloat>(lineWidth)); glLineWidth(static_cast<GLfloat>(lineWidth));
#ifndef DGL_USE_OPENGL3
drawTriangle<T>(pos1, pos2, pos3, true); drawTriangle<T>(pos1, pos2, pos3, true);
#else
notImplemented("Triangle::drawOutline");
#endif
} }


// deprecated calls // deprecated calls
template<typename T> template<typename T>
void Triangle<T>::draw() void Triangle<T>::draw()
{ {
#ifndef DGL_USE_OPENGL3
drawTriangle<T>(pos1, pos2, pos3, false); drawTriangle<T>(pos1, pos2, pos3, false);
#else
notImplemented("Triangle::draw");
#endif
} }


template<typename T> template<typename T>
void Triangle<T>::drawOutline() void Triangle<T>::drawOutline()
{ {
#ifndef DGL_USE_OPENGL3
drawTriangle<T>(pos1, pos2, pos3, true); drawTriangle<T>(pos1, pos2, pos3, true);
#else
notImplemented("Triangle::drawOutline");
#endif
} }


template class Triangle<double>; template class Triangle<double>;
@@ -219,12 +272,12 @@ template class Triangle<ushort>;
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// Rectangle // Rectangle


#ifndef DGL_USE_OPENGL3
template<typename T> template<typename T>
static void drawRectangle(const Rectangle<T>& rect, const bool outline) static void drawRectangle(const Rectangle<T>& rect, const bool outline)
{ {
DISTRHO_SAFE_ASSERT_RETURN(rect.isValid(),); DISTRHO_SAFE_ASSERT_RETURN(rect.isValid(),);


#ifndef DGL_USE_OPENGL3
glBegin(outline ? GL_LINE_LOOP : GL_QUADS); glBegin(outline ? GL_LINE_LOOP : GL_QUADS);


{ {
@@ -247,13 +300,17 @@ static void drawRectangle(const Rectangle<T>& rect, const bool outline)
} }


glEnd(); glEnd();
#endif
} }
#endif


template<typename T> template<typename T>
void Rectangle<T>::draw(const GraphicsContext&) void Rectangle<T>::draw(const GraphicsContext&)
{ {
#ifndef DGL_USE_OPENGL3
drawRectangle<T>(*this, false); drawRectangle<T>(*this, false);
#else
notImplemented("Rectangle::draw");
#endif
} }


template<typename T> template<typename T>
@@ -262,20 +319,32 @@ void Rectangle<T>::drawOutline(const GraphicsContext&, const T lineWidth)
DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,);


glLineWidth(static_cast<GLfloat>(lineWidth)); glLineWidth(static_cast<GLfloat>(lineWidth));
#ifndef DGL_USE_OPENGL3
drawRectangle<T>(*this, true); drawRectangle<T>(*this, true);
#else
notImplemented("Rectangle::drawOutline");
#endif
} }


// deprecated calls // deprecated calls
template<typename T> template<typename T>
void Rectangle<T>::draw() void Rectangle<T>::draw()
{ {
#ifndef DGL_USE_OPENGL3
drawRectangle<T>(*this, false); drawRectangle<T>(*this, false);
#else
notImplemented("Rectangle::draw");
#endif
} }


template<typename T> template<typename T>
void Rectangle<T>::drawOutline() void Rectangle<T>::drawOutline()
{ {
#ifndef DGL_USE_OPENGL3
drawRectangle<T>(*this, true); drawRectangle<T>(*this, true);
#else
notImplemented("Rectangle::drawOutline");
#endif
} }


template class Rectangle<double>; template class Rectangle<double>;
@@ -542,29 +611,33 @@ void ImageBaseKnob<OpenGLImage>::onDisplay()
pData->isReady = true; pData->isReady = true;
} }


#ifndef DGL_USE_OPENGL3
const int w = static_cast<int>(getWidth()); const int w = static_cast<int>(getWidth());
const int h = static_cast<int>(getHeight()); const int h = static_cast<int>(getHeight());


if (pData->rotationAngle != 0) if (pData->rotationAngle != 0)
{ {
#ifndef DGL_USE_OPENGL3
glPushMatrix(); glPushMatrix();
#endif


const int w2 = w/2; const int w2 = w/2;
const int h2 = h/2; const int h2 = h/2;


#ifndef DGL_USE_OPENGL3
glTranslatef(static_cast<float>(w2), static_cast<float>(h2), 0.0f); glTranslatef(static_cast<float>(w2), static_cast<float>(h2), 0.0f);
glRotatef(normValue*static_cast<float>(pData->rotationAngle), 0.0f, 0.0f, 1.0f); glRotatef(normValue*static_cast<float>(pData->rotationAngle), 0.0f, 0.0f, 1.0f);
#endif


Rectangle<int>(-w2, -h2, w, h).draw(context); Rectangle<int>(-w2, -h2, w, h).draw(context);


#ifndef DGL_USE_OPENGL3
glPopMatrix(); glPopMatrix();
#endif
} }
else else
{ {
Rectangle<int>(0, 0, w, h).draw(context); Rectangle<int>(0, 0, w, h).draw(context);
} }
#endif


glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);


Loading…
Cancel
Save