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]
2015-05-30 11:39:09 +00:00
|
|
|
auto OpenGLSurface::allocate() -> void {
|
2013-04-14 08:52:47 +00:00
|
|
|
glGenVertexArrays(1, &vao);
|
|
|
|
glBindVertexArray(vao);
|
|
|
|
glGenBuffers(3, &vbo[0]);
|
|
|
|
}
|
|
|
|
|
2017-07-24 05:23:40 +00:00
|
|
|
auto OpenGLSurface::size(uint w, uint h) -> void {
|
2013-04-09 13:31:46 +00:00
|
|
|
if(width == w && height == h) return;
|
|
|
|
width = w, height = h;
|
|
|
|
w = glrSize(w), h = glrSize(h);
|
|
|
|
|
|
|
|
if(texture) { glDeleteTextures(1, &texture); texture = 0; }
|
|
|
|
if(buffer) { delete[] buffer; buffer = nullptr; }
|
|
|
|
|
|
|
|
buffer = new uint32_t[w * h]();
|
|
|
|
glGenTextures(1, &texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
2014-01-05 09:59:17 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, getFormat(), getType(), buffer);
|
2013-04-09 13:31:46 +00:00
|
|
|
|
|
|
|
if(framebuffer) {
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer);
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
|
|
|
delete[] buffer;
|
|
|
|
buffer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]
2015-05-30 11:39:09 +00:00
|
|
|
auto OpenGLSurface::release() -> void {
|
2013-04-14 08:52:47 +00:00
|
|
|
if(vbo[0]) { glDeleteBuffers(3, &vbo[0]); for(auto &o : vbo) o = 0; }
|
|
|
|
if(vao) { glDeleteVertexArrays(1, &vao); vao = 0; }
|
2013-04-09 13:31:46 +00:00
|
|
|
if(vertex) { glDetachShader(program, vertex); glDeleteShader(vertex); vertex = 0; }
|
|
|
|
if(geometry) { glDetachShader(program, geometry); glDeleteShader(geometry); geometry = 0; }
|
|
|
|
if(fragment) { glDetachShader(program, fragment); glDeleteShader(fragment); fragment = 0; }
|
|
|
|
if(texture) { glDeleteTextures(1, &texture); texture = 0; }
|
|
|
|
if(framebuffer) { glDeleteFramebuffers(1, &framebuffer); framebuffer = 0; }
|
|
|
|
if(program) { glDeleteProgram(program); program = 0; }
|
|
|
|
width = 0, height = 0;
|
|
|
|
}
|
2013-04-14 08:52:47 +00:00
|
|
|
|
2017-07-24 05:23:40 +00:00
|
|
|
auto OpenGLSurface::render(uint sourceWidth, uint sourceHeight, uint targetWidth, uint targetHeight) -> void {
|
2013-04-14 08:52:47 +00:00
|
|
|
glViewport(0, 0, targetWidth, targetHeight);
|
|
|
|
|
|
|
|
float w = (float)sourceWidth / (float)glrSize(sourceWidth);
|
|
|
|
float h = (float)sourceHeight / (float)glrSize(sourceHeight);
|
|
|
|
float u = (float)targetWidth, v = (float)targetHeight;
|
|
|
|
GLint location;
|
|
|
|
|
|
|
|
GLfloat modelView[] = {
|
|
|
|
1, 0, 0, 0,
|
|
|
|
0, 1, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
0, 0, 0, 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
GLfloat projection[] = {
|
|
|
|
2.0f/u, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 2.0f/v, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, -1.0f, 0.0f,
|
|
|
|
-1.0f, -1.0f, 0.0f, 1.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
GLfloat modelViewProjection[4 * 4];
|
2019-07-07 09:44:09 +00:00
|
|
|
MatrixMultiply(modelViewProjection, modelView, 4, 4, projection, 4, 4);
|
2013-04-14 08:52:47 +00:00
|
|
|
|
|
|
|
GLfloat vertices[] = {
|
|
|
|
0, 0, 0, 1,
|
|
|
|
u, 0, 0, 1,
|
|
|
|
0, v, 0, 1,
|
|
|
|
u, v, 0, 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
GLfloat positions[4 * 4];
|
2017-07-24 05:23:40 +00:00
|
|
|
for(uint n = 0; n < 16; n += 4) {
|
2019-07-07 09:44:09 +00:00
|
|
|
MatrixMultiply(&positions[n], &vertices[n], 1, 4, modelViewProjection, 4, 4);
|
2013-04-14 08:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLfloat texCoords[] = {
|
|
|
|
0, 0,
|
|
|
|
w, 0,
|
|
|
|
0, h,
|
|
|
|
w, h,
|
|
|
|
};
|
|
|
|
|
|
|
|
glrUniformMatrix4fv("modelView", modelView);
|
|
|
|
glrUniformMatrix4fv("projection", projection);
|
|
|
|
glrUniformMatrix4fv("modelViewProjection", modelViewProjection);
|
|
|
|
|
|
|
|
glBindVertexArray(vao);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
|
2017-08-04 12:53:59 +00:00
|
|
|
GLint locationVertex = glGetAttribLocation(program, "vertex");
|
2013-04-14 08:52:47 +00:00
|
|
|
glEnableVertexAttribArray(locationVertex);
|
|
|
|
glVertexAttribPointer(locationVertex, 4, GL_FLOAT, GL_FALSE, 0, 0);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(GLfloat), positions, GL_STATIC_DRAW);
|
2017-08-04 12:53:59 +00:00
|
|
|
GLint locationPosition = glGetAttribLocation(program, "position");
|
2013-04-14 08:52:47 +00:00
|
|
|
glEnableVertexAttribArray(locationPosition);
|
|
|
|
glVertexAttribPointer(locationPosition, 4, GL_FLOAT, GL_FALSE, 0, 0);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo[2]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), texCoords, GL_STATIC_DRAW);
|
2017-08-04 12:53:59 +00:00
|
|
|
GLint locationTexCoord = glGetAttribLocation(program, "texCoord");
|
2013-04-14 08:52:47 +00:00
|
|
|
glEnableVertexAttribArray(locationTexCoord);
|
|
|
|
glVertexAttribPointer(locationTexCoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
|
|
|
|
|
|
|
glBindFragDataLocation(program, 0, "fragColor");
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
|
glDisableVertexAttribArray(locationVertex);
|
|
|
|
glDisableVertexAttribArray(locationPosition);
|
|
|
|
glDisableVertexAttribArray(locationTexCoord);
|
|
|
|
}
|