1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-25 18:30:07 +00:00

Switched to idiomatic source name, ensured latest project name is in all appropriate header places, threw texture coordinates slightly into the shader mix.

This commit is contained in:
Thomas Harte 2015-07-26 15:25:11 -04:00
parent e53fbcf9ea
commit 6252f6030f
14 changed files with 60 additions and 24 deletions

View File

@ -1,6 +1,6 @@
//
// Atari2600.cpp
// ElectrEm
// CLK
//
// Created by Thomas Harte on 14/07/2015.
// Copyright © 2015 Thomas Harte. All rights reserved.

View File

@ -1,6 +1,6 @@
//
// Atari2600.hpp
// ElectrEm
// CLK
//
// Created by Thomas Harte on 14/07/2015.
// Copyright © 2015 Thomas Harte. All rights reserved.

View File

@ -8,7 +8,7 @@
/* Begin PBXBuildFile section */
4B14144E1B5883E500E04248 /* Atari2600.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B14144B1B5883E500E04248 /* Atari2600.mm */; };
4B14144F1B5883E500E04248 /* OpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B14144D1B5883E500E04248 /* OpenGLView.m */; };
4B14144F1B5883E500E04248 /* CSCathodeRayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B14144D1B5883E500E04248 /* CSCathodeRayView.m */; };
4B1414511B5885DF00E04248 /* Atari2600.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6D7F921B58822000787C9A /* Atari2600.cpp */; };
4B14145B1B58879D00E04248 /* CPU6502.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1414571B58879D00E04248 /* CPU6502.cpp */; };
4B14145D1B5887A600E04248 /* CPU6502.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1414571B58879D00E04248 /* CPU6502.cpp */; };
@ -313,8 +313,8 @@
/* Begin PBXFileReference section */
4B14144A1B5883E500E04248 /* Atari2600.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Atari2600.h; sourceTree = "<group>"; };
4B14144B1B5883E500E04248 /* Atari2600.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Atari2600.mm; sourceTree = "<group>"; };
4B14144C1B5883E500E04248 /* OpenGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenGLView.h; sourceTree = "<group>"; };
4B14144D1B5883E500E04248 /* OpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OpenGLView.m; sourceTree = "<group>"; };
4B14144C1B5883E500E04248 /* CSCathodeRayView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSCathodeRayView.h; sourceTree = "<group>"; };
4B14144D1B5883E500E04248 /* CSCathodeRayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSCathodeRayView.m; sourceTree = "<group>"; };
4B1414501B58848C00E04248 /* ClockSignal-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ClockSignal-Bridging-Header.h"; sourceTree = "<group>"; };
4B1414571B58879D00E04248 /* CPU6502.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPU6502.cpp; sourceTree = "<group>"; };
4B1414581B58879D00E04248 /* CPU6502.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CPU6502.hpp; sourceTree = "<group>"; };
@ -970,8 +970,8 @@
4B1414501B58848C00E04248 /* ClockSignal-Bridging-Header.h */,
4B14144A1B5883E500E04248 /* Atari2600.h */,
4B14144B1B5883E500E04248 /* Atari2600.mm */,
4B14144C1B5883E500E04248 /* OpenGLView.h */,
4B14144D1B5883E500E04248 /* OpenGLView.m */,
4B14144C1B5883E500E04248 /* CSCathodeRayView.h */,
4B14144D1B5883E500E04248 /* CSCathodeRayView.m */,
4BB73ECF1B587A6700552FC2 /* Clock Signal.entitlements */,
4BB73EA11B587A5100552FC2 /* AppDelegate.swift */,
4BB73EA31B587A5100552FC2 /* Atari2600Document.swift */,
@ -1435,7 +1435,7 @@
4B14144E1B5883E500E04248 /* Atari2600.mm in Sources */,
4B14145B1B58879D00E04248 /* CPU6502.cpp in Sources */,
4BB73EA21B587A5100552FC2 /* AppDelegate.swift in Sources */,
4B14144F1B5883E500E04248 /* OpenGLView.m in Sources */,
4B14144F1B5883E500E04248 /* CSCathodeRayView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -7,7 +7,7 @@
//
#import <Foundation/Foundation.h>
#import "OpenGLView.h"
#import "CSCathodeRayView.h"
@interface CSAtari2600 : NSObject

View File

@ -1,6 +1,6 @@
//
// Atari2600.m
// ElectrEm
// CLK
//
// Created by Thomas Harte on 14/07/2015.
// Copyright © 2015 Thomas Harte. All rights reserved.

View File

@ -1,12 +1,12 @@
//
// OpenGLView.m
// ElectrEm
// CSCathodeRayView.m
// CLK
//
// Created by Thomas Harte on 16/07/2015.
// Copyright © 2015 Thomas Harte. All rights reserved.
//
#import "OpenGLView.h"
#import "CSCathodeRayView.h"
@import CoreVideo;
#import <OpenGL/gl3.h>
#import <OpenGL/gl3ext.h>
@ -18,6 +18,7 @@
GLuint _shaderProgram;
GLuint _arrayBuffer, _vertexArray;
GLint _positionAttribute;
GLint _textureCoordinatesAttribute;
}
- (void)prepareOpenGL
@ -38,6 +39,7 @@
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat);
// get the shader ready, set the clear colour
[self.openGLContext makeCurrentContext];
glClearColor(1.0, 0.0, 0.0, 1.0);
[self prepareShader];
@ -102,35 +104,59 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
#pragma mark - Frame output
// the main job of the vertex shader is just to map from an input area of [0,1]x[0,1], with the origin in the
// top left to OpenGL's [-1,1]x[-1,1] with the origin in the lower left, and to convert input data coordinates
// from integral to floating point.
const char *vertexShader =
"#version 150\n"
"\n"
"in vec2 position;\n"
"in vec2 srcCoordinates;\n"
"\n"
"out vec4 colour;\n"
"out vec2 srcCoordinatesVarying;\n"
"\n"
"void main (void)\n"
"{\n"
"colour = vec4(1.0, 1.0, 1.0, 1.0);\n"
"srcCoordinatesVarying = srcCoordinates;\n"
"gl_Position = vec4(position.x * 2.0 - 1.0, 1.0 - position.y * 2.0, 0.0, 1.0);\n"
"}\n";
// TODO: this should be factored out and be per project
const char *fragmentShader =
"#version 150\n"
"\n"
"in vec4 colour;\n"
"in vec2 srcCoordinatesVarying;\n"
"out vec4 fragColour;\n"
"\n"
"void main(void)\n"
"{\n"
"fragColour = colour;\n"
"fragColour = vec4(1.0, 1.0, 1.0, 1.0);\n"
"}\n";
#if defined(DEBUG)
- (void)logErrorForObject:(GLuint)object
{
GLint logLength;
glGetShaderiv(object, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar *log = (GLchar *)malloc(logLength);
glGetShaderInfoLog(object, logLength, &logLength, log);
NSLog(@"Compile log:\n%s", log);
free(log);
}
}
#endif
- (GLuint)compileShader:(const char *)source type:(GLenum)type
{
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &source, NULL);
glCompileShader(shader);
#ifdef DEBUG
[self logErrorForObject:shader];
#endif
return shader;
}
@ -144,15 +170,25 @@ const char *fragmentShader =
glAttachShader(_shaderProgram, _fragmentShader);
glLinkProgram(_shaderProgram);
#ifdef DEBUG
[self logErrorForObject:_shaderProgram];
#endif
glGenVertexArrays(1, &_vertexArray);
glBindVertexArray(_vertexArray);
glGenBuffers(1, &_arrayBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _arrayBuffer);
glUseProgram(_shaderProgram);
_positionAttribute = glGetAttribLocation(_shaderProgram, "position");
_textureCoordinatesAttribute = glGetAttribLocation(_shaderProgram, "srcCoordinates");
glEnableVertexAttribArray(_positionAttribute);
glEnableVertexAttribArray(_textureCoordinatesAttribute);
glVertexAttribPointer(_positionAttribute, 2, GL_UNSIGNED_SHORT, GL_TRUE, 4 * sizeof(GLushort), (void *)0);
glVertexAttribPointer(_textureCoordinatesAttribute, 2, GL_UNSIGNED_SHORT, GL_TRUE, 4 * sizeof(GLushort), (void *)(2 * sizeof(GLushort)));
}
- (void)drawRect:(NSRect)dirtyRect

View File

@ -3,4 +3,4 @@
//
#import "Atari2600.h"
#import "OpenGLView.h"
#import "CSCathodeRayView.h"

View File

@ -1,6 +1,6 @@
//
// Machine.h
// ElectrEm
// CLK
//
// Created by Thomas Harte on 29/06/2015.
// Copyright © 2015 Thomas Harte. All rights reserved.

View File

@ -1,6 +1,6 @@
//
// Machine.m
// ElectrEm
// CLK
//
// Created by Thomas Harte on 29/06/2015.
// Copyright © 2015 Thomas Harte. All rights reserved.

View File

@ -1,6 +1,6 @@
//
// CPU6502.cpp
// ElectrEm
// CLK
//
// Created by Thomas Harte on 09/07/2015.
// Copyright © 2015 Thomas Harte. All rights reserved.

View File

@ -1,6 +1,6 @@
//
// CPU6502.hpp
// ElectrEm
// CLK
//
// Created by Thomas Harte on 09/07/2015.
// Copyright © 2015 Thomas Harte. All rights reserved.

View File

@ -1,6 +1,6 @@
//
// CPU6502AllRAM.cpp
// ElectrEm
// CLK
//
// Created by Thomas Harte on 13/07/2015.
// Copyright © 2015 Thomas Harte. All rights reserved.

View File

@ -1,6 +1,6 @@
//
// CPU6502AllRAM.hpp
// ElectrEm
// CLK
//
// Created by Thomas Harte on 13/07/2015.
// Copyright © 2015 Thomas Harte. All rights reserved.