private void UIRenderersDraw(RenderEventArg arg)
 {
     UIRoot uiRoot = this.uiRoot;
     if (uiRoot != null)
     {
         uiRoot.Render(arg);
     }
 }
Example #2
0
 protected override void DoRender(RenderEventArg arg)
 {
     mat4 projection = arg.Camera.GetProjectionMat4();
     mat4 view = arg.Camera.GetViewMat4();
     mat4 model = mat4.identity();
     model = glm.translate(model, this.Position);
     model = glm.scale(model, new vec3(this.Scale, this.Scale, this.Scale));
     model = glm.rotate(model, this.radian, new vec3(0, 1, 0));
     this.SetUniform("projectionMatrix", projection);
     this.SetUniform("viewMatrix", view);
     this.SetUniform("modelMatrix", model);
     base.DoRender(arg);
 }
        private void glCanvas1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            Color clearColor = this.scene.ClearColor;
            OpenGL.ClearColor(clearColor.R / 255.0f, clearColor.G / 255.0f, clearColor.B / 255.0f, clearColor.A / 255.0f);
            OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            var arg = new RenderEventArg(RenderModes.Render, this.glCanvas1.ClientRectangle, this.scene.Camera);
            foreach (var sceneObject in this.scene.ObjectList)
            {
                foreach (var obj in sceneObject)
                {
                    obj.Render(arg);
                }
            }
        }
Example #4
0
        protected override void DoRender(RenderEventArg arg)
        {
            mat4 projection = arg.Camera.GetProjectionMat4();
            mat4 view       = arg.Camera.GetViewMat4();
            mat4 model      = glm.translate(mat4.identity(), this.BoundingBox.GetCenter());

            this.SetUniform("MVP", projection * view * model);
            if (pointColorRecord.IsMarked())
            {
                this.SetUniform("color", this.PointColor.ToVec4());
                pointColorRecord.CancelMark();
            }

            base.DoRender(arg);
        }
        private void glCanvas1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            RenderEventArg arg = new RenderEventArg(RenderModes.Render, this.glCanvas1.ClientRectangle, this.camera);
            IRenderable renderer = this.renderer;
            if (renderer != null)
            {
                renderer.Render(arg);
            }

            // Cross cursor shows where the mouse is.
            //GL.DrawText(this.lastmousePositionX - offset.X,
            //    this.glCanvas1.Height - (this.lastmousePositionY + offset.Y) - 1,
            //    Color.Red, "Courier New", crossCursorSize, "o");
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        public override void Render(RenderEventArg arg)
        {
            Renderer renderer = this.Renderer;

            if (renderer != null)
            {
                mat4 projection, view, model;
                if (this.TryGetMatrix(arg, out projection, out view, out model))
                {
                    renderer.SetUniform(strprojection, projection);
                    renderer.SetUniform(strview, view);
                    renderer.SetUniform(strmodel, model);
                    renderer.Render(arg);
                }
            }
        }
Example #7
0
        private void glCanvas1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);
            var list = this.terrainRendererList.ToArray();
            var arg  = new RenderEventArg(RenderModes.Render, this.glCanvas1.ClientRectangle, this.camera);

            foreach (var item in list)
            {
                item.Render(arg);
            }
            IBoundingBox boundingBox = this.boundingBox;

            if (boundingBox != null)
            {
                boundingBox.Render(Color.White, arg);
            }
        }
        protected override void DoRender(RenderEventArg arg)
        {
            // setup uniforms
            var now = DateTime.Now;
            float time = (float)now.Subtract(this.lastTime).TotalMilliseconds * 0.001f;
            this.SetUniform("time", time * timeElapsingSpeed);
            this.SetUniform("rainDrop", this.rainDrop);
            this.SetUniform("granularity", this.granularity);

            mat4 projection = arg.Camera.GetProjectionMat4();
            mat4 view = arg.Camera.GetViewMat4();
            mat4 model = mat4.identity();
            this.SetUniform("projectionMatrix", projection);
            this.SetUniform("viewMatrix", view);
            this.SetUniform("modelMatrix", model);

            base.DoRender(arg);
        }
        protected override void DoRender(RenderEventArg arg)
        {
            int[] viewport = OpenGL.GetViewport();
            if (this.width != viewport[2] || this.height != viewport[3])
            {
                Resize(viewport[2], viewport[3]);
            }

            // render to texture
            OpenGL.GetDelegateFor<OpenGL.glBindFramebufferEXT>()(OpenGL.GL_FRAMEBUFFER, frameBuffer[0]);
            OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            this.backfaceRenderer.Render(arg);
            OpenGL.GetDelegateFor<OpenGL.glBindFramebufferEXT>()(OpenGL.GL_FRAMEBUFFER, 0);

            this.raycastRenderer.Render(arg);
            // need or need not to resume the state of only one active texture unit?
            // glActiveTexture(GL_TEXTURE1);
            // glBindTexture(GL_TEXTURE_2D, 0);
            // glDisable(GL_TEXTURE_2D);
            // glActiveTexture(GL_TEXTURE2);
            // glBindTexture(GL_TEXTURE_3D, 0);
            // glDisable(GL_TEXTURE_3D);
            // glActiveTexture(GL_TEXTURE0);
            // glBindTexture(GL_TEXTURE_1D, 0);
            // glDisable(GL_TEXTURE_1D);
            // glActiveTexture(GL_TEXTURE0);

            // // for test the first pass
            // glBindFramebuffer(GL_READ_FRAMEBUFFER, g_frameBuffer);
            // checkFramebufferStatus();
            // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
            // glViewport(0, 0, g_winWidth, g_winHeight);
            // glClearColor(0.0, 0.0, 1.0, 1.0);
            // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            // GL_ERROR();
            // glBlitFramebuffer(0, 0, g_winWidth, g_winHeight,0, 0,
            // 		      g_winWidth, g_winHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
            // glBindFramebuffer(GL_FRAMEBUFFER, 0);
            // GL_ERROR();
            //this.depthTest.Off();
        }
 protected override void DoRender(RenderEventArg arg)
 {
     this.Highlighter.Render(arg);
     this.PickableRenderer.Render(arg);
 }
Example #11
0
        private void SceneRenderersDraw(RenderEventArg arg)
        {
            HighlightedPickableRenderer renderer = this.rendererDict[this.SelectedModel];
            if (renderer != null)
            {
                //if (cameraUpdated)
                {
                    UpdateMVP(renderer);
                    //cameraUpdated = false;
                }

                renderer.Render(arg);
            }
        }
Example #12
0
        private void RenderersDraw(RenderModes renderMode, bool renderScene = true, bool renderUI = true)
        {
            var arg = new RenderEventArg(renderMode, this.glCanvas1.ClientRectangle, this.camera, this.PickingGeometryType);
            if (renderMode == RenderModes.ColorCodedPicking)
            {
                if (renderScene)
                {
                    ColorCodedPicking.Render4Picking(arg, this.rendererDict[this.selectedModel].PickableRenderer);
                }
            }
            else if (renderMode == RenderModes.Render)
            {
                OpenGL.ClearColor(ClearColor.R / 255.0f, ClearColor.G / 255.0f, ClearColor.B / 255.0f, ClearColor.A / 255.0f);

                OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

                if (renderScene) { SceneRenderersDraw(arg); }
                if (renderUI) { UIRenderersDraw(arg); }
            }
        }
        protected override void DoRender(RenderEventArg arg)
        {
            // Activate the compute program and bind the output texture image
            computeProgram.Bind();
            OpenGL.GetDelegateFor<OpenGL.glBindImageTexture>()(
                (uint)computeProgram.GetUniformLocation("input_image"), input_image[0], 0, false, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_RGBA32F);
            OpenGL.GetDelegateFor<OpenGL.glBindImageTexture>()(
                (uint)computeProgram.GetUniformLocation("output_image"), intermediate_image[0], 0, false, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_RGBA32F);
            // Dispatch
            OpenGL.GetDelegateFor<OpenGL.glDispatchCompute>()(1, 512, 1);

            OpenGL.GetDelegateFor<OpenGL.glMemoryBarrier>()(OpenGL.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

            OpenGL.GetDelegateFor<OpenGL.glBindImageTexture>()(
                (uint)computeProgram.GetUniformLocation("input_image"), intermediate_image[0], 0, false, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_RGBA32F);
            OpenGL.GetDelegateFor<OpenGL.glBindImageTexture>()(
                (uint)computeProgram.GetUniformLocation("output_image"), output_image[0], 0, false, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_RGBA32F);
            // Dispatch
            OpenGL.GetDelegateFor<OpenGL.glDispatchCompute>()(1, 512, 1);
            OpenGL.GetDelegateFor<OpenGL.glMemoryBarrier>()(OpenGL.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

            //// Now bind the texture for rendering _from_
            //GL.GetDelegateFor<GL.glActiveTexture>()(GL.GL_TEXTURE0);
            //GL.BindTexture(GL.GL_TEXTURE_2D, output_image[0]);

            mat4 view = arg.Camera.GetViewMat4();
            mat4 projection = arg.Camera.GetProjectionMat4();
            this.renderer.SetUniform("mvp", projection * view);
            this.renderer.Render(arg);
        }
        protected override void DoRender(RenderEventArg arg)
        {
            this.depthTestSwitch.On();
            this.cullFaceSwitch.On();

            // Reset atomic counter
            OpenGL.GetDelegateFor<OpenGL.glBindBufferBase>()(OpenGL.GL_ATOMIC_COUNTER_BUFFER, 0, atomic_counter_buffer[0]);
            IntPtr data = OpenGL.MapBuffer(BufferTarget.AtomicCounterBuffer, MapBufferAccess.WriteOnly);
            unsafe
            {
                var array = (uint*)data.ToPointer();
                array[0] = 0;
            }
            OpenGL.UnmapBuffer(BufferTarget.AtomicCounterBuffer);
            OpenGL.GetDelegateFor<OpenGL.glBindBufferBase>()(OpenGL.GL_ATOMIC_COUNTER_BUFFER, 0, 0);

            // Clear head-pointer image
            OpenGL.BindBuffer(BufferTarget.PixelUnpackBuffer, head_pointer_clear_buffer[0]);
            OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, head_pointer_texture[0]);
            OpenGL.TexSubImage2D(TexSubImage2DTarget.Texture2D, 0, 0, 0, arg.CanvasRect.Width, arg.CanvasRect.Height, TexSubImage2DFormats.RedInteger, TexSubImage2DType.UnsignedByte, IntPtr.Zero);
            OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
            OpenGL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0);
            //

            // Bind head-pointer image for read-write
            OpenGL.GetDelegateFor<OpenGL.glBindImageTexture>()(0, head_pointer_texture[0], 0, false, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_R32UI);

            // Bind linked-list buffer for write
            OpenGL.GetDelegateFor<OpenGL.glBindImageTexture>()(1, linked_list_texture[0], 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA32UI);

            mat4 model = mat4.identity();
            mat4 view = arg.Camera.GetViewMat4();
            mat4 projection = arg.Camera.GetProjectionMat4();
            this.buildListsRenderer.SetUniform("model_matrix", model);
            this.buildListsRenderer.SetUniform("view_matrix", view);
            this.buildListsRenderer.SetUniform("projection_matrix", projection);
            this.resolve_lists.SetUniform("model_matrix", model);
            this.resolve_lists.SetUniform("view_matrix", view);
            this.resolve_lists.SetUniform("projection_matrix", projection);

            // first pass
            this.buildListsRenderer.Render(arg);
            // second pass
            this.resolve_lists.Render(arg);

            OpenGL.GetDelegateFor<OpenGL.glBindImageTexture>()(1, 0, 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA32UI);
            OpenGL.GetDelegateFor<OpenGL.glBindImageTexture>()(0, 0, 0, false, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_R32UI);

            this.cullFaceSwitch.Off();
            this.depthTestSwitch.Off();
        }