Browse Source

Handle deprecated functions in core code

Signed-off-by: falkTX <falktx@falktx.com>
pull/272/head
falkTX 4 years ago
parent
commit
2e94757471
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
7 changed files with 80 additions and 46 deletions
  1. +4
    -0
      Makefile.base.mk
  2. +10
    -0
      dgl/ImageWidgets.hpp
  3. +2
    -0
      dgl/OpenGL.hpp
  4. +1
    -1
      dgl/src/ImageBaseWidgets.cpp
  5. +11
    -1
      dgl/src/ImageWidgets.cpp
  6. +52
    -41
      dgl/src/OpenGL.cpp
  7. +0
    -3
      tests/Makefile

+ 4
- 0
Makefile.base.mk View File

@@ -327,6 +327,10 @@ DGL_FLAGS += -DHAVE_VULKAN
VULKAN_FLAGS = $(shell $(PKG_CONFIG) --cflags vulkan) VULKAN_FLAGS = $(shell $(PKG_CONFIG) --cflags vulkan)
VULKAN_LIBS = $(shell $(PKG_CONFIG) --libs vulkan) VULKAN_LIBS = $(shell $(PKG_CONFIG) --libs vulkan)


ifneq ($(WINDOWS),true)
VULKAN_LIBS += -ldl
endif

endif endif


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


+ 10
- 0
dgl/ImageWidgets.hpp View File

@@ -21,6 +21,12 @@
#include "ImageBaseWidgets.hpp" #include "ImageBaseWidgets.hpp"
#include "SubWidget.hpp" #include "SubWidget.hpp"


// TODO switch to use templated image type after merging widget-related PRs
#if defined(__GNUC__) && (__GNUC__ >= 6)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

START_NAMESPACE_DGL START_NAMESPACE_DGL


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -241,4 +247,8 @@ private:


END_NAMESPACE_DGL END_NAMESPACE_DGL


#if defined(__GNUC__) && (__GNUC__ >= 6)
# pragma GCC diagnostic pop
#endif

#endif // DGL_IMAGE_WIDGETS_HPP_INCLUDED #endif // DGL_IMAGE_WIDGETS_HPP_INCLUDED

+ 2
- 0
dgl/OpenGL.hpp View File

@@ -198,6 +198,8 @@ public:
// FIXME this should not be needed // FIXME this should not be needed
inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format) inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format)
{ loadFromMemory(rawData, Size<uint>(w, h), format); }; { loadFromMemory(rawData, Size<uint>(w, h), format); };
inline void draw(const GraphicsContext& context)
{ drawAt(context, Point<int>(0, 0)); };
inline void drawAt(const GraphicsContext& context, int x, int y) inline void drawAt(const GraphicsContext& context, int x, int y)
{ drawAt(context, Point<int>(x, y)); }; { drawAt(context, Point<int>(x, y)); };




+ 1
- 1
dgl/src/ImageBaseWidgets.cpp View File

@@ -57,7 +57,7 @@ void ImageBaseAboutWindow<ImageType>::setImage(const ImageType& image)
template <class ImageType> template <class ImageType>
bool ImageBaseAboutWindow<ImageType>::onKeyboard(const KeyboardEvent& ev) bool ImageBaseAboutWindow<ImageType>::onKeyboard(const KeyboardEvent& ev)
{ {
if (ev.press && ev.key == kCharEscape)
if (ev.press && ev.key == kKeyEscape)
{ {
close(); close();
return true; return true;


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

@@ -20,9 +20,15 @@
#include "Common.hpp" #include "Common.hpp"
#include "WidgetPrivateData.hpp" #include "WidgetPrivateData.hpp"


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


// TODO switch to use templated image type after merging widget-related PRs
#if defined(__GNUC__) && (__GNUC__ >= 6)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

START_NAMESPACE_DGL START_NAMESPACE_DGL


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -946,3 +952,7 @@ bool ImageSwitch::onMouse(const MouseEvent& ev)
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


END_NAMESPACE_DGL END_NAMESPACE_DGL

#if defined(__GNUC__) && (__GNUC__ >= 6)
# pragma GCC diagnostic pop
#endif

+ 52
- 41
dgl/src/OpenGL.cpp View File

@@ -63,6 +63,7 @@ void Line<T>::draw(const GraphicsContext&, const T width)
drawLine<T>(posStart, posEnd); drawLine<T>(posStart, posEnd);
} }


// deprecated calls
template<typename T> template<typename T>
void Line<T>::draw() void Line<T>::draw()
{ {
@@ -122,6 +123,7 @@ void Circle<T>::drawOutline(const GraphicsContext&, const T lineWidth)
drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, true); drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, true);
} }


// deprecated calls
template<typename T> template<typename T>
void Circle<T>::draw() void Circle<T>::draw()
{ {
@@ -178,6 +180,7 @@ void Triangle<T>::drawOutline(const GraphicsContext&, const T lineWidth)
drawTriangle<T>(pos1, pos2, pos3, true); drawTriangle<T>(pos1, pos2, pos3, true);
} }


// deprecated calls
template<typename T> template<typename T>
void Triangle<T>::draw() void Triangle<T>::draw()
{ {
@@ -244,6 +247,7 @@ void Rectangle<T>::drawOutline(const GraphicsContext&, const T lineWidth)
drawRectangle<T>(*this, true); drawRectangle<T>(*this, true);
} }


// deprecated calls
template<typename T> template<typename T>
void Rectangle<T>::draw() void Rectangle<T>::draw()
{ {
@@ -312,6 +316,47 @@ static void setupOpenGLImage(const OpenGLImage& image, GLuint textureId)
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
} }


static void drawOpenGLImage(const OpenGLImage& image, const Point<int>& pos, const GLuint textureId, bool& setupCalled)
{
if (textureId == 0 || image.isInvalid())
return;

if (! setupCalled)
{
setupOpenGLImage(image, textureId);
setupCalled = true;
}

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureId);

glBegin(GL_QUADS);

{
const int x = pos.getX();
const int y = pos.getY();
const int w = static_cast<int>(image.getWidth());
const int h = static_cast<int>(image.getHeight());

glTexCoord2f(0.0f, 0.0f);
glVertex2d(x, y);

glTexCoord2f(1.0f, 0.0f);
glVertex2d(x+w, y);

glTexCoord2f(1.0f, 1.0f);
glVertex2d(x+w, y+h);

glTexCoord2f(0.0f, 1.0f);
glVertex2d(x, y+h);
}

glEnd();

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

OpenGLImage::OpenGLImage() OpenGLImage::OpenGLImage()
: ImageBase(), : ImageBase(),
textureId(0), textureId(0),
@@ -362,7 +407,7 @@ void OpenGLImage::loadFromMemory(const char* const rdata, const Size<uint>& s, c


void OpenGLImage::drawAt(const GraphicsContext&, const Point<int>& pos) void OpenGLImage::drawAt(const GraphicsContext&, const Point<int>& pos)
{ {
drawAt(pos);
drawOpenGLImage(*this, pos, textureId, setupCalled);
} }


OpenGLImage& OpenGLImage::operator=(const OpenGLImage& image) noexcept OpenGLImage& OpenGLImage::operator=(const OpenGLImage& image) noexcept
@@ -374,55 +419,20 @@ OpenGLImage& OpenGLImage::operator=(const OpenGLImage& image) noexcept
return *this; return *this;
} }


// deprecated calls
void OpenGLImage::draw() void OpenGLImage::draw()
{ {
drawAt(Point<int>(0, 0));
drawOpenGLImage(*this, Point<int>(0, 0), textureId, setupCalled);
} }


void OpenGLImage::drawAt(const int x, const int y) void OpenGLImage::drawAt(const int x, const int y)
{ {
drawAt(Point<int>(x, y));
drawOpenGLImage(*this, Point<int>(x, y), textureId, setupCalled);
} }


void OpenGLImage::drawAt(const Point<int>& pos) void OpenGLImage::drawAt(const Point<int>& pos)
{ {
if (textureId == 0 || isInvalid())
return;

if (! setupCalled)
{
setupOpenGLImage(*this, textureId);
setupCalled = true;
}

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureId);

glBegin(GL_QUADS);

{
const int x = pos.getX();
const int y = pos.getY();
const int w = static_cast<int>(size.getWidth());
const int h = static_cast<int>(size.getHeight());

glTexCoord2f(0.0f, 0.0f);
glVertex2d(x, y);

glTexCoord2f(1.0f, 0.0f);
glVertex2d(x+w, y);

glTexCoord2f(1.0f, 1.0f);
glVertex2d(x+w, y+h);

glTexCoord2f(0.0f, 1.0f);
glVertex2d(x, y+h);
}

glEnd();

glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
drawOpenGLImage(*this, pos, textureId, setupCalled);
} }


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -430,7 +440,8 @@ void OpenGLImage::drawAt(const Point<int>& pos)
template <> template <>
void ImageBaseAboutWindow<OpenGLImage>::onDisplay() void ImageBaseAboutWindow<OpenGLImage>::onDisplay()
{ {
img.draw();
const GraphicsContext& context(getGraphicsContext());
img.draw(context);
} }


template class ImageBaseAboutWindow<OpenGLImage>; template class ImageBaseAboutWindow<OpenGLImage>;


+ 0
- 3
tests/Makefile View File

@@ -4,9 +4,6 @@
# Created by falkTX # Created by falkTX
# #


# debug mode by default
DEBUG=true

include ../Makefile.base.mk include ../Makefile.base.mk


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


Loading…
Cancel
Save