diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 44f629ee4..1d2903758 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -614,6 +614,8 @@ 4BC751B21D157E61006C31D9 /* 6522Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC751B11D157E61006C31D9 /* 6522Tests.swift */; }; 4BC76E691C98E31700E6EF73 /* FIRFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC76E671C98E31700E6EF73 /* FIRFilter.cpp */; }; 4BC76E6B1C98F43700E6EF73 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC76E6A1C98F43700E6EF73 /* Accelerate.framework */; }; + 4BC891AD20F6EAB300EDE5B3 /* Rectangle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC891AB20F6EAB300EDE5B3 /* Rectangle.cpp */; }; + 4BC891AE20F6EAB300EDE5B3 /* Rectangle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC891AB20F6EAB300EDE5B3 /* Rectangle.cpp */; }; 4BC91B831D1F160E00884B76 /* CommodoreTAP.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC91B811D1F160E00884B76 /* CommodoreTAP.cpp */; }; 4BC9DF451D044FCA00F44158 /* ROMImages in Resources */ = {isa = PBXBuildFile; fileRef = 4BC9DF441D044FCA00F44158 /* ROMImages */; }; 4BC9DF4F1D04691600F44158 /* 6560.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC9DF4D1D04691600F44158 /* 6560.cpp */; }; @@ -1356,6 +1358,8 @@ 4BC76E671C98E31700E6EF73 /* FIRFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FIRFilter.cpp; sourceTree = "<group>"; }; 4BC76E681C98E31700E6EF73 /* FIRFilter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = FIRFilter.hpp; sourceTree = "<group>"; }; 4BC76E6A1C98F43700E6EF73 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; }; + 4BC891AB20F6EAB300EDE5B3 /* Rectangle.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Rectangle.cpp; sourceTree = "<group>"; }; + 4BC891AC20F6EAB300EDE5B3 /* Rectangle.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Rectangle.hpp; sourceTree = "<group>"; }; 4BC91B811D1F160E00884B76 /* CommodoreTAP.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CommodoreTAP.cpp; sourceTree = "<group>"; }; 4BC91B821D1F160E00884B76 /* CommodoreTAP.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CommodoreTAP.hpp; sourceTree = "<group>"; }; 4BC9DF441D044FCA00F44158 /* ROMImages */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ROMImages; path = ../../../../ROMImages; sourceTree = "<group>"; }; @@ -2896,6 +2900,7 @@ children = ( 4B5073051DDD3B9400C48FBD /* ArrayBuilder.cpp */, 4BBF990A1C8FBA6F0075DAFB /* CRTOpenGL.cpp */, + 4BC891AB20F6EAB300EDE5B3 /* Rectangle.cpp */, 4BBF99081C8FBA6F0075DAFB /* TextureBuilder.cpp */, 4BBF99121C8FBA6F0075DAFB /* TextureTarget.cpp */, 4B5073061DDD3B9400C48FBD /* ArrayBuilder.hpp */, @@ -2903,6 +2908,7 @@ 4BBF990B1C8FBA6F0075DAFB /* CRTOpenGL.hpp */, 4BBF990E1C8FBA6F0075DAFB /* Flywheel.hpp */, 4BBF990F1C8FBA6F0075DAFB /* OpenGL.hpp */, + 4BC891AC20F6EAB300EDE5B3 /* Rectangle.hpp */, 4BBF99091C8FBA6F0075DAFB /* TextureBuilder.hpp */, 4BBF99131C8FBA6F0075DAFB /* TextureTarget.hpp */, 4BC3B74C1CD194CC00F86E85 /* Shaders */, @@ -3614,6 +3620,7 @@ 4B055AD81FAE9B180060FFFF /* Video.cpp in Sources */, 4B89452F201967B4007DE474 /* StaticAnalyser.cpp in Sources */, 4B894531201967B4007DE474 /* StaticAnalyser.cpp in Sources */, + 4BC891AE20F6EAB300EDE5B3 /* Rectangle.cpp in Sources */, 4B894539201967B4007DE474 /* Tape.cpp in Sources */, 4B055AE51FAE9B6F0060FFFF /* IntermediateShader.cpp in Sources */, 4B15A9FD208249BB005E6C8D /* StaticAnalyser.cpp in Sources */, @@ -3840,6 +3847,7 @@ 4BD3A30B1EE755C800B5B501 /* Video.cpp in Sources */, 4BBF99141C8FBA6F0075DAFB /* TextureBuilder.cpp in Sources */, 4B5FADBA1DE3151600AEC565 /* FileHolder.cpp in Sources */, + 4BC891AD20F6EAB300EDE5B3 /* Rectangle.cpp in Sources */, 4B643F3A1D77AD1900D431D6 /* CSStaticAnalyser.mm in Sources */, 4B1497881EE4A1DA00CE2596 /* ZX80O81P.cpp in Sources */, 4B894520201967B4007DE474 /* StaticAnalyser.cpp in Sources */, diff --git a/Outputs/CRT/Internals/Rectangle.cpp b/Outputs/CRT/Internals/Rectangle.cpp new file mode 100644 index 000000000..6600ef5bd --- /dev/null +++ b/Outputs/CRT/Internals/Rectangle.cpp @@ -0,0 +1,74 @@ +// +// Rectangle.cpp +// Clock Signal +// +// Created by Thomas Harte on 11/07/2018. +// Copyright © 2018 Thomas Harte. All rights reserved. +// + +#include "Rectangle.hpp" + +using namespace OpenGL; + +Rectangle::Rectangle(float x, float y, float width, float height): + pixel_shader_( + "#version 150\n" + + "in vec2 position;" + + "void main(void)" + "{" + "gl_Position = vec4(position, 0.0, 1.0);" + "}", + + "#version 150\n" + + "uniform vec4 colour;" + "out vec4 fragColour;" + + "void main(void)" + "{" + "fragColour = colour;" + "}" + ){ + pixel_shader_.bind(); + + glGenVertexArrays(1, &drawing_vertex_array_); + glGenBuffers(1, &drawing_array_buffer_); + + glBindVertexArray(drawing_vertex_array_); + glBindBuffer(GL_ARRAY_BUFFER, drawing_array_buffer_); + + GLint position_attribute = pixel_shader_.get_attrib_location("position"); + glEnableVertexAttribArray(static_cast<GLuint>(position_attribute)); + + glVertexAttribPointer( + (GLuint)position_attribute, + 2, + GL_FLOAT, + GL_FALSE, + 2 * sizeof(GLfloat), + (void *)0); + + colour_uniform_ = pixel_shader_.get_uniform_location("colour"); + + float buffer[4*2]; + + // Store positions. + buffer[0] = x; buffer[1] = y; + buffer[2] = x; buffer[3] = y + height; + buffer[4] = x + width; buffer[5] = y; + buffer[6] = x + width; buffer[7] = y + height; + + // Upload buffer. + glBindBuffer(GL_ARRAY_BUFFER, drawing_array_buffer_); + glBufferData(GL_ARRAY_BUFFER, sizeof(buffer), buffer, GL_STATIC_DRAW); +} + +void Rectangle::draw(float red, float green, float blue) { + pixel_shader_.bind(); + glUniform4f(colour_uniform_, red, green, blue, 1.0); + + glBindVertexArray(drawing_vertex_array_); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); +} diff --git a/Outputs/CRT/Internals/Rectangle.hpp b/Outputs/CRT/Internals/Rectangle.hpp new file mode 100644 index 000000000..b98e9a4df --- /dev/null +++ b/Outputs/CRT/Internals/Rectangle.hpp @@ -0,0 +1,41 @@ +// +// Rectangle.hpp +// Clock Signal +// +// Created by Thomas Harte on 11/07/2018. +// Copyright © 2018 Thomas Harte. All rights reserved. +// + +#ifndef Rectangle_hpp +#define Rectangle_hpp + +#include "OpenGL.hpp" +#include "Shaders/Shader.hpp" +#include <memory> + +namespace OpenGL { + +/*! + Provides a wrapper for drawing a solid, single-colour rectangle. +*/ +class Rectangle { + public: + /*! + Instantiates an instance of Rectange with the coordinates given. + */ + Rectangle(float x, float y, float width, float height); + + /*! + Draws this rectangle in the colour supplied. + */ + void draw(float red, float green, float blue); + + private: + Shader pixel_shader_; + GLuint drawing_vertex_array_ = 0, drawing_array_buffer_ = 0; + GLint colour_uniform_; +}; + +} + +#endif /* Rectangle_hpp */