apegat de mala manera els shaders del CCAE i fets uns apanyets per a vore si compila
This commit is contained in:
@@ -9,14 +9,14 @@
|
||||
#include <iterator> // Para istreambuf_iterator, operator==
|
||||
#include <string> // Para char_traits, string, operator+, operator==
|
||||
|
||||
#include "asset.h" // Para Asset, AssetType
|
||||
#include "external/jail_shader.h" // Para init, render
|
||||
#include "mouse.h" // Para updateCursorVisibility
|
||||
#include "options.h" // Para Options, options, OptionsVideo, Border
|
||||
#include "resource.h" // Para Resource
|
||||
#include "surface.h" // Para Surface, readPalFile
|
||||
#include "text.h" // Para Text
|
||||
#include "ui/notifier.h" // Para Notifier
|
||||
#include "asset.h" // Para Asset, AssetType
|
||||
#include "mouse.h" // Para updateCursorVisibility
|
||||
#include "options.h" // Para Options, options, OptionsVideo, Border
|
||||
#include "rendering/opengl/opengl_shader.h" // Para OpenGLShader
|
||||
#include "resource.h" // Para Resource
|
||||
#include "surface.h" // Para Surface, readPalFile
|
||||
#include "text.h" // Para Text
|
||||
#include "ui/notifier.h" // Para Notifier
|
||||
|
||||
// [SINGLETON]
|
||||
Screen* Screen::screen_ = nullptr;
|
||||
@@ -103,7 +103,6 @@ Screen::Screen(SDL_Window* window, SDL_Renderer* renderer)
|
||||
|
||||
// Muestra la ventana
|
||||
show();
|
||||
resetShaders();
|
||||
|
||||
// Extrae el nombre de las paletas desde su ruta
|
||||
processPaletteList();
|
||||
@@ -148,9 +147,6 @@ void Screen::setVideoMode(bool mode) {
|
||||
SDL_SetWindowFullscreen(window_, options.video.fullscreen);
|
||||
adjustWindowSize();
|
||||
adjustRenderLogicalSize();
|
||||
|
||||
// Reinicia los shaders
|
||||
resetShaders();
|
||||
}
|
||||
|
||||
// Camibia entre pantalla completa y ventana
|
||||
@@ -266,17 +262,6 @@ int Screen::getMaxZoom() {
|
||||
return MAX_ZOOM;
|
||||
}
|
||||
|
||||
// Reinicia los shaders
|
||||
void Screen::resetShaders() {
|
||||
if (options.video.shaders) {
|
||||
const std::string GLSL_FILE = options.video.border.enabled ? "crtpi_240.glsl" : "crtpi_192.glsl";
|
||||
std::ifstream f(Asset::get()->get(GLSL_FILE).c_str());
|
||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
|
||||
shader::init(window_, shaders_texture_, source);
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el renderizador para las surfaces
|
||||
void Screen::setRendererSurface(std::shared_ptr<Surface> surface) {
|
||||
(surface) ? renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(surface) : renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_);
|
||||
@@ -341,11 +326,11 @@ void Screen::surfaceToTexture() {
|
||||
void Screen::textureToRenderer() {
|
||||
SDL_Texture* texture_to_render = options.video.border.enabled ? border_texture_ : game_texture_;
|
||||
|
||||
if (options.video.shaders) {
|
||||
if (options.video.shaders && shader_backend_) {
|
||||
SDL_SetRenderTarget(renderer_, shaders_texture_);
|
||||
SDL_RenderTexture(renderer_, texture_to_render, nullptr, nullptr);
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
shader::render();
|
||||
shader_backend_->render();
|
||||
} else {
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||
@@ -439,4 +424,80 @@ void Screen::toggleIntegerScale() {
|
||||
// Getters
|
||||
SDL_Renderer* Screen::getRenderer() { return renderer_; }
|
||||
std::shared_ptr<Surface> Screen::getRendererSurface() { return (*renderer_surface_); }
|
||||
std::shared_ptr<Surface> Screen::getBorderSurface() { return border_surface_; }
|
||||
std::shared_ptr<Surface> Screen::getBorderSurface() { return border_surface_; }
|
||||
|
||||
std::vector<uint8_t> loadData(const std::string& filepath) {
|
||||
// Fallback a filesystem
|
||||
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
||||
if (!file) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::streamsize fileSize = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<uint8_t> data(fileSize);
|
||||
if (!file.read(reinterpret_cast<char*>(data.data()), fileSize)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Carga el contenido de los archivos GLSL
|
||||
void Screen::loadShaders() {
|
||||
if (vertex_shader_source_.empty()) {
|
||||
// Detectar si necesitamos OpenGL ES (Raspberry Pi)
|
||||
// Intentar cargar versión ES primero si existe
|
||||
std::string VERTEX_FILE = "crtpi_vertex_es.glsl";
|
||||
auto data = loadData(Asset::get()->get(VERTEX_FILE));
|
||||
|
||||
if (data.empty()) {
|
||||
// Si no existe versión ES, usar versión Desktop
|
||||
VERTEX_FILE = "crtpi_vertex.glsl";
|
||||
data = loadData(Asset::get()->get(VERTEX_FILE));
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Usando shaders OpenGL Desktop 3.3");
|
||||
} else {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Usando shaders OpenGL ES 3.0 (Raspberry Pi)");
|
||||
}
|
||||
|
||||
if (!data.empty()) {
|
||||
vertex_shader_source_ = std::string(data.begin(), data.end());
|
||||
}
|
||||
}
|
||||
if (fragment_shader_source_.empty()) {
|
||||
// Intentar cargar versión ES primero si existe
|
||||
std::string FRAGMENT_FILE = "crtpi_fragment_es.glsl";
|
||||
auto data = loadData(Asset::get()->get(FRAGMENT_FILE));
|
||||
|
||||
if (data.empty()) {
|
||||
// Si no existe versión ES, usar versión Desktop
|
||||
FRAGMENT_FILE = "crtpi_fragment.glsl";
|
||||
data = loadData(Asset::get()->get(FRAGMENT_FILE));
|
||||
}
|
||||
|
||||
if (!data.empty()) {
|
||||
fragment_shader_source_ = std::string(data.begin(), data.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa los shaders
|
||||
void Screen::initShaders() {
|
||||
#ifndef __APPLE__
|
||||
if (options.video.shaders) {
|
||||
loadShaders();
|
||||
if (!shader_backend_) {
|
||||
shader_backend_ = std::make_unique<Rendering::OpenGLShader>();
|
||||
}
|
||||
shader_backend_->init(window_, game_texture_, vertex_shader_source_, fragment_shader_source_);
|
||||
}
|
||||
#else
|
||||
// En macOS, OpenGL está deprecated y rinde mal
|
||||
// TODO: Implementar backend de Metal para shaders en macOS
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Shaders no disponibles en macOS (OpenGL deprecated). Usa Metal backend.");
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user