// Constructor internal D3DDevice(RenderTargetControl rendertarget) { // Set render target this.rendertarget = rendertarget; // Create resources list resources = new Dictionary <ID3DResource, ID3DResource>(); // We have no destructor GC.SuppressFinalize(this); }
// Disposer public void Dispose() { // Not already disposed? if (!isdisposed) { // Clean up foreach (ID3DResource res in resources) { res.UnloadResource(); } if (shaders != null) { shaders.Dispose(); } rendertarget = null; if (backbuffer != null) { backbuffer.Dispose(); } if (depthbuffer != null) { depthbuffer.Dispose(); } if (device != null) { device.Dispose(); } if (ObjectTable.Objects.Count > 1) //mxd. Direct3D itself is not disposed while the editor is running { //mxd. Get rid of any remaining D3D objects... foreach (ComObject o in ObjectTable.Objects) { if (o is Direct3D) { continue; // Don't dispose the device itself... } General.WriteLogLine("WARNING: D3D resource " + o + (o.Tag != null ? " (" + o.Tag + ")" : string.Empty) + " was not disposed properly!" + (o.CreationSource != null ? " Stack trace: " + o.CreationSource : string.Empty)); o.Dispose(); } #if DEBUG General.ShowWarningMessage("Some D3D resources were not disposed properly! See the event log for more details.", MessageBoxButtons.OK); #endif } // Done isrendering = false; //mxd isdisposed = true; } }
// Disposer internal void Dispose() { // Not already disposed? if (!isdisposed) { // Clean up foreach (ID3DResource res in resources.Values) { res.UnloadResource(); } if (shaders != null) { shaders.Dispose(); } rendertarget = null; if (backbuffer != null) { backbuffer.Dispose(); } if (depthbuffer != null) { depthbuffer.Dispose(); } if (device != null) { device.Dispose(); } if (font != null) { font.Dispose(); } if (fonttexture != null) { fonttexture.Dispose(); } // Done isdisposed = true; } }
public RenderDevice(RenderTargetControl rendertarget) { RenderTarget = rendertarget; CreateDevice(); DeclareUniform(UniformName.rendersettings, "rendersettings", UniformType.Vec4f); DeclareUniform(UniformName.projection, "projection", UniformType.Mat4); DeclareUniform(UniformName.desaturation, "desaturation", UniformType.Float); DeclareUniform(UniformName.highlightcolor, "highlightcolor", UniformType.Vec4f); DeclareUniform(UniformName.view, "view", UniformType.Mat4); DeclareUniform(UniformName.world, "world", UniformType.Mat4); DeclareUniform(UniformName.modelnormal, "modelnormal", UniformType.Mat4); DeclareUniform(UniformName.FillColor, "fillColor", UniformType.Vec4f); DeclareUniform(UniformName.vertexColor, "vertexColor", UniformType.Vec4f); DeclareUniform(UniformName.stencilColor, "stencilColor", UniformType.Vec4f); DeclareUniform(UniformName.lightPosAndRadius, "lightPosAndRadius", UniformType.Vec4fArray); DeclareUniform(UniformName.lightOrientation, "lightOrientation", UniformType.Vec4fArray); DeclareUniform(UniformName.light2Radius, "light2Radius", UniformType.Vec2fArray); DeclareUniform(UniformName.lightColor, "lightColor", UniformType.Vec4fArray); DeclareUniform(UniformName.ignoreNormals, "ignoreNormals", UniformType.Float); DeclareUniform(UniformName.spotLight, "spotLight", UniformType.Float); DeclareUniform(UniformName.campos, "campos", UniformType.Vec4f); DeclareUniform(UniformName.texturefactor, "texturefactor", UniformType.Vec4f); DeclareUniform(UniformName.fogsettings, "fogsettings", UniformType.Vec4f); DeclareUniform(UniformName.fogcolor, "fogcolor", UniformType.Vec4f); DeclareUniform(UniformName.sectorfogcolor, "sectorfogcolor", UniformType.Vec4f); DeclareUniform(UniformName.lightsEnabled, "lightsEnabled", UniformType.Float); // 2d fsaa CompileShader(ShaderName.display2d_fsaa, "display2d.shader", "display2d_fsaa"); // 2d normal CompileShader(ShaderName.display2d_normal, "display2d.shader", "display2d_normal"); CompileShader(ShaderName.display2d_fullbright, "display2d.shader", "display2d_fullbright"); // 2d things CompileShader(ShaderName.things2d_thing, "things2d.shader", "things2d_thing"); CompileShader(ShaderName.things2d_sprite, "things2d.shader", "things2d_sprite"); CompileShader(ShaderName.things2d_fill, "things2d.shader", "things2d_fill"); // non-fog 3d shaders CompileShader(ShaderName.world3d_main, "world3d.shader", "world3d_main"); CompileShader(ShaderName.world3d_fullbright, "world3d.shader", "world3d_fullbright"); CompileShader(ShaderName.world3d_main_highlight, "world3d.shader", "world3d_main_highlight"); CompileShader(ShaderName.world3d_fullbright_highlight, "world3d.shader", "world3d_fullbright_highlight"); CompileShader(ShaderName.world3d_vertex_color, "world3d.shader", "world3d_vertex_color"); CompileShader(ShaderName.world3d_main_vertexcolor, "world3d.shader", "world3d_main_vertexcolor"); CompileShader(ShaderName.world3d_constant_color, "world3d.shader", "world3d_constant_color"); // skybox shader CompileShader(ShaderName.world3d_skybox, "world3d_skybox.shader", "world3d_skybox"); // fog 3d shaders CompileShader(ShaderName.world3d_main_fog, "world3d.shader", "world3d_main_fog"); CompileShader(ShaderName.world3d_main_highlight_vertexcolor, "world3d.shader", "world3d_highlight_vertexcolor"); CompileShader(ShaderName.world3d_main_highlight_fog, "world3d.shader", "world3d_main_highlight_fog"); CompileShader(ShaderName.world3d_main_fog_vertexcolor, "world3d.shader", "world3d_main_fog_vertexcolor"); CompileShader(ShaderName.world3d_main_highlight_fog_vertexcolor, "world3d.shader", "world3d_main_highlight_fog_vertexcolor"); SetupSettings(); }