зеркало из https://github.com/xamarin/ios-samples.git
Add the beginning of the GLCameraRipple sample
This commit is contained in:
Родитель
51a6759a46
Коммит
1d44f7f97d
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using MonoTouch.Foundation;
|
||||
using MonoTouch.UIKit;
|
||||
|
||||
namespace GLCameraRipple
|
||||
{
|
||||
[Register ("AppDelegate")]
|
||||
public partial class AppDelegate : UIApplicationDelegate
|
||||
{
|
||||
UIWindow window;
|
||||
|
||||
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
|
||||
{
|
||||
window = new UIWindow (UIScreen.MainScreen.Bounds) {
|
||||
RootViewController = new RippleViewController ()
|
||||
};
|
||||
window.MakeKeyAndVisible ();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
<?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)' == '' ">iPhoneSimulator</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{96FCF082-6930-4167-BDEF-07ABB007205A}</ProjectGuid>
|
||||
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>GLCameraRipple</RootNamespace>
|
||||
<AssemblyName>GLCameraRipple</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="monotouch" />
|
||||
<Reference Include="OpenTK" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Info.plist" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
<Compile Include="RippleViewController.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Shaders\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Shaders\Shader.fsh" />
|
||||
<Content Include="Shaders\Shader.vsh" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GLCameraRipple", "GLCameraRipple.csproj", "{96FCF082-6930-4167-BDEF-07ABB007205A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|iPhoneSimulator = Debug|iPhoneSimulator
|
||||
Release|iPhoneSimulator = Release|iPhoneSimulator
|
||||
Debug|iPhone = Debug|iPhone
|
||||
Release|iPhone = Release|iPhone
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{96FCF082-6930-4167-BDEF-07ABB007205A}.Debug|iPhone.ActiveCfg = Debug|iPhone
|
||||
{96FCF082-6930-4167-BDEF-07ABB007205A}.Debug|iPhone.Build.0 = Debug|iPhone
|
||||
{96FCF082-6930-4167-BDEF-07ABB007205A}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
|
||||
{96FCF082-6930-4167-BDEF-07ABB007205A}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
|
||||
{96FCF082-6930-4167-BDEF-07ABB007205A}.Release|iPhone.ActiveCfg = Release|iPhone
|
||||
{96FCF082-6930-4167-BDEF-07ABB007205A}.Release|iPhone.Build.0 = Release|iPhone
|
||||
{96FCF082-6930-4167-BDEF-07ABB007205A}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
|
||||
{96FCF082-6930-4167-BDEF-07ABB007205A}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = GLCameraRipple.csproj
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,12 @@
|
|||
<?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>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using MonoTouch.Foundation;
|
||||
using MonoTouch.UIKit;
|
||||
|
||||
namespace GLCameraRipple
|
||||
{
|
||||
public class Application
|
||||
{
|
||||
// This is the main entry point of the application.
|
||||
static void Main (string[] args)
|
||||
{
|
||||
// if you want to use a different Application Delegate class from "AppDelegate"
|
||||
// you can specify it here.
|
||||
UIApplication.Main (args, null, "AppDelegate");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.ES20;
|
||||
using MonoTouch.GLKit;
|
||||
using MonoTouch.OpenGLES;
|
||||
using MonoTouch.Foundation;
|
||||
using MonoTouch.UIKit;
|
||||
using MonoTouch.AVFoundation;
|
||||
using MonoTouch.CoreVideo;
|
||||
using System.IO;
|
||||
|
||||
namespace GLCameraRipple
|
||||
{
|
||||
public class RippleViewController : GLKViewController {
|
||||
EAGLContext context;
|
||||
SizeF size;
|
||||
int meshFactor;
|
||||
NSString sessionPreset;
|
||||
CVOpenGLESTexture lumaTexture, chromaTexture;
|
||||
CVOpenGLESTextureCache videoTextureCache;
|
||||
|
||||
//
|
||||
// OpenGL components
|
||||
//
|
||||
const int UNIFORM_Y = 0;
|
||||
const int UNIFORM_UV = 1;
|
||||
const int ATTRIB_VERTEX = 0;
|
||||
const int ATTRIB_TEXCOORD = 1;
|
||||
|
||||
int [] uniforms = new int [2];
|
||||
int program;
|
||||
|
||||
public override void ViewDidLoad ()
|
||||
{
|
||||
base.ViewDidLoad ();
|
||||
|
||||
context = new EAGLContext (EAGLRenderingAPI.OpenGLES2);
|
||||
((GLKView)View).Context = context;
|
||||
PreferredFramesPerSecond = 60;
|
||||
size = UIScreen.MainScreen.Bounds.Size;
|
||||
View.ContentScaleFactor = UIScreen.MainScreen.Scale;
|
||||
|
||||
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad){
|
||||
meshFactor = 8;
|
||||
sessionPreset = AVCaptureSession.PresetiFrame1280x720;
|
||||
} else {
|
||||
meshFactor = 4;
|
||||
sessionPreset = AVCaptureSession.Preset640x480;
|
||||
}
|
||||
SetupGL ();
|
||||
SetupAVCapture ();
|
||||
}
|
||||
|
||||
public override void ViewDidUnload ()
|
||||
{
|
||||
base.ViewDidUnload ();
|
||||
TeardownAVCapture ();
|
||||
TeardownGL ();
|
||||
if (EAGLContext.CurrentContext == context)
|
||||
EAGLContext.SetCurrentContext (null);
|
||||
}
|
||||
|
||||
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
|
||||
{
|
||||
// Camera is fixed, only allow portrait
|
||||
return (toInterfaceOrientation == UIInterfaceOrientation.Portrait);
|
||||
}
|
||||
|
||||
void CleanupTextures ()
|
||||
{
|
||||
if (lumaTexture != null){
|
||||
lumaTexture.Dispose ();
|
||||
lumaTexture = null;
|
||||
}
|
||||
if (chromaTexture != null){
|
||||
chromaTexture.Dispose ();
|
||||
chromaTexture = null;
|
||||
}
|
||||
videoTextureCache.Flush (CVOptionFlags.None);
|
||||
}
|
||||
|
||||
void SetupGL ()
|
||||
{
|
||||
EAGLContext.SetCurrentContext (context);
|
||||
LoadShaders ();
|
||||
GL.UseProgram (program);
|
||||
GL.Uniform1 (uniforms [UNIFORM_Y], 0);
|
||||
GL.Uniform1 (uniforms [UNIFORM_UV], 1);
|
||||
}
|
||||
|
||||
void SetupAVCapture ()
|
||||
{
|
||||
}
|
||||
|
||||
void TeardownAVCapture ()
|
||||
{
|
||||
}
|
||||
|
||||
void TeardownGL ()
|
||||
{
|
||||
}
|
||||
|
||||
bool LoadShaders ()
|
||||
{
|
||||
int vertShader, fragShader;
|
||||
|
||||
program = GL.CreateProgram ();
|
||||
if (!CompileShader (out vertShader, All.VertexShader, "Shaders/Shader.vsh")){
|
||||
Console.WriteLine ("Failed to compile vertex shader");
|
||||
return false;
|
||||
}
|
||||
if (!CompileShader (out fragShader, All.FragmentShader, "Shaders/Shader.fsh")){
|
||||
Console.WriteLine ("Failed to compile fragment shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attach shaders
|
||||
GL.AttachShader (program, vertShader);
|
||||
GL.AttachShader (program, fragShader);
|
||||
|
||||
// Bind attribtue locations
|
||||
GL.BindAttribLocation (program, ATTRIB_VERTEX, "position");
|
||||
GL.BindAttribLocation (program, ATTRIB_TEXCOORD, "texCoord");
|
||||
|
||||
// Link the program
|
||||
if (!LinkProgram (program)){
|
||||
Console.WriteLine ("Failed to link the shader programs");
|
||||
GL.DeleteShader (vertShader);
|
||||
GL.DeleteShader (fragShader);
|
||||
GL.DeleteProgram (program);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get uniform locations
|
||||
uniforms [UNIFORM_Y] = GL.GetUniformLocation (program, "SamplerY");
|
||||
uniforms [UNIFORM_UV] = GL.GetUniformLocation (program, "SampleUV");
|
||||
GL.DeleteShader (vertShader);
|
||||
GL.DeleteShader (fragShader);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CompileShader (out int shader, All type, string path)
|
||||
{
|
||||
string shaderProgram = File.ReadAllText (path);
|
||||
int len = shaderProgram.Length, status = 0;
|
||||
shader = GL.CreateShader (type);
|
||||
|
||||
GL.ShaderSource (shader, 1, new string [] { shaderProgram }, ref len);
|
||||
GL.CompileShader (shader);
|
||||
GL.GetShader (shader, All.CompileStatus, ref status);
|
||||
if (status == 0){
|
||||
GL.DeleteShader (shader);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LinkProgram (int program)
|
||||
{
|
||||
GL.LinkProgram (program);
|
||||
int status = 0;
|
||||
GL.GetProgram (program, All.LinkStatus, ref status);
|
||||
return status != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
File: Shader.fsh
|
||||
Abstract: Fragment shader for converting Y/UV textures to RGB.
|
||||
Version: 1.0
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2012 Apple Inc. All Rights Reserved.
|
||||
|
||||
*/
|
||||
|
||||
uniform sampler2D SamplerY;
|
||||
uniform sampler2D SamplerUV;
|
||||
|
||||
varying highp vec2 texCoordVarying;
|
||||
|
||||
void main()
|
||||
{
|
||||
mediump vec3 yuv;
|
||||
lowp vec3 rgb;
|
||||
|
||||
yuv.x = texture2D(SamplerY, texCoordVarying).r;
|
||||
yuv.yz = texture2D(SamplerUV, texCoordVarying).rg - vec2(0.5, 0.5);
|
||||
|
||||
// BT.601, which is the standard for SDTV is provided as a reference
|
||||
/*
|
||||
rgb = mat3( 1, 1, 1,
|
||||
0, -.34413, 1.772,
|
||||
1.402, -.71414, 0) * yuv;
|
||||
*/
|
||||
|
||||
// Using BT.709 which is the standard for HDTV
|
||||
rgb = mat3( 1, 1, 1,
|
||||
0, -.18732, 1.8556,
|
||||
1.57481, -.46813, 0) * yuv;
|
||||
|
||||
gl_FragColor = vec4(rgb, 1);
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
File: Shader.vsh
|
||||
Abstract: Vertex shader that passes attributes through to fragment shader.
|
||||
Version: 1.0
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2012 Apple Inc. All Rights Reserved.
|
||||
|
||||
*/
|
||||
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoord;
|
||||
|
||||
varying vec2 texCoordVarying;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = position;
|
||||
texCoordVarying = texCoord;
|
||||
}
|
Загрузка…
Ссылка в новой задаче