Exemplo n.º 1
0
 public GLWpfControlRenderer(GLWpfControlSettings settings)
 {
     _context = new DxGlContext(settings);
 }
Exemplo n.º 2
0
        public DxGLFramebuffer([NotNull] DxGlContext context, int width, int height, double dpiScaleX, double dpiScaleY)
        {
            DxGlContext       = context;
            Width             = width;
            Height            = height;
            FramebufferWidth  = (int)Math.Ceiling(width * dpiScaleX);
            FramebufferHeight = (int)Math.Ceiling(height * dpiScaleY);

            var dxSharedHandle = IntPtr.Zero; // Unused windows-vista legacy sharing handle. Must always be null.

            DXInterop.CreateRenderTarget(
                context.DxDeviceHandle,
                FramebufferWidth,
                FramebufferHeight,
                Format.X8R8G8B8,// this is like A8 R8 G8 B8, but avoids issues with Gamma correction being applied twice.
                MultisampleType.None,
                0,
                false,
                out var dxRenderTargetHandle,
                ref dxSharedHandle);

            DxRenderTargetHandle = dxRenderTargetHandle;

            Wgl.DXSetResourceShareHandleNV(dxRenderTargetHandle, dxSharedHandle);

            GLFramebufferHandle   = GL.GenFramebuffer();
            GLSharedTextureHandle = GL.GenTexture();

            var genHandle = Wgl.DXRegisterObjectNV(
                context.GlDeviceHandle,
                dxRenderTargetHandle,
                (uint)GLSharedTextureHandle,
                (uint)TextureTarget.Texture2D,
                WGL_NV_DX_interop.AccessReadWrite);

            DxInteropRegisteredHandle = genHandle;

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, GLFramebufferHandle);
            GL.FramebufferTexture2D(
                FramebufferTarget.Framebuffer,
                FramebufferAttachment.ColorAttachment0,
                TextureTarget.Texture2D,
                GLSharedTextureHandle, 0);

            GLDepthRenderBufferHandle = GL.GenRenderbuffer();
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, GLDepthRenderBufferHandle);
            GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent24, FramebufferWidth, FramebufferHeight);
            GL.FramebufferRenderbuffer(
                FramebufferTarget.Framebuffer,
                FramebufferAttachment.DepthAttachment,
                RenderbufferTarget.Renderbuffer,
                GLDepthRenderBufferHandle);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);


            D3dImage = new D3DImage(96.0 * dpiScaleX, 96.0 * dpiScaleY);

            TranslateTransform = new TranslateTransform(0, height);
            FlipYTransform     = new ScaleTransform(1, -1);
        }