/// <summary> /// Binds a depth state object /// </summary> public void BindDepthState(DepthState state) { if (_currentDepthState == null || _currentDepthState.DepthMask != state.DepthMask) { GL.DepthMask(state.DepthMask); } // Commented out if conditions are base on the assumtion that depthFunc is only affected if depthmask is enabled, which seems to not be the case //if(DepthMask != newState.DepthMask && newState.DepthMask) //{ // DepthMask = newState.DepthMask; // GL.DepthMask(newState.DepthMask); //} if (_currentDepthState == null || _currentDepthState.DepthFunction != state.DepthFunction) { GL.DepthFunc(state.DepthFunction); } //if(DepthMask != newState.DepthMask && !newState.DepthMask) //{ // DepthMask = newState.DepthMask; // GL.DepthMask(newState.DepthMask); //} _currentDepthState = state; }
/// <summary> /// Creates a new graphics pipeline /// </summary> /// <param name="device">Glob device</param> /// <param name="vertex">Vertex shader</param> /// <param name="tesselationControl">Tesselation control shader - can be null</param> /// <param name="tesselationEvaluation">Tesselation evaluation shader - can be null</param> /// <param name="geometry">Geometry shader - can be null</param> /// <param name="fragment">Fragment shader</param> /// <param name="vertexFormat">Vertex buffer format - can be null</param> /// <param name="rasterizerState">Rasterization state - cull face and polygon mode</param> /// <param name="depthState">Depth state - depth test func and depth mask</param> /// <param name="blendState">Blend state - color/alpha blending mode - can be null</param> public GraphicsPipeline(Device device, Shader vertex, Shader fragment, Shader tesselationControl, Shader tesselationEvaluation, Shader geometry, VertexBufferFormat vertexFormat, RasterizerState rasterizerState, DepthState depthState, BlendState blendState = null) { _device = device; _shaderPipeline = _device.ShaderRepository.GetShaderPipeline(vertex, tesselationControl, tesselationEvaluation, geometry, fragment, null); _vertexFormat = vertexFormat; _rasterizerState = rasterizerState; _depthState = depthState; _blendState = blendState; if (_blendState == null) { _blendState = new BlendState(); } }
/// <summary> /// Changes all current states to null, so any future bind or state change will effectively skip redundant state change checks and should execute its OpenGL calls. /// </summary> public void Invalidate() { ShaderPipeline = null; _textureUnit.Invalidate(); _currentRasterizerState = null; _currentDepthState = null; _currentBlendState = null; _boundReadFramebuffer = -1; _boundDrawFramebuffer = -1; _boundBothFramebuffer = -1; _boundVertexFormat = null; _boundVertexSource = null; _bufferBindingManager.Invalidate(); }
/// <summary> /// Creates a new Glob Device. Can only be called once the OpenGL context is already created, for example by creating an OpenTK GameWindow. /// </summary> /// <param name="textOutput">Text output that will be used by Glob</param> /// <param name="fileManager">File manager that will be used by Glob</param> public Device(ITextOutputGlob textOutput, IFileManagerGlob fileManager) { TextOutput = textOutput; FileManager = fileManager; DeviceInfo = new DeviceInfo(); // TODO: move these to DeviceInfo.ToString() TextOutput.Print(OutputTypeGlob.Notify, "OpenGL: " + DeviceInfo.OpenGLVersion + " GLSL: " + DeviceInfo.GLSLVersion); TextOutput.Print(OutputTypeGlob.Notify, "Renderer: " + DeviceInfo.DeviceRenderer + ", " + DeviceInfo.DeviceVendor); // Print extensions StringBuilder allExtensionsStr = new StringBuilder(); foreach (string extension in DeviceInfo.Extensions) { allExtensionsStr.Append(extension); allExtensionsStr.Append(" "); } TextOutput.Print(OutputTypeGlob.Notify, DeviceInfo.Extensions.Count.ToString() + " GL extensions found"); TextOutput.Print(OutputTypeGlob.LogOnly, allExtensionsStr.ToString()); ShaderRepository = new ShaderRepository(this, "#extension GL_ARB_separate_shader_objects : enable\n"); ShaderRepository.StartFileWatcher(FileManager.GetPathShaderSource("")); _bufferBindingManager = new BufferBindingManager(); DebugMessageManager = new DebugMessageManager(true); _textureUnit = new TextureUnitState(); _currentRasterizerState = new RasterizerState(); _currentDepthState = new DepthState(); _currentBlendState = new BlendState(); // Create and bind a global vertex array object _vaoGlobal = GL.GenVertexArray(); GL.BindVertexArray(_vaoGlobal); }
/// <summary> /// Creates a new graphics pipeline /// </summary> /// <param name="device">Glob device</param> /// <param name="vertex">Vertex shader</param> /// <param name="fragment">Fragment shader</param> /// <param name="vertexFormat">Vertex buffer format - can be null</param> /// <param name="rasterizerState">Rasterization state - cull face and polygon mode</param> /// <param name="depthState">Depth state - depth test func and depth mask</param> /// <param name="blendState">Blend state - color/alpha blending mode - can be null</param> public GraphicsPipeline(Device device, Shader vertex, Shader fragment, VertexBufferFormat vertexFormat, RasterizerState rasterizerState, DepthState depthState, BlendState blendState = null) : this(device, vertex, fragment, null, null, null, vertexFormat, rasterizerState, depthState, blendState) { }