Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix compile errors for latest Elements #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Oxygene/Toffee/OS X/Metal/MetalExample/ExampleHelpers.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace MetalExample;

interface
uses
Metal,
MetalKit;


type
MetalHelper = class
public
class method createBox(_device: MTLDevice) : VertexBuffer;
end;

implementation

class method MetalHelper.createBox(_device: MTLDevice): VertexBuffer;

const

BOX_VERTICES: array of Single = [
// Positions // Normals
// unten
-0.5, -0.5, -0.5, 0.0, 0.0, -1.0, // 0
0.5, -0.5, -0.5, 0.0, 0.0, -1.0, // 1
0.5, 0.5, -0.5, 0.0, 0.0, -1.0, //2
-0.5, 0.5, -0.5, 0.0, 0.0, -1.0, //3
// Oben
-0.5, -0.5, 0.5, 0.0, 0.0, 1.0, //4
0.5, -0.5, 0.5, 0.0, 0.0, 1.0, //5
0.5, 0.5, 0.5, 0.0, 0.0, 1.0, // 6
-0.5, 0.5, 0.5, 0.0, 0.0, 1.0, //7
//Links
-0.5, 0.5, 0.5, -1.0, 0.0, 0.0, //8
-0.5, 0.5, -0.5, -1.0, 0.0, 0.0, //9
-0.5, -0.5, -0.5, -1.0, 0.0, 0.0, //10
-0.5, -0.5, 0.5, -1.0, 0.0, 0.0, //11
//Rechts
0.5, 0.5, 0.5, 1.0, 0.0, 0.0, //12
0.5, 0.5, -0.5, 1.0, 0.0, 0.0, //13
0.5, -0.5, -0.5, 1.0, 0.0, 0.0, //14
0.5, -0.5, 0.5, 1.0, 0.0, 0.0, //15
// hinten
-0.5, -0.5, -0.5, 0.0, -1.0, 0.0, //16
0.5, -0.5, -0.5, 0.0, -1.0, 0.0, //17
0.5, -0.5, 0.5, 0.0, -1.0, 0.0, //18
-0.5, -0.5, 0.5, 0.0, -1.0, 0.0, //19

-0.5, 0.5, -0.5, 0.0, 1.0, 0.0,
0.5, 0.5, -0.5, 0.0, 1.0, 0.0,
0.5, 0.5, 0.5, 0.0, 1.0, 0.0,
-0.5, 0.5, 0.5, 0.0, 1.0, 0.0];


{ The indices define 2 triangles per cube face, 6 faces total }
INDICES: array of UInt16 = [
2, 1, 0, 0, 3, 2, // Unten
4, 5, 6, 6, 7, 4, // Oben
8, 9, 10, 10, 11, 8, //Links
14, 13, 12, 12, 15, 14,// Rechts
16, 17, 18, 18, 19, 16 , //Hinten
22, 21, 20, 20, 23, 22]; // Vorne
begin
var FBox := new VertexArray(BOX_VERTICES, 6, INDICES);
result := VertexBuffer.newBuffer(_device) SoureArray(FBox);
end;

end.
106 changes: 105 additions & 1 deletion Oxygene/Toffee/OS X/Metal/MetalExample/ExampleMetalView.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,38 @@ interface
MetalKit;

type
mouseDownstate = enum(none, cmd, shift, alt, ctrl);
[IBObject]
Metal_View = public class(MTKView)
private

trackingArea: NSTrackingArea;
fMousePos : NSPoint;
{$HIDE H6}
fMouseDownPos : NSPoint;
mState : mouseDownstate;
{$SHOW H6}
{$HIDE H7}
fMousein : Boolean;
fFilllayer : Boolean := true;
{$SHOW H7}
method setTrackingAreas;

private
fMouseDelegate : nullable MetalMouseDelegate;
public
method awakeFromNib; override;
method setFrameSize(newSize: NSSize); override;

method mouseEntered(&event: not nullable NSEvent); override;
method mouseExited(&event: not nullable NSEvent); override;
method mouseDown(&event: not nullable NSEvent); override;
method mouseUp(&event: not nullable NSEvent); override;
method mouseMoved(&event: not nullable NSEvent); override;
method mouseDragged(&event: not nullable NSEvent); override;

property MouseDelegate : nullable MetalMouseDelegate read fMouseDelegate write fMouseDelegate;

end;

implementation
Expand All @@ -19,8 +47,84 @@ implementation
inherited;
device := MTLCreateSystemDefaultDevice();
if device = nil then
NSLog("Could not create a default MetalDevice!!")
NSLog("Could not create a default MetalDevice!!");
setTrackingAreas;
end;

method Metal_View.mouseEntered(&event: not nullable NSEvent);
begin
fMousein := true;
NSLog("mouseEntered");
if fMouseDelegate:DontShowCursor then
begin
NSCursor.hide;
fMouseDelegate:showCrosshair := true;
end;
end;

method Metal_View.mouseExited(&event: not nullable NSEvent);
begin
fMousein := false;
NSLog("mouseExited");
// if fMouseDelegate:DontShowCursor then
NSCursor.unhide;
fMouseDelegate:showCrosshair := false;
end;

method Metal_View.mouseDown(&event: not nullable NSEvent);
begin
NSLog("mouseDown");
end;

method Metal_View.mouseUp(&event: not nullable NSEvent);
begin
NSLog("mouseUp");
end;

method Metal_View.mouseMoved(&event: not nullable NSEvent);
begin
fMousePos :=convertPointToBacking(
convertPoint(&event.locationInWindow) fromView(nil));
fMouseDelegate:MouseMove(fMousePos.x, fMousePos.y);
// NSLog("mouseMoved");
end;

method Metal_View.mouseDragged(&event: not nullable NSEvent);
begin
fMousePos :=convertPointToBacking(
convertPoint(&event.locationInWindow) fromView(nil));
fMouseDelegate:MouseMove(fMousePos.x, fMousePos.y);
// NSLog("mouseDragged");
end;



method Metal_View.setTrackingAreas;
begin
// Remove existing tracking area if necessary.
if trackingArea <> nil then
removeTrackingArea(trackingArea);

// Create new tracking area.
var options: NSTrackingAreaOptions := [
NSTrackingAreaOptions.MouseEnteredAndExited,
NSTrackingAreaOptions.MouseMoved,
NSTrackingAreaOptions.ActiveInActiveApp,
NSTrackingAreaOptions.NSTrackingInVisibleRect
,NSTrackingAreaOptions.EnabledDuringMouseDrag

// NSTrackingAreaOptions.ActiveInActiveApp,
];
trackingArea := new NSTrackingArea() withRect(frame) options(options) owner(self) userInfo(nil);
addTrackingArea(trackingArea);
end;

method Metal_View.setFrameSize(newSize: NSSize);
begin
inherited setFrameSize(newSize);
setTrackingAreas;
end;



end.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
method switchApp(const AppId : Integer);
//method MainWindowController.switchApp(const AppId: Integer);
begin
var App : MTKViewDelegate := nil;
var App : MetalBaseDelegate := nil;
case AppId of

0 : begin
Expand All @@ -29,10 +29,14 @@
App := new MetalExample3 InitWithMetalKitView(ViewGL);
TimeLabel.label := '"Basic Texturing" running';
end;

3 : begin
App := new MetalExample4 InitWithMetalKitView(ViewGL);
TimeLabel.label := '"Basic Texturing" with Blend running';
end;

4 : begin
App := new MetalExample5 InitWithMetalKitView(ViewGL);
TimeLabel.label := '"Draw a Cube" running';
end
else
begin
Expand All @@ -51,7 +55,7 @@
renderer := App;
renderer.mtkView(ViewGL) drawableSizeWillChange(ViewGL.drawableSize);
ViewGL.delegate := renderer;

ViewGL.MouseDelegate := App;
end;
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ interface
var ViewGL: Metal_View;
[IBOutlet]
var TimeLabel : NSToolbarItem;

[IBAction]
method pressAppButton(sender: id);

// Overrides from NSWindowController
method init: instancetype; override;
method init: InstanceType; override;
method windowDidLoad; override;

end;
Expand All @@ -43,6 +44,8 @@ implementation
begin
switchApp(-1);
ViewGL.preferredFramesPerSecond := 60;
ViewGL.depthStencilPixelFormat := MTLPixelFormat.Depth32Float;
//ViewGL.depthStencilTexture
end;
end;

Expand Down
16 changes: 11 additions & 5 deletions Oxygene/Toffee/OS X/Metal/MetalExample/MainWindowController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gMs-7I-f7w" customClass="Metal_View">
<rect key="frame" x="0.0" y="0.0" width="674" height="420"/>
<rect key="frame" x="10" y="10" width="656" height="404"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</customView>
</subviews>
Expand All @@ -42,21 +42,26 @@
<action selector="pressAppButton:" target="-2" id="que-tj-DWG"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="E1376B8C-C6EE-41ED-99ED-C50846C540A0" label="Buffers" paletteLabel="Buffers" tag="1" image="NSApplicationIcon" id="cLD-md-mIt">
<toolbarItem implicitItemIdentifier="E1376B8C-C6EE-41ED-99ED-C50846C540A0" label="Buffers" paletteLabel="Buffers" toolTip="Show Vertexbuffer" tag="1" image="NSApplicationIcon" id="cLD-md-mIt">
<connections>
<action selector="pressAppButton:" target="-2" id="Ive-zU-Pkc"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="57588774-2ECD-4F51-8CAE-4B204E1F2D11" label="Texture" paletteLabel="Texture" tag="2" image="NSApplicationIcon" id="sFH-as-3pN">
<toolbarItem implicitItemIdentifier="57588774-2ECD-4F51-8CAE-4B204E1F2D11" label="Texture" paletteLabel="Texture" toolTip="Simple Texture" tag="2" image="NSApplicationIcon" id="sFH-as-3pN">
<connections>
<action selector="pressAppButton:" target="-2" id="NLU-T3-iNZ"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="C72D4495-EAF1-433B-BB8D-951BE62DA337" label="TextureBlend" paletteLabel="TextureBlend" tag="3" image="NSApplicationIcon" id="WrR-0X-Xiq">
<toolbarItem implicitItemIdentifier="C72D4495-EAF1-433B-BB8D-951BE62DA337" label="TextureBlend" paletteLabel="TextureBlend" toolTip="Blend two Textures" tag="3" image="NSApplicationIcon" id="WrR-0X-Xiq">
<connections>
<action selector="pressAppButton:" target="-2" id="UNC-kq-ucm"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="1D9689B9-2A9C-47A7-B32A-D1A1355CB712" label="Draw Cube" paletteLabel="Draw Cube" toolTip="Draw a Cube" tag="4" image="NSApplicationIcon" id="L7Q-3V-hz2">
<connections>
<action selector="pressAppButton:" target="-2" id="Ws7-GB-SVo"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="B20549DE-71B5-4871-934F-DBF173AA0D84" label="Timelabel" paletteLabel="Timelabel" tag="-1" image="NSComputer" id="B49-Dp-Jrk">
<nil key="toolTip"/>
<size key="minSize" width="38" height="17"/>
Expand All @@ -77,11 +82,12 @@
<toolbarItem reference="cLD-md-mIt"/>
<toolbarItem reference="sFH-as-3pN"/>
<toolbarItem reference="WrR-0X-Xiq"/>
<toolbarItem reference="L7Q-3V-hz2"/>
<toolbarItem reference="oW0-8F-L0i"/>
<toolbarItem reference="B49-Dp-Jrk"/>
</defaultToolbarItems>
</toolbar>
<point key="canvasLocation" x="135" y="93.5"/>
<point key="canvasLocation" x="135" y="93"/>
</window>
<userDefaultsController representsSharedInstance="YES" id="xBt-do-dpi"/>
</objects>
Expand Down
20 changes: 18 additions & 2 deletions Oxygene/Toffee/OS X/Metal/MetalExample/MetalExample.elements
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
<AllowLegacyOutParams>False</AllowLegacyOutParams>
<AllowLegacyCreate>False</AllowLegacyCreate>
<AllowUnsafeCode>False</AllowUnsafeCode>
<UseLegacyPreprocessor>true</UseLegacyPreprocessor>
<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
<SDK>macOS</SDK>
<MangleTypeNames>True</MangleTypeNames>
<CreateAppBundle>True</CreateAppBundle>
<InfoPListFile>.\Resources\Info.plist</InfoPListFile>
<EntitlementsFile>Resources\Entitlements.entitlements</EntitlementsFile>
<MacIconFile>.\Resources\App.icns</MacIconFile>
<DefaultUses>RemObjects.Elements.RTL</DefaultUses>
<DefaultLanguage>Oxygene</DefaultLanguage>
<EntitlementsFile>.\Resources\Entitlements.entitlements</EntitlementsFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Optimize>false</Optimize>
Expand All @@ -29,6 +31,7 @@
<CaptureConsoleOutput>False</CaptureConsoleOutput>
<WarnOnCaseMismatch>True</WarnOnCaseMismatch>
<XmlDoc>False</XmlDoc>
<UseLegacyPreprocessor>true</UseLegacyPreprocessor>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<Optimize>true</Optimize>
Expand All @@ -38,6 +41,7 @@
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<CaptureConsoleOutput>False</CaptureConsoleOutput>
<WarnOnCaseMismatch>True</WarnOnCaseMismatch>
<UseLegacyPreprocessor>false</UseLegacyPreprocessor>
</PropertyGroup>
<ItemGroup>
<Reference Include="Cocoa" />
Expand All @@ -49,6 +53,7 @@
<Reference Include="CoreFoundation" />
<Reference Include="Metal" />
<Reference Include="MetalKit" />
<Reference Include="SceneKit" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppDelegate.pas" />
Expand All @@ -57,6 +62,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Resources" />
<Folder Include="MetalHelper" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\Info.plist" />
Expand All @@ -78,11 +84,21 @@
<Compile Include="MetalExample3.pas" />
<Compile Include="MetalExample4.pas" />
<MetalShader Include="Shader\AAPLShaders4.metal" />
<Compile Include="MetalVertexBuffer.pas" />
<Compile Include="MainWindowController.Metal.pas" />
<Compile Include="MetalExampleTypes.pas" />
<None Include="Shader\AAPLShaderTypes.h" />
<Compile Include="MetalShaderLoader.pas" />
<Compile Include="MetalExample5.pas" />
<Compile Include="MetalHelper\MetalGlobals.pas" />
<Compile Include="MetalHelper\MetalMatrix3.pas" />
<Compile Include="MetalHelper\MetalMatrix4.pas" />
<Compile Include="MetalHelper\Metalvec2.pas" />
<Compile Include="MetalHelper\MetalVec3.pas" />
<Compile Include="MetalHelper\MetalVec4.pas" />
<Compile Include="MetalHelper\MetalVertexArrays.pas" />
<Compile Include="MetalHelper\MetalVertexBuffer.pas" />
<MetalShader Include="Shader\AAPLShaders5.metal" />
<Compile Include="ExampleHelpers.pas" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\RemObjects Software\Elements\RemObjects.Elements.Toffee.targets" />
</Project>
3 changes: 2 additions & 1 deletion Oxygene/Toffee/OS X/Metal/MetalExample/MetalExample2.pas
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ implementation


renderEncoder.setRenderPipelineState(_pipelineState);

renderEncoder.setTriangleFillMode(MTLTriangleFillMode.Fill);
renderEncoder.setCullMode(MTLCullMode.None);

// We call -[MTLRenderCommandEncoder setVertexBuffer:offset:atIndex:] to send data in our
// preloaded MTLBuffer from our ObjC code here to our Metal 'vertexShader' function
Expand Down
Loading