Skip to content

Commit e0b48a5

Browse files
author
redcode
committedJul 23, 2016
WIP.
1 parent d2a15a1 commit e0b48a5

20 files changed

+219
-92
lines changed
 

‎development/Xcode/μZX (OS X).xcodeproj/project.pbxproj

+12-3
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,24 @@
172172
path = "OS X & iOS";
173173
sourceTree = "<group>";
174174
};
175-
6497FB9E1B74D157001B0196 /* shaders */ = {
175+
6497FB9E1B74D157001B0196 /* Shaders */ = {
176+
isa = PBXGroup;
177+
children = (
178+
64BFD2511D430F170006FD23 /* GLSL */,
179+
);
180+
name = Shaders;
181+
path = shaders;
182+
sourceTree = "<group>";
183+
};
184+
64BFD2511D430F170006FD23 /* GLSL */ = {
176185
isa = PBXGroup;
177186
children = (
178187
64F5DE7B1A28EB3900D29077 /* SABR.vsh */,
179188
64F5DE7A1A28EB3900D29077 /* SABR.fsh */,
180189
6483DD331D3BD50100807C53 /* Simple.vsh */,
181190
6483DD351D3C609800807C53 /* Simple.fsh */,
182191
);
183-
path = shaders;
192+
path = GLSL;
184193
sourceTree = "<group>";
185194
};
186195
64DEF6821B7A449E000F4F01 /* Images */ = {
@@ -337,7 +346,7 @@
337346
isa = PBXGroup;
338347
children = (
339348
64DEF6821B7A449E000F4F01 /* Images */,
340-
6497FB9E1B74D157001B0196 /* shaders */,
349+
6497FB9E1B74D157001B0196 /* Shaders */,
341350
64F5DEB31A28EB6600D29077 /* ROMs */,
342351
);
343352
name = Common;

‎development/Xcode/μZX (iOS).xcodeproj/project.pbxproj

+19-10
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
6496E71F1D3967BB00835482 /* CoreAudioOutputPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6496E71E1D3967BB00835482 /* CoreAudioOutputPlayer.cpp */; };
1616
6496E7241D39684A00835482 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6496E7221D39684A00835482 /* AudioToolbox.framework */; };
1717
6497FBA01B74D180001B0196 /* ROMs in Resources */ = {isa = PBXBuildFile; fileRef = 6497FB9F1B74D180001B0196 /* ROMs */; };
18-
6497FBA31B74D1CD001B0196 /* SimpleVertex.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 6497FBA21B74D1CD001B0196 /* SimpleVertex.glsl */; };
19-
6497FBA51B74D3F6001B0196 /* SimplePixel.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 6497FBA41B74D3F6001B0196 /* SimplePixel.glsl */; };
2018
649D9A741D3B19C6008720B3 /* GLVideoView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 649D9A731D3B19C6008720B3 /* GLVideoView.mm */; };
2119
64B7D8A11D4008CC007175DA /* OpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64B7D8A01D4008CC007175DA /* OpenGL.cpp */; };
2220
64BFD24C1D41F1D50006FD23 /* Matrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64BFD24B1D41F1D50006FD23 /* Matrix.cpp */; };
21+
64BFD24F1D42E4DE0006FD23 /* Simple.vsh in Resources */ = {isa = PBXBuildFile; fileRef = 64BFD24D1D42E4DE0006FD23 /* Simple.vsh */; };
22+
64BFD2501D42E4DE0006FD23 /* Simple.fsh in Resources */ = {isa = PBXBuildFile; fileRef = 64BFD24E1D42E4DE0006FD23 /* Simple.fsh */; };
2323
64DEF67E1B794F4E000F4F01 /* Joystick.png in Resources */ = {isa = PBXBuildFile; fileRef = 64DEF67D1B794F4E000F4F01 /* Joystick.png */; };
2424
64EC80581B722D2E00C15EFE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 64EC80571B722D2E00C15EFE /* main.m */; };
2525
64EC805B1B722D2E00C15EFE /* MainController.m in Sources */ = {isa = PBXBuildFile; fileRef = 64EC805A1B722D2E00C15EFE /* MainController.m */; };
@@ -58,13 +58,13 @@
5858
6496E71E1D3967BB00835482 /* CoreAudioOutputPlayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CoreAudioOutputPlayer.cpp; sourceTree = "<group>"; };
5959
6496E7221D39684A00835482 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
6060
6497FB9F1B74D180001B0196 /* ROMs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = ROMs; sourceTree = "<group>"; };
61-
6497FBA21B74D1CD001B0196 /* SimpleVertex.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SimpleVertex.glsl; sourceTree = "<group>"; };
62-
6497FBA41B74D3F6001B0196 /* SimplePixel.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SimplePixel.glsl; sourceTree = "<group>"; };
6361
649D9A721D3B19C6008720B3 /* GLVideoView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLVideoView.h; sourceTree = "<group>"; };
6462
649D9A731D3B19C6008720B3 /* GLVideoView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GLVideoView.mm; sourceTree = "<group>"; };
6563
64B7D8A01D4008CC007175DA /* OpenGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OpenGL.cpp; sourceTree = "<group>"; };
6664
64BFD24A1D41F1D00006FD23 /* Matrix.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Matrix.hpp; sourceTree = "<group>"; };
6765
64BFD24B1D41F1D50006FD23 /* Matrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Matrix.cpp; sourceTree = "<group>"; };
66+
64BFD24D1D42E4DE0006FD23 /* Simple.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = Simple.vsh; sourceTree = "<group>"; };
67+
64BFD24E1D42E4DE0006FD23 /* Simple.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = Simple.fsh; sourceTree = "<group>"; };
6868
64DEF67D1B794F4E000F4F01 /* Joystick.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Joystick.png; sourceTree = "<group>"; };
6969
64E106241CAAB17A0007743B /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = "<group>"; };
7070
64EC80521B722D2E00C15EFE /* μZX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "μZX.app"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -142,15 +142,24 @@
142142
path = "OS X & iOS";
143143
sourceTree = "<group>";
144144
};
145-
6497FBA11B74D190001B0196 /* shaders */ = {
145+
6497FBA11B74D190001B0196 /* Shaders */ = {
146146
isa = PBXGroup;
147147
children = (
148-
6497FBA21B74D1CD001B0196 /* SimpleVertex.glsl */,
149-
6497FBA41B74D3F6001B0196 /* SimplePixel.glsl */,
148+
64BFD2521D430FE50006FD23 /* GLSL-ES */,
150149
);
150+
name = Shaders;
151151
path = shaders;
152152
sourceTree = "<group>";
153153
};
154+
64BFD2521D430FE50006FD23 /* GLSL-ES */ = {
155+
isa = PBXGroup;
156+
children = (
157+
64BFD24D1D42E4DE0006FD23 /* Simple.vsh */,
158+
64BFD24E1D42E4DE0006FD23 /* Simple.fsh */,
159+
);
160+
path = "GLSL-ES";
161+
sourceTree = "<group>";
162+
};
154163
64EC80491B722D2D00C15EFE = {
155164
isa = PBXGroup;
156165
children = (
@@ -234,7 +243,7 @@
234243
64EC807E1B72337000C15EFE /* Common */ = {
235244
isa = PBXGroup;
236245
children = (
237-
6497FBA11B74D190001B0196 /* shaders */,
246+
6497FBA11B74D190001B0196 /* Shaders */,
238247
6497FB9F1B74D180001B0196 /* ROMs */,
239248
);
240249
name = Common;
@@ -409,10 +418,10 @@
409418
64421D3D1D38320D003CD4A5 /* MachineView.xib in Resources */,
410419
64EC80611B722D2E00C15EFE /* Main.storyboard in Resources */,
411420
6497FBA01B74D180001B0196 /* ROMs in Resources */,
412-
6497FBA31B74D1CD001B0196 /* SimpleVertex.glsl in Resources */,
413421
64DEF67E1B794F4E000F4F01 /* Joystick.png in Resources */,
422+
64BFD24F1D42E4DE0006FD23 /* Simple.vsh in Resources */,
414423
64EC80661B722D2E00C15EFE /* LaunchScreen.xib in Resources */,
415-
6497FBA51B74D3F6001B0196 /* SimplePixel.glsl in Resources */,
424+
64BFD2501D42E4DE0006FD23 /* Simple.fsh in Resources */,
416425
64EC80631B722D2E00C15EFE /* Images.xcassets in Resources */,
417426
);
418427
runOnlyForDeploymentPostprocessing = 0;

‎resources/OS X/property lists/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>1222</string>
24+
<string>1246</string>
2525
<key>LSMinimumSystemVersion</key>
2626
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
2727
<key>NSHumanReadableCopyright</key>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//#version 110
2+
3+
uniform sampler2D texture;
4+
varying lowp vec2 texture_point;
5+
6+
void main(void)
7+
{
8+
gl_FragColor = texture2D(texture, texture_point);
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//#version 110
2+
3+
attribute vec2 vertex;
4+
uniform mat4 transform;
5+
varying vec2 texture_point;
6+
7+
void main(void)
8+
{
9+
gl_Position = vec4(vertex.x, vertex.y, 0.0, 1.0) * transform;
10+
texture_point = vec2(vertex.x, -vertex.y) * vec2(0.5) + vec2(0.5);
11+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎resources/common/shaders/SimplePixel.glsl

-7
This file was deleted.

‎resources/common/shaders/SimpleVertex.glsl

-9
This file was deleted.

‎resources/iOS/UI/MachineView.xib

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" variant="6xAndEarlier" propertyAccessControl="none">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" variant="6xAndEarlier" propertyAccessControl="none">
33
<dependencies>
44
<deployment version="1072" identifier="iOS"/>
55
<development version="5100" identifier="xcode"/>
@@ -8,24 +8,25 @@
88
<objects>
99
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MachineViewController">
1010
<connections>
11+
<outlet property="_videoOutputView" destination="TKW-zG-72O" id="oaE-jR-3Cd"/>
1112
<outlet property="view" destination="iN0-l3-epB" id="dBh-7O-mcD"/>
1213
</connections>
1314
</placeholder>
1415
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
1516
<view contentMode="scaleToFill" id="iN0-l3-epB">
16-
<rect key="frame" x="0.0" y="20" width="408" height="516"/>
17+
<rect key="frame" x="0.0" y="20" width="352" height="331"/>
1718
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1819
<subviews>
1920
<view contentMode="scaleToFill" id="TKW-zG-72O" customClass="GLVideoView">
20-
<rect key="frame" x="0.0" y="0.0" width="408" height="315"/>
21+
<rect key="frame" x="0.0" y="0.0" width="352" height="296"/>
2122
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2223
<color key="backgroundColor" red="0.92615244389883267" green="0.79587435955079466" blue="1" alpha="1" colorSpace="calibratedRGB"/>
2324
</view>
2425
</subviews>
2526
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
2627
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
2728
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
28-
<point key="canvasLocation" x="257" y="315"/>
29+
<point key="canvasLocation" x="229" y="222.5"/>
2930
</view>
3031
</objects>
3132
</document>

‎sources/OS X & iOS/GLVideoView.mm

+73-18
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ static CVReturn draw(
5555
)
5656
{
5757
mutex.lock();
58-
zsize index = activeInstances.size();
5958

60-
while (index)
59+
for (auto view : activeInstances)
6160
{
62-
GLVideoView *view = activeInstances[--index];
6361
CGLSetCurrentContext(view->_CGLContext);
6462
view->_renderer->draw(true);
6563
}
@@ -93,8 +91,14 @@ - (id) initWithFrame: (NSRect) frame
9391
_CGLContext = _GLContext.CGLContextObj;
9492

9593
SET_CONTEXT;
96-
_renderer = new GLFrameBufferRenderer();
97-
_renderer->set_geometry(self.bounds, Z_SCALING_EXPAND);
94+
95+
glDisable(GL_DEPTH_TEST);
96+
97+
(_renderer = new GLFrameBufferRenderer())->set_geometry
98+
(Rectangle<Real>([self respondsToSelector: @selector(convertSizeToBacking:)]
99+
? [self convertSizeToBacking: self.bounds.size]
100+
: self.bounds.size),
101+
Z_SCALING_EXPAND);
98102

99103
NSBundle *bundle = [NSBundle mainBundle];
100104
std::string *error;
@@ -160,13 +164,12 @@ - (void) lockFocus
160164

161165
+ (void) draw: (CADisplayLink *) sender
162166
{
163-
zsize index = activeInstances.size();
164-
165-
while (index)
167+
for (auto view : activeInstances)
166168
{
167-
GLVideoView *view = activeInstances[--index];
168169
[EAGLContext setCurrentContext: view->_GLContext];
170+
glClear(GL_COLOR_BUFFER_BIT);
169171
view->_renderer->draw(true);
172+
[view->_GLContext presentRenderbuffer: GL_RENDERBUFFER];
170173
}
171174

172175
RESTORE_CONTEXT;
@@ -176,20 +179,14 @@ + (void) draw: (CADisplayLink *) sender
176179
+ (Class) layerClass {return [CAEAGLLayer class];}
177180

178181

179-
- (void) render
180-
{
181-
glClearColor(0, 104.0/255.0, 55.0/255.0, 1.0);
182-
glClear(GL_COLOR_BUFFER_BIT);
183-
[_GLContext presentRenderbuffer: GL_RENDERBUFFER];
184-
}
185-
186-
187182
- (id) initWithCoder: (NSCoder *) coder
188183
{
189184
if ((self = [super initWithCoder: coder]))
190185
{
191186
(_EAGLLayer = (CAEAGLLayer *) self.layer).opaque = YES;
192187

188+
/*_EAGLLayer.drawableProperties = @{ kEAGLDrawablePropertyRetainedBacking : [NSNumber numberWithBool: YES],
189+
kEAGLDrawablePropertyColorFormat : kEAGLColorFormatRGBA8};*/
193190
if (!(_GLContext = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2]))
194191
{
195192
NSLog(@"Failed to initialize OpenGLES 2.0 context");
@@ -202,6 +199,11 @@ - (id) initWithCoder: (NSCoder *) coder
202199
exit(1);
203200
}
204201

202+
SET_CONTEXT;
203+
204+
glDisable(GL_DEPTH_TEST);
205+
glClearColor(0, 104.0/255.0, 55.0/255.0, 1.0);
206+
205207
glGenRenderbuffers(1, &_renderBuffer);
206208
glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffer);
207209
[_GLContext renderbufferStorage: GL_RENDERBUFFER fromDrawable: _EAGLLayer];
@@ -211,7 +213,59 @@ - (id) initWithCoder: (NSCoder *) coder
211213
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
212214
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _renderBuffer);
213215

214-
[self render];
216+
_renderer = new GLFrameBufferRenderer();
217+
218+
Rectangle<Real> bounds = self.bounds;
219+
UIScreen *screen = UIScreen.mainScreen;
220+
221+
if ([screen respondsToSelector: @selector(displayLinkWithTarget:selector:)])
222+
bounds.size *= screen.scale;
223+
224+
NSLog(@"%@ x %f", NSStringFromCGRect(bounds), UIScreen.mainScreen.scale);
225+
_renderer->set_geometry(bounds, Z_SCALING_EXPAND);
226+
227+
NSBundle *bundle = [NSBundle mainBundle];
228+
std::string *error;
229+
230+
NSString *sourceCode = [NSString
231+
stringWithContentsOfFile: [bundle pathForResource: @"Simple" ofType: @"vsh"]
232+
encoding: NSUTF8StringEncoding
233+
error: nullptr];
234+
235+
if (!_renderer->set_vertex_shader((Character *)sourceCode.UTF8String, &error))
236+
{
237+
NSLog(@"Can not compile OpenGL vertext shader:\n%s", error->c_str());
238+
/*[[NSAlert alertWithError: [NSError errorWithDomain: @"OpenGL" code: 0 userInfo:
239+
@{NSLocalizedDescriptionKey: @"Can not compile OpenGL vertext shader",
240+
NSLocalizedRecoverySuggestionErrorKey: [NSString stringWithUTF8String: error->c_str()]}]]
241+
runModal];*/
242+
243+
delete error;
244+
}
245+
246+
sourceCode = [NSString
247+
stringWithContentsOfFile: [bundle pathForResource: @"Simple" ofType: @"fsh"]
248+
encoding: NSUTF8StringEncoding
249+
error: nullptr];
250+
251+
if (!_renderer->set_fragment_shader((Character *)sourceCode.UTF8String, &error))
252+
{
253+
NSLog(@"Can not compile OpenGL fragment shader:\n%s", error->c_str());
254+
/*[[NSAlert alertWithError: [NSError errorWithDomain: @"OpenGL" code: 0 userInfo:
255+
@{NSLocalizedDescriptionKey: @"Can not compile OpenGL fragment shader",
256+
NSLocalizedRecoverySuggestionErrorKey: [NSString stringWithUTF8String: error->c_str()]}]]
257+
runModal];*/
258+
259+
delete error;
260+
}
261+
262+
_renderer->create_shader_program();
263+
264+
//glClearColor(0, 104.0/255.0, 55.0/255.0, 1.0);
265+
//glClear(GL_COLOR_BUFFER_BIT);
266+
//[_GLContext presentRenderbuffer: GL_RENDERBUFFER];
267+
268+
RESTORE_CONTEXT;
215269
}
216270

217271
//NSLog(@"init GL");
@@ -270,6 +324,7 @@ - (void) drawRect: (NSRect) frame
270324
}
271325

272326
_renderer->draw(false);
327+
273328
_flags.reshaped = NO;
274329
//}
275330

0 commit comments

Comments
 (0)
Please sign in to comment.