1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-27 16:31:31 +00:00

Certainly at least seriously considering a separate holder for the "compile a shader" logic. Otherwise taking steps back towards PAL/NTSC decoding.

This commit is contained in:
Thomas Harte 2016-02-07 17:32:38 -05:00
parent 602327cd9d
commit 4d0a218a57
8 changed files with 75 additions and 12 deletions

View File

@ -16,6 +16,7 @@
4B1414601B58885000E04248 /* WolfgangLorenzTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B14145F1B58885000E04248 /* WolfgangLorenzTests.swift */; };
4B1414621B58888700E04248 /* KlausDormannTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1414611B58888700E04248 /* KlausDormannTests.swift */; };
4B2039941C67E20B001375C3 /* TextureTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2039921C67E20B001375C3 /* TextureTarget.cpp */; };
4B2039991C67FA92001375C3 /* Shader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2039971C67FA92001375C3 /* Shader.cpp */; };
4B2409551C45AB05004DA684 /* Speaker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2409531C45AB05004DA684 /* Speaker.cpp */; };
4B2E2D951C399D1200138695 /* ElectronDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B2E2D931C399D1200138695 /* ElectronDocument.xib */; };
4B2E2D9A1C3A06EC00138695 /* Atari2600.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E2D971C3A06EC00138695 /* Atari2600.cpp */; };
@ -343,7 +344,9 @@
4B1414611B58888700E04248 /* KlausDormannTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KlausDormannTests.swift; sourceTree = "<group>"; };
4B2039921C67E20B001375C3 /* TextureTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextureTarget.cpp; sourceTree = "<group>"; };
4B2039931C67E20B001375C3 /* TextureTarget.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = TextureTarget.hpp; sourceTree = "<group>"; };
4B2039951C67E2A3001375C3 /* OpenGL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OpenGL.h; sourceTree = "<group>"; };
4B2039951C67E2A3001375C3 /* OpenGL.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = OpenGL.hpp; sourceTree = "<group>"; };
4B2039971C67FA92001375C3 /* Shader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Shader.cpp; sourceTree = "<group>"; };
4B2039981C67FA92001375C3 /* Shader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Shader.hpp; sourceTree = "<group>"; };
4B2409531C45AB05004DA684 /* Speaker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Speaker.cpp; path = ../../Outputs/Speaker.cpp; sourceTree = "<group>"; };
4B2409541C45AB05004DA684 /* Speaker.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Speaker.hpp; path = ../../Outputs/Speaker.hpp; sourceTree = "<group>"; };
4B24095A1C45DF85004DA684 /* Stepper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Stepper.hpp; sourceTree = "<group>"; };
@ -696,7 +699,9 @@
4B7BFEFD1C6446EF00089C1C /* CRTFrameBuilder.cpp */,
4B2039921C67E20B001375C3 /* TextureTarget.cpp */,
4B2039931C67E20B001375C3 /* TextureTarget.hpp */,
4B2039951C67E2A3001375C3 /* OpenGL.h */,
4B2039951C67E2A3001375C3 /* OpenGL.hpp */,
4B2039971C67FA92001375C3 /* Shader.cpp */,
4B2039981C67FA92001375C3 /* Shader.hpp */,
);
name = CRT;
path = ../../Outputs/CRT;
@ -1623,6 +1628,7 @@
4B2409551C45AB05004DA684 /* Speaker.cpp in Sources */,
4B55CE4E1C3B3BDA0093A61B /* CSMachine.mm in Sources */,
4B2E2D9D1C3A070400138695 /* Electron.cpp in Sources */,
4B2039991C67FA92001375C3 /* Shader.cpp in Sources */,
4B69FB3D1C4D908A00B5F0AA /* Tape.cpp in Sources */,
4B55CE5D1C3B7D6F0093A61B /* CSCathodeRayView.m in Sources */,
4B2E2D9A1C3A06EC00138695 /* Atari2600.cpp in Sources */,

View File

@ -25,8 +25,12 @@ static const uint32_t kCRTFixedPointOffset = 0x04000000;
#define kRetraceXMask 0x01
#define kRetraceYMask 0x02
void CRT::set_new_timing(unsigned int cycles_per_line, unsigned int height_of_display, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator)
void CRT::set_new_timing(unsigned int cycles_per_line, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator)
{
_colour_space = colour_space;
_colour_cycle_numerator = colour_cycle_numerator;
_colour_cycle_denominator = colour_cycle_denominator;
const unsigned int syncCapacityLineChargeThreshold = 3;
const unsigned int millisecondsHorizontalRetraceTime = 7; // source: Dictionary of Video and Television Technology, p. 234
const unsigned int scanlinesVerticalRetraceTime = 10; // source: ibid
@ -72,11 +76,11 @@ void CRT::set_new_display_type(unsigned int cycles_per_line, DisplayType display
switch(displayType)
{
case DisplayType::PAL50:
set_new_timing(cycles_per_line, 312, 1135, 4);
set_new_timing(cycles_per_line, 312, ColourSpace::YUV, 1135, 4);
break;
case DisplayType::NTSC60:
set_new_timing(cycles_per_line, 262, 545, 2);
set_new_timing(cycles_per_line, 262, ColourSpace::YIQ, 545, 2);
break;
}
}
@ -111,9 +115,9 @@ CRT::CRT() :
construct_openGL();
}
CRT::CRT(unsigned int cycles_per_line, unsigned int height_of_display, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator, unsigned int number_of_buffers, ...) : CRT()
CRT::CRT(unsigned int cycles_per_line, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator, unsigned int number_of_buffers, ...) : CRT()
{
set_new_timing(cycles_per_line, height_of_display, colour_cycle_numerator, colour_cycle_denominator);
set_new_timing(cycles_per_line, height_of_display, colour_space, colour_cycle_numerator, colour_cycle_denominator);
va_list buffer_sizes;
va_start(buffer_sizes, number_of_buffers);

View File

@ -28,6 +28,16 @@ class CRT {
NTSC60
};
enum ColourSpace {
YIQ,
YUV
};
enum OutputDevice {
Monitor,
Television
};
/*! Constructs the CRT with a specified clock rate, height and colour subcarrier frequency.
The requested number of buffers, each with the requested number of bytes per pixel,
is created for the machine to write raw pixel data to.
@ -55,7 +65,7 @@ class CRT {
@see @c set_rgb_sampling_function , @c set_composite_sampling_function
*/
CRT(unsigned int cycles_per_line, unsigned int height_of_display, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator, unsigned int number_of_buffers, ...);
CRT(unsigned int cycles_per_line, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator, unsigned int number_of_buffers, ...);
/*! Constructs the CRT with the specified clock rate, with the display height and colour
subcarrier frequency dictated by a standard display type and with the requested number of
@ -68,7 +78,7 @@ class CRT {
/*! Resets the CRT with new timing information. The CRT then continues as though the new timing had
been provided at construction. */
void set_new_timing(unsigned int cycles_per_line, unsigned int height_of_display, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator);
void set_new_timing(unsigned int cycles_per_line, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator);
/*! Resets the CRT with new timing information derived from a new display type. The CRT then continues
as though the new timing had been provided at construction. */
@ -182,7 +192,9 @@ class CRT {
`float phase_for_clock_cycle(int cycle)` that returns the colour phase at the beginning of
the supplied cycle.
*/
void set_phase_function(const char *shader);
// void set_phase_function(const char *shader);
void set_output_device(OutputDevice output_device);
private:
CRT();
@ -196,6 +208,11 @@ class CRT {
unsigned int _cycles_per_line;
unsigned int _height_of_display;
// colour invormation
ColourSpace _colour_space;
unsigned int _colour_cycle_numerator;
unsigned int _colour_cycle_denominator;
// properties directly derived from there
unsigned int _hsync_error_window; // the permitted window around the expected sync position in which a sync pulse will be recognised; calculated once at init

View File

@ -9,7 +9,8 @@
#include "CRT.hpp"
#include <stdlib.h>
#include "OpenGL.h"
#include "OpenGL.hpp"
#include "TextureTarget.hpp"
using namespace Outputs;
@ -30,6 +31,10 @@ struct CRT::OpenGLState {
CRTSize textureSize;
OpenGL::TextureTarget *compositeTexture;
OpenGL::TextureTarget *colourTexture;
OpenGL::TextureTarget *filteredTexture;
GLuint compile_shader(const char *source, GLenum type)
{
GLuint shader = glCreateShader(type);

9
Outputs/CRT/Shader.cpp Normal file
View File

@ -0,0 +1,9 @@
//
// Shader.cpp
// Clock Signal
//
// Created by Thomas Harte on 07/02/2016.
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#include "Shader.hpp"

22
Outputs/CRT/Shader.hpp Normal file
View File

@ -0,0 +1,22 @@
//
// Shader.hpp
// Clock Signal
//
// Created by Thomas Harte on 07/02/2016.
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#ifndef Shader_hpp
#define Shader_hpp
namespace OpenGL {
class Shader {
public:
Shader(const char *vertex_shader, const char *fragment_shader);
~Shader();
void bind();
};
}
#endif /* Shader_hpp */

View File

@ -9,7 +9,7 @@
#ifndef TextureTarget_hpp
#define TextureTarget_hpp
#include "OpenGL.h"
#include "OpenGL.hpp"
namespace OpenGL {