public virtual void Dispose() { if (font != null) { font.Dispose(); } if (colorFBO != null) { colorFBO.Dispose(); } if (depthFBO != null) { depthFBO.Dispose(); } if (skybox != null) { skybox.Dispose(); } skybox = null; colorFBO = null; depthFBO = null; font = null; world = null; Node.ObjectCount = 0; GLSLShader.UnBindShader(); GLSLShader.SetShader("default.shader", ""); }
/// <summary> /// renderoi worldin valosta päin (pelkän depthin) /// </summary> public static void SetupShadows(Renderable world, int lightNo, bool withParticles) { if (UseShadowMapping == false) { return; } if (Light.Lights.Count == 0) { Log.WriteLine("SetupShadows requires at least one light source!", false); return; } GL.Disable(EnableCap.Blend); GL.ColorMask(false, false, false, false); GL.Disable(EnableCap.CullFace); GL.PolygonOffset(1, 1); GL.Enable(EnableCap.PolygonOffsetFill); fbo.BindDepth(); fbo.BindFBO(); fbo.Clear(); // kuvakulma valosta päin GLExt.LoadMatrix(ref Light.Lights[lightNo].OrigOrientationMatrix); GLExt.Translate(-Light.Lights[lightNo].Position.X, -Light.Lights[lightNo].Position.Y, -Light.Lights[lightNo].Position.Z); SetTextureMatrix(); Frustum.CalculateFrustum(); VBO.FastRenderPass = true; depthShader.UseProgram(); world.Render(); if (withParticles) { depthShaderAlphaTest.UseProgram(); Particles.Render(); GLSLShader.UnBindShader(); } VBO.FastRenderPass = false; fbo.UnBindFBO(); GL.Disable(EnableCap.PolygonOffsetFill); GL.Enable(EnableCap.CullFace); GL.ColorMask(true, true, true, true); GLExt.LoadIdentity(); GameClass.NumOfObjects = 0; ShadowMapping.UnBindLightMask(); }
/// <summary> /// renderoi vbo /// </summary> public void Render() { GL.ActiveTexture(TextureUnit.Texture0); if (VBO.FastRenderPass == false) { if (Shader != null) { Shader.UseProgram(); } } if (Settings.UseGL3 == true) { GL.BindVertexArray(vaoID); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID); if (GLSLShader.CurrentShader != null) { GLSLShader.CurrentShader.SetUniforms(); GLSLShader.CurrentShader.SetAttributes(); } GL.DrawElements(BeginMode.Triangles, numOfIndices, DrawElementsType.UnsignedShort, IntPtr.Zero); GL.BindVertexArray(0); return; } else { // gl2 GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID); if (GLSLShader.CurrentShader != null) { GLSLShader.CurrentShader.SetUniforms(); GLSLShader.CurrentShader.SetAttributes(); } else { GLSLShader.UnBindShader(); } GL.DrawElements(BeginMode.Triangles, numOfIndices, DrawElementsType.UnsignedShort, IntPtr.Zero); } }
// debug public void RenderSkeleton() { if (Settings.UseGL3 == false) { GLSLShader.UnBindShader(); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.DepthTest); GLExt.PushMatrix(); { GL.Translate(Position.X, Position.Y, Position.Z); GL.Rotate(Rotation.X, 1, 0, 0); GL.Rotate(Rotation.Y, 0, 1, 0); GL.Rotate(Rotation.Z, 0, 0, 1); GL.Rotate(-90, 1, 0, 0); GL.Scale(Scale.X, Scale.Y, Scale.Z); GL.PointSize(5); GLExt.Color4(1, 0, 0, 1); GL.Begin(BeginMode.Points); for (int q = 0; q < numJoints; q++) { GL.Vertex3(skeleton[q].pos); } GL.End(); GL.PointSize(1); GLExt.Color4(0, 1, 0, 1); GL.Begin(BeginMode.Lines); for (int q = 0; q < numJoints; q++) { if (skeleton[q].parent != -1) { GL.Vertex3(skeleton[skeleton[q].parent].pos); GL.Vertex3(skeleton[q].pos); } } GL.End(); } GLExt.PopMatrix(); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Texture2D); GLExt.Color4(1, 1, 1, 1); } }
/// <summary> /// putsaa listat ja poista gl-datat /// </summary> public void ClearArrays() { Texture.DisposeAll(); GLSLShader.DisposeAll(); Material.DisposeAll(); Particles.DisposeAll(); Light.Lights.Clear(); Path.Paths.Clear(); world = null; world = new Renderable("World"); Node.ObjectCount = 0; for (int q = 0; q < Texture.MaxTextures; q++) { Texture.UnBind(q); } GLSLShader.UnBindShader(); GLSLShader.SetShader("default.shader", ""); GC.Collect(); GC.WaitForPendingFinalizers(); }