mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-13 03:33:57 +02:00
Update to v094r23 release.
byuu says: The library window is gone, and replaced with hiro::BrowserWindow::openFolder(). This gives navigation capabilities to game loading, and it also completes our slotted cart selection code. As an added bonus, it's less code this way, too. I also set the window size to consistent sizes between all emulated systems, so that switching between SFC and GB don't cause the window size to keep changing, and so that the scaling size is consistent (eg at normal scale, GB @ 3x is closer to SNES @ 2x.) This means black borders in GB/GBA mode, but it doesn't look that bad, and it's not like many people ever use these modes anyway. Finally, added the placeholder tabs for video, audio and timing. I don't intend to add the timing calculator code to v095 (it might be better as a separate tool), but I'll add the ability to set video/audio rates, at least. Glitch 1: despite selecting the first item in the BrowserDialog list, if you press enter when the window appears, it doesn't activate the item until you press an arrow key first. Glitch 2: in Game Boy mode, if you set the 4x window size, it's not honoring the full requested height because the viewport is smaller than the window. 8+ years of trying to get GTK+ and Qt to simply set the god damned window size I ask for, and I still can't get them to do it reliably. Remaining issues: - finish configuration panels (video, audio, timing) - fix ruby driver compilation on Windows - add DIP switch selection window (NSS) [I may end up punting this one to v096]
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
void OpenGL::shader(const char* pathname) {
|
||||
auto OpenGL::shader(const string& pathname) -> void {
|
||||
for(auto& program : programs) program.release();
|
||||
programs.reset();
|
||||
|
||||
@@ -29,11 +29,11 @@ void OpenGL::shader(const char* pathname) {
|
||||
string text = node.text();
|
||||
if(node.name() == "width") {
|
||||
if(text.endsWith("%")) relativeWidth = real(text.rtrim("%")) / 100.0;
|
||||
else absoluteWidth = decimal(text);
|
||||
else absoluteWidth = text.decimal();
|
||||
}
|
||||
if(node.name() == "height") {
|
||||
if(text.endsWith("%")) relativeHeight = real(text.rtrim("%")) / 100.0;
|
||||
else absoluteHeight = decimal(text);
|
||||
else absoluteHeight = text.decimal();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ void OpenGL::shader(const char* pathname) {
|
||||
allocateHistory(historySize);
|
||||
}
|
||||
|
||||
void OpenGL::allocateHistory(unsigned size) {
|
||||
auto OpenGL::allocateHistory(unsigned size) -> void {
|
||||
for(auto& frame : history) glDeleteTextures(1, &frame.texture);
|
||||
history.reset();
|
||||
while(size--) {
|
||||
@@ -65,12 +65,12 @@ void OpenGL::allocateHistory(unsigned size) {
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenGL::lock(uint32_t*& data, unsigned& pitch) {
|
||||
auto OpenGL::lock(uint32_t*& data, unsigned& pitch) -> bool {
|
||||
pitch = width * sizeof(uint32_t);
|
||||
return data = buffer;
|
||||
}
|
||||
|
||||
void OpenGL::clear() {
|
||||
auto OpenGL::clear() -> void {
|
||||
for(auto& p : programs) {
|
||||
glUseProgram(p.program);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, p.framebuffer);
|
||||
@@ -83,7 +83,7 @@ void OpenGL::clear() {
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void OpenGL::refresh() {
|
||||
auto OpenGL::refresh() -> void {
|
||||
clear();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
@@ -180,7 +180,7 @@ void OpenGL::refresh() {
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenGL::init() {
|
||||
auto OpenGL::init() -> bool {
|
||||
if(!OpenGLBind()) return false;
|
||||
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
@@ -199,13 +199,13 @@ bool OpenGL::init() {
|
||||
OpenGLSurface::allocate();
|
||||
glrLinkProgram(program);
|
||||
|
||||
shader(nullptr);
|
||||
shader("");
|
||||
return initialized = true;
|
||||
}
|
||||
|
||||
void OpenGL::term() {
|
||||
auto OpenGL::term() -> void {
|
||||
if(initialized == false) return;
|
||||
shader(nullptr); //release shader resources (eg frame[] history)
|
||||
shader(""); //release shader resources (eg frame[] history)
|
||||
OpenGLSurface::release();
|
||||
if(buffer) { delete[] buffer; buffer = nullptr; }
|
||||
initialized = false;
|
||||
|
@@ -22,18 +22,23 @@ namespace ruby {
|
||||
struct OpenGL;
|
||||
|
||||
struct OpenGLTexture {
|
||||
auto getFormat() const -> GLuint;
|
||||
auto getType() const -> GLuint;
|
||||
|
||||
GLuint texture = 0;
|
||||
unsigned width = 0;
|
||||
unsigned height = 0;
|
||||
GLuint format = GL_RGBA8;
|
||||
GLuint filter = GL_LINEAR;
|
||||
GLuint wrap = GL_CLAMP_TO_BORDER;
|
||||
|
||||
GLuint getFormat() const;
|
||||
GLuint getType() const;
|
||||
};
|
||||
|
||||
struct OpenGLSurface : OpenGLTexture {
|
||||
auto allocate() -> void;
|
||||
auto size(unsigned width, unsigned height) -> void;
|
||||
auto release() -> void;
|
||||
auto render(unsigned sourceWidth, unsigned sourceHeight, unsigned targetWidth, unsigned targetHeight) -> void;
|
||||
|
||||
GLuint program = 0;
|
||||
GLuint framebuffer = 0;
|
||||
GLuint vao = 0;
|
||||
@@ -42,14 +47,13 @@ struct OpenGLSurface : OpenGLTexture {
|
||||
GLuint geometry = 0;
|
||||
GLuint fragment = 0;
|
||||
uint32_t* buffer = nullptr;
|
||||
|
||||
void allocate();
|
||||
void size(unsigned width, unsigned height);
|
||||
void release();
|
||||
void render(unsigned sourceWidth, unsigned sourceHeight, unsigned targetWidth, unsigned targetHeight);
|
||||
};
|
||||
|
||||
struct OpenGLProgram : OpenGLSurface {
|
||||
auto bind(OpenGL* instance, const Markup::Node& node, const string& pathname) -> void;
|
||||
auto parse(OpenGL* instance, string& source) -> void;
|
||||
auto release() -> void;
|
||||
|
||||
unsigned phase = 0; //frame counter
|
||||
unsigned modulo = 0; //frame counter modulus
|
||||
unsigned absoluteWidth = 0;
|
||||
@@ -57,13 +61,17 @@ struct OpenGLProgram : OpenGLSurface {
|
||||
double relativeWidth = 0;
|
||||
double relativeHeight = 0;
|
||||
vector<OpenGLTexture> pixmaps;
|
||||
|
||||
void bind(OpenGL* instance, const Markup::Node& node, const string& pathname);
|
||||
void parse(OpenGL* instance, string& source);
|
||||
void release();
|
||||
};
|
||||
|
||||
struct OpenGL : OpenGLProgram {
|
||||
auto shader(const string& pathname) -> void;
|
||||
auto allocateHistory(unsigned size) -> void;
|
||||
auto lock(uint32_t*& data, unsigned& pitch) -> bool;
|
||||
auto clear() -> void;
|
||||
auto refresh() -> void;
|
||||
auto init() -> bool;
|
||||
auto term() -> void;
|
||||
|
||||
vector<OpenGLProgram> programs;
|
||||
vector<OpenGLTexture> history;
|
||||
GLuint inputFormat = GL_RGBA8;
|
||||
@@ -72,22 +80,14 @@ struct OpenGL : OpenGLProgram {
|
||||
struct Setting {
|
||||
string name;
|
||||
string value;
|
||||
bool operator< (const Setting& source) { return name < source.name; }
|
||||
bool operator==(const Setting& source) { return name == source.name; }
|
||||
Setting() {}
|
||||
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;
|
||||
|
||||
void shader(const char* pathname);
|
||||
void allocateHistory(unsigned size);
|
||||
bool lock(uint32_t*& data, unsigned& pitch);
|
||||
void clear();
|
||||
void refresh();
|
||||
bool init();
|
||||
void term();
|
||||
};
|
||||
|
||||
#include "texture.hpp"
|
||||
|
@@ -1,13 +1,13 @@
|
||||
void OpenGLProgram::bind(OpenGL* instance, const Markup::Node& node, const string& pathname) {
|
||||
auto OpenGLProgram::bind(OpenGL* instance, const Markup::Node& node, const string& pathname) -> void {
|
||||
filter = glrFilter(node["filter"].text());
|
||||
wrap = glrWrap(node["wrap"].text());
|
||||
modulo = glrModulo(node["modulo"].integer());
|
||||
|
||||
string w = node["width"].text(), h = node["height"].text();
|
||||
if(w.endsWith("%")) relativeWidth = real(w.rtrim("%")) / 100.0;
|
||||
else absoluteWidth = decimal(w);
|
||||
else absoluteWidth = w.decimal();
|
||||
if(h.endsWith("%")) relativeHeight = real(h.rtrim("%")) / 100.0;
|
||||
else absoluteHeight = decimal(h);
|
||||
else absoluteHeight = h.decimal();
|
||||
|
||||
format = glrFormat(node["format"].text());
|
||||
|
||||
@@ -71,7 +71,7 @@ void OpenGLProgram::bind(OpenGL* instance, const Markup::Node& node, const strin
|
||||
}
|
||||
|
||||
//apply manifest settings to shader source #in tags
|
||||
void OpenGLProgram::parse(OpenGL* instance, string& source) {
|
||||
auto OpenGLProgram::parse(OpenGL* instance, string& source) -> void {
|
||||
lstring lines = source.split("\n");
|
||||
for(auto& line : lines) {
|
||||
string s = line;
|
||||
@@ -89,7 +89,7 @@ void OpenGLProgram::parse(OpenGL* instance, string& source) {
|
||||
source = lines.merge("\n");
|
||||
}
|
||||
|
||||
void OpenGLProgram::release() {
|
||||
auto OpenGLProgram::release() -> void {
|
||||
OpenGLSurface::release();
|
||||
for(auto& pixmap : pixmaps) glDeleteTextures(1, &pixmap.texture);
|
||||
pixmaps.reset();
|
||||
|
@@ -1,10 +1,10 @@
|
||||
void OpenGLSurface::allocate() {
|
||||
auto OpenGLSurface::allocate() -> void {
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
glGenBuffers(3, &vbo[0]);
|
||||
}
|
||||
|
||||
void OpenGLSurface::size(unsigned w, unsigned h) {
|
||||
auto OpenGLSurface::size(unsigned w, unsigned h) -> void {
|
||||
if(width == w && height == h) return;
|
||||
width = w, height = h;
|
||||
w = glrSize(w), h = glrSize(h);
|
||||
@@ -25,7 +25,7 @@ void OpenGLSurface::size(unsigned w, unsigned h) {
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLSurface::release() {
|
||||
auto OpenGLSurface::release() -> void {
|
||||
if(vbo[0]) { glDeleteBuffers(3, &vbo[0]); for(auto &o : vbo) o = 0; }
|
||||
if(vao) { glDeleteVertexArrays(1, &vao); vao = 0; }
|
||||
if(vertex) { glDetachShader(program, vertex); glDeleteShader(vertex); vertex = 0; }
|
||||
@@ -37,7 +37,7 @@ void OpenGLSurface::release() {
|
||||
width = 0, height = 0;
|
||||
}
|
||||
|
||||
void OpenGLSurface::render(unsigned sourceWidth, unsigned sourceHeight, unsigned targetWidth, unsigned targetHeight) {
|
||||
auto OpenGLSurface::render(unsigned sourceWidth, unsigned sourceHeight, unsigned targetWidth, unsigned targetHeight) -> void {
|
||||
glViewport(0, 0, targetWidth, targetHeight);
|
||||
|
||||
float w = (float)sourceWidth / (float)glrSize(sourceWidth);
|
||||
|
@@ -1,10 +1,10 @@
|
||||
GLuint OpenGLTexture::getFormat() const {
|
||||
auto OpenGLTexture::getFormat() const -> GLuint {
|
||||
if(format == GL_R32I) return GL_RED_INTEGER;
|
||||
if(format == GL_R32UI) return GL_RED_INTEGER;
|
||||
return GL_BGRA;
|
||||
}
|
||||
|
||||
GLuint OpenGLTexture::getType() const {
|
||||
auto OpenGLTexture::getType() const -> GLuint {
|
||||
if(format == GL_R32I) return GL_UNSIGNED_INT;
|
||||
if(format == GL_R32UI) return GL_UNSIGNED_INT;
|
||||
if(format == GL_RGB10_A2) return GL_UNSIGNED_INT_2_10_10_10_REV;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
static unsigned glrSize(unsigned size) {
|
||||
static auto glrSize(unsigned size) -> unsigned {
|
||||
return size;
|
||||
//return bit::round(size); //return nearest power of two
|
||||
}
|
||||
|
||||
static GLuint glrFormat(const string& format) {
|
||||
static auto glrFormat(const string& format) -> GLuint {
|
||||
if(format == "r32i" ) return GL_R32I;
|
||||
if(format == "r32ui" ) return GL_R32UI;
|
||||
if(format == "rgba8" ) return GL_RGBA8;
|
||||
@@ -15,53 +15,53 @@ static GLuint glrFormat(const string& format) {
|
||||
return GL_RGBA8;
|
||||
}
|
||||
|
||||
static GLuint glrFilter(const string& filter) {
|
||||
static auto glrFilter(const string& filter) -> GLuint {
|
||||
if(filter == "nearest") return GL_NEAREST;
|
||||
if(filter == "linear" ) return GL_LINEAR;
|
||||
return GL_LINEAR;
|
||||
}
|
||||
|
||||
static GLuint glrWrap(const string& wrap) {
|
||||
static auto glrWrap(const string& wrap) -> GLuint {
|
||||
if(wrap == "border") return GL_CLAMP_TO_BORDER;
|
||||
if(wrap == "edge" ) return GL_CLAMP_TO_EDGE;
|
||||
if(wrap == "repeat") return GL_REPEAT;
|
||||
return GL_CLAMP_TO_BORDER;
|
||||
}
|
||||
|
||||
static unsigned glrModulo(unsigned modulo) {
|
||||
static auto glrModulo(unsigned modulo) -> unsigned {
|
||||
if(modulo) return modulo;
|
||||
return 300; //divisible by 2, 3, 4, 5, 6, 10, 12, 15, 20, 25, 30, 50, 60, 100, 150
|
||||
}
|
||||
|
||||
static GLuint glrProgram() {
|
||||
static auto glrProgram() -> GLuint {
|
||||
GLuint program = 0;
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&program);
|
||||
return program;
|
||||
}
|
||||
|
||||
static void glrUniform1i(const string& name, GLint value) {
|
||||
static auto glrUniform1i(const string& name, GLint value) -> void {
|
||||
GLint location = glGetUniformLocation(glrProgram(), name);
|
||||
glUniform1i(location, value);
|
||||
}
|
||||
|
||||
static void glrUniform4f(const string& name, GLfloat value0, GLfloat value1, GLfloat value2, GLfloat value3) {
|
||||
static auto glrUniform4f(const string& name, GLfloat value0, GLfloat value1, GLfloat value2, GLfloat value3) -> void {
|
||||
GLint location = glGetUniformLocation(glrProgram(), name);
|
||||
glUniform4f(location, value0, value1, value2, value3);
|
||||
}
|
||||
|
||||
static void glrUniformMatrix4fv(const string& name, GLfloat *values) {
|
||||
static auto glrUniformMatrix4fv(const string& name, GLfloat* values) -> void {
|
||||
GLint location = glGetUniformLocation(glrProgram(), name);
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, values);
|
||||
}
|
||||
|
||||
static void glrParameters(GLuint filter, GLuint wrap) {
|
||||
static auto glrParameters(GLuint filter, GLuint wrap) -> void {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
|
||||
}
|
||||
|
||||
static GLuint glrCreateShader(GLuint program, GLuint type, const char* source) {
|
||||
static auto glrCreateShader(GLuint program, GLuint type, const char* source) -> GLuint {
|
||||
GLuint shader = glCreateShader(type);
|
||||
glShaderSource(shader, 1, &source, 0);
|
||||
glCompileShader(shader);
|
||||
@@ -80,7 +80,7 @@ static GLuint glrCreateShader(GLuint program, GLuint type, const char* source) {
|
||||
return shader;
|
||||
}
|
||||
|
||||
static void glrLinkProgram(GLuint program) {
|
||||
static auto glrLinkProgram(GLuint program) -> void {
|
||||
glLinkProgram(program);
|
||||
GLint result = GL_FALSE;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &result);
|
||||
|
Reference in New Issue
Block a user