зеркало из https://github.com/xamarin/mac-samples.git
Add new sample for GLSL Shaders.
This commit is contained in:
Родитель
8b7ff3cc14
Коммит
1f9fa03a23
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.AppKit;
|
||||
using MonoMac.ObjCRuntime;
|
||||
|
||||
namespace GLSLShader
|
||||
{
|
||||
public partial class AppDelegate : NSApplicationDelegate
|
||||
{
|
||||
MainWindowController mainWindowController;
|
||||
|
||||
public AppDelegate ()
|
||||
{
|
||||
}
|
||||
|
||||
public override void FinishedLaunching (NSObject notification)
|
||||
{
|
||||
mainWindowController = new MainWindowController ();
|
||||
mainWindowController.Window.MakeKeyAndOrderFront (this);
|
||||
}
|
||||
|
||||
public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
void main()
|
||||
{
|
||||
gl_FragColor = vec4(0.0,0.0,1.0,1.0);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
void main()
|
||||
{
|
||||
gl_Position = ftransform();
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{15E135C5-055E-4906-9407-B4F8079DFD13}</ProjectGuid>
|
||||
<ProjectTypeGuids>{1C533B1C-72DD-4CB1-9F6B-BF11D93BCFBE};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>GLSLShader</RootNamespace>
|
||||
<AssemblyName>GLSLShader</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="MonoMac">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MainWindow.cs">
|
||||
<DependentUpon>MainWindow.xib</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MainWindowController.cs">
|
||||
<DependentUpon>MainWindow.xib</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow.xib.designer.cs">
|
||||
<DependentUpon>MainWindow.xib</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="AppDelegate.cs">
|
||||
<DependentUpon>MainMenu.xib</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MainMenu.xib.designer.cs">
|
||||
<DependentUpon>MainMenu.xib</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MyOpenGLView.cs" />
|
||||
<Compile Include="Scene.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="MainWindow.xib" />
|
||||
<Page Include="MainMenu.xib" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Info.plist" />
|
||||
<None Include="README.md" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Mono\MonoMac\v0.0\Mono.MonoMac.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="GLSL\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="GLSL\shader.frag" />
|
||||
<Content Include="GLSL\shader.vert" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GLSLShader", "GLSLShader.csproj", "{15E135C5-055E-4906-9407-B4F8079DFD13}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Distribution|Any CPU = Distribution|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{15E135C5-055E-4906-9407-B4F8079DFD13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{15E135C5-055E-4906-9407-B4F8079DFD13}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{15E135C5-055E-4906-9407-B4F8079DFD13}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{15E135C5-055E-4906-9407-B4F8079DFD13}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = GLSLShader.csproj
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.yourcompany.GLSLShader</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>GLSLShader</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.6</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.AppKit;
|
||||
using MonoMac.ObjCRuntime;
|
||||
|
||||
namespace GLSLShader
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
static void Main (string[] args)
|
||||
{
|
||||
NSApplication.Init ();
|
||||
NSApplication.Main (args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,18 @@
|
|||
// ------------------------------------------------------------------------------
|
||||
// <autogenerated>
|
||||
// This code was generated by a tool.
|
||||
// Mono Runtime Version: 4.0.30319.1
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </autogenerated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace GLSLShader {
|
||||
|
||||
|
||||
// Should subclass MonoMac.AppKit.NSResponder
|
||||
[MonoMac.Foundation.Register("AppDelegate")]
|
||||
public partial class AppDelegate {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.AppKit;
|
||||
|
||||
namespace GLSLShader
|
||||
{
|
||||
public partial class MainWindow : MonoMac.AppKit.NSWindow
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
// Called when created from unmanaged code
|
||||
public MainWindow (IntPtr handle) : base (handle)
|
||||
{
|
||||
Initialize ();
|
||||
}
|
||||
|
||||
// Called when created directly from a XIB file
|
||||
[Export ("initWithCoder:")]
|
||||
public MainWindow (NSCoder coder) : base (coder)
|
||||
{
|
||||
Initialize ();
|
||||
}
|
||||
|
||||
// Shared initialization code
|
||||
void Initialize ()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,252 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">1060</int>
|
||||
<string key="IBDocument.SystemVersion">10J869</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">804</string>
|
||||
<string key="IBDocument.AppKitVersion">1038.35</string>
|
||||
<string key="IBDocument.HIToolboxVersion">461.00</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="NS.object.0">804</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="7"/>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="IBDocument.Metadata">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys" id="0">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSCustomObject" id="1001">
|
||||
<string key="NSClassName">MainWindowController</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="1003">
|
||||
<string key="NSClassName">FirstResponder</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="1004">
|
||||
<string key="NSClassName">NSApplication</string>
|
||||
</object>
|
||||
<object class="NSWindowTemplate" id="748157544">
|
||||
<int key="NSWindowStyleMask">15</int>
|
||||
<int key="NSWindowBacking">2</int>
|
||||
<string key="NSWindowRect">{{131, 74}, {606, 354}}</string>
|
||||
<int key="NSWTFlags">611844096</int>
|
||||
<string key="NSWindowTitle">GLSLShader</string>
|
||||
<string key="NSWindowClass">MainWindow</string>
|
||||
<nil key="NSViewClass"/>
|
||||
<string key="NSWindowContentMaxSize">{1.79769e+308, 1.79769e+308}</string>
|
||||
<object class="NSView" key="NSWindowView" id="312036702">
|
||||
<reference key="NSNextResponder"/>
|
||||
<int key="NSvFlags">256</int>
|
||||
<object class="NSMutableArray" key="NSSubviews">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSCustomView" id="319156736">
|
||||
<reference key="NSNextResponder" ref="312036702"/>
|
||||
<int key="NSvFlags">274</int>
|
||||
<string key="NSFrameSize">{611, 354}</string>
|
||||
<reference key="NSSuperview" ref="312036702"/>
|
||||
<string key="NSClassName">MyOpenGLView</string>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrameSize">{606, 354}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
</object>
|
||||
<string key="NSScreenRect">{{0, 0}, {1280, 778}}</string>
|
||||
<string key="NSMaxSize">{1.79769e+308, 1.79769e+308}</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
||||
<object class="NSMutableArray" key="connectionRecords">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">window</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="748157544"/>
|
||||
</object>
|
||||
<int key="connectionID">6</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">openGLView</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="319156736"/>
|
||||
</object>
|
||||
<int key="connectionID">8</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">0</int>
|
||||
<reference key="object" ref="0"/>
|
||||
<reference key="children" ref="1000"/>
|
||||
<nil key="parent"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-2</int>
|
||||
<reference key="object" ref="1001"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">File's Owner</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-1</int>
|
||||
<reference key="object" ref="1003"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">First Responder</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-3</int>
|
||||
<reference key="object" ref="1004"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">Application</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">2</int>
|
||||
<reference key="object" ref="748157544"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="312036702"/>
|
||||
</object>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">3</int>
|
||||
<reference key="object" ref="312036702"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="319156736"/>
|
||||
</object>
|
||||
<reference key="parent" ref="748157544"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">7</int>
|
||||
<reference key="object" ref="319156736"/>
|
||||
<reference key="parent" ref="312036702"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="flattenedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>-1.IBPluginDependency</string>
|
||||
<string>-2.IBPluginDependency</string>
|
||||
<string>-3.IBPluginDependency</string>
|
||||
<string>2.IBEditorWindowLastContentRect</string>
|
||||
<string>2.IBPluginDependency</string>
|
||||
<string>2.IBWindowTemplateEditedContentRect</string>
|
||||
<string>2.NSWindowTemplate.visibleAtLaunch</string>
|
||||
<string>3.IBPluginDependency</string>
|
||||
<string>7.IBPluginDependency</string>
|
||||
<string>7.IBViewBoundsToFrameTransform</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>{{309, 638}, {606, 354}}</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>{{309, 638}, {606, 354}}</string>
|
||||
<boolean value="YES"/>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<object class="NSAffineTransform">
|
||||
<bytes key="NSTransformStruct">AUKsAABDKwAAA</bytes>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="unlocalizedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<nil key="activeLocalization"/>
|
||||
<object class="NSMutableDictionary" key="localizations">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">8</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">MainWindow</string>
|
||||
<string key="superclassName">NSWindow</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBUserSource</string>
|
||||
<string key="minorKey"/>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">MainWindowController</string>
|
||||
<string key="superclassName">NSWindowController</string>
|
||||
<object class="NSMutableDictionary" key="actions">
|
||||
<string key="NS.key.0">goFullScreen:</string>
|
||||
<string key="NS.object.0">id</string>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="actionInfosByName">
|
||||
<string key="NS.key.0">goFullScreen:</string>
|
||||
<object class="IBActionInfo" key="NS.object.0">
|
||||
<string key="name">goFullScreen:</string>
|
||||
<string key="candidateClassName">id</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="outlets">
|
||||
<string key="NS.key.0">openGLView</string>
|
||||
<string key="NS.object.0">MyOpenGLView</string>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
|
||||
<string key="NS.key.0">openGLView</string>
|
||||
<object class="IBToOneOutletInfo" key="NS.object.0">
|
||||
<string key="name">openGLView</string>
|
||||
<string key="candidateClassName">MyOpenGLView</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBUserSource</string>
|
||||
<string key="minorKey"/>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">MyOpenGLView</string>
|
||||
<string key="superclassName">NSView</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBUserSource</string>
|
||||
<string key="minorKey"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
|
||||
<integer value="3000" key="NS.object.0"/>
|
||||
</object>
|
||||
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
|
||||
<nil key="IBDocument.LastKnownRelativeProjectPath"/>
|
||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
||||
</data>
|
||||
</archive>
|
|
@ -0,0 +1,46 @@
|
|||
// ------------------------------------------------------------------------------
|
||||
// <autogenerated>
|
||||
// This code was generated by a tool.
|
||||
// Mono Runtime Version: 4.0.30319.1
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </autogenerated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace GLSLShader {
|
||||
|
||||
|
||||
// Should subclass MonoMac.AppKit.NSWindow
|
||||
[MonoMac.Foundation.Register("MainWindow")]
|
||||
public partial class MainWindow {
|
||||
}
|
||||
|
||||
// Should subclass MonoMac.AppKit.NSWindowController
|
||||
[MonoMac.Foundation.Register("MainWindowController")]
|
||||
public partial class MainWindowController {
|
||||
|
||||
private MyOpenGLView __mt_openGLView;
|
||||
|
||||
#pragma warning disable 0169
|
||||
[MonoMac.Foundation.Export("goFullScreen:")]
|
||||
partial void goFullScreen (MonoMac.Foundation.NSObject sender);
|
||||
|
||||
[MonoMac.Foundation.Connect("openGLView")]
|
||||
private MyOpenGLView openGLView {
|
||||
get {
|
||||
this.__mt_openGLView = ((MyOpenGLView)(this.GetNativeField("openGLView")));
|
||||
return this.__mt_openGLView;
|
||||
}
|
||||
set {
|
||||
this.__mt_openGLView = value;
|
||||
this.SetNativeField("openGLView", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Should subclass MonoMac.AppKit.NSView
|
||||
[MonoMac.Foundation.Register("MyOpenGLView")]
|
||||
public partial class MyOpenGLView {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,186 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.AppKit;
|
||||
|
||||
namespace GLSLShader
|
||||
{
|
||||
public partial class MainWindowController : MonoMac.AppKit.NSWindowController
|
||||
{
|
||||
|
||||
bool isInFullScreenMode;
|
||||
|
||||
// full-screen mode
|
||||
NSWindow fullScreenWindow;
|
||||
MyOpenGLView fullScreenView;
|
||||
Scene scene;
|
||||
bool isAnimating;
|
||||
|
||||
#region Constructors
|
||||
|
||||
// Call to load from the XIB/NIB file
|
||||
public MainWindowController () : base("MainWindow")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//strongly typed window accessor
|
||||
public new MainWindow Window {
|
||||
get { return (MainWindow)base.Window; }
|
||||
}
|
||||
|
||||
public override void AwakeFromNib ()
|
||||
{
|
||||
// Allocate the scene object
|
||||
scene = new Scene ();
|
||||
|
||||
// Assign the view's MainController to us
|
||||
openGLView.MainController = this;
|
||||
|
||||
// reset the viewport and update OpenGL Context
|
||||
openGLView.UpdateView ();
|
||||
|
||||
// Activate the display link now
|
||||
openGLView.StartAnimation ();
|
||||
|
||||
isAnimating = true;
|
||||
}
|
||||
|
||||
partial void goFullScreen (NSObject sender)
|
||||
{
|
||||
isInFullScreenMode = true;
|
||||
|
||||
// Pause the non-fullscreen view
|
||||
openGLView.StopAnimation ();
|
||||
|
||||
RectangleF mainDisplayRect;
|
||||
RectangleF viewRect;
|
||||
|
||||
// Create a screen-sized window on the display you want to take over
|
||||
// Note, mainDisplayRect has a non-zero origin if the key window is on a secondary display
|
||||
mainDisplayRect = NSScreen.MainScreen.Frame;
|
||||
|
||||
fullScreenWindow = new NSWindow (mainDisplayRect, NSWindowStyle.Borderless, NSBackingStore.Buffered, true);
|
||||
|
||||
// Set the window level to be above the menu bar
|
||||
fullScreenWindow.Level = NSWindowLevel.MainMenu + 1;
|
||||
|
||||
// Perform any other window configuration you desire
|
||||
fullScreenWindow.IsOpaque = true;
|
||||
fullScreenWindow.HidesOnDeactivate = true;
|
||||
|
||||
// Create a view with a double-buffered OpenGL context and attach it to the window
|
||||
// By specifying the non-fullscreen context as the shareContext, we automatically inherit the
|
||||
// OpenGL objects (textures, etc) it has defined
|
||||
viewRect = new RectangleF (0, 0, mainDisplayRect.Size.Width, mainDisplayRect.Size.Height);
|
||||
|
||||
fullScreenView = new MyOpenGLView (viewRect, openGLView.OpenGLContext);
|
||||
fullScreenWindow.ContentView = fullScreenView;
|
||||
|
||||
// Show the window
|
||||
fullScreenWindow.MakeKeyAndOrderFront (this);
|
||||
|
||||
// Set the scene with the full-screen viewport and viewing transformation
|
||||
Scene.ResizeGLScene (viewRect);
|
||||
|
||||
// Assign the view's MainController to self
|
||||
fullScreenView.MainController = this;
|
||||
|
||||
if (!isAnimating) {
|
||||
// Mark the view as needing drawing to initalize its contents
|
||||
fullScreenView.NeedsDisplay = true;
|
||||
} else {
|
||||
// Start playing the animation
|
||||
fullScreenView.StartAnimation ();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void goWindow ()
|
||||
{
|
||||
isInFullScreenMode = false;
|
||||
|
||||
// use OrderOut here instead of Close or nasty things will happen with Garbage Collection and a double free
|
||||
fullScreenWindow.OrderOut (this);
|
||||
fullScreenView.DeAllocate ();
|
||||
fullScreenWindow.Dispose ();
|
||||
fullScreenWindow = null;
|
||||
|
||||
// Switch to the non-fullscreen context
|
||||
openGLView.OpenGLContext.MakeCurrentContext ();
|
||||
|
||||
if (!isAnimating) {
|
||||
// Mark the view as needing drawing
|
||||
// The animation has advanced while we were in full-screen mode, so its current contents are stale
|
||||
openGLView.NeedsDisplay = true;
|
||||
|
||||
} else {
|
||||
// continue playing the animation
|
||||
openGLView.StartAnimation ();
|
||||
}
|
||||
}
|
||||
|
||||
public void startAnimation ()
|
||||
{
|
||||
if (isAnimating)
|
||||
return;
|
||||
|
||||
if (!isInFullScreenMode)
|
||||
openGLView.StartAnimation ();
|
||||
else
|
||||
fullScreenView.StartAnimation ();
|
||||
|
||||
isAnimating = true;
|
||||
}
|
||||
|
||||
public void stopAnimation ()
|
||||
{
|
||||
if (!isAnimating)
|
||||
return;
|
||||
|
||||
if (!isInFullScreenMode)
|
||||
openGLView.StopAnimation ();
|
||||
else
|
||||
fullScreenView.StopAnimation ();
|
||||
|
||||
isAnimating = false;
|
||||
}
|
||||
|
||||
public override void KeyDown (NSEvent theEvent)
|
||||
{
|
||||
var c = theEvent.CharactersIgnoringModifiers [0];
|
||||
|
||||
switch (c) {
|
||||
|
||||
// [Esc] exits full-screen mode
|
||||
case (char)27:
|
||||
if (isInFullScreenMode)
|
||||
goWindow ();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Accessor property for our scene object
|
||||
public Scene Scene {
|
||||
get { return scene; }
|
||||
}
|
||||
|
||||
public void toggleFullScreen (NSObject sender)
|
||||
{
|
||||
if (!isInFullScreenMode)
|
||||
goFullScreen (sender);
|
||||
else
|
||||
goWindow ();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,249 @@
|
|||
//=====================================================================
|
||||
// http://www.cocoa-mono.org
|
||||
//
|
||||
// Copyright (c) 2011 Kenneth J. Pouncey
|
||||
//
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.AppKit;
|
||||
using MonoMac.CoreVideo;
|
||||
using MonoMac.CoreGraphics;
|
||||
using MonoMac.OpenGL;
|
||||
|
||||
namespace GLSLShader
|
||||
{
|
||||
public partial class MyOpenGLView : MonoMac.AppKit.NSView
|
||||
{
|
||||
|
||||
NSOpenGLContext openGLContext;
|
||||
NSOpenGLPixelFormat pixelFormat;
|
||||
MainWindowController controller;
|
||||
CVDisplayLink displayLink;
|
||||
NSObject notificationProxy;
|
||||
|
||||
[Export("initWithFrame:")]
|
||||
public MyOpenGLView (RectangleF frame) : this(frame, null)
|
||||
{
|
||||
}
|
||||
|
||||
public MyOpenGLView (RectangleF frame,NSOpenGLContext context) : base(frame)
|
||||
{
|
||||
var attribs = new object [] {
|
||||
NSOpenGLPixelFormatAttribute.Accelerated,
|
||||
NSOpenGLPixelFormatAttribute.NoRecovery,
|
||||
NSOpenGLPixelFormatAttribute.DoubleBuffer,
|
||||
NSOpenGLPixelFormatAttribute.ColorSize, 24,
|
||||
NSOpenGLPixelFormatAttribute.DepthSize, 16 };
|
||||
|
||||
pixelFormat = new NSOpenGLPixelFormat (attribs);
|
||||
|
||||
if (pixelFormat == null)
|
||||
Console.WriteLine ("No OpenGL pixel format");
|
||||
|
||||
// NSOpenGLView does not handle context sharing, so we draw to a custom NSView instead
|
||||
openGLContext = new NSOpenGLContext (pixelFormat, context);
|
||||
|
||||
openGLContext.MakeCurrentContext ();
|
||||
|
||||
// Synchronize buffer swaps with vertical refresh rate
|
||||
openGLContext.SwapInterval = true;
|
||||
|
||||
// Initialize our newly created view.
|
||||
InitGL ();
|
||||
|
||||
SetupDisplayLink ();
|
||||
|
||||
// Look for changes in view size
|
||||
// Note, -reshape will not be called automatically on size changes because NSView does not export it to override
|
||||
notificationProxy = NSNotificationCenter.DefaultCenter.AddObserver (NSView.NSViewGlobalFrameDidChangeNotification, HandleReshape);
|
||||
}
|
||||
|
||||
public override void DrawRect (RectangleF dirtyRect)
|
||||
{
|
||||
// Ignore if the display link is still running
|
||||
if (!displayLink.IsRunning && controller != null)
|
||||
DrawView ();
|
||||
}
|
||||
|
||||
public override bool AcceptsFirstResponder ()
|
||||
{
|
||||
// We want this view to be able to receive key events
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void LockFocus ()
|
||||
{
|
||||
base.LockFocus ();
|
||||
if (openGLContext.View != this)
|
||||
openGLContext.View = this;
|
||||
}
|
||||
|
||||
public override void KeyDown (NSEvent theEvent)
|
||||
{
|
||||
controller.KeyDown (theEvent);
|
||||
}
|
||||
|
||||
public override void MouseDown (NSEvent theEvent)
|
||||
{
|
||||
controller.MouseDown (theEvent);
|
||||
}
|
||||
|
||||
// All Setup For OpenGL Goes Here
|
||||
public bool InitGL ()
|
||||
{
|
||||
// Enables Smooth Shading
|
||||
GL.ShadeModel (ShadingModel.Smooth);
|
||||
// Set background color to black
|
||||
GL.ClearColor (Color.Black);
|
||||
|
||||
// Setup Depth Testing
|
||||
|
||||
// Depth Buffer setup
|
||||
GL.ClearDepth (1.0);
|
||||
// Enables Depth testing
|
||||
GL.Enable (EnableCap.DepthTest);
|
||||
// The type of depth testing to do
|
||||
GL.DepthFunc (DepthFunction.Lequal);
|
||||
|
||||
// Really Nice Perspective Calculations
|
||||
GL.Hint (HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void DrawView ()
|
||||
{
|
||||
// This method will be called on both the main thread (through -drawRect:) and a secondary thread (through the display link rendering loop)
|
||||
// Also, when resizing the view, -reshape is called on the main thread, but we may be drawing on a secondary thread
|
||||
// Add a mutex around to avoid the threads accessing the context simultaneously
|
||||
openGLContext.CGLContext.Lock ();
|
||||
|
||||
// Make sure we draw to the right context
|
||||
openGLContext.MakeCurrentContext ();
|
||||
|
||||
// Delegate to the scene object for rendering
|
||||
controller.Scene.DrawGLScene ();
|
||||
|
||||
openGLContext.FlushBuffer ();
|
||||
|
||||
openGLContext.CGLContext.Unlock ();
|
||||
}
|
||||
|
||||
private void SetupDisplayLink ()
|
||||
{
|
||||
// Create a display link capable of being used with all active displays
|
||||
displayLink = new CVDisplayLink ();
|
||||
|
||||
// Set the renderer output callback function
|
||||
displayLink.SetOutputCallback (MyDisplayLinkOutputCallback);
|
||||
|
||||
// Set the display link for the current renderer
|
||||
CGLContext cglContext = openGLContext.CGLContext;
|
||||
CGLPixelFormat cglPixelFormat = PixelFormat.CGLPixelFormat;
|
||||
displayLink.SetCurrentDisplay (cglContext, cglPixelFormat);
|
||||
|
||||
}
|
||||
|
||||
public CVReturn MyDisplayLinkOutputCallback (CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut)
|
||||
{
|
||||
CVReturn result = GetFrameForTime (inOutputTime);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private CVReturn GetFrameForTime (CVTimeStamp outputTime)
|
||||
{
|
||||
// There is no autorelease pool when this method is called because it will be called from a background thread
|
||||
// It's important to create one or you will leak objects
|
||||
using (NSAutoreleasePool pool = new NSAutoreleasePool ()) {
|
||||
|
||||
// Update the animation
|
||||
DrawView ();
|
||||
}
|
||||
|
||||
return CVReturn.Success;
|
||||
|
||||
}
|
||||
|
||||
public NSOpenGLContext OpenGLContext {
|
||||
get { return openGLContext; }
|
||||
}
|
||||
|
||||
public NSOpenGLPixelFormat PixelFormat {
|
||||
get { return pixelFormat; }
|
||||
}
|
||||
|
||||
public MainWindowController MainController {
|
||||
set { controller = value; }
|
||||
}
|
||||
|
||||
public void UpdateView ()
|
||||
{
|
||||
// This method will be called on the main thread when resizing, but we may be drawing on a secondary thread through the display link
|
||||
// Add a mutex around to avoid the threads accessing the context simultaneously
|
||||
openGLContext.CGLContext.Lock ();
|
||||
|
||||
// Delegate to the scene object to update for a change in the view size
|
||||
controller.Scene.ResizeGLScene (Bounds);
|
||||
openGLContext.Update ();
|
||||
|
||||
openGLContext.CGLContext.Unlock ();
|
||||
}
|
||||
|
||||
private void HandleReshape (NSNotification note)
|
||||
{
|
||||
UpdateView ();
|
||||
}
|
||||
|
||||
public void StartAnimation ()
|
||||
{
|
||||
if (displayLink != null && !displayLink.IsRunning)
|
||||
displayLink.Start ();
|
||||
}
|
||||
|
||||
public void StopAnimation ()
|
||||
{
|
||||
if (displayLink != null && displayLink.IsRunning)
|
||||
displayLink.Stop ();
|
||||
}
|
||||
|
||||
// Clean up the notifications
|
||||
public void DeAllocate ()
|
||||
{
|
||||
displayLink.Stop ();
|
||||
displayLink.SetOutputCallback (null);
|
||||
|
||||
NSNotificationCenter.DefaultCenter.RemoveObserver (notificationProxy);
|
||||
}
|
||||
|
||||
[Export("toggleFullScreen:")]
|
||||
public void toggleFullScreen (NSObject sender)
|
||||
{
|
||||
controller.toggleFullScreen (sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
GLSLShader
|
||||
==========
|
||||
|
||||
DESCRIPTION:
|
||||
|
||||
Simple GLSL shader harness program. Does nothing more than draw a line
|
||||
on the screen. The color is controlled by the shader.vert GSL source.
|
||||
|
||||
Concepts shown:
|
||||
|
||||
Create a shader program.
|
||||
Load GLSL source from a file.
|
||||
Compile the source to attach to a Shader program.
|
||||
Use Program Parameters.
|
||||
Shader Program linkage.
|
||||
Obtaining log info for the different program objects.
|
||||
|
||||
===========================================================================
|
||||
SAMPLE REQUIREMENTS
|
||||
|
||||
The supplied solution requires MonoMac bindings from the Mono Project.
|
||||
|
||||
===========================================================================
|
||||
CHANGES FROM PREVIOUS VERSIONS:
|
||||
|
||||
n/a
|
|
@ -0,0 +1,174 @@
|
|||
//=====================================================================
|
||||
// http://www.cocoa-mono.org
|
||||
//
|
||||
// Copyright (c) 2011 Kenneth J. Pouncey
|
||||
//
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.AppKit;
|
||||
|
||||
using MonoMac.OpenGL;
|
||||
|
||||
namespace GLSLShader
|
||||
{
|
||||
public class Scene
|
||||
{
|
||||
|
||||
int shaderProgram;
|
||||
int vertexShader;
|
||||
int fragmentShader;
|
||||
int geometryShader;
|
||||
|
||||
public Scene () : base()
|
||||
{
|
||||
SetupShaders ();
|
||||
}
|
||||
|
||||
// Resize And Initialize The GL Window
|
||||
// - See also the method in the MyOpenGLView Constructor about the NSView.NSViewGlobalFrameDidChangeNotification
|
||||
public void ResizeGLScene (RectangleF bounds)
|
||||
{
|
||||
// Reset The Current Viewport
|
||||
GL.Viewport (0, 0, (int)bounds.Size.Width, (int)bounds.Size.Height);
|
||||
// Select The Projection Matrix
|
||||
GL.MatrixMode (MatrixMode.Projection);
|
||||
// Reset The Projection Matrix
|
||||
GL.LoadIdentity ();
|
||||
|
||||
GL.Ortho (0, bounds.Width, bounds.Height, 0, 0, 1);
|
||||
|
||||
// Select The Modelview Matrix
|
||||
GL.MatrixMode (MatrixMode.Modelview);
|
||||
// Reset The Modelview Matrix
|
||||
GL.LoadIdentity ();
|
||||
}
|
||||
|
||||
private void SetupShaders ()
|
||||
{
|
||||
|
||||
// Create the shader objects
|
||||
vertexShader = GL.CreateShader (ShaderType.VertexShader);
|
||||
fragmentShader = GL.CreateShader (ShaderType.FragmentShader);
|
||||
geometryShader = GL.CreateShader (ShaderType.GeometryShaderExt);
|
||||
|
||||
// Load the source into a string
|
||||
string vertexShaderSource = LoadShaderSource ("shader.vert");
|
||||
// Attach the loaded source string to the shader object
|
||||
GL.ShaderSource (vertexShader, vertexShaderSource);
|
||||
// Compile the shader
|
||||
GL.CompileShader (vertexShader);
|
||||
|
||||
// Load the source into a string
|
||||
string fragmentShaderSource = LoadShaderSource ("shader.frag");
|
||||
// Attach the loaded source string to the shader object
|
||||
GL.ShaderSource (fragmentShader, fragmentShaderSource);
|
||||
// Compile the shader
|
||||
GL.CompileShader (fragmentShader);
|
||||
|
||||
// Create a Program object
|
||||
shaderProgram = GL.CreateProgram ();
|
||||
|
||||
// Attach our compiled shaders
|
||||
GL.AttachShader (shaderProgram, vertexShader);
|
||||
GL.AttachShader (shaderProgram, fragmentShader);
|
||||
|
||||
// Set the parameters
|
||||
GL.ProgramParameter (shaderProgram, AssemblyProgramParameterArb.GeometryInputType, (int)All.Lines);
|
||||
GL.ProgramParameter (shaderProgram, AssemblyProgramParameterArb.GeometryOutputType, (int)All.Line);
|
||||
|
||||
// Set the max vertices
|
||||
int maxVertices;
|
||||
GL.GetInteger (GetPName.MaxGeometryOutputVertices, out maxVertices);
|
||||
GL.ProgramParameter (shaderProgram, AssemblyProgramParameterArb.GeometryVerticesOut, maxVertices);
|
||||
|
||||
// Link the program
|
||||
GL.LinkProgram (shaderProgram);
|
||||
// Tell the GL Context to use the program
|
||||
GL.UseProgram (shaderProgram);
|
||||
|
||||
// Output our shader object errors if there were problems
|
||||
ShaderLog ("Vertex Shader:", vertexShader);
|
||||
ShaderLog ("Fragment Shader:", fragmentShader);
|
||||
ShaderLog ("Shader Program:", shaderProgram);
|
||||
}
|
||||
|
||||
// Output the log of an object
|
||||
private void ShaderLog (string whichObj, int obj)
|
||||
{
|
||||
int infoLogLen = 0;
|
||||
var infoLog = "Is good to go.";
|
||||
|
||||
GL.GetProgram (obj, ProgramParameter.InfoLogLength, out infoLogLen);
|
||||
|
||||
if (infoLogLen > 0)
|
||||
infoLog = GL.GetProgramInfoLog (obj);
|
||||
|
||||
Console.WriteLine ("{0} {1}", whichObj, infoLog);
|
||||
|
||||
}
|
||||
|
||||
// Load the source code of a GLSL program from the content
|
||||
private string LoadShaderSource (string name)
|
||||
{
|
||||
|
||||
var path = NSBundle.MainBundle.ResourcePath + Path.DirectorySeparatorChar + "GLSL";
|
||||
var filePath = path + Path.DirectorySeparatorChar + name;
|
||||
StreamReader streamReader = new StreamReader (filePath);
|
||||
string text = streamReader.ReadToEnd ();
|
||||
streamReader.Close ();
|
||||
|
||||
return text;
|
||||
|
||||
}
|
||||
|
||||
// This method renders our scene and where all of your drawing code will go.
|
||||
// The main thing to note is that we've factored the drawing code out of the NSView subclass so that
|
||||
// the full-screen and non-fullscreen views share the same states for rendering
|
||||
public bool DrawGLScene ()
|
||||
{
|
||||
// Clear The Screen And The Depth Buffer
|
||||
GL.Clear (ClearBufferMask.ColorBufferBit);// | ClearBufferMask.DepthBufferBit);
|
||||
// Reset The Current Modelview Matrix
|
||||
GL.LoadIdentity ();
|
||||
|
||||
// Obtain the viewport object so that we can obtain our width and height
|
||||
int[] viewport = new int[4];
|
||||
GL.GetInteger (GetPName.Viewport, viewport);
|
||||
|
||||
// Setup our vertex to output.
|
||||
// Simple line from top to bottom of the screen
|
||||
GL.Begin (BeginMode.Lines);
|
||||
GL.Vertex2 (viewport [2] / 2, 0);
|
||||
GL.Vertex2 (viewport [2] / 2, viewport [3]);
|
||||
GL.End ();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче