Exemple #1
0
 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;
 }
Exemple #2
0
            public OpenGLBackbuffer(
				ModernGLDevice 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.glCreateFramebuffers(1, out handle);
                Handle = handle;
                glDevice.BindFramebuffer(Handle);

                // Create and attach the color buffer
                glDevice.glCreateRenderbuffers(1, out colorAttachment);
                if (multiSampleCount > 0)
                {
                    glDevice.glNamedRenderbufferStorageMultisample(
                        colorAttachment,
                        multiSampleCount,
                        GLenum.GL_RGBA8,
                        width,
                        height
                    );
                }
                else
                {
                    glDevice.glNamedRenderbufferStorage(
                        colorAttachment,
                        GLenum.GL_RGBA8,
                        width,
                        height
                    );
                }
                glDevice.glNamedFramebufferRenderbuffer(
                    Handle,
                    GLenum.GL_COLOR_ATTACHMENT0,
                    GLenum.GL_RENDERBUFFER,
                    colorAttachment
                );

                if (depthFormat == DepthFormat.None)
                {
                    // Don't bother creating a depth/stencil buffer.
                    depthStencilAttachment = 0;
                    return;
                }

                // Create and attach the depth/stencil buffer
                glDevice.glCreateRenderbuffers(1, out depthStencilAttachment);
                if (multiSampleCount > 0)
                {
                    glDevice.glNamedRenderbufferStorageMultisample(
                        depthStencilAttachment,
                        multiSampleCount,
                        XNAToGL.DepthStorage[(int) depthFormat],
                        width,
                        height
                    );
                }
                else
                {
                    glDevice.glNamedRenderbufferStorage(
                        depthStencilAttachment,
                        XNAToGL.DepthStorage[(int) depthFormat],
                        width,
                        height
                    );
                }
                glDevice.glNamedFramebufferRenderbuffer(
                    Handle,
                    GLenum.GL_DEPTH_ATTACHMENT,
                    GLenum.GL_RENDERBUFFER,
                    depthStencilAttachment
                );
                if (depthFormat == DepthFormat.Depth24Stencil8)
                {
                    glDevice.glNamedFramebufferRenderbuffer(
                        Handle,
                        GLenum.GL_STENCIL_ATTACHMENT,
                        GLenum.GL_RENDERBUFFER,
                        depthStencilAttachment
                    );
                }
            }