/// <summary> /// Initializes a new instance of the <see cref="GraphicsDevice" /> class. /// </summary> /// <param name="adapter">The graphics adapter.</param> /// <param name="graphicsProfile">The graphics profile.</param> /// <param name="presentationParameters">The presentation options.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="presentationParameters"/> is <see langword="null"/>. /// </exception> public GraphicsDevice( GraphicsAdapter adapter, GraphicsProfile graphicsProfile, PresentationParameters presentationParameters ) { if (presentationParameters == null) { throw new ArgumentNullException("presentationParameters"); } // Set the properties from the constructor parameters. Adapter = adapter; PresentationParameters = presentationParameters; GraphicsProfile = graphicsProfile; // Set up the OpenGL Device. Loads entry points. GLDevice = new OpenGLDevice(PresentationParameters); // Force set the default render states. BlendState = BlendState.Opaque; DepthStencilState = DepthStencilState.Default; RasterizerState = RasterizerState.CullCounterClockwise; // Initialize the Texture/Sampler state containers Textures = new TextureCollection(this); SamplerStates = new SamplerStateCollection(this); // Clear constant buffers vertexConstantBuffers.Clear(); pixelConstantBuffers.Clear(); // First draw will need to set the shaders. vertexShaderDirty = true; pixelShaderDirty = true; // Set the default viewport and scissor rect. Viewport = new Viewport(PresentationParameters.Bounds); ScissorRectangle = Viewport.Bounds; // Free all the cached shader programs. programCache.Clear(); shaderProgram = null; }
public void Dispose() { uint handle = Handle; glDevice.BindFramebuffer(0); glDevice.glDeleteFramebuffers(1, ref handle); glDevice.glDeleteRenderbuffers(1, ref colorAttachment); if (depthStencilAttachment != 0) { glDevice.glDeleteRenderbuffers(1, ref depthStencilAttachment); } if (Texture != 0) { glDevice.glDeleteTextures(1, ref Texture); } glDevice = null; Handle = 0; }
public OpenGLBackbuffer( OpenGLDevice device, int width, int height, DepthFormat depthFormat, int multiSampleCount ) { Width = width; Height = height; glDevice = device; DepthFormat = depthFormat; MultiSampleCount = multiSampleCount; Texture = 0; // Generate and bind the FBO. uint handle; glDevice.glGenFramebuffers(1, out handle); Handle = handle; glDevice.BindFramebuffer(Handle); // Create and attach the color buffer glDevice.glGenRenderbuffers(1, out colorAttachment); glDevice.glBindRenderbuffer(GLenum.GL_RENDERBUFFER, colorAttachment); if (multiSampleCount > 0) { glDevice.glRenderbufferStorageMultisample( GLenum.GL_RENDERBUFFER, multiSampleCount, GLenum.GL_RGBA8, width, height ); } else { glDevice.glRenderbufferStorage( GLenum.GL_RENDERBUFFER, GLenum.GL_RGBA8, width, height ); } glDevice.glFramebufferRenderbuffer( GLenum.GL_FRAMEBUFFER, GLenum.GL_COLOR_ATTACHMENT0, GLenum.GL_RENDERBUFFER, colorAttachment ); if (depthFormat == DepthFormat.None) { // Don't bother creating a depth/stencil buffer. depthStencilAttachment = 0; // Keep this state sane. glDevice.glBindRenderbuffer(GLenum.GL_RENDERBUFFER, 0); return; } // Create and attach the depth/stencil buffer glDevice.glGenRenderbuffers(1, out depthStencilAttachment); glDevice.glBindRenderbuffer(GLenum.GL_RENDERBUFFER, depthStencilAttachment); if (multiSampleCount > 0) { glDevice.glRenderbufferStorageMultisample( GLenum.GL_RENDERBUFFER, multiSampleCount, XNAToGL.DepthStorage[(int) depthFormat], width, height ); } else { glDevice.glRenderbufferStorage( GLenum.GL_RENDERBUFFER, XNAToGL.DepthStorage[(int) depthFormat], width, height ); } glDevice.glFramebufferRenderbuffer( GLenum.GL_FRAMEBUFFER, GLenum.GL_DEPTH_ATTACHMENT, GLenum.GL_RENDERBUFFER, depthStencilAttachment ); if (depthFormat == DepthFormat.Depth24Stencil8) { glDevice.glFramebufferRenderbuffer( GLenum.GL_FRAMEBUFFER, GLenum.GL_STENCIL_ATTACHMENT, GLenum.GL_RENDERBUFFER, depthStencilAttachment ); } // Keep this state sane. glDevice.glBindRenderbuffer(GLenum.GL_RENDERBUFFER, 0); }