public static ITexture2D New(VideoTypes videoType, IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) { ITexture2D api = null; #if WIN32 if (videoType == VideoTypes.D3D9) api = new D3D9.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); #endif #if WIN32 || WINRT || WP8 if (videoType == VideoTypes.D3D11) api = new D3D11.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); #endif #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl if (videoType == VideoTypes.OpenGL) api = new OpenGL.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); #endif #if XNA if (videoType == VideoTypes.XNA) api = new XNA.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); #endif #if VITA if (videoType == VideoTypes.Vita) api = new Vita.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); #endif if (api == null) Debug.ThrowError("Texture2DAPI", "Unsuported InputType: " + videoType); return api; }
public Texture2D(IDisposableResource parent, string filename, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) : base(parent) { Image.New(filename, false, delegate (object sender, bool succeeded) { if (succeeded) { var image = (Image)sender; init(parent, image, image.Size.Width, image.Size.Height, generateMipmaps, MultiSampleTypes.None, image.SurfaceFormat, RenderTargetUsage.PlatformDefault, usage, false, loadedCallback); } else { FailedToLoad = true; Dispose(); if (loadedCallback != null) loadedCallback(this, false); } }); }
protected override bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { initSuccess = base.init(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback); if (!initSuccess) return false; try { if (usage == BufferUsages.Write) Debug.ThrowError("RenderTarget", "Only Textures may be writable"); if (image != null) { width = image.Size.Width; height = image.Size.Height; surfaceFormat = image.SurfaceFormat; } renderTargetCom = new RenderTargetCom(); var error = renderTargetCom.Init(video.com, width, height, com, 0, video.surfaceFormat(surfaceFormat), usage == BufferUsages.Read); switch (error) { case RenderTargetError.RenderTargetView: Debug.ThrowError("RenderTarget", "Failed to create RenderTargetView"); break; case RenderTargetError.StagingTexture: Debug.ThrowError("RenderTarget", "Failed to create Staging Texture"); break; } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) loadedCallback(this, false); return false; } Loaded = true; if (loadedCallback != null) loadedCallback(this, true); return true; }
protected override bool init(DisposableI parent, string fileName, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { if (!base.init(parent, fileName, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback)) { return(false); } try { if (usage == BufferUsages.Write) { Debug.ThrowError("RenderTarget", "Only Textures may be writable"); } frameBuffer = new G.FrameBuffer(); frameBuffer.SetColorTarget(texture, 0); } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } return(false); } Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } return(true); }
public RenderTarget(DisposableI parent, string fileName, MultiSampleTypes multiSampleType, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback) : base(parent, fileName, false, usage, loadedCallback) { }
protected virtual bool init(DisposableI parent, string fileName, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { try { if (usage == BufferUsages.Read && !isRenderTarget) { Debug.ThrowError("Texture2D", "Only RenderTargets may be readable"); } video = parent.FindParentOrSelfWithException <Video>(); if (isRenderTarget) { generateMipmaps = false; } if (fileName != null) { texture = new G.Texture2D("/Application/" + fileName, generateMipmaps); } else { texture = new G.Texture2D(width, height, generateMipmaps, Video.surfaceFormat(surfaceFormat), isRenderTarget ? G.PixelBufferOption.Renderable : G.PixelBufferOption.None); } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } return(false); } if (!isRenderTarget) { Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } } return(true); }
public RenderTarget(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) : base(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback) { if (initSuccess) initDepthStencil(width, height, depthStencilFormat); }
public Texture2D(IDisposableResource parent, string filename, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) : base(parent) { Image.New(filename, false, delegate(object sender, bool succeeded) { if (succeeded) { var image = (Image)sender; init(parent, image, image.Size.Width, image.Size.Height, generateMipmaps, MultiSampleTypes.None, image.SurfaceFormat, RenderTargetUsage.PlatformDefault, usage, false, false, loadedCallback); } else { FailedToLoad = true; Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } } }); }
protected virtual bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, bool lockable, Loader.LoadedCallbackMethod loadedCallback) { byte[][] mipmaps = null; int[] mipmapSizes = null, mipmapPitches = null; try { video = parent.FindParentOrSelfWithException <Video>(); if (isRenderTarget) { generateMipmaps = false; } // load image data if (image != null) { mipmaps = new byte[image.Mipmaps.Length][]; mipmapSizes = new int[image.Mipmaps.Length]; mipmapPitches = new int[image.Mipmaps.Length]; for (int i = 0; i != mipmaps.Length; ++i) { var imageMipmap = image.Mipmaps[i]; mipmaps[i] = image.Compressed ? imageMipmap.Data : imageMipmap.SwapRBColorChannels(); mipmapSizes[i] = imageMipmap.Data.Length; mipmapPitches[i] = imageMipmap.Pitch; } Size = image.Size; surfaceFormat = image.SurfaceFormat; PixelByteSize = image.CalculatePixelByteSize(); } else { if (width == 0 || height == 0) { Debug.ThrowError("Texture2D", "Width or Height cannot be 0"); } Size = new Size2(width, height); PixelByteSize = Image.CalculatePixelByteSize((surfaceFormat == SurfaceFormats.Defualt ? Video.DefaultSurfaceFormat() : surfaceFormat), width, height); } TexelOffset = (1 / Size.ToVector2()) * .5f; SizeF = Size.ToVector2(); // init texture REIGN_D3DUSAGE nativeUsage = isRenderTarget ? REIGN_D3DUSAGE.RENDERTARGET : REIGN_D3DUSAGE.NONE; REIGN_D3DPOOL nativePool = (mipmaps != null && !video.Caps.ExDevice) ? REIGN_D3DPOOL.MANAGED : REIGN_D3DPOOL.DEFAULT; if (usage == BufferUsages.Read) { if (!isRenderTarget) { Debug.ThrowError("Texture2D", "Only RenderTargets may be readable"); } // NOTE: Staging texture and states will be created in the RenderTarget } if (usage == BufferUsages.Write) { if (mipmaps != null) { if (video.Caps.ExDevice) { nativeUsage |= REIGN_D3DUSAGE.DYNAMIC; } } else { nativeUsage |= REIGN_D3DUSAGE.DYNAMIC; } } com = new Texture2DCom(); var error = com.Init(video.com, Size.Width, Size.Height, generateMipmaps, mipmaps, mipmapSizes, mipmapPitches, 0, nativePool, nativeUsage, video.surfaceFormat(surfaceFormat), isRenderTarget); switch (error) { case TextureError.Texture: Debug.ThrowError("Texture2D", "Failed to create Texture2D"); break; case TextureError.SystemTexture: Debug.ThrowError("Texture2D", "Failed to create System Texture2D"); break; } if (!video.Caps.ExDevice && nativePool != REIGN_D3DPOOL.MANAGED) { LostDevice_image = image; LostDevice_width = width; LostDevice_height = height; LostDevice_generateMipmaps = generateMipmaps; LostDevice_multiSampleType = multiSampleType; LostDevice_surfaceFormat = surfaceFormat; LostDevice_renderTargetUsage = renderTargetUsage; LostDevice_usage = usage; LostDevice_isRenderTarget = isRenderTarget; LostDevice_lockable = lockable; LostDevice_pool = nativePool; } if (nativePool == REIGN_D3DPOOL.DEFAULT && !video.Caps.ExDevice && !video.deviceReseting) { video.DeviceLost += deviceLost; video.DeviceReset += deviceReset; } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } return(false); } if (!isRenderTarget) { Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } } return(true); }
public RenderTarget(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) : base(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback) { if (initSuccess) { initDepthStencil(width, height, depthStencilFormat); } }
public static RenderTarget New(DisposableI parent, string fileName, MultiSampleTypes multiSampleType, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback) { return(new RenderTarget(parent, fileName, multiSampleType, usage, renderTargetUsage, loadedCallback)); }
public RenderTarget(DisposableI parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback) : base(parent, width, height, surfaceFormat, usage, loadedCallback) { initDepthStencilFormat = depthStencilFormat; }
public static RenderTarget New(DisposableI parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback) { return(new RenderTarget(parent, width, height, multiSampleType, surfaceFormat, depthStencilFormat, usage, renderTargetUsage, loadedCallback)); }
protected virtual bool init(DisposableI parent, string fileName, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { try { if (usage == BufferUsages.Read && !isRenderTarget) Debug.ThrowError("Texture2D", "Only RenderTargets may be readable"); video = parent.FindParentOrSelfWithException<Video>(); if (isRenderTarget) generateMipmaps = false; if (fileName != null) { texture = new G.Texture2D("/Application/" + fileName, generateMipmaps); } else { texture = new G.Texture2D(width, height, generateMipmaps, Video.surfaceFormat(surfaceFormat), isRenderTarget ? G.PixelBufferOption.Renderable : G.PixelBufferOption.None); } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) loadedCallback(this, false); return false; } if (!isRenderTarget) { Loaded = true; if (loadedCallback != null) loadedCallback(this, true); } return true; }
protected virtual bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { long[] mipmaps = null; int[] mipmapSizes = null, mipmapPitches = null; try { video = parent.FindParentOrSelfWithException <Video>(); if (isRenderTarget) { generateMipmaps = false; } // load image data if (image != null) { mipmaps = new long[image.Mipmaps.Length]; mipmapSizes = new int[image.Mipmaps.Length]; mipmapPitches = new int[image.Mipmaps.Length]; for (int i = 0; i != mipmaps.Length; ++i) { var imageMipmap = image.Mipmaps[i]; IntPtr mipmapPtr = Marshal.AllocHGlobal(imageMipmap.Data.Length); Marshal.Copy(imageMipmap.Data, 0, mipmapPtr, imageMipmap.Data.Length); mipmapSizes[i] = imageMipmap.Data.Length; mipmapPitches[i] = imageMipmap.Pitch; mipmaps[i] = mipmapPtr.ToInt64(); } Size = image.Size; surfaceFormat = image.SurfaceFormat; PixelByteSize = image.CalculatePixelByteSize(); } else { if (width == 0 || height == 0) { Debug.ThrowError("Texture2D", "Width or Height cannot be 0"); } Size = new Size2(width, height); PixelByteSize = Image.CalculatePixelByteSize((surfaceFormat == SurfaceFormats.Defualt ? Video.DefaultSurfaceFormat() : surfaceFormat), width, height); } SizeF = Size.ToVector2(); // init texture REIGN_D3D11_USAGE usageType = REIGN_D3D11_USAGE.DEFAULT; REIGN_D3D11_CPU_ACCESS_FLAG cpuAccessFlags = (REIGN_D3D11_CPU_ACCESS_FLAG)0; if (usage == BufferUsages.Read) { if (!isRenderTarget) { Debug.ThrowError("Texture2D", "Only RenderTargets may be readable"); } // NOTE: Staging texture and states will be created in the RenderTarget //usageType = REIGN_D3D11_USAGE.STAGING; //cpuAccessFlags = REIGN_D3D11_CPU_ACCESS_FLAG.READ; } if (usage == BufferUsages.Write) { usageType = REIGN_D3D11_USAGE.DYNAMIC; cpuAccessFlags = REIGN_D3D11_CPU_ACCESS_FLAG.WRITE; } com = new Texture2DCom(); var error = com.Init(video.com, Size.Width, Size.Height, generateMipmaps, mipmaps != null, mipmaps, mipmapSizes, mipmapPitches, 0, video.surfaceFormat(surfaceFormat), usageType, cpuAccessFlags, isRenderTarget); switch (error) { case TextureError.Texture: Debug.ThrowError("Texture2D", "Failed to create Texture2D"); break; case TextureError.ShaderResourceView: Debug.ThrowError("Texture2D", "Failed to create ShaderResourceView"); break; } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } return(false); } finally { if (mipmaps != null) { for (int i = 0; i != mipmaps.Length; ++i) { if (mipmaps[i] != 0) { Marshal.FreeHGlobal(new IntPtr(mipmaps[i])); } } } } if (!isRenderTarget) { Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } } return(true); }
public static RenderTarget New(DisposableI parent, string fileName, MultiSampleTypes multiSampleType, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback) { return new RenderTarget(parent, fileName, multiSampleType, usage, renderTargetUsage, loadedCallback); }
protected override bool init(DisposableI parent, string fileName, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { if (!base.init(parent, fileName, image, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback)) { return(false); } try { if (usage == BufferUsages.Write) { Debug.ThrowError("RenderTarget", "Only Textures may be writable"); } if (fileName == null) { // TODO: handle multiSampleType types #if SILVERLIGHT var xUsage = X.RenderTargetUsage.PreserveContents; #else var xUsage = X.RenderTargetUsage.PlatformContents; #endif switch (renderTargetUsage) { case RenderTargetUsage.PlatformDefault: #if SILVERLIGHT xUsage = X.RenderTargetUsage.PreserveContents; #else xUsage = X.RenderTargetUsage.PlatformContents; #endif break; case RenderTargetUsage.PreserveContents: xUsage = X.RenderTargetUsage.PreserveContents; break; case RenderTargetUsage.DiscardContents: xUsage = X.RenderTargetUsage.DiscardContents; break; } X.DepthFormat format = X.DepthFormat.None; if (initDepthStencilFormat != DepthStencilFormats.None) { switch (initDepthStencilFormat) { case DepthStencilFormats.Defualt: format = X.DepthFormat.Depth24; break; case DepthStencilFormats.Depth24Stencil8: format = X.DepthFormat.Depth24Stencil8; break; case DepthStencilFormats.Depth16: format = X.DepthFormat.Depth16; break; case DepthStencilFormats.Depth24: format = X.DepthFormat.Depth24; break; default: Debug.ThrowError("RenderTarget", "Unsuported DepthStencilFormat type"); break; } } renderTarget = new X.RenderTarget2D(video.Device, width, height, false, Video.surfaceFormat(surfaceFormat), format, 0, xUsage); } else { Debug.ThrowError("RenderTarget", "(Load image data into RenderTarget Texture) -- Not implemented yet..."); } texture = renderTarget; } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } return(false); } Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } return(true); }
public static IRenderTarget New(IDisposableResource parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) { return(New(VideoAPI.DefaultAPI, parent, (Image)null, width, height, false, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback)); }
protected unsafe override bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { initSuccess = base.init(parent, image, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback); if (!initSuccess) return false; try { if (usage == BufferUsages.Write) Debug.ThrowError("RenderTarget", "Only Textures may be writable"); uint frameBufferTEMP = 0; GL.GenFramebuffers(1, &frameBufferTEMP); frameBuffer = frameBufferTEMP; uint error; string errorName; if (Video.checkForError(out error, out errorName)) Debug.ThrowError("RenderTarget", string.Format("{0} {1}: Failed to create renderTarget", error, errorName)); } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) loadedCallback(this, false); return false; } Loaded = true; if (loadedCallback != null) loadedCallback(this, true); return true; }
protected override bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, bool lockable, Loader.LoadedCallbackMethod loadedCallback) { initSuccess = base.init(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, lockable, loadedCallback); if (!initSuccess) { return(false); } try { if (usage == BufferUsages.Write) { Debug.ThrowError("RenderTarget", "Only Textures may be writable"); } if (image != null) { width = image.Size.Width; height = image.Size.Height; surfaceFormat = image.SurfaceFormat; } renderTargetCom = new RenderTargetCom(); var error = renderTargetCom.Init(video.com, com, width, height, 0, video.surfaceFormat(surfaceFormat), usage == BufferUsages.Read, lockable); switch (error) { case RenderTargetError.RenderTarget: Debug.ThrowError("RenderTarget", "Failed to create RenderTarget"); break; case RenderTargetError.StagingTexture: Debug.ThrowError("RenderTarget", "Failed to create Staging Texture"); break; } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } return(false); } Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } return(true); }
protected virtual bool init(DisposableI parent, string fileName, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { try { if (usage == BufferUsages.Read && !isRenderTarget) { Debug.ThrowError("Texture2D", "Only RenderTargets may be readable"); } video = parent.FindParentOrSelfWithException <Video>(); if (!isRenderTarget) { if (fileName != null || image != null) { #if SILVERLIGHT texture = new X.Texture2D(video.Device, image.Size.Width, image.Size.Height, image.Mipmaps.Length != 0, Video.surfaceFormat(surfaceFormat)); for (int i = 0; i != image.Mipmaps.Length; ++i) { var mipmap = image.Mipmaps[i]; texture.SetData <byte>(i, null, mipmap.Data, 0, mipmap.Data.Length); } #else texture = parent.FindParentOrSelfWithException <RootDisposable>().Content.Load <X.Texture2D>(Streams.StripFileExt(fileName)); loadedFromContentManager = true; #endif } else { texture = new X.Texture2D(video.Device, width, height, generateMipmaps, Video.surfaceFormat(surfaceFormat)); } Size = new Size2(texture.Width, texture.Height); PixelByteSize = Image.CalculatePixelByteSize(surfaceFormat, texture.Width, texture.Height); } else { Size = new Size2(width, height); PixelByteSize = Image.CalculatePixelByteSize(surfaceFormat, width, height); } TexelOffset = (1 / Size.ToVector2()) * .5f; SizeF = Size.ToVector2(); } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } return(false); } if (!isRenderTarget) { Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } } return(true); }
public Texture2D(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) : base(parent) { init(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, false, false, loadedCallback); }
protected virtual bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { long[] mipmaps = null; int[] mipmapSizes = null, mipmapPitches = null; try { video = parent.FindParentOrSelfWithException<Video>(); if (isRenderTarget) generateMipmaps = false; // load image data if (image != null) { mipmaps = new long[image.Mipmaps.Length]; mipmapSizes = new int[image.Mipmaps.Length]; mipmapPitches = new int[image.Mipmaps.Length]; for (int i = 0; i != mipmaps.Length; ++i) { var imageMipmap = image.Mipmaps[i]; IntPtr mipmapPtr = Marshal.AllocHGlobal(imageMipmap.Data.Length); Marshal.Copy(imageMipmap.Data, 0, mipmapPtr, imageMipmap.Data.Length); mipmapSizes[i] = imageMipmap.Data.Length; mipmapPitches[i] = imageMipmap.Pitch; mipmaps[i] = mipmapPtr.ToInt64(); } Size = image.Size; surfaceFormat = image.SurfaceFormat; PixelByteSize = image.CalculatePixelByteSize(); } else { if (width == 0 || height == 0) Debug.ThrowError("Texture2D", "Width or Height cannot be 0"); Size = new Size2(width, height); PixelByteSize = Image.CalculatePixelByteSize((surfaceFormat == SurfaceFormats.Defualt ? Video.DefaultSurfaceFormat() : surfaceFormat), width, height); } SizeF = Size.ToVector2(); // init texture REIGN_D3D11_USAGE usageType = REIGN_D3D11_USAGE.DEFAULT; REIGN_D3D11_CPU_ACCESS_FLAG cpuAccessFlags = (REIGN_D3D11_CPU_ACCESS_FLAG)0; if (usage == BufferUsages.Read) { if (!isRenderTarget) Debug.ThrowError("Texture2D", "Only RenderTargets may be readable"); // NOTE: Staging texture and states will be created in the RenderTarget //usageType = REIGN_D3D11_USAGE.STAGING; //cpuAccessFlags = REIGN_D3D11_CPU_ACCESS_FLAG.READ; } if (usage == BufferUsages.Write) { usageType = REIGN_D3D11_USAGE.DYNAMIC; cpuAccessFlags = REIGN_D3D11_CPU_ACCESS_FLAG.WRITE; } com = new Texture2DCom(); var error = com.Init(video.com, Size.Width, Size.Height, generateMipmaps, mipmaps != null, mipmaps, mipmapSizes, mipmapPitches, 0, video.surfaceFormat(surfaceFormat), usageType, cpuAccessFlags, isRenderTarget); switch (error) { case TextureError.Texture: Debug.ThrowError("Texture2D", "Failed to create Texture2D"); break; case TextureError.ShaderResourceView: Debug.ThrowError("Texture2D", "Failed to create ShaderResourceView"); break; } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) loadedCallback(this, false); return false; } finally { if (mipmaps != null) { for (int i = 0; i != mipmaps.Length; ++i) { if (mipmaps[i] != 0) Marshal.FreeHGlobal(new IntPtr(mipmaps[i])); } } } if (!isRenderTarget) { Loaded = true; if (loadedCallback != null) loadedCallback(this, true); } return true; }
public static ITexture2D New(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) { return New(VideoAPI.DefaultAPI, parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); }
protected unsafe virtual bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { try { if (usage == BufferUsages.Read && !isRenderTarget) Debug.ThrowError("Texture2D", "Only RenderTargets may be readable"); video = parent.FindParentOrSelfWithException<Video>(); if (isRenderTarget) generateMipmaps = false; uint texturesTEMP = 0; GL.GenTextures(1, &texturesTEMP); Texture = texturesTEMP; if (Texture == 0) Debug.ThrowError("Texture2D", "Failed to Generate Texture"); GL.BindTexture(GL.TEXTURE_2D, Texture); if (!generateMipmaps) GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR); else GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_LINEAR); GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.LINEAR); hasMipmaps = false; if (image != null) { var imageType = image.GetType(); #if NaCl if (imageType == typeof(ImageBMPC)) #else if (imageType == typeof(ImagePNG) || imageType == typeof(ImageJPG) || imageType == typeof(ImageBMP) || imageType == typeof(ImageBMPC)) #endif { uint pixelOrder, byteSizes; int format = Video.surfaceFormat(surfaceFormat, out pixelOrder, out byteSizes); var mipmap = image.Mipmaps[0]; fixed (byte* data = mipmap.Data) { GL.TexImage2D(GL.TEXTURE_2D, 0, format, mipmap.Size.Width, mipmap.Size.Height, 0, pixelOrder, byteSizes, data); if (generateMipmaps) { hasMipmaps = true; GL.GenerateMipmap(GL.TEXTURE_2D); } } } else if (imageType == typeof(ImageDDS) || imageType == typeof(ImagePVR)) { if (image.Mipmaps.Length != Image.Mipmap.CalculateMipmapLvls(image.Size.Width, image.Size.Height)) { Debug.ThrowError("Texture2D", "Compressed Textures require full mipmap chain"); } GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_LINEAR); hasMipmaps = true; bool compressed = false; uint format = 0; string errorType = null; if (imageType == typeof(ImageDDS)) { var imageDDS = (ImageDDS)image; compressed = imageDDS.Compressed; format = imageDDS.FormatGL; errorType = "DDS"; } else if (imageType == typeof(ImagePVR)) { var imagePVR = (ImagePVR)image; compressed = imagePVR.Compressed; format = imagePVR.FormatGL; errorType = "PVR"; } if (compressed) { for (int i = 0; i < image.Mipmaps.Length; ++i) { var mipmap = image.Mipmaps[i]; fixed (byte* data = mipmap.Data) { // look up:: libtxc_dxtn.so for linux with mesa GL.CompressedTexImage2D(GL.TEXTURE_2D, i, format, mipmap.Size.Width, mipmap.Size.Height, 0, mipmap.Data.Length, data); } } } else { Debug.ThrowError("Texture2D", "Loading uncompresed " + errorType + " textures not supported"); } } Size = image.Size; PixelByteSize = image.CalculatePixelByteSize(); } else { //GL.TexImage2D(GL.TEXTURE_2D, 0, Video.surfaceFormat(surfaceFormat), width, height, 0, GL.RGBA, GL.UNSIGNED_BYTE, IntPtr.Zero.ToPointer()); uint pixelOrder, byteSizes; int format = Video.surfaceFormat(surfaceFormat, out pixelOrder, out byteSizes); GL.TexImage2D(GL.TEXTURE_2D, 0, format, width, height, 0, pixelOrder, byteSizes, IntPtr.Zero.ToPointer()); if (generateMipmaps) { hasMipmaps = true; GL.GenerateMipmap(GL.TEXTURE_2D); } Size = new Size2(width, height); PixelByteSize = Image.CalculatePixelByteSize((surfaceFormat == SurfaceFormats.Defualt ? Video.DefaultSurfaceFormat() : surfaceFormat), width, height); } SizeF = Size.ToVector2(); uint error; string errorName; if (Video.checkForError(out error, out errorName)) { Debug.ThrowError("Texture2D", string.Format("{0} {1}: Failed to load/create texture", error, errorName)); } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) loadedCallback(this, false); return false; } if (!isRenderTarget) { Loaded = true; if (loadedCallback != null) loadedCallback(this, true); } return true; }
protected virtual bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, bool lockable, Loader.LoadedCallbackMethod loadedCallback) { byte[][] mipmaps = null; int[] mipmapSizes = null, mipmapPitches = null; try { video = parent.FindParentOrSelfWithException<Video>(); if (isRenderTarget) generateMipmaps = false; // load image data if (image != null) { mipmaps = new byte[image.Mipmaps.Length][]; mipmapSizes = new int[image.Mipmaps.Length]; mipmapPitches = new int[image.Mipmaps.Length]; for (int i = 0; i != mipmaps.Length; ++i) { var imageMipmap = image.Mipmaps[i]; mipmaps[i] = image.Compressed ? imageMipmap.Data : imageMipmap.SwapRBColorChannels(); mipmapSizes[i] = imageMipmap.Data.Length; mipmapPitches[i] = imageMipmap.Pitch; } Size = image.Size; surfaceFormat = image.SurfaceFormat; PixelByteSize = image.CalculatePixelByteSize(); } else { if (width == 0 || height == 0) Debug.ThrowError("Texture2D", "Width or Height cannot be 0"); Size = new Size2(width, height); PixelByteSize = Image.CalculatePixelByteSize((surfaceFormat == SurfaceFormats.Defualt ? Video.DefaultSurfaceFormat() : surfaceFormat), width, height); } TexelOffset = (1 / Size.ToVector2()) * .5f; SizeF = Size.ToVector2(); // init texture REIGN_D3DUSAGE nativeUsage = isRenderTarget ? REIGN_D3DUSAGE.RENDERTARGET : REIGN_D3DUSAGE.NONE; REIGN_D3DPOOL nativePool = (mipmaps != null && !video.Caps.ExDevice) ? REIGN_D3DPOOL.MANAGED : REIGN_D3DPOOL.DEFAULT; if (usage == BufferUsages.Read) { if (!isRenderTarget) Debug.ThrowError("Texture2D", "Only RenderTargets may be readable"); // NOTE: Staging texture and states will be created in the RenderTarget } if (usage == BufferUsages.Write) { if (mipmaps != null) { if (video.Caps.ExDevice) nativeUsage |= REIGN_D3DUSAGE.DYNAMIC; } else { nativeUsage |= REIGN_D3DUSAGE.DYNAMIC; } } com = new Texture2DCom(); var error = com.Init(video.com, Size.Width, Size.Height, generateMipmaps, mipmaps, mipmapSizes, mipmapPitches, 0, nativePool, nativeUsage, video.surfaceFormat(surfaceFormat), isRenderTarget); switch (error) { case TextureError.Texture: Debug.ThrowError("Texture2D", "Failed to create Texture2D"); break; case TextureError.SystemTexture: Debug.ThrowError("Texture2D", "Failed to create System Texture2D"); break; } if (!video.Caps.ExDevice && nativePool != REIGN_D3DPOOL.MANAGED) { LostDevice_image = image; LostDevice_width = width; LostDevice_height = height; LostDevice_generateMipmaps = generateMipmaps; LostDevice_multiSampleType = multiSampleType; LostDevice_surfaceFormat = surfaceFormat; LostDevice_renderTargetUsage = renderTargetUsage; LostDevice_usage = usage; LostDevice_isRenderTarget = isRenderTarget; LostDevice_lockable = lockable; LostDevice_pool = nativePool; } if (nativePool == REIGN_D3DPOOL.DEFAULT && !video.Caps.ExDevice && !video.deviceReseting) { video.DeviceLost += deviceLost; video.DeviceReset += deviceReset; } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) loadedCallback(this, false); return false; } if (!isRenderTarget) { Loaded = true; if (loadedCallback != null) loadedCallback(this, true); } return true; }
public Texture2D(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) : base(parent) { init(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, false, loadedCallback); }
protected override bool init(DisposableI parent, string fileName, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { if (!base.init(parent, fileName, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback)) return false; try { if (usage == BufferUsages.Write) Debug.ThrowError("RenderTarget", "Only Textures may be writable"); frameBuffer = new G.FrameBuffer(); frameBuffer.SetColorTarget(texture, 0); } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) loadedCallback(this, false); return false; } Loaded = true; if (loadedCallback != null) loadedCallback(this, true); return true; }
protected unsafe virtual bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { try { if (usage == BufferUsages.Read && !isRenderTarget) { Debug.ThrowError("Texture2D", "Only RenderTargets may be readable"); } video = parent.FindParentOrSelfWithException <Video>(); if (isRenderTarget) { generateMipmaps = false; } uint texturesTEMP = 0; GL.GenTextures(1, &texturesTEMP); Texture = texturesTEMP; if (Texture == 0) { Debug.ThrowError("Texture2D", "Failed to Generate Texture"); } GL.BindTexture(GL.TEXTURE_2D, Texture); if (!generateMipmaps) { GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR); } else { GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_LINEAR); } GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.LINEAR); hasMipmaps = false; if (image != null) { var imageType = image.GetType(); #if NaCl if (imageType == typeof(ImageBMPC)) #else if (imageType == typeof(ImagePNG) || imageType == typeof(ImageJPG) || imageType == typeof(ImageBMP) || imageType == typeof(ImageBMPC)) #endif { uint pixelOrder, byteSizes; int format = Video.surfaceFormat(surfaceFormat, out pixelOrder, out byteSizes); var mipmap = image.Mipmaps[0]; fixed(byte *data = mipmap.Data) { GL.TexImage2D(GL.TEXTURE_2D, 0, format, mipmap.Size.Width, mipmap.Size.Height, 0, pixelOrder, byteSizes, data); if (generateMipmaps) { hasMipmaps = true; GL.GenerateMipmap(GL.TEXTURE_2D); } } } else if (imageType == typeof(ImageDDS) || imageType == typeof(ImagePVR)) { if (image.Mipmaps.Length != Image.Mipmap.CalculateMipmapLvls(image.Size.Width, image.Size.Height)) { Debug.ThrowError("Texture2D", "Compressed Textures require full mipmap chain"); } GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_LINEAR); hasMipmaps = true; bool compressed = false; uint format = 0; string errorType = null; if (imageType == typeof(ImageDDS)) { var imageDDS = (ImageDDS)image; compressed = imageDDS.Compressed; format = imageDDS.FormatGL; errorType = "DDS"; } else if (imageType == typeof(ImagePVR)) { var imagePVR = (ImagePVR)image; compressed = imagePVR.Compressed; format = imagePVR.FormatGL; errorType = "PVR"; } if (compressed) { for (int i = 0; i < image.Mipmaps.Length; ++i) { var mipmap = image.Mipmaps[i]; fixed(byte *data = mipmap.Data) { // look up:: libtxc_dxtn.so for linux with mesa GL.CompressedTexImage2D(GL.TEXTURE_2D, i, format, mipmap.Size.Width, mipmap.Size.Height, 0, mipmap.Data.Length, data); } } } else { Debug.ThrowError("Texture2D", "Loading uncompresed " + errorType + " textures not supported"); } } Size = image.Size; PixelByteSize = image.CalculatePixelByteSize(); } else { //GL.TexImage2D(GL.TEXTURE_2D, 0, Video.surfaceFormat(surfaceFormat), width, height, 0, GL.RGBA, GL.UNSIGNED_BYTE, IntPtr.Zero.ToPointer()); uint pixelOrder, byteSizes; int format = Video.surfaceFormat(surfaceFormat, out pixelOrder, out byteSizes); GL.TexImage2D(GL.TEXTURE_2D, 0, format, width, height, 0, pixelOrder, byteSizes, IntPtr.Zero.ToPointer()); if (generateMipmaps) { hasMipmaps = true; GL.GenerateMipmap(GL.TEXTURE_2D); } Size = new Size2(width, height); PixelByteSize = Image.CalculatePixelByteSize((surfaceFormat == SurfaceFormats.Defualt ? Video.DefaultSurfaceFormat() : surfaceFormat), width, height); } SizeF = Size.ToVector2(); uint error; string errorName; if (Video.checkForError(out error, out errorName)) { Debug.ThrowError("Texture2D", string.Format("{0} {1}: Failed to load/create texture", error, errorName)); } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } return(false); } if (!isRenderTarget) { Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } } return(true); }
public static ITexture2D New(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) { return(New(VideoAPI.DefaultAPI, parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback)); }
public static ITexture2D New(VideoTypes videoType, IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) { ITexture2D api = null; #if WIN32 if (videoType == VideoTypes.D3D9) { api = new D3D9.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); } #endif #if WIN32 || WINRT || WP8 if (videoType == VideoTypes.D3D11) { api = new D3D11.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); } #endif #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl if (videoType == VideoTypes.OpenGL) { api = new OpenGL.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); } #endif #if XNA if (videoType == VideoTypes.XNA) { api = new XNA.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); } #endif #if VITA if (videoType == VideoTypes.Vita) { api = new Vita.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback); } #endif if (api == null) { Debug.ThrowError("Texture2DAPI", "Unsuported InputType: " + videoType); } return(api); }
protected virtual bool init(DisposableI parent, string fileName, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { try { if (usage == BufferUsages.Read && !isRenderTarget) Debug.ThrowError("Texture2D", "Only RenderTargets may be readable"); video = parent.FindParentOrSelfWithException<Video>(); if (!isRenderTarget) { if (fileName != null || image != null) { #if SILVERLIGHT texture = new X.Texture2D(video.Device, image.Size.Width, image.Size.Height, image.Mipmaps.Length != 0, Video.surfaceFormat(surfaceFormat)); for (int i = 0; i != image.Mipmaps.Length; ++i) { var mipmap = image.Mipmaps[i]; texture.SetData<byte>(i, null, mipmap.Data, 0, mipmap.Data.Length); } #else texture = parent.FindParentOrSelfWithException<RootDisposable>().Content.Load<X.Texture2D>(Streams.StripFileExt(fileName)); loadedFromContentManager = true; #endif } else { texture = new X.Texture2D(video.Device, width, height, generateMipmaps, Video.surfaceFormat(surfaceFormat)); } Size = new Size2(texture.Width, texture.Height); PixelByteSize = Image.CalculatePixelByteSize(surfaceFormat, texture.Width, texture.Height); } else { Size = new Size2(width, height); PixelByteSize = Image.CalculatePixelByteSize(surfaceFormat, width, height); } TexelOffset = (1 / Size.ToVector2()) * .5f; SizeF = Size.ToVector2(); } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) loadedCallback(this, false); return false; } if (!isRenderTarget) { Loaded = true; if (loadedCallback != null) loadedCallback(this, true); } return true; }
public static RenderTarget New(DisposableI parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback) { return new RenderTarget(parent, width, height, multiSampleType, surfaceFormat, depthStencilFormat, usage, renderTargetUsage, loadedCallback); }
public static IRenderTarget New(IDisposableResource parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) { return New(VideoAPI.DefaultAPI, parent, (Image)null, width, height, false, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); }
protected override bool init(DisposableI parent, string fileName, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { if (!base.init(parent, fileName, image, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback)) return false; try { if (usage == BufferUsages.Write) Debug.ThrowError("RenderTarget", "Only Textures may be writable"); if (fileName == null) { // TODO: handle multiSampleType types #if SILVERLIGHT var xUsage = X.RenderTargetUsage.PreserveContents; #else var xUsage = X.RenderTargetUsage.PlatformContents; #endif switch (renderTargetUsage) { case RenderTargetUsage.PlatformDefault: #if SILVERLIGHT xUsage = X.RenderTargetUsage.PreserveContents; #else xUsage = X.RenderTargetUsage.PlatformContents; #endif break; case RenderTargetUsage.PreserveContents: xUsage = X.RenderTargetUsage.PreserveContents; break; case RenderTargetUsage.DiscardContents: xUsage = X.RenderTargetUsage.DiscardContents; break; } X.DepthFormat format = X.DepthFormat.None; if (initDepthStencilFormat != DepthStencilFormats.None) { switch (initDepthStencilFormat) { case DepthStencilFormats.Defualt: format = X.DepthFormat.Depth24; break; case DepthStencilFormats.Depth24Stencil8: format = X.DepthFormat.Depth24Stencil8; break; case DepthStencilFormats.Depth16: format = X.DepthFormat.Depth16; break; case DepthStencilFormats.Depth24: format = X.DepthFormat.Depth24; break; default: Debug.ThrowError("RenderTarget", "Unsuported DepthStencilFormat type"); break; } } renderTarget = new X.RenderTarget2D(video.Device, width, height, false, Video.surfaceFormat(surfaceFormat), format, 0, xUsage); } else { Debug.ThrowError("RenderTarget", "(Load image data into RenderTarget Texture) -- Not implemented yet..."); } texture = renderTarget; } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) loadedCallback(this, false); return false; } Loaded = true; if (loadedCallback != null) loadedCallback(this, true); return true; }
protected unsafe override bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback) { initSuccess = base.init(parent, image, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback); if (!initSuccess) { return(false); } try { if (usage == BufferUsages.Write) { Debug.ThrowError("RenderTarget", "Only Textures may be writable"); } uint frameBufferTEMP = 0; GL.GenFramebuffers(1, &frameBufferTEMP); frameBuffer = frameBufferTEMP; uint error; string errorName; if (Video.checkForError(out error, out errorName)) { Debug.ThrowError("RenderTarget", string.Format("{0} {1}: Failed to create renderTarget", error, errorName)); } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } return(false); } Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } return(true); }