public static ShaderCreationArguments TranslateShader(List <string> inputShaderLines, string fullPath, DateTime createdDate) { string firstLine = inputShaderLines[0]; StaticLogger.Logger.DebugFormat("Shader {0} has first line {1}", fullPath, firstLine); bool urielInterpretable = firstLine.StartsWith(UrielShaderDirective_LineStart); if (!urielInterpretable) { ShaderBlobType defaultType = ShaderBlobType.UrielStandard_FromFile(); StaticLogger.Logger.DebugFormat("Shader is not Uriel Interpretable - proceeding with conversion to default ShaderBlobType {0}", defaultType); var alteredLines = ModifyLinesForShaderToy(inputShaderLines, defaultType.FragmentShaderVersion, defaultType.Uniforms); return(new ShaderCreationArguments() { Type = defaultType, SimpleName = "FromFile", FragmentShaderSource = alteredLines, TexturePath = string.Empty, Changed = createdDate, FileName = fullPath }); } else { // TODO: the type should eventually come from the uriel directive var defaultnonInterpretableType = ShaderBlobType.Texture_FromFile(); StaticLogger.Logger.DebugFormat("Shader is Uriel Interpretable - proceeding with conversion to default ShaderBlobType {0}", defaultnonInterpretableType); var alteredLines = ModifyLinesForShaderToy(inputShaderLines, defaultnonInterpretableType.FragmentShaderVersion, defaultnonInterpretableType.Uniforms); var urielFields = firstLine.Split(new char[] { UrielShaderDirective_Separator }).ToList(); StaticLogger.Logger.DebugFormat("UrielFields has {0} members", urielFields.Count); // urielFields[0]; @"//URIEL" // urielFields[1]; Z:\TextureStore\UrielTexture.png var possibleTextureAbsolutePath = urielFields[1].Trim(); StaticLogger.Logger.DebugFormat("Texture Path is {0}", possibleTextureAbsolutePath); bool useTexture = !string.IsNullOrWhiteSpace(possibleTextureAbsolutePath); return(new ShaderCreationArguments() { Type = ShaderBlobType.Texture_FromFile(), SimpleName = "FromFile", FragmentShaderSource = alteredLines, TexturePath = possibleTextureAbsolutePath, Changed = createdDate, FileName = fullPath }); } }
public static ShaderCreationArguments BadShaderArguments() { return(new ShaderCreationArguments() { Type = ShaderBlobType.Time(), SimpleName = "BadShader", FragmentShaderSource = new List <string>(BuiltInShaderSource.BadShader), }); }
public VertexArray(VertexLocations vertexLocations, ShaderBlobType type, RawVertexData vertexInformation) { if (vertexLocations == null) { throw new ArgumentNullException(nameof(vertexLocations)); } // Allocate buffers referenced by this vertex array _BufferPosition = new GlBuffer <float>(vertexInformation.positions, BufferTarget.ArrayBuffer); // Generate VAO name ArrayName = Gl.GenVertexArray(); // First bind create the VAO Gl.BindVertexArray(ArrayName); // Select the buffer object Gl.BindBuffer(BufferTarget.ArrayBuffer, _BufferPosition.BufferName); // Format the vertex information: 2 floats from the current buffer Gl.VertexAttribPointer((uint)vertexLocations.Location_Position, floats_per_position, VertexAttribType.Float, false, stride, startingLocation); // Enable attribute Gl.EnableVertexAttribArray((uint)vertexLocations.Location_Position); if (type.UseIndexing) { _BufferIndex = new GlBuffer <uint>(vertexInformation.indexes, BufferTarget.ElementArrayBuffer); Gl.BindBuffer(BufferTarget.ElementArrayBuffer, _BufferIndex.BufferName); Count = vertexInformation.indexes.Length; } else { Count = (vertexInformation.positions.Length / floats_per_position); } if (type.VertexFormat == VertexFormat.WithColor || type.VertexFormat == VertexFormat.WithColorAndTexture) { _BufferColor = new GlBuffer <float>(vertexInformation.colors, BufferTarget.ArrayBuffer); Gl.BindBuffer(BufferTarget.ArrayBuffer, _BufferColor.BufferName); // Format the vertex information: 3 floats from the current buffer Gl.VertexAttribPointer((uint)vertexLocations.Location_Color, floats_per_color, VertexAttribType.Float, false, stride, startingLocation); // Enable attribute Gl.EnableVertexAttribArray((uint)vertexLocations.Location_Color); } if (type.VertexFormat == VertexFormat.WithTexture || type.VertexFormat == VertexFormat.WithColorAndTexture) { _BufferTex = new GlBuffer <float>(vertexInformation.textures, BufferTarget.ArrayBuffer); Gl.BindBuffer(BufferTarget.ArrayBuffer, _BufferTex.BufferName); // Format the vertex information: 2 floats from the current buffer Gl.VertexAttribPointer((uint)vertexLocations.Location_Texture, floats_per_textureCoordinate, VertexAttribType.Float, false, stride, startingLocation); // Enable attribute Gl.EnableVertexAttribArray((uint)vertexLocations.Location_Texture); } }
public static List <ShaderCreationArguments> BuildZoo() { var toReturn = new List <ShaderCreationArguments>(); var SimplestShader_Args = new ShaderCreationArguments() { Type = ShaderBlobType.PlainVertexNoUniforms(), SimpleName = "SimplestShader", FragmentShaderSource = new List <string>(BuiltInShaderSource.SimpleShader), }; var SimplestShader_WithTime_Args = new ShaderCreationArguments() { Type = ShaderBlobType.Time(), SimpleName = "SimplestShader_WithTime", FragmentShaderSource = new List <string>(BuiltInShaderSource.ShaderNoResolution), }; var BaseShader_Args = new ShaderCreationArguments() { Type = ShaderBlobType.Standard(), SimpleName = "BaseShader", FragmentShaderSource = new List <string>(BuiltInShaderSource.BaseShader), }; var BaseShader2_Args = new ShaderCreationArguments() { Type = ShaderBlobType.Standard(), SimpleName = "BaseShader2", FragmentShaderSource = new List <string>(BuiltInShaderSource.BaseShader2), }; var BaseShaderAlternate_Args = new ShaderCreationArguments() { Type = ShaderBlobType.Standard(), SimpleName = "BaseShaderAlternate", FragmentShaderSource = new List <string>(BuiltInShaderSource.BaseShaderAlternate), }; var ColorNoIndex_Args = new ShaderCreationArguments() { Type = ShaderBlobType.Color_NoIndex(), SimpleName = "Color_NoIndex", FragmentShaderSource = new List <string>(BuiltInShaderSource.ColorTest), }; var ColorIndex_Args = new ShaderCreationArguments() { Type = ShaderBlobType.Color_WithIndex(), SimpleName = "Color_Index", FragmentShaderSource = new List <string>(BuiltInShaderSource.ColorTest), }; var ColorTest_Args = new ShaderCreationArguments() { Type = ShaderBlobType.TextureStandard(), SimpleName = "TexTest", FragmentShaderSource = new List <string>(BuiltInShaderSource.TextureTest), TexturePath = @"Z:\ShaderStore\MultiColorTest.png" }; var TexTest_Args = new ShaderCreationArguments() { Type = ShaderBlobType.TextureStandard(), SimpleName = "TexTest", FragmentShaderSource = new List <string>(BuiltInShaderSource.TextureTest), TexturePath = @"Z:\ShaderStore\ColorTest.png" }; var TexTest2_Args = new ShaderCreationArguments() { Type = ShaderBlobType.TextureStandard(), SimpleName = "TexTest2", FragmentShaderSource = new List <string>(BuiltInShaderSource.TextureTest), TexturePath = @"Z:\ShaderStore\ColorTest2.png" }; var TexTest3_Args = new ShaderCreationArguments() { Type = ShaderBlobType.TextureStandard(), SimpleName = "TexTest3", FragmentShaderSource = new List <string>(BuiltInShaderSource.TextureTest), TexturePath = @"Z:\ShaderStore\ColorTest3.png" }; var TexTest4_Args = new ShaderCreationArguments() { Type = ShaderBlobType.TextureStandard(), SimpleName = "TexTest4", FragmentShaderSource = new List <string>(BuiltInShaderSource.TextureTest), TexturePath = @"Z:\ShaderStore\ColorTest4.png" }; var TexTest5_Args = new ShaderCreationArguments() { Type = ShaderBlobType.TextureStandard(), SimpleName = "TexTest5", FragmentShaderSource = new List <string>(BuiltInShaderSource.TextureTest), TexturePath = @"Z:\ShaderStore\ColorTest5.png" }; var TexTestSkull_Args = new ShaderCreationArguments() { Type = ShaderBlobType.TextureStandard(), SimpleName = "TexTestSkull", FragmentShaderSource = new List <string>(BuiltInShaderSource.TextureTest), TexturePath = @"Z:\ShaderStore\Mega-Skull.png" }; var TexTestSkull2_Args = new ShaderCreationArguments() { Type = ShaderBlobType.TextureStandard(), SimpleName = "TexTestSkull2", FragmentShaderSource = new List <string>(BuiltInShaderSource.TextureTest), TexturePath = @"Z:\ShaderStore\Mega-Skull2.png" }; var TexTestSkull3_Args = new ShaderCreationArguments() { Type = ShaderBlobType.TextureStandard(), SimpleName = "TexTestSkull2", FragmentShaderSource = new List <string>(BuiltInShaderSource.TextureTest), TexturePath = @"Z:\ShaderStore\Mega-Skull3.png" }; toReturn.Add(SimplestShader_Args); toReturn.Add(SimplestShader_WithTime_Args); toReturn.Add(BaseShader_Args); toReturn.Add(BaseShader2_Args); toReturn.Add(BaseShaderAlternate_Args); toReturn.Add(ColorNoIndex_Args); toReturn.Add(ColorIndex_Args); toReturn.Add(ColorTest_Args); toReturn.Add(TexTest_Args); toReturn.Add(TexTest2_Args); toReturn.Add(TexTest3_Args); toReturn.Add(TexTest4_Args); toReturn.Add(TexTest5_Args); toReturn.Add(TexTestSkull_Args); toReturn.Add(TexTestSkull2_Args); toReturn.Add(TexTestSkull3_Args); return(toReturn); }