/// <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;
        }
        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;
        }
	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");
		}
	}
 public ShaderException(string message, string shaderLog, string shaderSource, ShaderType shaderType)
     : base(message)
 {
     ShaderLog = shaderLog;
     ShaderSource = shaderSource;
     ShaderType = shaderType;
 }
Exemple #5
0
        public static Shader FromFile(ShaderType type, string fileName)
        {
            Shader shader = new Shader(type, string.Empty);
            shader.LoadSource(fileName);

            return shader;
        }
Exemple #6
0
		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;
		}
        /// <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;
        }
Exemple #8
0
        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;
        }
Exemple #9
0
 public ShaderFile(ShaderType type, string filename, string friendlyName)
     : base(type)
 {
     this.filename = filename;
     this.friendlyName = friendlyName;
     this.fileWatcher = new FileModifiedWatcher(filename);
 }
Exemple #10
0
 public int CreateShader(ShaderType shaderType)
 {
     GraphicsContext.Assert();
     int shader = GL.CreateShader(shaderType);
     OpenGlErrorHelper.CheckGlError();
     return shader;
 }
 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;
 }
Exemple #12
0
        /// <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;
        }
        /// <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";
        }
Exemple #14
0
		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;
		}
        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;
        }
Exemple #16
0
        int LoadShader(ShaderType type, string source)
        {
            int shader = GL.CreateShader(type);
            if (shader == 0)
                throw new InvalidOperationException("Unable to create shader");

            int length = 0;
            GL.ShaderSource(shader, 1, new string[] { source }, (int[])null);
            GL.CompileShader(shader);

            int compiled = 0;
            GL.GetShader(shader, ShaderParameter.CompileStatus, out compiled);
            if (compiled == 0)
            {
                length = 0;
                GL.GetShader(shader, ShaderParameter.InfoLogLength, out length);
                if (length > 0)
                {
                    var log = new StringBuilder(length);
                    GL.GetShaderInfoLog(shader, length, out length, log);
                    Console.WriteLine("Couldn't compile shader: " + log.ToString());
                }

                GL.DeleteShader(shader);
                throw new InvalidOperationException("Unable to compile shader of type : " + type.ToString());
            }

            return shader;
        }
Exemple #17
0
 public FunctionDescription(string name, string body, bool entryPoint, ShaderType type)
 {
     Name = name;
     EntryPoint = entryPoint;
     Body = body;
     Type = type;
 }
Exemple #18
0
        internal Shader(ShaderType type, string filename)
        {
            Type = type;
            Filename = filename;

            Handle = GL.CreateShader(Type);
        }
Exemple #19
0
 public static string ReadShader(string path, ShaderType type)
 {
     string extension = string.Empty;
     switch (type)
     {
         case ShaderType.FragmentShader:
             extension = ".frag";
             break;
         case ShaderType.VertexShader:
             extension = ".vert";
             break;
         case ShaderType.GeometryShader:
             extension = ".geom";
             break;
         case ShaderType.TessEvaluationShader:
             extension = ".tess";
             break;
         case ShaderType.TessControlShader:
             extension = ".tctrl";
             break;
         case ShaderType.ComputeShader:
             extension = ".comp";
             break;
     }
     string output = File.ReadAllText(Directory.GetCurrentDirectory() + "/" + path + extension);
     return output;
 }
Exemple #20
0
        public Shader(string name, string file, ShaderType type)
        {
            this.ShaderName = name;
            this.ShaderFile = file;

            switch (type)
            {
            case ShaderType.VertexShader:
                this.HasVertexShader = true;
                break;
            case ShaderType.FragmentShader:
                this.HasFragmentShader = true;
                break;
            case ShaderType.GeometryShader:
                this.HasGeometryShader = true;
                break;
            case ShaderType.TessControlShader:
                this.HasTessControlShader = true;
                break;
            case ShaderType.TessEvaluationShader:
                this.HasTessEvaluationShader = true;
                break;
            case ShaderType.ComputeShader:
                this.HasComputeShader = true;
                break;
            }
        }
Exemple #21
0
		protected Shader(Shader original) :
			base(original)
		{
			this.Identifier = original.Identifier;
			this.type = original.type;
			original.Identifier = 0;
		}
Exemple #22
0
 public void Load(string path, ShaderType type, string version = "")
 {
     var source = IO.ASCIIFileHelper.ReadFileToEnd(path);
     source = version + "\n" + source;
     var name = Path.GetFileNameWithoutExtension(path);
     Load(source, name, type);
 }
Exemple #23
0
 public Shader(ShaderType type, string shaderCode)
 {
     Type = type;
     ShaderCode = shaderCode;
     ReplaceLayoutLocations();
     ID = CreateShader(type, ShaderCode);
 }
Exemple #24
0
 /// <summary>
 /// Create a shader using a stream as the source and a ShaderType parameter.
 /// </summary>
 /// <param name="shaderType">The shader type (fragment or vertex)</param>
 /// <param name="source">The stream for the shader.</param>
 public Shader(ShaderType shaderType, Stream source) {
     if (shaderType == ShaderType.Vertex) {
         shader = new SFML.Graphics.Shader(source, null);
     }
     else {
         shader = new SFML.Graphics.Shader(null, source);
     }
 }
        public ShaderComponent(ShaderType type, string filename)
        {
            this.type = type;
            this.filename = filename;
            this.id = GL.CreateShader(this.type);

            this.load();
        }
Exemple #26
0
 public ResourceShader( string name, string source, ShaderType shaderType )
     : base(name)
 {
     this.type = ResourceType.SHADER;
       this.shader = new Shader( name, source, shaderType );
       this.shader.resource = this;
       this.IsValid = true;
 }
 public ShaderFile Load(string fileName, ShaderType shaderType)
 {
     var path = Path.Combine(this.pathPrefix, fileName);
     if (this.appendExtensionsForSingleFiles)
         path = this.appendExtension(path, shaderType);
     
     return new ShaderFile(shaderType, path, fileName);
 }
Exemple #28
0
 NShaderType(Object T)
 {
     if (T is VertexShaderTag)
         value = ShaderType.VertexShader;
     else if (T is FragmentShaderTag)
         value = ShaderType.FragmentShader;
     else throw new ArgumentException("Invalid parameter: " + T.GetType().Name);
 }
Exemple #29
0
 private void loadShader(String code, ShaderType type, out int address)
 {
     address = GL.CreateShader(type);
     GL.ShaderSource(address, code);
     GL.CompileShader(address);
     GL.AttachShader(ProgramID, address);
     Console.WriteLine(GL.GetShaderInfoLog(address));
 }
        public SSShader(ShaderType type, string shaderName, string shaderProgramText)
        {
            this.type = type;
            this.shaderProgramText = shaderProgramText;
            this.shaderName = shaderName;

            this.loadShader();
        }