From b5bcadb8d3f1890096eecaa51342a54d21bc36ee Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 7 Feb 2016 22:18:55 -0500 Subject: [PATCH] Reinstated clipped CRT output, with more appropriate ownership of the decision. --- Machines/Electron/Electron.cpp | 1 + .../Documents/ElectronDocument.swift | 1 - Outputs/CRT/CRT.cpp | 1 + Outputs/CRT/CRT.hpp | 19 +++++++++++++++++++ Outputs/CRT/CRTOpenGL.cpp | 14 +++++++------- Outputs/CRT/Shader.cpp | 3 ++- 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index af47f4d06..86ddbfd2e 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -35,6 +35,7 @@ Machine::Machine() : "float texValue = texture(texID, coordinate).r;" "return vec3(step(4.0/256.0, mod(texValue, 8.0/256.0)), step(2.0/256.0, mod(texValue, 4.0/256.0)), step(1.0/256.0, mod(texValue, 2.0/256.0)));" "}"); + _crt.set_visible_area(Outputs::Rect(0.2f, 0.0625f, 0.75f, 0.75f)); memset(_keyStates, 0, sizeof(_keyStates)); memset(_palette, 0xf, sizeof(_palette)); diff --git a/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift b/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift index 4568d6982..449cec717 100644 --- a/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift @@ -28,7 +28,6 @@ class ElectronDocument: MachineDocument { super.windowControllerDidLoadNib(aController) electron.view = openGLView electron.audioQueue = self.audioQueue -// openGLView.frameBounds = CGRectMake(0.0225, 0.0625, 0.75, 0.75) } override var windowNibName: String? { diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index b80bbc6dc..c854f787c 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -110,6 +110,7 @@ CRT::CRT() : _is_in_hsync(false), _is_in_vsync(false), _current_frame_mutex(new std::mutex), + _visible_area(Rect(0, 0, 1, 1)), _rasterPosition({.x = 0, .y = 0}) { construct_openGL(); diff --git a/Outputs/CRT/CRT.hpp b/Outputs/CRT/CRT.hpp index c66574438..d9766acd8 100644 --- a/Outputs/CRT/CRT.hpp +++ b/Outputs/CRT/CRT.hpp @@ -19,6 +19,20 @@ namespace Outputs { +struct Rect { + struct { + float x, y; + } origin; + + struct { + float width, height; + } size; + + Rect() {} + Rect(float x, float y, float width, float height) : + origin({.x = x, .y = y}), size({.width = width, .height =height}) {} +}; + class CRT { public: ~CRT(); @@ -195,6 +209,10 @@ class CRT { // void set_phase_function(const char *shader); void set_output_device(OutputDevice output_device); + void set_visible_area(Rect visible_area) + { + _visible_area = visible_area; + } private: CRT(); @@ -303,6 +321,7 @@ class CRT { CRTFrame *_current_frame, *_last_drawn_frame; std::shared_ptr _current_frame_mutex; int _frame_read_pointer; + Rect _visible_area; struct OpenGLState; OpenGLState *_openGL_state; diff --git a/Outputs/CRT/CRTOpenGL.cpp b/Outputs/CRT/CRTOpenGL.cpp index fba197fa8..967dbdfba 100644 --- a/Outputs/CRT/CRTOpenGL.cpp +++ b/Outputs/CRT/CRTOpenGL.cpp @@ -137,19 +137,19 @@ void CRT::push_size_uniforms(unsigned int output_width, unsigned int output_heig glUniform2f(_openGL_state->windowSizeUniform, output_width, output_height); } -// GLfloat outputAspectRatioMultiplier = 1.0;//(viewSize.x / viewSize.y) / (4.0 / 3.0); + GLfloat outputAspectRatioMultiplier = ((float)output_width / (float)output_height) / (4.0f / 3.0f); -// _aspectRatioCorrectedBounds = _frameBounds; + Rect _aspect_ratio_corrected_bounds = _visible_area; -// CGFloat bonusWidth = (outputAspectRatioMultiplier - 1.0f) * _frameBounds.size.width; -// _aspectRatioCorrectedBounds.origin.x -= bonusWidth * 0.5f * _aspectRatioCorrectedBounds.size.width; -// _aspectRatioCorrectedBounds.size.width *= outputAspectRatioMultiplier; + GLfloat bonusWidth = (outputAspectRatioMultiplier - 1.0f) * _visible_area.size.width; + _aspect_ratio_corrected_bounds.origin.x -= bonusWidth * 0.5f * _aspect_ratio_corrected_bounds.size.width; + _aspect_ratio_corrected_bounds.size.width *= outputAspectRatioMultiplier; if(_openGL_state->boundsOriginUniform >= 0) - glUniform2f(_openGL_state->boundsOriginUniform, 0.0, 0.0); //(GLfloat)_aspectRatioCorrectedBounds.origin.x, (GLfloat)_aspectRatioCorrectedBounds.origin.y); + glUniform2f(_openGL_state->boundsOriginUniform, (GLfloat)_aspect_ratio_corrected_bounds.origin.x, (GLfloat)_aspect_ratio_corrected_bounds.origin.y); if(_openGL_state->boundsSizeUniform >= 0) - glUniform2f(_openGL_state->boundsSizeUniform, 1.0, 1.0);//(GLfloat)_aspectRatioCorrectedBounds.size.width, (GLfloat)_aspectRatioCorrectedBounds.size.height); + glUniform2f(_openGL_state->boundsSizeUniform, (GLfloat)_aspect_ratio_corrected_bounds.size.width, (GLfloat)_aspect_ratio_corrected_bounds.size.height); } void CRT::set_composite_sampling_function(const char *shader) diff --git a/Outputs/CRT/Shader.cpp b/Outputs/CRT/Shader.cpp index 1864c3ac2..c89a41c3b 100644 --- a/Outputs/CRT/Shader.cpp +++ b/Outputs/CRT/Shader.cpp @@ -51,7 +51,8 @@ Shader::Shader(const char *vertex_shader, const char *fragment_shader) Shader::~Shader() { - glDeleteProgram(_shader_program); + // TODO: ensure this is destructed within the correct context. +// glDeleteProgram(_shader_program); } void Shader::bind()