1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-03 11:30:02 +00:00

Allows a CRT machine owner to set the target frame buffer for OpenGL output, breaking the assumption that it'll be zero.

This commit is contained in:
Thomas Harte 2017-11-12 19:29:22 -05:00
parent ebdb80c908
commit 70039d22f1
5 changed files with 21 additions and 2 deletions

View File

@ -170,6 +170,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate, public LockProtectedDeleg
// Since OS X v10.6, Macs have had a gamma of 2.2. // Since OS X v10.6, Macs have had a gamma of 2.2.
_machine->get_crt()->set_output_gamma(2.2f); _machine->get_crt()->set_output_gamma(2.2f);
_machine->get_crt()->set_target_framebuffer(0);
} }
- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty { - (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty {

View File

@ -11,6 +11,7 @@
#include <cstdio> #include <cstdio>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include "../../StaticAnalyser/StaticAnalyser.hpp" #include "../../StaticAnalyser/StaticAnalyser.hpp"
#include "../../Machines/Utility/MachineForTarget.hpp" #include "../../Machines/Utility/MachineForTarget.hpp"
@ -175,6 +176,9 @@ int main(int argc, char *argv[]) {
SDL_GLContext gl_context = SDL_GL_CreateContext(window); SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context); SDL_GL_MakeCurrent(window, gl_context);
GLint target_framebuffer = 0;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &target_framebuffer);
// For vanilla SDL purposes, assume system ROMs can be found in one of: // For vanilla SDL purposes, assume system ROMs can be found in one of:
// //
// /usr/local/share/CLK/[system]; or // /usr/local/share/CLK/[system]; or
@ -221,6 +225,7 @@ int main(int argc, char *argv[]) {
// Setup output, assuming a CRT machine for now, and prepare a best-effort updater. // Setup output, assuming a CRT machine for now, and prepare a best-effort updater.
machine->crt_machine()->setup_output(4.0 / 3.0); machine->crt_machine()->setup_output(4.0 / 3.0);
machine->crt_machine()->get_crt()->set_output_gamma(2.2f); machine->crt_machine()->get_crt()->set_output_gamma(2.2f);
machine->crt_machine()->get_crt()->set_target_framebuffer(target_framebuffer);
// For now, lie about audio output intentions. // For now, lie about audio output intentions.
auto speaker = machine->crt_machine()->get_speaker(); auto speaker = machine->crt_machine()->get_speaker();

View File

@ -241,6 +241,13 @@ class CRT {
openGL_output_builder_.draw_frame(output_width, output_height, only_if_dirty); openGL_output_builder_.draw_frame(output_width, output_height, only_if_dirty);
} }
/*! Sets the OpenGL framebuffer to which output is drawn. */
inline void set_target_framebuffer(GLint framebuffer) {
enqueue_openGL_function( [framebuffer, this] {
openGL_output_builder_.set_target_framebuffer(framebuffer);
});
}
/*! Sets the gamma exponent for the simulated screen. */ /*! Sets the gamma exponent for the simulated screen. */
void set_input_gamma(float gamma); void set_input_gamma(float gamma);

View File

@ -75,6 +75,10 @@ bool OpenGLOutputBuilder::get_is_television_output() {
return output_device_ == OutputDevice::Television || !rgb_input_shader_program_; return output_device_ == OutputDevice::Television || !rgb_input_shader_program_;
} }
void OpenGLOutputBuilder::set_target_framebuffer(GLint target_framebuffer) {
target_framebuffer_ = target_framebuffer;
}
void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int output_height, bool only_if_dirty) { void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int output_height, bool only_if_dirty) {
// lock down any other draw_frames // lock down any other draw_frames
draw_mutex_.lock(); draw_mutex_.lock();
@ -219,7 +223,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
// copy framebuffer to the intended place // copy framebuffer to the intended place
glDisable(GL_BLEND); glDisable(GL_BLEND);
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, static_cast<GLuint>(target_framebuffer_));
glViewport(0, 0, (GLsizei)output_width, (GLsizei)output_height); glViewport(0, 0, (GLsizei)output_width, (GLsizei)output_height);
glActiveTexture(pixel_accumulation_texture_unit); glActiveTexture(pixel_accumulation_texture_unit);

View File

@ -50,6 +50,7 @@ class OpenGLOutputBuilder {
// Other things the caller may have provided. // Other things the caller may have provided.
std::string composite_shader_; std::string composite_shader_;
std::string rgb_shader_; std::string rgb_shader_;
GLint target_framebuffer_ = 0;
// Methods used by the OpenGL code // Methods used by the OpenGL code
void prepare_output_shader(); void prepare_output_shader();
@ -146,6 +147,7 @@ class OpenGLOutputBuilder {
composite_src_output_y_++; composite_src_output_y_++;
} }
void set_target_framebuffer(GLint target_framebuffer);
void draw_frame(unsigned int output_width, unsigned int output_height, bool only_if_dirty); void draw_frame(unsigned int output_width, unsigned int output_height, bool only_if_dirty);
void set_openGL_context_will_change(bool should_delete_resources); void set_openGL_context_will_change(bool should_delete_resources);
void set_composite_sampling_function(const std::string &shader); void set_composite_sampling_function(const std::string &shader);