/// <inheritdoc />
		public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
		{
			ThrowIfDisposed();

			GL.Disable(EnableCap.CullFace);
			GL.Disable(EnableCap.DepthTest);

			// Send the vertices to the shader
			this.VertexBuffer.Bind();
			this.VertexBuffer.EnableAttributes();

			this.VertexIndexesBuffer.Bind();

			Matrix4 modelViewProjection = this.ActorTransform.GetModelMatrix() * viewMatrix * projectionMatrix;

			this.BoxShader.Enable();
			this.BoxShader.SetMVPMatrix(modelViewProjection);
			this.BoxShader.SetLineColour(this.LineColour);

			// Now draw the box
			GL.DrawElements
			(
				PrimitiveType.LineLoop,
				24,
				DrawElementsType.UnsignedByte,
				new IntPtr(0)
			);

			this.VertexBuffer.DisableAttributes();
		}
Example #2
0
        /// <inheritdoc />
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
        {
            ThrowIfDisposed();

            if (!this.IsInitialized)
            {
                return;
            }

            this.Shader.Enable();
            this.Shader.Wireframe.Enabled = this.ShouldRenderWireframe;
            if (this.Shader.Wireframe.Enabled)
            {
                this.Shader.Wireframe.SetWireframeLineWidth(2);
                this.Shader.Wireframe.SetWireframeFadeWidth(2);
                this.Shader.Wireframe.SetViewportMatrix(camera.GetViewportMatrix());
            }

            Matrix4 modelView           = this.ActorTransform.GetModelMatrix() * viewMatrix;
            Matrix4 modelViewProjection = modelView * projectionMatrix;

            // TODO: Fix frustum culling
            foreach (ModelGroup modelGroup in this.Model.Groups)
            {
                RenderGroup(modelGroup, modelViewProjection);
            }

            // Render bounding boxes
            if (this.ShouldRenderBounds)
            {
                // TODO: Ordering
                foreach (ModelGroup modelGroup in this.Model.Groups)
                {
                    this.BoundingBoxLookup[modelGroup].Render(viewMatrix, projectionMatrix, camera);
                }
            }

            if (this.ShouldRenderDoodads)
            {
                foreach (var doodadInstanceSet in this.DoodadSets[this.DoodadSet])
                {
                    //doodadInstanceSet.ShouldRenderBounds = this.ShouldRenderBounds;
                }

                foreach (var doodadInstanceSet in this.DoodadSets[this.DoodadSet])
                {
                    doodadInstanceSet.Render(viewMatrix, projectionMatrix, camera);
                }
            }

            // TODO: Summarize the render batches from each group that has the same material ID

            // TODO: Render each block of batches with the same material ID

            // TODO: Shade light effects and vertex colours

            // TODO: Render each doodad in the currently selected doodad set

            // TODO: Play sound emitters here?
        }
Example #3
0
        /// <inheritdoc />
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
        {
            ThrowIfDisposed();

            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);

            this.Vertices.Bind();
            this.Vertices.EnableAttributes();
            this.VertexIndexes.Bind();

            Matrix4 modelViewProjection = this.ActorTransform.GetModelMatrix() * viewMatrix * projectionMatrix;

            // Set the default line colour (a light gray)
            this.Shader.SetLineColour(new Color4(64, 64, 64, 255));
            this.Shader.SetMVPMatrix(modelViewProjection);

            int lineCount = ((Quads * 2) + 2) * 2;

            GL.DrawElements
            (
                PrimitiveType.Lines,
                lineCount,
                DrawElementsType.UnsignedShort,
                IntPtr.Zero
            );

            this.Vertices.DisableAttributes();
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Everlook.Viewport.ViewportRenderer"/> class.
        /// </summary>
        /// <param name="viewportWidget">The widget which the viewport should be rendered to.</param>
        public ViewportRenderer(ViewportArea viewportWidget)
        {
            this.ViewportWidget = viewportWidget;
            this.Camera         = new ViewportCamera();
            this.Movement       = new CameraMovement(this.Camera);

            this.IsInitialized = false;
        }
Example #5
0
        /// <summary>
        /// Renders the current object in the current OpenGL context.
        /// </summary>
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            GL.UseProgram(this.ImageShaderID);

            // Render the object
            // Send the vertices to the shader
            GL.EnableVertexAttribArray(0);
            GL.BindBuffer(BufferTarget.ArrayBuffer, this.VertexBufferID);
            GL.VertexAttribPointer(
                0,
                2,
                VertexAttribPointerType.Float,
                false,
                0,
                0);

            // Send the UV coordinates to the shader
            GL.EnableVertexAttribArray(1);
            GL.BindBuffer(BufferTarget.ArrayBuffer, this.UVBufferID);
            GL.VertexAttribPointer(
                1,
                2,
                VertexAttribPointerType.Float,
                false,
                0,
                0);

            // Set the texture ID as a uniform sampler in unit 0
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, this.GLTextureID);
            int textureVariableHandle = GL.GetUniformLocation(this.ImageShaderID, "imageTextureSampler");
            int textureUnit           = 0;

            GL.Uniform1(textureVariableHandle, 1, ref textureUnit);

            // Set the model view matrix
            Matrix4 modelViewProjection = this.ImageTransform.GetModelMatrix() * viewMatrix * projectionMatrix;

            // Send the model matrix to the shader
            int projectionShaderVariableHandle = GL.GetUniformLocation(this.ImageShaderID, "ModelViewProjection");

            GL.UniformMatrix4(projectionShaderVariableHandle, false, ref modelViewProjection);

            // Finally, draw the image
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, this.VertexIndexBufferID);
            GL.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, 0);

            // Release the attribute arrays
            GL.DisableVertexAttribArray(0);
            GL.DisableVertexAttribArray(1);
        }
Example #6
0
        /// <inheritdoc />
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
        {
            ThrowIfDisposed();

            if (!this.IsInitialized)
            {
                return;
            }

            this.Shader.Enable();

            // Render the object
            // Send the vertices to the shader
            GL.EnableVertexAttribArray(0);
            this.VertexBuffer.Bind();
            GL.VertexAttribPointer(
                0,
                2,
                VertexAttribPointerType.Float,
                false,
                0,
                0);

            // Send the UV coordinates to the shader
            GL.EnableVertexAttribArray(1);
            this.UVBuffer.Bind();
            GL.VertexAttribPointer(
                1,
                2,
                VertexAttribPointerType.Float,
                false,
                0,
                0);

            // Set the channel mask
            this.Shader.SetChannelMask(this.ChannelMask);

            // Set the texture ID as a uniform sampler in unit 0
            this.Shader.SetTexture(this.Texture);

            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            // Set the model view matrix
            Matrix4 modelViewProjection = this.ActorTransform.GetModelMatrix() * viewMatrix * projectionMatrix;

            // Send the model matrix to the shader
            this.Shader.SetMVPMatrix(modelViewProjection);

            // Finally, draw the image
            this.VertexIndexBuffer.Bind();
            GL.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, 0);

            // Release the attribute arrays
            GL.DisableVertexAttribArray(0);
            GL.DisableVertexAttribArray(1);
        }
Example #7
0
        /// <inheritdoc />
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            this.Shader.Wireframe.Enabled = this.ShouldRenderWireframe;
            if (this.Shader.Wireframe.Enabled)
            {
                this.Shader.Wireframe.SetViewportMatrix(camera.GetViewportMatrix());
            }

            Matrix4 modelView           = this.ActorTransform.GetModelMatrix() * viewMatrix;
            Matrix4 modelViewProjection = modelView * projectionMatrix;

            // TODO: Fix frustum culling
            foreach (ModelGroup modelGroup in this.Model.Groups
                     .OrderByDescending(modelGroup => VectorMath.Distance(camera.Position, modelGroup.GetPosition().AsOpenTKVector())))
            {
                RenderGroup(modelGroup, modelViewProjection);

                if (this.ShouldRenderBounds)
                {
                    // Now, draw the model's bounding box

                    // Transform the bounding box into world space
                    BoundingBox groupBoundingBox = modelGroup.GetBoundingBox().ToOpenGLBoundingBox().Transform(ref modelView);
                    if (camera.CanSee(groupBoundingBox))
                    {
                        // continue;
                        RenderBoundingBox(modelGroup, modelViewProjection, Color4.LimeGreen);
                    }
                    else
                    {
                        RenderBoundingBox(modelGroup, modelViewProjection, Color4.Red);
                    }
                }
            }

            // TODO: Summarize the render batches from each group that has the same material ID

            // TODO: Render each block of batches with the same material ID

            // TODO: Shade light effects and vertex colours

            // TODO: Render each doodad in the currently selected doodad set

            // TODO: Play sound emitters here?
        }
Example #8
0
        /// <inheritdoc />
        public void RenderInstances(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera, int count)
        {
            ThrowIfDisposed();

            if (_vertexBuffer is null || _vertexIndexesBuffer is null)
            {
                return;
            }

            GL.Disable(EnableCap.CullFace);
            GL.Disable(EnableCap.DepthTest);

            // Send the vertices to the shader
            _vertexBuffer.Bind();
            _vertexBuffer.EnableAttributes();

            _vertexIndexesBuffer.Bind();

            var modelViewProjection = this.ActorTransform.GetModelMatrix() * viewMatrix * projectionMatrix;

            _boxShader.Enable();
            _boxShader.SetIsInstance(true);
            _boxShader.SetMVPMatrix(modelViewProjection);
            _boxShader.SetLineColour(this.LineColour);
            _boxShader.SetViewMatrix(viewMatrix);
            _boxShader.SetProjectionMatrix(projectionMatrix);

            // Now draw the box
            GL.DrawElementsInstanced
            (
                PrimitiveType.LineLoop,
                24,
                DrawElementsType.UnsignedByte,
                new IntPtr(0),
                count
            );

            _vertexBuffer.DisableAttributes();
        }
Example #9
0
        /// <inheritdoc />
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            Matrix4 modelViewProjection = this.ActorTransform.GetModelMatrix() * viewMatrix * projectionMatrix;

            this.Shader.Enable();

            GL.BindBuffer(BufferTarget.ArrayBuffer, this.VertexBufferID);
            GL.EnableVertexAttribArray(0);

            // Position pointer
            GL.VertexAttribPointer
            (
                0,
                3,
                VertexAttribPointerType.Float,
                false,
                0,
                0
            );

            // Bone weight pointer
            GL.VertexAttribPointer
            (
                1,
                4,
                VertexAttribPointerType.Byte,
                false,
                12,
                12
            );

            // Bone index pointer
            GL.VertexAttribPointer
            (
                2,
                4,
                VertexAttribPointerType.Byte,
                false,
                16,
                16
            );

            // Normal pointer
            GL.VertexAttribPointer
            (
                3,
                3,
                VertexAttribPointerType.Float,
                false,
                20,
                20
            );

            // UV1 pointer
            GL.VertexAttribPointer
            (
                4,
                2,
                VertexAttribPointerType.Float,
                false,
                32,
                32
            );

            // UV2 pointer
            GL.VertexAttribPointer
            (
                5,
                2,
                VertexAttribPointerType.Float,
                false,
                40,
                40
            );
        }
Example #10
0
 /// <summary>
 /// Renders the current object in the current OpenGL context.
 /// </summary>
 public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
 {
     throw new NotImplementedException();
 }
Example #11
0
 public ChangeLightingModeCommand(ViewportCamera viewportCamera)
 {
     _viewportCamera = viewportCamera;
 }
Example #12
0
 /// <inheritdoc />
 public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
 {
     _target.ActorTransform = this.ActorTransform;
     _target.Render(viewMatrix, projectionMatrix, camera);
     _target.ActorTransform = _defaultTransform;
 }
Example #13
0
 public ChangeViewCommand(ViewportCamera viewportCamera)
 {
     _viewportCamera = viewportCamera;
 }
Example #14
0
        /// <summary>
        /// Renders the current object in the current OpenGL context.
        /// </summary>
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            Matrix4 modelViewProjection = this.ActorTransform.GetModelMatrix() * viewMatrix * projectionMatrix;

            GL.UseProgram(this.SimpleShaderID);

            GL.BindBuffer(BufferTarget.ArrayBuffer, this.VertexBufferID);
            GL.EnableVertexAttribArray(0);

            // Position pointer
            GL.VertexAttribPointer(
                0,
                3,
                VertexAttribPointerType.Float,
                false,
                0,
                0);

            // Bone weight pointer
            GL.VertexAttribPointer(
                1,
                4,
                VertexAttribPointerType.Byte,
                false,
                12,
                12);

            // Bone index pointer
            GL.VertexAttribPointer(
                2,
                4,
                VertexAttribPointerType.Byte,
                false,
                16,
                16);

            // Normal pointer
            GL.VertexAttribPointer(
                3,
                3,
                VertexAttribPointerType.Float,
                false,
                20,
                20);

            // UV1 pointer
            GL.VertexAttribPointer(
                4,
                2,
                VertexAttribPointerType.Float,
                false,
                32,
                32);

            // UV2 pointer
            GL.VertexAttribPointer(
                5,
                2,
                VertexAttribPointerType.Float,
                false,
                40,
                40);

            // Simple: Render all skins
            MDXSkin firstSkin = this.Model.Skins.First();

            foreach (MDXSkinSection skinSection in firstSkin.Submeshes)
            {
            }
        }
Example #15
0
        /// <inheritdoc />
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
        {
            ThrowIfDisposed();

            if (!this.IsInitialized)
            {
                return;
            }

            this.VertexBuffer.Bind();
            this.VertexBuffer.EnableAttributes();

            GL.Enable(EnableCap.DepthTest);

            Matrix4 modelViewMatrix     = this.ActorTransform.GetModelMatrix() * viewMatrix;
            Matrix4 modelViewProjection = modelViewMatrix * projectionMatrix;

            this.Shader.Enable();
            this.Shader.SetIsInstance(false);
            this.Shader.SetModelMatrix(this.ActorTransform.GetModelMatrix());
            this.Shader.SetViewMatrix(viewMatrix);
            this.Shader.SetProjectionMatrix(projectionMatrix);
            this.Shader.SetMVPMatrix(modelViewProjection);

            this.Shader.Wireframe.Enabled = this.ShouldRenderWireframe;
            if (this.ShouldRenderWireframe)
            {
                this.Shader.Wireframe.SetWireframeColour(EverlookConfiguration.Instance.WireframeColour);
                this.Shader.Wireframe.SetViewportMatrix(camera.GetViewportMatrix());

                // Override blend setting
                GL.Enable(EnableCap.Blend);
            }

            foreach (var skin in this.Model.Skins)
            {
                this.SkinIndexArrayBuffers[skin].Bind();
                if (this.ShouldRenderWireframe)
                {
                    // Override blend setting
                    GL.Enable(EnableCap.Blend);
                }

                foreach (var renderBatch in skin.RenderBatches)
                {
                    if (renderBatch.ShaderID == 0xFFFFu)
                    {
                        continue;
                    }

                    PrepareBatchForRender(renderBatch);

                    var skinSection = skin.Sections[renderBatch.SkinSectionIndex];
                    GL.DrawElements
                    (
                        PrimitiveType.Triangles,
                        skinSection.TriangleCount,
                        DrawElementsType.UnsignedShort,
                        new IntPtr(skinSection.StartTriangleIndex * 2)
                    );
                }
            }

            // Render bounding boxes
            if (this.ShouldRenderBounds)
            {
                this.BoundingBox.Render(viewMatrix, projectionMatrix, camera);
            }

            // Release the attribute arrays
            this.VertexBuffer.DisableAttributes();
        }
Example #16
0
 public RestrictedCamera(ViewportCamera vpc)
 {
     ActivateManualy = false;
     this.vpc        = vpc;
 }