public void CreateTextureRender(GLContext control, EventHandler thumbnailUpdate, int width = 50, int height = 50)
        {
            var shader = GlobalShaders.GetShader("SCREEN");

            Framebuffer frameBuffer = new Framebuffer(FramebufferTarget.Framebuffer, width, height);

            frameBuffer.Bind();

            GL.ClearColor(0, 0, 0, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Viewport(0, 0, width, height);

            GL.Disable(EnableCap.Blend);

            shader.Enable();

            //Draw the texture onto the framebuffer
            ScreenQuadRender.Draw(shader, RenderableTex.ID);

            //Disable shader and textures
            GL.UseProgram(0);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            var thumbnail = frameBuffer.ReadImagePixels(true);

            thumbnail.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);

            //Dispose frame buffer
            frameBuffer.Dispoe();
            frameBuffer.DisposeRenderBuffer();

            this.Thumbnail = thumbnail;
            thumbnailUpdate?.Invoke(this, EventArgs.Empty);
        }
        private void GenerateRender(GLContext control, EventHandler thumbnailUpdate)
        {
            Framebuffer frameBuffer = new Framebuffer(FramebufferTarget.Framebuffer, Width, Height);

            frameBuffer.Bind();

            GL.ClearColor(0, 0, 0, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Viewport(0, 0, control.Width, control.Height);

            var camMtx  = Camera.ViewMatrix;
            var projMtx = Camera.ProjectionMatrix;

            //Draw all the models into the current camera screen
            //     scene.Draw(control, Pass.OPAQUE);
            //     scene.Draw(control, Pass.TRANSPARENT);

            //Disable shader and textures
            GL.UseProgram(0);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            RenderedScreen = (GLTexture2D)frameBuffer.Attachments[1];
            var thumbnail = frameBuffer.ReadImagePixels(true);

            //Dispose frame buffer
            frameBuffer.Dispoe();
            frameBuffer.DisposeRenderBuffer();

            this.Thumbnail = thumbnail;
            thumbnailUpdate?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 3
0
        public static int CreateTextureRender(int textureID, int width, int height)
        {
            if (lutCache.ContainsKey(textureID.ToString()))
            {
                return(lutCache[textureID.ToString()]);
            }

            var shader = GlobalShaders.GetShader("LUT_DISPLAY");

            Framebuffer frameBuffer = new Framebuffer(FramebufferTarget.Framebuffer, width, height, PixelInternalFormat.Rgba16f, 1);

            frameBuffer.Bind();

            GL.Disable(EnableCap.Blend);

            shader.Enable();

            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture3D, textureID);
            shader.SetInt("dynamic_texture_array", 1);

            GL.ClearColor(0, 0, 0, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Viewport(0, 0, width, height);

            //Draw the texture onto the framebuffer
            ScreenQuadRender.Draw();

            //Disable shader and textures
            GL.UseProgram(0);
            GL.BindTexture(TextureTarget.Texture3D, 0);

            var image = (GLTexture2D)frameBuffer.Attachments[0];

            ID = image.ID;

            lutCache.Add(textureID.ToString(), ID);
            return(ID);
        }
        public IPickable FindPickableAtPosition(GLContext context, List <IPickable> drawables, Vector2 position)
        {
            Init(context);

            var camera = context.Camera;

            pickingBuffer.Bind();
            GL.Viewport(0, 0, context.Width, context.Height);
            GL.ClearColor(1, 0, 0, 1);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            ColorPassIDs.Clear();
            pickingIndex = 1;

            //Draw the pickable objects. Drawn IDs will be passed into ColorPassIDs
            foreach (var drawable in drawables)
            {
                drawable.DrawColorPicking(context);
            }

            GL.UseProgram(0);

            GL.ReadPixels((int)position.X, (int)position.Y, 1, 1, PixelFormat.Rgba, PixelType.UnsignedByte, ref pickingColor);
            GL.ReadPixels((int)position.X, (int)position.Y, 1, 1, PixelFormat.DepthComponent, PixelType.Float, ref Depth);
            //Get normalized depth for z depth
            NormalizedPickingDepth = -(camera.ZFar * camera.ZNear / (Depth * (camera.ZFar - camera.ZNear) - camera.ZFar));

            pickingBuffer.Unbind();

            foreach (var drawable in drawables)
            {
                drawable.IsHovered = false;
            }

            return(SearchPickedColor(pickingColor));
        }
 public override void Attach(FramebufferAttachment attachment, Framebuffer target)
 {
     target.Bind();
     GL.FramebufferTexture2D(target.Target, attachment, TextureTarget.Texture2D, ID, 0);
 }
        public void CreateMaterialRender(GLContext control, GenericPickableMesh mesh,
                                         RenderObject renderObject, EventHandler thumbnailUpdated, int width = 50, int height = 50)
        {
            ShaderProgram shader = this.GetShader();

            if (shader == null)
            {
                return;
            }

            Framebuffer frameBuffer = new Framebuffer(FramebufferTarget.Framebuffer, width, height);

            frameBuffer.Bind();

            //Create a simple mvp matrix to render the material data
            Matrix4 modelMatrix = Matrix4.CreateTranslation(0, 0, -12);
            Matrix4 viewMatrix  = Matrix4.Identity;
            Matrix4 mtxProj     = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(90), 1.0f, 1.0f, 1000f);
            Matrix4 viewProj    = mtxProj * viewMatrix;

            GL.UseProgram(shader.program);
            shader.SetMatrix4x4("mtxCam", ref viewProj);
            shader.SetMatrix4x4("mtxMdl", ref modelMatrix);
            shader.SetVector3("camPosition", control.Camera.TargetPosition);
            shader.SetVector2("iResolution", new Vector2(control.Width, control.Height));
            shader.SetInt("materialRenderDisplay", 1);

            GL.ClearColor(0, 0, 0, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Viewport(0, 0, width, height);

            //Render material data onto a textured sphere
            Render(control, shader, mesh);

            GL.Enable(EnableCap.Blend);
            GL.BlendFuncSeparate(
                BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha,
                BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);

            //Draw the model to render onto
            switch (renderObject)
            {
            case RenderObject.Sphere:
                DrawSphere(control);
                break;

            case RenderObject.Plane:
                DrawPlane(control);
                break;
            }

            //Disable the uniform data
            shader.SetInt("materialRenderDisplay", 0);

            //Disable shader and textures
            GL.UseProgram(0);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            var thumbnail = frameBuffer.ReadImagePixels(true);

            //Dispose frame buffer
            frameBuffer.Dispoe();
            frameBuffer.DisposeRenderBuffer();

            this.Thumbnail = thumbnail;
            thumbnailUpdated?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 7
0
 public void Attach(FramebufferAttachment attachment, Framebuffer target)
 {
     target.Bind();
     GL.FramebufferRenderbuffer(target.Target, attachment, RenderbufferTarget.Renderbuffer, ID);
 }
        public static GLTexture2D CreateTextureRender(GLTexture texture, int arrayLevel, int mipLevel, bool force = false)
        {
            if (!force && cubemapCache.ContainsKey(texture.ID.ToString()))
            {
                return(cubemapCache[texture.ID.ToString()]);
            }
            else
            {
                if (cubemapCache.ContainsKey(texture.ID.ToString()))
                {
                    cubemapCache[texture.ID.ToString()]?.Dispose();
                }
            }

            int width  = texture.Width * 4;
            int height = texture.Height * 3;

            width  = 512;
            height = 256;

            var shader        = GlobalShaders.GetShader("EQUIRECTANGULAR");
            var textureOutput = GLTexture2D.CreateUncompressedTexture(width, height, PixelInternalFormat.Rgba32f);

            textureOutput.MipCount = texture.MipCount;

            texture.Bind();

            textureOutput.Bind();
            textureOutput.GenerateMipmaps();
            textureOutput.Unbind();

            Framebuffer frameBuffer = new Framebuffer(FramebufferTarget.Framebuffer, width, height);

            frameBuffer.Bind();

            GL.Disable(EnableCap.Blend);

            shader.Enable();
            shader.SetBoolToInt("is_array", texture is GLTextureCubeArray);

            if (texture is GLTextureCubeArray)
            {
                GL.ActiveTexture(TextureUnit.Texture1);
                texture.Bind();
                shader.SetInt("dynamic_texture_array", 1);
            }
            else
            {
                GL.ActiveTexture(TextureUnit.Texture1);
                texture.Bind();
                shader.SetInt("dynamic_texture", 1);
            }

            for (int i = 0; i < textureOutput.MipCount; i++)
            {
                int mipWidth  = (int)(width * Math.Pow(0.5, i));
                int mipHeight = (int)(height * Math.Pow(0.5, i));
                frameBuffer.Resize(mipWidth, mipHeight);

                GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0,
                                      textureOutput.ID, i);

                shader.SetInt("arrayLevel", arrayLevel);
                shader.SetInt("mipLevel", mipLevel);

                GL.ClearColor(0, 0, 0, 0);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                GL.Viewport(0, 0, mipWidth, mipHeight);

                //Draw the texture onto the framebuffer
                ScreenQuadRender.Draw();

                break;
            }

            //Disable shader and textures
            GL.UseProgram(0);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            if (cubemapCache.ContainsKey(texture.ID.ToString()))
            {
                cubemapCache[texture.ID.ToString()] = textureOutput;
            }
            else
            {
                cubemapCache.Add(texture.ID.ToString(), textureOutput);
            }
            return(textureOutput);
        }
 public virtual void Attach(FramebufferAttachment attachment, Framebuffer target)
 {
     target.Bind();
     GL.FramebufferTexture(target.Target, attachment, ID, 0);
 }