Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude more logic when compiling with librashader=false #1541

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions desktop-ui/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ sdl2 := true
local := true
lto := true
librashader := true
flags += -I. -I.. -I../ares -I../thirdparty -I../thirdparty/librashader/include -DMIA_LIBRARY
flags += -I. -I.. -I../ares -I../thirdparty -DMIA_LIBRARY

ifeq ($(librashader), true)
flags += -I../thirdparty/librashader/include
else
flags += -DNO_LIBRASHADER
endif

nall.path := ../nall
include $(nall.path)/GNUmakefile
Expand Down Expand Up @@ -37,13 +43,15 @@ tzxfile.path := $(thirdparty.path)/TZXFile
ymfm.path := $(thirdparty.path)/ymfm
include $(thirdparty.path)/GNUmakefile

ifeq ($(platform),macos)
librashader.path := $(thirdparty.path)/librashader/target/optimized/librashader.dylib
else ifeq ($(platform), windows)
ifneq ($(wildcard $(thirdparty.path)/librashader/target/aarch64-pc-windows-msvc/optimized/librashader.dll),)
librashader.path := $(thirdparty.path)/librashader/target/aarch64-pc-windows-msvc/optimized/librashader.dll
else
librashader.path := $(thirdparty.path)/librashader/target/optimized/librashader.dll
ifeq ($(librashader), true)
ifeq ($(platform),macos)
librashader.path := $(thirdparty.path)/librashader/target/optimized/librashader.dylib
else ifeq ($(platform), windows)
ifneq ($(wildcard $(thirdparty.path)/librashader/target/aarch64-pc-windows-msvc/optimized/librashader.dll),)
librashader.path := $(thirdparty.path)/librashader/target/aarch64-pc-windows-msvc/optimized/librashader.dll
else
librashader.path := $(thirdparty.path)/librashader/target/optimized/librashader.dll
endif
endif
endif

Expand Down Expand Up @@ -92,20 +100,18 @@ $(all.objects): | $(object.path)

all: output
ifneq ($(MAKECMDGOALS),clean)
ifeq ($(platform),macos)
ifeq ($(librashader), true)
ifeq ($(wildcard $(librashader.path)),)
$(error Tried to compile ares for macOS with librashader enabled, but no librashader library was found. Compile it with thirdparty/librashader/build-librashader.sh, or disable librashader by compiling ares with librashader=false)
endif
ares.dylibs += $(librashader.path)
ifeq ($(librashader), true)
ifeq ($(platform),macos)
ifeq ($(wildcard $(librashader.path)),)
$(error Tried to compile ares for macOS with librashader enabled, but no librashader library was found. Compile it with thirdparty/librashader/build-librashader.sh, or disable librashader by compiling ares with librashader=false)
endif
else ifeq ($(platform), windows)
ifeq ($(librashader), true)
ifeq ($(wildcard $(librashader.path)),)
$(error Tried to compile ares for Windows with librashader enabled, but no librashader library was found. Compile it with thirdparty/librashader/build-librashader.sh, or disable librashader by compiling ares with librashader=false)
endif
ares.dylibs += $(librashader.path)
else ifeq ($(platform), windows)
ifeq ($(wildcard $(librashader.path)),)
$(error Tried to compile ares for Windows with librashader enabled, but no librashader library was found. Compile it with thirdparty/librashader/build-librashader.sh, or disable librashader by compiling ares with librashader=false)
endif
endif
endif
endif
endif

output: $(all.objects) | $(output.path)
Expand Down
9 changes: 7 additions & 2 deletions desktop-ui/presentation/presentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,13 @@ auto Presentation::showIcon(bool visible) -> void {

auto Presentation::loadShaders() -> void {
videoShaderMenu.reset();
videoShaderMenu.setEnabled(ruby::video.hasShader());
if(!ruby::video.hasShader()) return;
#if !defined(NO_LIBRASHADER)
const auto hasShader = ruby::video.hasShader();
#else
const auto hasShader = false;
#endif
videoShaderMenu.setEnabled(hasShader);
if(!hasShader) return;

Group shaders;

Expand Down
9 changes: 6 additions & 3 deletions ruby/video/opengl/main.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#if defined(PLATFORM_MACOS)
#import <mach-o/dyld.h>
#endif
auto OpenGL::setShader(const string& pathname) -> void {
settings.reset();

auto OpenGL::setShader(const string& pathname) -> void {
#if !defined(NO_LIBRASHADER)
format = inputFormat;
filter = GL_NEAREST;
wrap = GL_CLAMP_TO_BORDER;
Expand Down Expand Up @@ -31,6 +31,7 @@ auto OpenGL::setShader(const string& pathname) -> void {
return;
}
}
#endif
}

auto OpenGL::clear() -> void {
Expand Down Expand Up @@ -66,7 +67,7 @@ auto OpenGL::output() -> void {
u32 x = (outputWidth - targetWidth) / 2;
u32 y = (outputHeight - targetHeight) / 2;

if(_chain != NULL) {
if(has_shader()) {
// Shader path: our intermediate framebuffer matches the output size
if(!framebuffer || framebufferWidth != outputWidth || framebufferHeight != outputHeight) {
if(framebuffer) {
Expand Down Expand Up @@ -122,6 +123,7 @@ auto OpenGL::initialize(const string& shader) -> bool {
glDisable(GL_STENCIL_TEST);
glEnable(GL_DITHER);

#if !defined(NO_LIBRASHADER)
_libra = librashader_load_instance();
if(!_libra.instance_loaded) {
print("OpenGL: Failed to load librashader: shaders will be disabled\n");
Expand All @@ -130,6 +132,7 @@ auto OpenGL::initialize(const string& shader) -> bool {
if(_libra.gl_init_context(resolveSymbol) != NULL) {
print("OpenGL: Failed to initialize librashader context: shaders will be disabled\n");
};
#endif

setShader(shader);
return initialized = true;
Expand Down
20 changes: 9 additions & 11 deletions ruby/video/opengl/opengl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

#include "bind.hpp"
#include "utility.hpp"
#include "librashader_ld.h"

#if !defined(NO_LIBRASHADER)
#include "librashader_ld.h"
#endif

struct OpenGL;

Expand Down Expand Up @@ -46,9 +49,14 @@ struct OpenGLSurface : OpenGLTexture {
GLuint framebufferHeight = 0;
u32* buffer = nullptr;

#if !defined(NO_LIBRASHADER)
libra_instance_t _libra;
libra_shader_preset_t _preset = NULL;
libra_gl_filter_chain_t _chain = NULL;
auto has_shader() { return _chain != NULL; };
#else
auto has_shader() const { return false; };
#endif
u32 frameCount = 0;
};

Expand All @@ -68,16 +76,6 @@ struct OpenGL : OpenGLSurface {
u32 outputY = 0;
u32 outputWidth = 0;
u32 outputHeight = 0;
struct Setting {
string name;
string value;
bool operator< (const Setting& source) const { return name < source.name; }
bool operator==(const Setting& source) const { return name == source.name; }
Setting() = default;
Setting(const string& name) : name(name) {}
Setting(const string& name, const string& value) : name(name), value(value) {}
};
set<Setting> settings;
bool initialized = false;
};

Expand Down
4 changes: 3 additions & 1 deletion ruby/video/opengl/surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ auto OpenGLSurface::render(u32 sourceWidth, u32 sourceHeight, u32 targetX, u32 t
glBindTexture(GL_TEXTURE_2D, texture);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

if(_chain != NULL) {
if(has_shader()) {
#if !defined(NO_LIBRASHADER)
libra_source_image_gl_t input = {texture, format, sourceWidth, sourceHeight};
libra_viewport_t viewport{(float)targetX, (float)targetY, targetWidth, targetHeight};
libra_output_framebuffer_gl_t output = {framebuffer, framebufferTexture, framebufferFormat};
Expand All @@ -35,6 +36,7 @@ auto OpenGLSurface::render(u32 sourceWidth, u32 sourceHeight, u32 targetX, u32 t
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, framebufferHeight, framebufferWidth, 0, 0, 0, framebufferWidth, framebufferHeight, GL_COLOR_BUFFER_BIT, filter);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
#endif
} else {
glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
Expand Down