diff --git a/Makefile.plugins.mk b/Makefile.plugins.mk index ffa3d015..3bc341b9 100644 --- a/Makefile.plugins.mk +++ b/Makefile.plugins.mk @@ -213,6 +213,18 @@ HAVE_DGL = false 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 ($(HAVE_VULKAN),true) DGL_FLAGS += -DDGL_VULKAN -DHAVE_DGL @@ -313,6 +325,9 @@ $(DPF_PATH)/build/libdgl-cairo.a: $(DPF_PATH)/build/libdgl-opengl.a: $(MAKE) -C $(DPF_PATH)/dgl opengl +$(DPF_PATH)/build/libdgl-opengl3.a: + $(MAKE) -C $(DPF_PATH)/dgl opengl3 + $(DPF_PATH)/build/libdgl-stub.a: $(MAKE) -C $(DPF_PATH)/dgl stub diff --git a/dgl/Makefile b/dgl/Makefile index 6eb1d192..893e34ee 100644 --- a/dgl/Makefile +++ b/dgl/Makefile @@ -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) ifeq ($(MACOS),true) @@ -112,10 +124,11 @@ endif 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)$(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) -@mkdir -p ../build @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 -@mkdir -p ../build/dgl @echo "Compiling $< (Vulkan variant)" @@ -214,6 +245,7 @@ debug: -include $(OBJS_common:%.o=%.d) -include $(OBJS_cairo:%.o=%.d) -include $(OBJS_opengl:%.o=%.d) +-include $(OBJS_opengl3:%.o=%.d) -include $(OBJS_stub:%.o=%.d) -include $(OBJS_vulkan:%.o=%.d) diff --git a/dgl/src/OpenGL.cpp b/dgl/src/OpenGL.cpp index 145c315c..0992cc32 100644 --- a/dgl/src/OpenGL.cpp +++ b/dgl/src/OpenGL.cpp @@ -33,6 +33,15 @@ START_NAMESPACE_DGL +// ----------------------------------------------------------------------- + +#ifdef DGL_USE_OPENGL3 +static void notImplemented(const char* const name) +{ + d_stderr2("OpenGL3 function not implemented: %s", name); +} +#endif + // ----------------------------------------------------------------------- // Color @@ -43,18 +52,22 @@ void Color::setFor(const GraphicsContext&, const bool includeAlpha) glColor4f(red, green, blue, alpha); else glColor3f(red, green, blue); +#else + notImplemented("Color::setFor"); + // unused + (void)includeAlpha; #endif } // ----------------------------------------------------------------------- // Line +#ifndef DGL_USE_OPENGL3 template static void drawLine(const Point& posStart, const Point& posEnd) { DISTRHO_SAFE_ASSERT_RETURN(posStart != posEnd,); -#ifndef DGL_USE_OPENGL3 glBegin(GL_LINES); { @@ -63,23 +76,31 @@ static void drawLine(const Point& posStart, const Point& posEnd) } glEnd(); -#endif } +#endif template void Line::draw(const GraphicsContext&, const T width) { +#ifndef DGL_USE_OPENGL3 DISTRHO_SAFE_ASSERT_RETURN(width != 0,); glLineWidth(static_cast(width)); drawLine(posStart, posEnd); +#else + notImplemented("Line::draw"); +#endif } // deprecated calls template void Line::draw() { +#ifndef DGL_USE_OPENGL3 drawLine(posStart, posEnd); +#else + notImplemented("Line::draw"); +#endif } template class Line; @@ -92,6 +113,7 @@ template class Line; // ----------------------------------------------------------------------- // Circle +#ifndef DGL_USE_OPENGL3 template static void drawCircle(const Point& pos, const uint numSegments, @@ -106,7 +128,6 @@ static void drawCircle(const Point& pos, const T origy = pos.getY(); double t, x = size, y = 0.0; -#ifndef DGL_USE_OPENGL3 glBegin(outline ? GL_LINE_LOOP : GL_POLYGON); for (uint i=0; i& pos, } glEnd(); -#endif } +#endif template void Circle::draw(const GraphicsContext&) { +#ifndef DGL_USE_OPENGL3 drawCircle(fPos, fNumSegments, fSize, fSin, fCos, false); +#else + notImplemented("Circle::draw"); +#endif } template @@ -134,20 +159,32 @@ void Circle::drawOutline(const GraphicsContext&, const T lineWidth) DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); glLineWidth(static_cast(lineWidth)); +#ifndef DGL_USE_OPENGL3 drawCircle(fPos, fNumSegments, fSize, fSin, fCos, true); +#else + notImplemented("Circle::drawOutline"); +#endif } // deprecated calls template void Circle::draw() { +#ifndef DGL_USE_OPENGL3 drawCircle(fPos, fNumSegments, fSize, fSin, fCos, false); +#else + notImplemented("Circle::draw"); +#endif } template void Circle::drawOutline() { +#ifndef DGL_USE_OPENGL3 drawCircle(fPos, fNumSegments, fSize, fSin, fCos, true); +#else + notImplemented("Circle::drawOutline"); +#endif } template class Circle; @@ -160,6 +197,7 @@ template class Circle; // ----------------------------------------------------------------------- // Triangle +#ifndef DGL_USE_OPENGL3 template static void drawTriangle(const Point& pos1, const Point& pos2, @@ -168,7 +206,6 @@ static void drawTriangle(const Point& pos1, { DISTRHO_SAFE_ASSERT_RETURN(pos1 != pos2 && pos1 != pos3,); -#ifndef DGL_USE_OPENGL3 glBegin(outline ? GL_LINE_LOOP : GL_TRIANGLES); { @@ -178,13 +215,17 @@ static void drawTriangle(const Point& pos1, } glEnd(); -#endif } +#endif template void Triangle::draw(const GraphicsContext&) { +#ifndef DGL_USE_OPENGL3 drawTriangle(pos1, pos2, pos3, false); +#else + notImplemented("Triangle::draw"); +#endif } template @@ -193,20 +234,32 @@ void Triangle::drawOutline(const GraphicsContext&, const T lineWidth) DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); glLineWidth(static_cast(lineWidth)); +#ifndef DGL_USE_OPENGL3 drawTriangle(pos1, pos2, pos3, true); +#else + notImplemented("Triangle::drawOutline"); +#endif } // deprecated calls template void Triangle::draw() { +#ifndef DGL_USE_OPENGL3 drawTriangle(pos1, pos2, pos3, false); +#else + notImplemented("Triangle::draw"); +#endif } template void Triangle::drawOutline() { +#ifndef DGL_USE_OPENGL3 drawTriangle(pos1, pos2, pos3, true); +#else + notImplemented("Triangle::drawOutline"); +#endif } template class Triangle; @@ -219,12 +272,12 @@ template class Triangle; // ----------------------------------------------------------------------- // Rectangle +#ifndef DGL_USE_OPENGL3 template static void drawRectangle(const Rectangle& rect, const bool outline) { DISTRHO_SAFE_ASSERT_RETURN(rect.isValid(),); -#ifndef DGL_USE_OPENGL3 glBegin(outline ? GL_LINE_LOOP : GL_QUADS); { @@ -247,13 +300,17 @@ static void drawRectangle(const Rectangle& rect, const bool outline) } glEnd(); -#endif } +#endif template void Rectangle::draw(const GraphicsContext&) { +#ifndef DGL_USE_OPENGL3 drawRectangle(*this, false); +#else + notImplemented("Rectangle::draw"); +#endif } template @@ -262,20 +319,32 @@ void Rectangle::drawOutline(const GraphicsContext&, const T lineWidth) DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); glLineWidth(static_cast(lineWidth)); +#ifndef DGL_USE_OPENGL3 drawRectangle(*this, true); +#else + notImplemented("Rectangle::drawOutline"); +#endif } // deprecated calls template void Rectangle::draw() { +#ifndef DGL_USE_OPENGL3 drawRectangle(*this, false); +#else + notImplemented("Rectangle::draw"); +#endif } template void Rectangle::drawOutline() { +#ifndef DGL_USE_OPENGL3 drawRectangle(*this, true); +#else + notImplemented("Rectangle::drawOutline"); +#endif } template class Rectangle; @@ -542,29 +611,33 @@ void ImageBaseKnob::onDisplay() pData->isReady = true; } -#ifndef DGL_USE_OPENGL3 const int w = static_cast(getWidth()); const int h = static_cast(getHeight()); if (pData->rotationAngle != 0) { +#ifndef DGL_USE_OPENGL3 glPushMatrix(); +#endif const int w2 = w/2; const int h2 = h/2; +#ifndef DGL_USE_OPENGL3 glTranslatef(static_cast(w2), static_cast(h2), 0.0f); glRotatef(normValue*static_cast(pData->rotationAngle), 0.0f, 0.0f, 1.0f); +#endif Rectangle(-w2, -h2, w, h).draw(context); +#ifndef DGL_USE_OPENGL3 glPopMatrix(); +#endif } else { Rectangle(0, 0, w, h).draw(context); } -#endif glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D);