Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagons committed Mar 13, 2019
2 parents 4daee8d + 373cd3b commit 7207bdd
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 28 deletions.
18 changes: 12 additions & 6 deletions Pixels.xcodeproj/PixelsShaders.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
3A2839BC2238FED900D0FD69 /* ContentResourcePIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 3A2839BB2238FED900D0FD69 /* ContentResourcePIX.metal */; };
3A2839BD2238FED900D0FD69 /* ContentResourcePIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 3A2839BB2238FED900D0FD69 /* ContentResourcePIX.metal */; };
3A77CD8021B169FC006BB415 /* error.metal in Sources */ = {isa = PBXBuildFile; fileRef = 3A77CD7F21B169FC006BB415 /* error.metal */; };
3A77CD8121B169FC006BB415 /* error.metal in Sources */ = {isa = PBXBuildFile; fileRef = 3A77CD7F21B169FC006BB415 /* error.metal */; };
740EE376212DD5030065F49B /* noise.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE35E212DD5030065F49B /* noise.metal */; };
740EE377212DD5030065F49B /* ContentResourceImagePIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE35F212DD5030065F49B /* ContentResourceImagePIX.metal */; };
740EE377212DD5030065F49B /* ContentResourceFlipPIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE35F212DD5030065F49B /* ContentResourceFlipPIX.metal */; };
740EE378212DD5030065F49B /* ContentGeneratorNoisePIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE360212DD5030065F49B /* ContentGeneratorNoisePIX.metal */; };
740EE379212DD5030065F49B /* EffectMergerLumaBlurPIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE361212DD5030065F49B /* EffectMergerLumaBlurPIX.metal */; };
740EE37A212DD5030065F49B /* ContentGeneratorPolygonPIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE362212DD5030065F49B /* ContentGeneratorPolygonPIX.metal */; };
Expand Down Expand Up @@ -58,7 +60,7 @@
74E9F6D22193815F00F541DE /* ContentGeneratorPolygonPIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE362212DD5030065F49B /* ContentGeneratorPolygonPIX.metal */; };
74E9F6D32193815F00F541DE /* ContentGeneratorRectanglePIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 748859DE212F36EB00E04F17 /* ContentGeneratorRectanglePIX.metal */; };
74E9F6D42193815F00F541DE /* ContentResourceCameraPIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE372212DD5030065F49B /* ContentResourceCameraPIX.metal */; };
74E9F6D52193815F00F541DE /* ContentResourceImagePIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE35F212DD5030065F49B /* ContentResourceImagePIX.metal */; };
74E9F6D52193815F00F541DE /* ContentResourceFlipPIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE35F212DD5030065F49B /* ContentResourceFlipPIX.metal */; };
74E9F6D62193815F00F541DE /* EffectMergerBlendPIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 7424A1B0212F5A5600401654 /* EffectMergerBlendPIX.metal */; };
74E9F6D72193815F00F541DE /* EffectMergerCrossPIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 740EE366212DD5030065F49B /* EffectMergerCrossPIX.metal */; };
74E9F6D82193815F00F541DE /* EffectMergerDisplacePIX.metal in Sources */ = {isa = PBXBuildFile; fileRef = 7473B4FA214175C0008C6F23 /* EffectMergerDisplacePIX.metal */; };
Expand Down Expand Up @@ -96,9 +98,10 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
3A2839BB2238FED900D0FD69 /* ContentResourcePIX.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = ContentResourcePIX.metal; sourceTree = "<group>"; };
3A77CD7F21B169FC006BB415 /* error.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = error.metal; sourceTree = "<group>"; };
740EE35E212DD5030065F49B /* noise.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = noise.metal; sourceTree = "<group>"; };
740EE35F212DD5030065F49B /* ContentResourceImagePIX.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = ContentResourceImagePIX.metal; sourceTree = "<group>"; };
740EE35F212DD5030065F49B /* ContentResourceFlipPIX.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = ContentResourceFlipPIX.metal; sourceTree = "<group>"; };
740EE360212DD5030065F49B /* ContentGeneratorNoisePIX.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = ContentGeneratorNoisePIX.metal; sourceTree = "<group>"; };
740EE361212DD5030065F49B /* EffectMergerLumaBlurPIX.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = EffectMergerLumaBlurPIX.metal; sourceTree = "<group>"; };
740EE362212DD5030065F49B /* ContentGeneratorPolygonPIX.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = ContentGeneratorPolygonPIX.metal; sourceTree = "<group>"; };
Expand Down Expand Up @@ -154,7 +157,8 @@
740EE362212DD5030065F49B /* ContentGeneratorPolygonPIX.metal */,
748859DE212F36EB00E04F17 /* ContentGeneratorRectanglePIX.metal */,
740EE372212DD5030065F49B /* ContentResourceCameraPIX.metal */,
740EE35F212DD5030065F49B /* ContentResourceImagePIX.metal */,
740EE35F212DD5030065F49B /* ContentResourceFlipPIX.metal */,
3A2839BB2238FED900D0FD69 /* ContentResourcePIX.metal */,
7424A1B0212F5A5600401654 /* EffectMergerBlendPIX.metal */,
740EE366212DD5030065F49B /* EffectMergerCrossPIX.metal */,
7473B4FA214175C0008C6F23 /* EffectMergerDisplacePIX.metal */,
Expand Down Expand Up @@ -324,8 +328,9 @@
748859DF212F36EB00E04F17 /* ContentGeneratorRectanglePIX.metal in Sources */,
740EE38D212DD5030065F49B /* NilPIX.metal in Sources */,
740EE383212DD5030065F49B /* EffectSingleBlurPIX.metal in Sources */,
740EE377212DD5030065F49B /* ContentResourceImagePIX.metal in Sources */,
740EE377212DD5030065F49B /* ContentResourceFlipPIX.metal in Sources */,
3A77CD8021B169FC006BB415 /* error.metal in Sources */,
3A2839BC2238FED900D0FD69 /* ContentResourcePIX.metal in Sources */,
740EE37D212DD5030065F49B /* EffectSingleKaleidoscopePIX.metal in Sources */,
74B488A0214121930033B3B5 /* EffectSingleFlipFlopPIX.metal in Sources */,
);
Expand Down Expand Up @@ -364,7 +369,7 @@
74E9F6E62193815F00F541DE /* EffectSingleLevelsPIX.metal in Sources */,
74E9F6E22193815F00F541DE /* EffectSingleEdgePIX.metal in Sources */,
74E9F6D22193815F00F541DE /* ContentGeneratorPolygonPIX.metal in Sources */,
74E9F6D52193815F00F541DE /* ContentResourceImagePIX.metal in Sources */,
74E9F6D52193815F00F541DE /* ContentResourceFlipPIX.metal in Sources */,
74E9F6D72193815F00F541DE /* EffectMergerCrossPIX.metal in Sources */,
74E9F6F12193815F00F541DE /* SpritePIX.metal in Sources */,
74E9F6E32193815F00F541DE /* EffectSingleFlipFlopPIX.metal in Sources */,
Expand All @@ -376,6 +381,7 @@
74E9F6E02193815F00F541DE /* EffectSingleChromaKeyPIX.metal in Sources */,
74E9F6E92193815F00F541DE /* EffectSingleResPIX.metal in Sources */,
3A77CD8121B169FC006BB415 /* error.metal in Sources */,
3A2839BD2238FED900D0FD69 /* ContentResourcePIX.metal in Sources */,
74E9F6DE2193815F00F541DE /* EffectSingleBlurPIX.metal in Sources */,
74E9F6F52193815F00F541DE /* QuadVTX.metal in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ struct VertexOut{
float2 texCoord;
};

fragment float4 contentResourceImagePIX(VertexOut out [[stage_in]],
texture2d<float> inTex [[ texture(0) ]],
sampler s [[ sampler(0) ]]) {
fragment float4 contentResourceFlipPIX(VertexOut out [[stage_in]],
texture2d<float> inTex [[ texture(0) ]],
sampler s [[ sampler(0) ]]) {

float u = out.texCoord[0];
float v = out.texCoord[1];
Expand Down
4 changes: 2 additions & 2 deletions Shaders/EffectMergerBlendPIX.metal
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ fragment float4 effectMergerBlendPIX(VertexOut out [[stage_in]],
}
break;
case 3: // Center
bu = 0.5 + (u - 0.5) * (aw / bw);
bv = 0.5 + (v - 0.5) * (ah / bh);
bu = 0.5 + ((u - 0.5) * aw) / bw;
bv = 0.5 + ((v - 0.5) * ah) / bh;
break;
}

Expand Down
4 changes: 2 additions & 2 deletions Shaders/EffectMergerCrossPIX.metal
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ fragment float4 effectMergerCrossPIX(VertexOut out [[stage_in]],
}
break;
case 3: // Center
bu = 0.5 + (u - 0.5) * (aw / bw);
bv = 0.5 + (v - 0.5) * (ah / bh);
bu = 0.5 + ((u - 0.5) * aw) / bw;
bv = 0.5 + ((v - 0.5) * ah) / bh;
break;
}
float4 cb = inTexB.sample(s, float2(bu, bv));
Expand Down
4 changes: 2 additions & 2 deletions Shaders/EffectMergerReorderPIX.metal
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ fragment float4 effectMergerReorderPIX(VertexOut out [[stage_in]],
}
break;
case 3: // Center
bu = 0.5 + (u - 0.5) * (aw / bw);
bv = 0.5 + (v - 0.5) * (ah / bh);
bu = 0.5 + ((u - 0.5) * aw) / bw;
bv = 0.5 + ((v - 0.5) * ah) / bh;
break;
}
float4 cb = inTexB.sample(s, float2(bu, bv));
Expand Down
6 changes: 5 additions & 1 deletion Source/PIX/Content/Resource/ImagePIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import AppKit

public class ImagePIX: PIXResource {

override open var shader: String { return "contentResourceImagePIX" }
#if os(iOS)
override open var shader: String { return "contentResourceFlipPIX" }
#elseif os(macOS)
override open var shader: String { return "contentResourcePIX" }
#endif

// MARK: - Public Properties

Expand Down
12 changes: 6 additions & 6 deletions Source/PIX/PIXRendered.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ public extension PIX {
})
}

var renderedPixelBuffer: CVPixelBuffer? {
guard let res = resolution else { return nil }
guard let cgImage = renderedCGImage else { return nil }
public var renderedPixelBuffer: CVPixelBuffer? {
guard let res = resolution else { pixels.log(.error, nil, "renderedPixelBuffer: no res."); return nil }
guard let cgImage = renderedCGImage else { pixels.log(.error, nil, "renderedPixelBuffer: no cgImage."); return nil }
var maybePixelBuffer: CVPixelBuffer?
let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue,
kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue]
let status = CVPixelBufferCreate(kCFAllocatorDefault, res.w, res.h, Pixels.main.bits.os, attrs as CFDictionary, &maybePixelBuffer)
guard status == kCVReturnSuccess, let pixelBuffer = maybePixelBuffer else { return nil }
guard status == kCVReturnSuccess, let pixelBuffer = maybePixelBuffer else { pixels.log(.error, nil, "renderedPixelBuffer: CVPixelBufferCreate failed with status \(status)"); return nil }
let flags = CVPixelBufferLockFlags(rawValue: 0)
guard kCVReturnSuccess == CVPixelBufferLockBaseAddress(pixelBuffer, flags) else { return nil }
guard kCVReturnSuccess == CVPixelBufferLockBaseAddress(pixelBuffer, flags) else { pixels.log(.error, nil, "renderedPixelBuffer: CVPixelBufferLockBaseAddress failed."); return nil }
defer { CVPixelBufferUnlockBaseAddress(pixelBuffer, flags) }
guard let context = CGContext(data: CVPixelBufferGetBaseAddress(pixelBuffer), width: res.w, height: res.h, bitsPerComponent: Pixels.main.bits.rawValue, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer), space: Pixels.main.colorSpace.cg, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { return nil }
guard let context = CGContext(data: CVPixelBufferGetBaseAddress(pixelBuffer), width: res.w, height: res.h, bitsPerComponent: Pixels.main.bits.rawValue, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer), space: Pixels.main.colorSpace.cg, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { pixels.log(.error, nil, "renderedPixelBuffer: context failed to be created."); return nil }
context.draw(cgImage, in: CGRect(x: 0, y: 0, width: res.width, height: res.height))
return pixelBuffer
}
Expand Down
4 changes: 3 additions & 1 deletion Source/PIX/PIXRes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ public extension PIX {
if [.portrait, .portraitUpsideDown].contains(UIApplication.shared.statusBarOrientation) { return size }
else { return CGSize(width: size.height, height: size.width) }
#elseif os(macOS)
return NSScreen.main?.frame.size ?? Res._128.size
let size = NSScreen.main?.frame.size ?? Res._128.size
let scale = NSScreen.main?.backingScaleFactor ?? 1.0
return CGSize(width: size.width * scale, height: size.height * scale)
#endif
case .size(let size): return size
case .custom(let w, let h): return CGSize(width: w, height: h)
Expand Down
6 changes: 1 addition & 5 deletions Source/PIX/View/PIXView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ public class PIXView: _View {
width = resolutionAspect <= viewAspect ? bounds.width : bounds.width * dynamicAspect
height = resolutionAspect >= viewAspect ? bounds.height : bounds.height * dynamicAspect
case .pixelPerfect:
#if os(iOS)
let scale: CGFloat = UIScreen.main.nativeScale
#elseif os(macOS)
let scale: CGFloat = 1.0
#endif
let scale: CGFloat = PIX.Res.scale
width = res.width / scale
height = res.height / scale
case .fill:
Expand Down

0 comments on commit 7207bdd

Please sign in to comment.