本文整理汇总了C#中ShaderType类的典型用法代码示例。如果您正苦于以下问题:C# ShaderType类的具体用法?C# ShaderType怎么用?C# ShaderType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ShaderType类属于命名空间,在下文中一共展示了ShaderType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
/// <summary>
/// Public translation interface.
/// Translates the given method to GLSL
/// </summary>
/// <param name="s">Shader type definition.</param>
/// <param name="m">A method representing a shader to translate.</param>
/// <param name="attr">The shader type as attribute (either FragmentShaderAttribute or VertexShaderAttribute</param>
/// <param name="type">The shader type as ShaderType</param>
/// <returns>The translated GLSL shader source</returns>
public FunctionDescription Transform(TypeDefinition s, MethodDefinition m, CustomAttribute attr,
ShaderType type)
{
if (s == null)
throw new ArgumentNullException("s");
if (m == null)
throw new ArgumentNullException("m");
if (attr == null)
throw new ArgumentNullException("attr");
var ctx = new DecompilerContext(s.Module)
{
CurrentType = s,
CurrentMethod = m,
CancellationToken = CancellationToken.None
};
var d = AstMethodBodyBuilder.CreateMethodBody(m, ctx);
var glsl = new GlslVisitor(d, attr, ctx);
_functions.UnionWith(glsl.Functions);
var entry = (bool)attr.ConstructorArguments.FirstOrDefault().Value;
var sig = entry ? "void main()" : GlslVisitor.GetSignature(m);
var code = glsl.Result;
var desc = new FunctionDescription(entry ? "main" : Shader.GetMethodName(m), sig + code, entry, type);
_dependencies.UnionWith(glsl.Dependencies);
return desc;
}
示例2: compileShader
public static int compileShader(ShaderType shaderType, String shaderSource)
{
int shaderHandle = GL.CreateShader(shaderType);
if (shaderHandle != 0)
{
// Pass in the shader source.
GL.ShaderSource(shaderHandle, shaderSource);
// Compile the shader.
GL.CompileShader(shaderHandle);
// Get the compilation status.
int[] compileStatus = new int[1];
GL.GetShader(shaderHandle,ShaderParameter.CompileStatus, compileStatus);
// If the compilation failed, delete the shader.
if (compileStatus[0] == 0)
{
string shaderInfoLog = GL.GetShaderInfoLog(shaderHandle);
MessageBox.Show("Error creating shader: " + shaderInfoLog);
GL.DeleteShader(shaderHandle);
shaderHandle = 0;
}
}
if (shaderHandle == 0)
{
MessageBox.Show("Error creating shader.");
}
return shaderHandle;
}
示例3: OnGUI
void OnGUI() {
const int height = 20;
int width = (int)position.width;// -16;
pmdFile = EditorGUI.ObjectField(
new Rect(0, 0, width, height), "PMD File" , pmdFile, typeof(Object), false);
// シェーダの種類
shader_type = (ShaderType)EditorGUI.EnumPopup(new Rect(0, height, width, height), "Shader Type", shader_type);
// 剛体を入れるかどうか
rigidFlag = EditorGUI.Toggle(new Rect(0, height * 2, width / 2, height), "Rigidbody", rigidFlag);
// Mecanimを使うかどうか
use_mecanim = EditorGUI.Toggle(new Rect(0, height * 3, width / 2, height), "Use Mecanim", use_mecanim);
// IKを使うかどうか
use_ik = EditorGUI.Toggle(new Rect(0, height * 4, width / 2, height), "Use IK", use_ik);
int buttonHeight = height * 5;
if (pmdFile != null) {
if (GUI.Button(new Rect(0, buttonHeight, width / 2, height), "Convert")) {
new PMDLoaderScript(pmdFile, shader_type, rigidFlag, use_mecanim, use_ik);
pmdFile = null; // 読み終わったので空にする
}
} else {
EditorGUI.LabelField(new Rect(0, buttonHeight, width, height), "Missing", "Select PMD File");
}
}
示例4: ShaderException
public ShaderException(string message, string shaderLog, string shaderSource, ShaderType shaderType)
: base(message)
{
ShaderLog = shaderLog;
ShaderSource = shaderSource;
ShaderType = shaderType;
}
示例5: FromFile
public static Shader FromFile(ShaderType type, string fileName)
{
Shader shader = new Shader(type, string.Empty);
shader.LoadSource(fileName);
return shader;
}
示例6: CompileShaderObject
protected int CompileShaderObject(ShaderType type, string name)
{
string ext = type == ShaderType.VertexShader ? "vert" : "frag";
string filename = "glsl{0}{1}.{2}".F(Path.DirectorySeparatorChar, name, ext);
string code;
using (var file = new StreamReader(GlobalFileSystem.Open(filename)))
code = file.ReadToEnd();
var shader = GL.CreateShader(type);
ErrorHandler.CheckGlError();
GL.ShaderSource(shader, code);
ErrorHandler.CheckGlError();
GL.CompileShader(shader);
ErrorHandler.CheckGlError();
int success;
GL.GetShader(shader, ShaderParameter.CompileStatus, out success);
ErrorHandler.CheckGlError();
if (success == (int)All.False)
{
int len;
GL.GetShader(shader, ShaderParameter.InfoLogLength, out len);
var log = new StringBuilder(len);
unsafe
{
GL.GetShaderInfoLog(shader, len, null, log);
}
Log.Write("graphics", "GL Info Log:\n{0}", log.ToString());
throw new InvalidProgramException("Compile error in shader object '{0}'".F(filename));
}
return shader;
}
示例7: GetShaderSource
/// <summary>
/// Gets shader's source code for color coded picking.
/// </summary>
/// <param name="shaderType"></param>
/// <returns></returns>
private static string GetShaderSource(ShaderType shaderType)
{
string result = string.Empty;
switch (shaderType)
{
case ShaderType.VertexShader:
if (vertexShader == null)
{
vertexShader = ManifestResourceLoader.LoadTextFile(@"Resources.Highlight.vert");
}
result = vertexShader;
break;
case ShaderType.FragmentShader:
if (fragmentShader == null)
{
fragmentShader = ManifestResourceLoader.LoadTextFile(@"Resources.Highlight.frag");
}
result = fragmentShader;
break;
default:
throw new NotImplementedException();
}
return result;
}
示例8: CompileShader
public static int CompileShader(ShaderType type, string source)
{
int shader = GL.CreateShader(type);
GL.ShaderSource(shader, source);
GL.CompileShader(shader);
int compileResult;
GL.GetShader(shader, ShaderParameter.CompileStatus, out compileResult);
if (compileResult == 0)
{
int infoLogLength;
GL.GetShader(shader, ShaderParameter.InfoLogLength, out infoLogLength);
string infolog;
GL.GetShaderInfoLog(shader, out infolog);
GL.DeleteShader(shader);
//std::vector<GLchar> infoLog(infoLogLength);
//glGetShaderInfoLog(shader, infoLog.size(), NULL, &infoLog[0]);
//std::cerr << "shader compilation failed: " << &infoLog[0];
//glDeleteShader(shader);
shader = 0;
}
return shader;
}
示例9: ShaderFile
public ShaderFile(ShaderType type, string filename, string friendlyName)
: base(type)
{
this.filename = filename;
this.friendlyName = friendlyName;
this.fileWatcher = new FileModifiedWatcher(filename);
}
示例10: CreateShader
public int CreateShader(ShaderType shaderType)
{
GraphicsContext.Assert();
int shader = GL.CreateShader(shaderType);
OpenGlErrorHelper.CheckGlError();
return shader;
}
示例11: CreateShader
public static int CreateShader(string shaderSource, ShaderType type){
int shaderHandle = GL.CreateShader( type );
GL.ShaderSource( shaderHandle, shaderSource );
GL.CompileShader( shaderHandle );
Console.WriteLine(GL.GetShaderInfoLog(shaderHandle));
return shaderHandle;
}
示例12: Shader
/// <summary>
/// Creates a shader from a string of shader source code.
/// </summary>
/// <param name="shaderCode">The source code for the shader.</param>
/// <param name="shaderType">Same as the argument to glCreateShader. For example ShaderType.VertexShader
/// or ShaderType.FragmentShader.</param>
public Shader(string shaderCode, ShaderType shaderType)
{
_object = 0;
_refCount = 0;
//create the shader object
_object = GL.CreateShader(shaderType);
if (_object == 0)
throw new Exception("glCreateShader failed");
//set the source code
GL.ShaderSource(_object, shaderCode);
// compile
GL.CompileShader(_object);
// throw exception if compile error occurred
int status;
GL.GetShader(_object, ShaderParameter.CompileStatus, out status);
if (status == 0) {
string msg = "Compile failure in shader: ";
string strInfoLog;
GL.GetShaderInfoLog((int)_object, out strInfoLog);
msg += strInfoLog;
GL.DeleteShader(_object);
_object = 0;
throw new Exception(msg);
}
_refCount = 1;
}
示例13: ShaderBuilder
/// <summary>
/// Constructor to create a new ShaderBuilder instance.
/// </summary>
/// <param name="type">The shader type to generate the source for</param>
/// <param name="twoDimensional">If true, some helper code for two dimensional shaders will be included</param>
/// <param name="parent">Previous shader in the pipeline (if any)</param>
public ShaderBuilder(ShaderType type, bool twoDimensional, ShaderBuilder parent = null)
{
Type = type;
_twoDimensional = twoDimensional;
// Prepare an empty list of OpenGL extensions
_extensions = new List<String>();
// Set up variable lists
_uniforms = new List<ShaderVariable>();
_attribs = new List<ShaderVariable>();
_varyings = new List<ShaderVariable>();
if (type == ShaderType.VertexShader && twoDimensional) {
AddUniform(ShaderVarType.Vec2, "screen_resolution");
}
// If the builder is given a parent, copy any outputs
// from that shader as inputs for this one
if (parent != null) {
foreach (var vary in parent._varyings) {
AddVarying(vary.Type, vary.Identifier);
}
}
Logic = "";
// Default fragment colour output variable identifier
FragOutIdentifier = "out_colour";
}
示例14: CreateCompiledSubShader
private static int CreateCompiledSubShader(ShaderType shaderType, string subShaderCode)
{
uint shaderHandle = GLCore.CreateShader(shaderType);
GLHelper.ShaderSource(shaderHandle, subShaderCode.Replace("precision mediump float;", ""));
GLCore.CompileShader(shaderHandle);
return (int)shaderHandle;
}
示例15: CompileShader
public static bool CompileShader(ShaderType type, string file, out int shader)
{
string src = System.IO.File.ReadAllText(file);
shader = GL.CreateShader(type);
GL.ShaderSource(shader, 1, new string[] { src }, (int[])null);
GL.CompileShader(shader);
#if DEBUG
int logLength = 0;
GL.GetShader (shader, ShaderParameter.InfoLogLength, out logLength);
if (logLength > 0)
{
var infoLog = new System.Text.StringBuilder ();
GL.GetShaderInfoLog (shader, logLength, out logLength, infoLog);
Console.WriteLine ("Shader compile log:\n{0}", infoLog);
}
#endif
int status = 0;
GL.GetShader(shader, ShaderParameter.CompileStatus, out status);
if (status == 0)
{
GL.DeleteShader(shader);
return false;
}
return true;
}