public void Render(ShaderBlob toRender, UniformValues uniforms, Size s) { Gl.Viewport(0, 0, s.Width, s.Height); Gl.Clear(ClearBufferMask.ColorBufferBit); // Select the program for drawing Gl.UseProgram(toRender.Program.ProgramName); Gl.UseProgram(toRender.Program.ProgramName); SetUniforms(toRender.Program.UniformLocations, uniforms); if (toRender.CreationArguments.Type.UseTexture) { Gl.BindTexture(TextureTarget.Texture2d, toRender.TextureName); } // Use the vertex array Gl.BindVertexArray(toRender.VertexArray.ArrayName); GlErrorLogger.Check(); // Draw triangle if (toRender.CreationArguments.Type.UseIndexing) { Gl.DrawElements(PrimitiveType.Triangles, toRender.VertexArray.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); } else { Gl.DrawArrays(PrimitiveType.Triangles, 0, toRender.VertexArray.Count); } GlErrorLogger.Check(); }
private void Loop() { //if (FrameTracker.frameCount % 1000 == 0 && FrameTracker.frameCount != 0) //{ // StaticLogger.Logger.Debug("Regenerating."); // RegenerateGlControl(); //} if (this.configuration.WorkflowMode == UrielWorkflowMode.EditorMode) { CreateNewShaderAndSelect(); this.CurrentShader = LoadNewShaderFromSelection(this.CurrentShader); } this.FrameTracker.StartFrame(); double time = (DateTime.UtcNow - StartTime).TotalSeconds; if (this.CurrentShader.CreationArguments.Type.Uniforms.Contains(KnownFragmentShaderUniform.CursorPosition) || this.CurrentShader.CreationArguments.Type.Uniforms.Contains(KnownFragmentShaderUniform.CursorMovement)) { UpdateKeys(); } Vertex2f resolution = new Vertex2f(this.Size.Width, this.Size.Height); UniformValues uniforms = new UniformValues() { Resolution = resolution, Time = time, CursorMovement = this.tks.Movement, CursorPosition = this.tks.Position }; renderLoop.Render(this.CurrentShader, uniforms, this.RenderControl.Size); this.FrameTracker.EndFrame(); if (this.configuration.WorkflowMode == UrielWorkflowMode.EditorMode) { StatusStrip_Update(time); } }
private void SetUniforms(UniformLocations uniformsLocations, UniformValues uniformsValues) { if (LocationValidation.Enabled(uniformsLocations.Location_iTime)) { Gl.Uniform1f <float>(uniformsLocations.Location_iTime, 1, (float)uniformsValues.Time); } if (LocationValidation.Enabled(uniformsLocations.Location_iResolution)) { Gl.Uniform2f(uniformsLocations.Location_iResolution, 1, uniformsValues.Resolution); } if (LocationValidation.Enabled(uniformsLocations.Location_iCursorPosition)) { Gl.Uniform3f(uniformsLocations.Location_iCursorPosition, 1, uniformsValues.CursorPosition); } if (LocationValidation.Enabled(uniformsLocations.Location_iCursorMovement)) { Gl.Uniform3f(uniformsLocations.Location_iCursorMovement, 1, uniformsValues.CursorMovement); } }