public void GetInvalidSource() { var source = RenderTestUtils.ResourceShaders.GetShaderSource("invalid.frag"); var shader = new ShaderObject(source, ShaderType.FragmentShader); Assert.AreEqual(source, shader.GetShaderSource()); }
public ShaderProgram(string[] vertexSource, string[] fragmentSource) { //create vertex and fragment shaders //create the objects in a way that will call the Dispose function when GC cleans them up using (ShaderObject vertex = new ShaderObject(ShaderType.VertexShader, vertexSource)) using (ShaderObject fragment = new ShaderObject(ShaderType.FragmentShader, fragmentSource)) { //tell the gpu to create a shader program, and give us the ID number for it ProgramID = Gl.CreateProgram(); //connect the vertex and fragment shaders to it Gl.AttachShader(ProgramID, vertex.ShaderID); Gl.AttachShader(ProgramID, fragment.ShaderID); //link program, not sure what this means Gl.LinkProgram(ProgramID); //check for errors Gl.GetProgram(ProgramID, ProgramProperty.LinkStatus, out int linked); if (linked == 0) { //it f****d up } //get the location of the uniform variables in the shaders attribUniformLoc = Gl.GetUniformLocation(ProgramID, "uMVP"); //get the location of the position and color attributes in the shaders attribPositionLoc = Gl.GetAttribLocation(ProgramID, "aPosition"); attribColorLoc = Gl.GetAttribLocation(ProgramID, "aColor"); //you should probably check to make sure those worked too, but im lazy } }
/// <summary> /// Creates and compiles a new <see cref="ShaderObject"/> to be accessed by <paramref name="name"/> /// for subsequent calls to <see cref="AddShader(string, string[])"/>. /// </summary> /// <param name="name">The unique identifier to associate with <paramref name="shaderSource"/></param> /// <param name="shaderSource">The shader's GLSL source code</param> /// <param name="shaderType">Determines which shader stage this shader will be used for when linking the program</param> /// <returns><c>true</c> if the shader was added and compiled successfully</returns> public bool AddSource(string name, string shaderSource, ShaderType shaderType) { var shader = new ShaderObject(shaderSource, shaderType); shaderObjectByName[name] = shader; return(shader.WasCompiledSuccessfully); }
public void FromInvalidSource() { var source = RenderTestUtils.ResourceShaders.GetShaderSource("invalid.frag"); var shader = new ShaderObject(source, ShaderType.FragmentShader); Assert.IsFalse(shader.WasCompiledSuccessfully); }
public void SetShaderTypeGeom() { var source = RenderTestUtils.ResourceShaders.GetShaderSource("valid.frag"); var shader = new ShaderObject(source, ShaderType.GeometryShader); Assert.AreEqual(ShaderType.GeometryShader, shader.ShaderType); }
public void FromInvalidSource() { // The logs are driver dependent, so just check that it produces some sort of error message. var source = RenderTestUtils.ResourceShaders.GetShaderSource("invalid.frag"); var shader = new ShaderObject(source, ShaderType.FragmentShader); Assert.IsTrue(shader.GetInfoLog().ToLower().Contains("error")); }
/// <summary> /// Allocate an instance of the type. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating the instance. /// </param> /// <returns> /// It returns an instance of a specific type. /// </returns> public override object Allocate(GraphicsContext ctx) { ShaderObject shaderObject = new ShaderObject(ShaderStage.Vertex); shaderObject.LoadSource(ShaderSource); return(shaderObject); }
public void TestVertex() { using (ShaderObject shaderObject = new ShaderObject(ShaderStage.Vertex)) { // Load source Assert.DoesNotThrow(delegate() { shaderObject.LoadSource("OpenGL.Shaders.Line.Vertex.glsl"); }); // Compile Assert.DoesNotThrow(delegate() { shaderObject.Create(_Context); }); } }
public void TestVertex() { using (ShaderObject shaderObject = new ShaderObject(ShaderStage.Vertex)) { // Load source Assert.DoesNotThrow(delegate() { shaderObject.LoadSource("OpenGL.Shaders.Line.Vertex.glsl"); }); // Compile Assert.DoesNotThrow(delegate() { shaderObject.Create(_Context); }); } }
public ShaderObject[] GetBallShaders() { if (ballShaders == null) { List<ShaderObject> shaders = new List<ShaderObject>(); for (int r = 0; r < VARIATIONS + 1; r++) { for (int g = 0; g < VARIATIONS + 1; g++) { for (int b = 0; b < VARIATIONS + 1; b++) { if (r == VARIATIONS && g == VARIATIONS && b == VARIATIONS) continue; ShaderObject shader = new ShaderObject(); Color color = new Color((r * 1.0f) / VARIATIONS, (g * 1.0f) / VARIATIONS, (b * 1.0f) / VARIATIONS, 1.0f); shader.name = RGBToHex(r, g, b); shader.label = ShaderStore.GetColorName(shader.name); shader.shader = flatShader; shader.price = 200; shader.colors = new Color[] { color }; shaders.Add(shader); } } } ShaderObject cycle = new ShaderObject(); cycle.name = "rainbow cycle"; cycle.label = "rainbow cycle"; cycle.shader = cycleShader; cycle.price = 20000; cycle.colors = new Color[] { new Color(0, 0, 0, 1) }; shaders.Add(cycle); ShaderObject hardcore = new ShaderObject(); hardcore.name = hardLabel; hardcore.label = hardLabel; hardcore.shader = hardShader; hardcore.price = 50000; hardcore.colors = new Color[] { new Color(0.54f, 0, 0.54f, 1) }; shaders.Add(hardcore); ShaderObject ultraHardcore = new ShaderObject(); ultraHardcore.name = ultraHardLabel; ultraHardcore.label = ultraHardLabel; ultraHardcore.shader = hardShader; ultraHardcore.price = 100000; ultraHardcore.colors = new Color[] { new Color(0.95f, 0.95f, 0.95f, 1) }; shaders.Add(ultraHardcore); ballShaders = shaders.ToArray(); } return ballShaders; }
//---------------------------------------- public DataObjectBase GetObject(Object obj) { if (obj == null) { return(null); } if (objects.ContainsKey(obj)) { return(objects[obj]); } if (obj is Shader) { var dataobject = new ShaderObject(obj as Shader); objects[obj] = dataobject; return(dataobject); } if (obj is Mesh) { var dataobject = new MeshObject(obj as Mesh); objects[obj] = dataobject; return(dataobject); } if (obj is Texture) { TextureObject dataobject = null; dataobject = new TextureObject(obj as Texture); //dataobject = new TextureObject(Texture2D.whiteTexture); objects[obj] = dataobject; return(dataobject); } if (obj is FxCanvasObject) { var dataobject = new CanvasObject(obj as FxCanvasObject); objects[obj] = dataobject; return(dataobject); } if (obj is AnimationClip) { var dataobject = new AnimationClipObject(obj as AnimationClip); objects[obj] = dataobject; return(dataobject); } return(null); }
public void TestGeometry() { if (!_Context.Caps.GlExtensions.GeometryShader4_ARB && !_Context.Caps.GlExtensions.GeometryShader4_EXT) Assert.Inconclusive("geometry shader not supported"); using (ShaderObject shaderObject = new ShaderObject(ShaderStage.Geometry)) { // Load source Assert.DoesNotThrow(delegate () { shaderObject.LoadSource("OpenGL.Shaders.Line.Geometry.glsl"); }); // Compile Assert.DoesNotThrow(delegate () { shaderObject.Create(_Context); }); } }
/// <summary> /// Allocate an instance of the type mocked for spying. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating the instance. /// </param> /// <returns> /// It returns an instance of a specific type. /// </returns> public override T AllocateSpy <T>(GraphicsContext ctx) { T shaderObjectSpy = (T)CreateTypeSpy(typeof(ShaderObject), ShaderStage.Vertex); ShaderObject shaderObject = shaderObjectSpy as ShaderObject; if (shaderObject != null) { shaderObject.LoadSource(ShaderSource); } return(shaderObjectSpy); }
public Exporter(ExportMode mode = ExportMode.Generic) { _exportMode = mode; ShaderObject.RegisterShaders(); TextureObject.RegisterFormat(); //-----------time-------------------- { var obj = Object.FindObjectOfType <SceneConfig>(); var dataobject = new TimeInformation(obj); objects[obj] = dataobject; } }
public void TestGeometry() { if (!_Context.Caps.GlExtensions.GeometryShader4_ARB && !_Context.Caps.GlExtensions.GeometryShader4_EXT) { Assert.Inconclusive("geometry shader not supported"); } using (ShaderObject shaderObject = new ShaderObject(ShaderStage.Geometry)) { // Load source Assert.DoesNotThrow(delegate() { shaderObject.LoadSource("OpenGL.Shaders.Line.Geometry.glsl"); }); // Compile Assert.DoesNotThrow(delegate() { shaderObject.Create(_Context); }); } }
public void TestFragment() { using (ShaderObject shaderObject = new ShaderObject(ShaderStage.Fragment)) { // Load source Assert.DoesNotThrow(delegate () { shaderObject.LoadSource("OpenGL.Shaders.Line.Fragment.glsl"); }); // Compile Assert.DoesNotThrow(delegate () { shaderObject.Create(_Context); }); } using (ShaderObject shaderObject = new ShaderObject(ShaderStage.Fragment)) { // Load source Assert.DoesNotThrow(delegate () { shaderObject.LoadSource("OpenGL.Shaders.Line.Fragment.glsl"); }); // Compile Assert.DoesNotThrow(delegate () { shaderObject.Create(_Context, new ShaderCompilerContext("HAL_COLOR_PER_VERTEX")); }); } }
public void TestFragment() { using (ShaderObject shaderObject = new ShaderObject(ShaderStage.Fragment)) { // Load source Assert.DoesNotThrow(delegate() { shaderObject.LoadSource("OpenGL.Shaders.Line.Fragment.glsl"); }); // Compile Assert.DoesNotThrow(delegate() { shaderObject.Create(_Context); }); } using (ShaderObject shaderObject = new ShaderObject(ShaderStage.Fragment)) { // Load source Assert.DoesNotThrow(delegate() { shaderObject.LoadSource("OpenGL.Shaders.Line.Fragment.glsl"); }); // Compile Assert.DoesNotThrow(delegate() { shaderObject.Create(_Context, new ShaderCompilerContext("HAL_COLOR_PER_VERTEX")); }); } }
public void TestCreateObject(string objectId) { ShadersLibrary.Object shaderObjectInfo = ShadersLibrary.Instance.GetObject(objectId); Assert.IsNotNull(shaderObjectInfo); ShaderObject shaderObject = shaderObjectInfo.Create(); try { Assert.IsNotNull(shaderObject); Assert.DoesNotThrow(delegate { shaderObject.Create(_Context); }); } finally { if (shaderObject != null) { shaderObject.Dispose(); } } }
/// <summary> /// Allocate an instance of the type. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating the instance. /// </param> /// <returns> /// It returns an instance of a specific type. /// </returns> public override object Allocate(GraphicsContext ctx) { ShaderProgram shaderProgram = new ShaderProgram("TestProgram"); ShaderObject vertexShaderObject = new ShaderObject(ShaderStage.Vertex); vertexShaderObject.LoadSource(VertexShaderSource); ShaderObject fragmentShaderObject = new ShaderObject(ShaderStage.Fragment); fragmentShaderObject.LoadSource(FragmentShaderSource); shaderProgram.AttachShader(vertexShaderObject); shaderProgram.AttachShader(fragmentShaderObject); return(shaderProgram); }
public void AppendShaderInfoLog(ShaderObject shader) { // Append compilation errors for the current shader. errorLog.AppendLine($"{shader.ShaderType} Log:"); string error = GL.GetShaderInfoLog(shader.Id); if (error == "") { errorLog.AppendLine("No Error"); } else { errorLog.AppendLine(error); } errorLog.AppendLine(); // line between shaders }
/// <summary> /// Creates and links a new <see cref="Shader"/> from <see cref="ShaderObject"/> /// based on the keys in <paramref name="sourceNames"/>. Invalid keys are ignored. /// </summary> /// <param name="name">A unique name for the shader program</param> /// <param name="sourceNames">A collection of shader object names/></param> /// <returns><c>true</c> if the shader was added and linked successfully</returns> /// <exception cref="KeyNotFoundException">A key in <paramref name="sourceNames"/> /// does not refer to an available shader source</exception> public bool AddShader(string name, params string[] sourceNames) { var shader = new Shader(); var shaderObjects = new ShaderObject[sourceNames.Length]; for (int i = 0; i < sourceNames.Length; i++) { // Throw an exception because this is likely a design time typo. if (!shaderObjectByName.TryGetValue(sourceNames[i], out shaderObjects[i])) { throw new KeyNotFoundException($"Source not found for key {sourceNames[i]}"); } } shader.LoadShaders(shaderObjects); shaderByName[name] = shader; return(shader.LinkStatusIsOk); }
public void Link() { // Create vertex and frament shaders // Note: they can be disposed after linking to program; resources are freed when deleting the program using (ShaderObject vObject = new ShaderObject(ShaderType.VertexShader, VertexSource.ToArray())) using (ShaderObject fObject = new ShaderObject(ShaderType.FragmentShader, FragmentSource.ToArray())) { // Create program ProgramName = Gl.CreateProgram(); // Attach shaders Gl.AttachShader(ProgramName, vObject.ShaderName); Gl.AttachShader(ProgramName, fObject.ShaderName); // Link program Gl.LinkProgram(ProgramName); int linked; Gl.GetProgram(ProgramName, ProgramProperty.LinkStatus, out linked); var LinkedStatus = linked != 0; Validate(LinkedStatus); this.UniformLocations = new UniformLocations() { Location_iTime = Gl.GetUniformLocation(ProgramName, "iTime"), Location_iResolution = Gl.GetUniformLocation(ProgramName, "iResolution"), Location_iCursorPosition = Gl.GetUniformLocation(ProgramName, "iCursorPosition"), Location_iCursorMovement = Gl.GetUniformLocation(ProgramName, "iCursorMovement"), }; this.UniformLocations.ValidateAllPresent(expectedUniforms); this.VertexLocations = new VertexLocations() { Location_Position = Gl.GetAttribLocation(ProgramName, "aPosition"), Location_Color = Gl.GetAttribLocation(ProgramName, "aColor"), Location_Texture = Gl.GetAttribLocation(ProgramName, "aTexCoord") }; this.VertexLocations.ValidateAllPresent(expectedVertexes); } }
/// <summary> /// Allocate an instance of the type mocked for spying. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating the instance. /// </param> /// <returns> /// It returns an instance of a specific type. /// </returns> public override T AllocateSpy <T>(GraphicsContext ctx) { T shaderProgramSpy = (T)CreateTypeSpy(_InstanceType, "Test"); ShaderProgram shaderProgram = shaderProgramSpy as ShaderProgram; if (shaderProgram != null) { ShaderObject vertexShaderObject = new ShaderObject(ShaderStage.Vertex); vertexShaderObject.LoadSource(VertexShaderSource); ShaderObject fragmentShaderObject = new ShaderObject(ShaderStage.Fragment); fragmentShaderObject.LoadSource(FragmentShaderSource); shaderProgram.AttachShader(vertexShaderObject); shaderProgram.AttachShader(fragmentShaderObject); } return(shaderProgramSpy); }
public void FromNullSource() { var shader = new ShaderObject("", ShaderType.FragmentShader); Assert.IsFalse(shader.WasCompiledSuccessfully); }
private void SelectBallShader(ShaderObject shader) { ShaderController controller = GetComponent<ShaderController>(); if (PrefsController.DidBuyBallShader(shader.name)) { controller.SetBallShader(shader.name); PopulateBallShaders(); } else if (shader.price <= PrefsController.GetTotalCoins()) { PrefsController.SubTotalCoins(shader.price); PrefsController.BuyBallShader(shader.name, true); controller.SetBallShader(shader.name); PopulateBallShaders(); } }
public static void ResetShaders(ShaderObject[] ballShaders, ShaderObject[] wallShaders) { foreach (ShaderObject shader in ballShaders) { BuyBallShader(shader.name, false); } foreach (ShaderObject shader in wallShaders) { BuyWallShader(shader.name, false); } }
private int GetBallShaderState(ShaderObject shader) { int state = -1; if (shader.name == PrefsController.GetBallShader()) { state = STATE_EQUIPPED; } else if (PrefsController.DidBuyBallShader(shader.name)) { state = STATE_DID_BUY; } else if (shader.price <= PrefsController.GetTotalCoins()) { state = STATE_CAN_AFFORD; } else { state = STATE_CANT_AFFORD; } return state; }
public void GetNullSource() { var shader = new ShaderObject(null, ShaderType.FragmentShader); Assert.AreEqual("", shader.GetShaderSource()); }
public void FromNullSource() { var shader = new ShaderObject("", ShaderType.FragmentShader); Assert.AreEqual("", shader.GetInfoLog()); }
public ChangeShaderCommand(Camera cam, GameObject gameObject, Exporter exporter) { ObjectType = CommandTypeChangeShader; //------------------------------------------------- var viewMatrix = cam.worldToCameraMatrix; var projectMatrix = cam.projectionMatrix; matrixVP = projectMatrix * viewMatrix; matirxObjectToWorld = gameObject.transform.localToWorldMatrix; //------------------ var renderer = gameObject.GetComponent <Renderer>(); var shader = renderer.material.shader; _shaderObject = exporter.GetObject(shader) as ShaderObject; //------------------ renderer.GetPropertyBlock(block); var count = shader.GetPropertyCount(); for (var i = 0; i < count; i++) { var p = new ShaderParameter(shader.GetPropertyName(i), ShaderParameter.GetTypeFromPropertyType(shader.GetPropertyType(i))); switch (p.type) { case ShaderParameter.ParameterTypeColor: p.colorValue = block.GetColor(p.name); if (p.colorValue == new Color(0, 0, 0, 0)) { p.colorValue = renderer.material.GetColor(p.name); } break; case ShaderParameter.ParameterTypeFloat: p.floatValue = block.GetFloat(p.name); if (p.floatValue == 0.0f) { p.floatValue = renderer.material.GetFloat(p.name); } break; case ShaderParameter.ParameterTypeTexture2D: { var tex = renderer.material.GetTexture(p.name); if (tex == null) { tex = Texture2D.whiteTexture; } p.textureValue = exporter.GetObject(tex) as TextureObject; } break; case ShaderParameter.ParameterTypeFloat4: p.vectorValue = block.GetVector(p.name); if (p.vectorValue == new Vector4(0, 0, 0, 0)) { p.vectorValue = renderer.material.GetVector(p.name); } break; } _parameters.Add(p); if (p.type == ShaderParameter.ParameterTypeTexture2D) { var texcoord = new ShaderParameter(p.name + "_ST", ShaderParameter.ParameterTypeFloat4); //texcoord.vectorValue = renderer.material.GetVector(texcoord.name); texcoord.vectorValue = block.GetVector(texcoord.name); if (texcoord.vectorValue == new Vector4(0, 0, 0, 0)) { texcoord.vectorValue = renderer.material.GetVector(texcoord.name); } _parameters.Add(texcoord); } } //------------------------------------------------------ }
public SystemRender(ShaderObject inShader) { m_PBR_Shader = inShader; }