Support fully headless builds
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
79e74ef909
commit
a00020e597
14 changed files with 175 additions and 61 deletions
|
@ -15,16 +15,23 @@
|
|||
* For a full copy of the GNU General Public License see the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef HEADLESS
|
||||
#include "OpenGL.hpp"
|
||||
#endif
|
||||
|
||||
#include "src/nanovg/nanovg.h"
|
||||
|
||||
#define NANOVG_GL2_IMPLEMENTATION
|
||||
// #define NANOVG_GLES2_IMPLEMENTATION
|
||||
#include "src/nanovg/nanovg_gl.h"
|
||||
|
||||
#define NANOVG_FBO_VALID 1
|
||||
#include "src/nanovg/nanovg_gl_utils.h"
|
||||
#ifdef HEADLESS
|
||||
struct NVGLUframebuffer;
|
||||
void nvgluBindFramebuffer(NVGLUframebuffer* fb) {}
|
||||
NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h, int imageFlags) { return nullptr; }
|
||||
void nvgluDeleteFramebuffer(NVGLUframebuffer* fb) {}
|
||||
#else
|
||||
# define NANOVG_GLES2_IMPLEMENTATION
|
||||
# define NANOVG_FBO_VALID 1
|
||||
# include "src/nanovg/nanovg_gl.h"
|
||||
# include "src/nanovg/nanovg_gl_utils.h"
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 6)
|
||||
# pragma GCC diagnostic push
|
||||
|
@ -38,18 +45,6 @@
|
|||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// typedef struct NVGLUframebuffer {
|
||||
// NVGcontext* ctx;
|
||||
// GLuint fbo;
|
||||
// GLuint rbo;
|
||||
// GLuint texture;
|
||||
// int image;
|
||||
// } NVGLUframebuffer;
|
||||
//
|
||||
// void nvgluBindFramebuffer(NVGLUframebuffer* fb) {}
|
||||
// NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h, int imageFlags) { return nullptr; }
|
||||
// void nvgluDeleteFramebuffer(NVGLUframebuffer* fb) {}
|
||||
|
||||
#define GLFWAPI
|
||||
|
||||
extern "C" {
|
||||
|
@ -63,5 +58,7 @@ GLFWAPI int glfwGetKeyScancode(int key) { return 0; }
|
|||
|
||||
}
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "../src/Rack/dep/glfw/deps/stb_image_write.h"
|
||||
#ifndef HEADLESS
|
||||
# define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
# include "../src/Rack/dep/glfw/deps/stb_image_write.h"
|
||||
#endif
|
||||
|
|
|
@ -25,15 +25,10 @@
|
|||
* the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#define NANOVG_GL2 1
|
||||
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
|
||||
#include "../src/Rack/dep/glfw/deps/stb_image_write.h"
|
||||
#include <GL/osmesa.h>
|
||||
|
||||
#include <window/Window.hpp>
|
||||
#include <asset.hpp>
|
||||
#include <widget/Widget.hpp>
|
||||
|
@ -49,9 +44,24 @@
|
|||
#endif
|
||||
|
||||
#include "DistrhoPlugin.hpp"
|
||||
#include "extra/Thread.hpp"
|
||||
#include "../WindowParameters.hpp"
|
||||
|
||||
#ifndef HEADLESS
|
||||
# include "../src/Rack/dep/glfw/deps/stb_image_write.h"
|
||||
# include "extra/Thread.hpp"
|
||||
# include <GL/osmesa.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HEADLESS
|
||||
namespace rack {
|
||||
namespace app {
|
||||
widget::Widget* createMenuBar() { return new widget::Widget; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
namespace rack {
|
||||
namespace window {
|
||||
|
||||
|
@ -103,14 +113,20 @@ struct WindowParams {
|
|||
float rackBrightness = 1.0f;
|
||||
};
|
||||
|
||||
struct Window::Internal : public Thread {
|
||||
struct Window::Internal
|
||||
#ifndef HEADLESS
|
||||
: public Thread
|
||||
#endif
|
||||
{
|
||||
DISTRHO_NAMESPACE::Plugin* plugin = nullptr;
|
||||
DISTRHO_NAMESPACE::WindowParameters params;
|
||||
DISTRHO_NAMESPACE::WindowParametersCallback* callback = nullptr;
|
||||
Context* context = nullptr;
|
||||
Window* self = nullptr;
|
||||
#ifndef HEADLESS
|
||||
OSMesaContext mesa = nullptr;
|
||||
GLubyte* mesaBuffer = nullptr;
|
||||
#endif
|
||||
|
||||
math::Vec size = minWindowSize;
|
||||
std::string lastWindowTitle;
|
||||
|
@ -127,6 +143,7 @@ struct Window::Internal : public Thread {
|
|||
|
||||
bool fbDirtyOnSubpixelChange = true;
|
||||
|
||||
#ifndef HEADLESS
|
||||
void run() override {
|
||||
self->run();
|
||||
int i=0;
|
||||
|
@ -146,6 +163,7 @@ struct Window::Internal : public Thread {
|
|||
}
|
||||
d_stdout("thread quit");
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
Window::Window() {
|
||||
|
@ -154,6 +172,7 @@ Window::Window() {
|
|||
internal->self = this;
|
||||
}
|
||||
|
||||
#ifndef HEADLESS
|
||||
static void flipBitmap(uint8_t* pixels, int width, int height, int depth) {
|
||||
for (int y = 0; y < height / 2; y++) {
|
||||
int flipY = height - y - 1;
|
||||
|
@ -163,11 +182,13 @@ static void flipBitmap(uint8_t* pixels, int width, int height, int depth) {
|
|||
std::memcpy(&pixels[flipY * width * depth], tmp, width * depth);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void WindowInit(Window* const window, DISTRHO_NAMESPACE::Plugin* const plugin)
|
||||
{
|
||||
window->internal->plugin = plugin;
|
||||
|
||||
#ifndef HEADLESS
|
||||
window->internal->mesa = OSMesaCreateContextExt(OSMESA_RGBA, 24, 8, 0, nullptr);
|
||||
DISTRHO_SAFE_ASSERT_RETURN(window->internal->mesa != nullptr,);
|
||||
|
||||
|
@ -196,6 +217,7 @@ void WindowInit(Window* const window, DISTRHO_NAMESPACE::Plugin* const plugin)
|
|||
// window->vg = nvgCreateGLES2(nvgFlags);
|
||||
// window->fbVg = nvgCreateSharedGLES2(window->vg, nvgFlags);
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
// Load default Blendish font
|
||||
window->uiFont = window->loadFont(asset::system("res/fonts/DejaVuSans.ttf"));
|
||||
|
@ -210,6 +232,7 @@ void WindowInit(Window* const window, DISTRHO_NAMESPACE::Plugin* const plugin)
|
|||
APP->scene->onContextCreate(e);
|
||||
}
|
||||
|
||||
#ifndef HEADLESS
|
||||
d_stdout("all good with mesa and GL? %d | %p %p %p", ok, window->internal->mesa, window->vg, window->fbVg);
|
||||
// window->internal->startThread();
|
||||
|
||||
|
@ -277,6 +300,7 @@ void WindowInit(Window* const window, DISTRHO_NAMESPACE::Plugin* const plugin)
|
|||
delete[] pixels;
|
||||
|
||||
d_stdout("idle - after png");
|
||||
#endif
|
||||
}
|
||||
|
||||
void WindowMods(Window* const window, const int mods)
|
||||
|
@ -296,6 +320,7 @@ Window::~Window() {
|
|||
internal->fontCache.clear();
|
||||
internal->imageCache.clear();
|
||||
|
||||
#ifndef HEADLESS
|
||||
// #if defined NANOVG_GL2
|
||||
nvgDeleteGL2(vg);
|
||||
nvgDeleteGL2(fbVg);
|
||||
|
@ -310,6 +335,8 @@ Window::~Window() {
|
|||
OSMesaDestroyContext(internal->mesa);
|
||||
|
||||
delete[] internal->mesaBuffer;
|
||||
#endif
|
||||
|
||||
delete internal;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,16 @@
|
|||
* For a full copy of the GNU General Public License see the LICENSE file.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is an edited version of VCVRack's common.cpp
|
||||
* Copyright (C) 2016-2021 VCV.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <common.hpp>
|
||||
#include <string.hpp>
|
||||
|
||||
|
|
|
@ -8,6 +8,16 @@
|
|||
|
||||
#include "DistrhoPluginUtils.hpp"
|
||||
|
||||
/**
|
||||
* This file is an edited version of VCVRack's context.cpp
|
||||
* Copyright (C) 2016-2021 VCV.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
namespace rack {
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* For a full copy of the GNU General Public License see the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "OpenGL.hpp"
|
||||
#include <cstdio>
|
||||
|
||||
// fix blendish build, missing symbol in debug mode
|
||||
#ifdef DEBUG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue