public RenderTarget2D ( GraphicsDevice graphicsDevice, int width, int height, int numberLevels, SurfaceFormat format ) { // throw new NotImplementedException(); texture = new Texture2D( graphicsDevice, width, height, numberLevels, TextureUsage.None, format ); // create framebuffer /*GL.GenBuffers(1, ref textureFrameBuffer); GL.BindBuffer(All.Framebuffer, textureFrameBuffer); // attach renderbuffer GL.FramebufferTexture2D(All.Framebuffer, All.ColorAttachment0, All.Texture2D, textureFrameBuffer, 0); // attach depth buffer uint depthRenderbuffer; GL.GenRenderbuffers(1, ref depthRenderbuffer); GL.BindRenderbuffer(All.Renderbuffer, depthRenderbuffer); GL.RenderbufferStorage(All.Renderbuffer, All.DepthComponent16, width, height); GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment, All.Renderbuffer, depthRenderbuffer); // unbind frame buffer GL.BindBuffer(All.Framebuffer, 0);*/ }
public BitmapContent(SurfaceFormat format, int width, int height, byte[] data) { this.Format = format; this.Width = width; this.Height = height; this.Data = data; }
/// <summary> /// 根据图像格式(SurfaceFormat) 创建Bitmap /// </summary> /// <param name="width">宽度</param> /// <param name="height">高度</param> /// <param name="format">图像格式</param> /// <returns></returns> public static Bitmap CreateBitmap(GraphicsDevice p_GraphicsDevice, int p_Width, int p_Height, SurfaceFormat format) { return new Bitmap { Texture = new Texture2D(p_GraphicsDevice, p_Width, p_Height, false, format) }; }
public FlipTexture2D(GraphicsDevice graphicsDeivce, int width, int height, bool mipMap, SurfaceFormat format, int numberTextures) { textures = new Texture2D[numberTextures]; for (int i = 0; i < textures.Length; ++i) textures[i] = new Texture2D(graphicsDeivce, width, height, mipMap, format); }
public PostProcesses(SurfaceFormat? surface = null, DepthFormat? depth = null, bool mipmap = false, RenderTargetUsage? usage = null) { FormatSurface = surface; FormatDepth = depth; MipMap = mipmap; Usage = usage; }
public RenderTarget2D( GraphicsDevice graphicsDevice, int width, int height, int numberLevels, SurfaceFormat format, MultiSampleType multiSampleType, int multiSampleQuality) : this(graphicsDevice, width, height, numberLevels > 1, format, DepthFormat.Unknown, 0, RenderTargetUsage.PreserveContents) { }
public IntermediateRenderTarget GetIntermediateTexture(int width, int height, bool mipmap, SurfaceFormat SurfaceFormat, DepthFormat DepthFormat, int preferedMultisampleCount, RenderTargetUsage RenderTargetUsage) { // Look for a matching rendertarget in the cache for (int i = 0; i < intermediateTextures.Count; i++) { if (intermediateTextures[i].InUse == false && height == intermediateTextures[i].RenderTarget.Height && width == intermediateTextures[i].RenderTarget.Width && preferedMultisampleCount == intermediateTextures[i].RenderTarget.MultiSampleCount && SurfaceFormat == intermediateTextures[i].RenderTarget.Format && DepthFormat == intermediateTextures[i].RenderTarget.DepthStencilFormat && RenderTargetUsage == intermediateTextures[i].RenderTarget.RenderTargetUsage && (mipmap == true && intermediateTextures[i].RenderTarget.LevelCount > 0 || mipmap == false && intermediateTextures[i].RenderTarget.LevelCount == 0) ) { intermediateTextures[i].InUse = true; return intermediateTextures[i]; } } // We didn't find one, let's make one IntermediateRenderTarget newTexture = new IntermediateRenderTarget(); newTexture.RenderTarget = new RenderTarget2D(device,width, height, mipmap, SurfaceFormat,DepthFormat, preferedMultisampleCount, RenderTargetUsage ); intermediateTextures.Add(newTexture); newTexture.InUse = true; return newTexture; }
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, width, height, mipMap, preferredFormat) { RenderTargetUsage = usage; //allocateOpenGLTexture(); }
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, width, height, mipMap, preferredFormat) { RenderTargetUsage = usage; DepthStencilFormat = preferredDepthFormat; }
private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) { // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (preferredMultiSampleCount > 1) { multisampleDesc.Count = preferredMultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), Dimension = DepthStencilViewDimension.Texture2D }); } }
public RenderTarget2D (GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) :base (graphicsDevice, width, height, mipMap, preferredFormat) { #if IPHONE if(GraphicsDevice.OpenGLESVersion == MonoTouch.OpenGLES.EAGLRenderingAPI.OpenGLES2) { GL20.GenFramebuffers(1, ref frameBuffer); } else { RenderTargetUsage = usage; DepthStencilFormat = preferredDepthFormat; } #elif ANDROID if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { GL20.GenFramebuffers(1, ref frameBuffer); } else { RenderTargetUsage = usage; DepthStencilFormat = preferredDepthFormat; } #else RenderTargetUsage = usage; DepthStencilFormat = preferredDepthFormat; #endif }
internal static int GetFormatSize(SurfaceFormat format) { switch (format) { case SurfaceFormat.Dxt1: return 8; case SurfaceFormat.Dxt3: case SurfaceFormat.Dxt5: return 16; case SurfaceFormat.Alpha8: return 1; case SurfaceFormat.Bgr565: case SurfaceFormat.Bgra4444: case SurfaceFormat.Bgra5551: case SurfaceFormat.HalfSingle: case SurfaceFormat.NormalizedByte2: return 2; case SurfaceFormat.Color: case SurfaceFormat.Single: case SurfaceFormat.Rg32: case SurfaceFormat.HalfVector2: case SurfaceFormat.NormalizedByte4: case SurfaceFormat.Rgba1010102: return 4; case SurfaceFormat.HalfVector4: case SurfaceFormat.Rgba64: case SurfaceFormat.Vector2: return 8; case SurfaceFormat.Vector4: return 16; default: throw new ArgumentException("Should be a value defined in SurfaceFormat", "Format"); } }
public static RenderTarget2D CreateRenderTarget(GraphicsDevice device, int numberLevels, SurfaceFormat surface, int width, int height) { MultiSampleType type = device.PresentationParameters.MultiSampleType; // If the card can't use the surface format if (!GraphicsAdapter.DefaultAdapter.CheckDeviceFormat( DeviceType.Hardware, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Format, TextureUsage.None, QueryUsages.None, ResourceType.RenderTarget, surface)) { // Fall back to current display format surface = device.DisplayMode.Format; } // Or it can't accept that surface format // with the current AA settings else if (!GraphicsAdapter.DefaultAdapter.CheckDeviceMultiSampleType( DeviceType.Hardware, surface, device.PresentationParameters.IsFullScreen, type)) { // Fall back to no antialiasing type = MultiSampleType.None; } // Create our render target return new RenderTarget2D(device, width, height, numberLevels, surface, type, 0, RenderTargetUsage.PreserveContents); }
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, width, height, mipMap, preferredFormat, true) { RenderTarget2D renderTarget2D = this; this.DepthStencilFormat = preferredDepthFormat; this.MultiSampleCount = preferredMultiSampleCount; this.RenderTargetUsage = usage; if (preferredDepthFormat == DepthFormat.None) return; Threading.BlockOnUIThread((Action) (() => { GL.GenRenderbuffers(1, out renderTarget2D.glDepthStencilBuffer); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderTarget2D.glDepthStencilBuffer); RenderbufferStorage local_0 = RenderbufferStorage.DepthComponent16; switch (preferredDepthFormat) { case DepthFormat.Depth24Stencil8: local_0 = RenderbufferStorage.Depth24Stencil8; break; case DepthFormat.Depth24: local_0 = RenderbufferStorage.DepthComponent24; break; case DepthFormat.Depth16: local_0 = RenderbufferStorage.DepthComponent16; break; } if (renderTarget2D.MultiSampleCount == 0) GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, local_0, renderTarget2D.width, renderTarget2D.height); else GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, renderTarget2D.MultiSampleCount, local_0, renderTarget2D.width, renderTarget2D.height); })); }
public ESTexture2D(byte[] data, SurfaceFormat pixelFormat, int width, int height, Size size, ALL11 filter) { if (GraphicsDevice.OpenGLESVersion != OpenTK.Graphics.GLContextVersion.Gles2_0) { using(Bitmap bm = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888)) { using (var buffer = ByteBuffer.Wrap(data)) { bm.CopyPixelsFromBuffer(buffer); } InitWithBitmap(bm, filter); } } else { var imagePtr = IntPtr.Zero; try { imagePtr = Marshal.AllocHGlobal (data.Length); Marshal.Copy (data, 0, imagePtr, data.Length); InitWithData(imagePtr, pixelFormat, width, height, size, filter); } finally { Marshal.FreeHGlobal (imagePtr); } } }
public Dof(IRenderContext renderContext) : base(renderContext) { depthMapFormat = DefaultDepthMapFormat; Settings = DofSettings.Default; cameraFrustum = new BoundingFrustum(Matrix.Identity); }
public SsaoMapBlur(Effect effect, SpriteBatch spriteBatch, int width, int height, SurfaceFormat format, int radius, float amount) { if (effect == null) throw new ArgumentNullException("effect"); if (spriteBatch == null) throw new ArgumentNullException("spriteBatch"); if (width < 1) throw new ArgumentOutOfRangeException("width"); if (height < 1) throw new ArgumentOutOfRangeException("height"); if (radius < MinAmount || MaxRadius < radius) throw new ArgumentOutOfRangeException("value"); if (amount < MinAmount) throw new ArgumentOutOfRangeException("value"); this.effect = effect; this.spriteBatch = spriteBatch; Width = width; Height = height; Radius = radius; Amount = amount; graphicsDevice = effect.GraphicsDevice; normalDepthMap = effect.Parameters["NormalDepthMap"]; horizontalBlurTechnique = effect.Techniques["HorizontalBlur"]; verticalBlurTechnique = effect.Techniques["VerticalBlur"]; InitializeEffectParameters(); backingRenderTarget = new RenderTarget2D(graphicsDevice, width, height, false, format, DepthFormat.None, 0, RenderTargetUsage.PlatformContents); }
public BackBuffer(GraphicsDevice graphicsDevice, string name) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } this.graphicsDevice = graphicsDevice; Name = name; var pp = graphicsDevice.PresentationParameters; width = pp.BackBufferWidth; height = pp.BackBufferHeight; mipMap = true; surfaceFormat = pp.BackBufferFormat; depthFormat = pp.DepthStencilFormat; multiSampleCount = pp.MultiSampleCount; renderTargetUsage = pp.RenderTargetUsage; renderTargetCount = 1; currentIndex = 0; activated = false; disposed = false; }
public RenderTarget2D UpdateCustomRenderTarget(RenderTarget2D renderTarget, IGameContext gameContext, SurfaceFormat? surfaceFormat, DepthFormat? depthFormat, int? multiSampleCount) { if (IsCustomRenderTargetOutOfDate(renderTarget, gameContext, surfaceFormat, depthFormat, multiSampleCount)) { if (renderTarget != null) { renderTarget.Dispose(); } if (gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth == 0 && gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight == 0) { return null; } renderTarget = new RenderTarget2D( gameContext.Graphics.GraphicsDevice, gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth, gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight, false, surfaceFormat ?? gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferFormat, depthFormat ?? gameContext.Graphics.GraphicsDevice.PresentationParameters.DepthStencilFormat, multiSampleCount ?? gameContext.Graphics.GraphicsDevice.PresentationParameters.MultiSampleCount, RenderTargetUsage.PreserveContents); } return renderTarget; }
public CudaVideoWriter(String fileName, Size frameSize, double fps, SurfaceFormat format = SurfaceFormat.BGR) { using (CvString s = new CvString(fileName)) { _ptr = CudaInvoke.cudaVideoWriterCreate(s, ref frameSize, fps, format); } }
internal DisplayMode(int width, int height, int refreshRate, SurfaceFormat format) { this.width = width; this.height = height; this.refreshRate = refreshRate; this.format = format; }
static public SharpDX.DXGI.Format ToFormat(SurfaceFormat format) { switch (format) { case SurfaceFormat.Color: default: return SharpDX.DXGI.Format.R8G8B8A8_UNorm; case SurfaceFormat.Bgr565: return SharpDX.DXGI.Format.B5G6R5_UNorm; case SurfaceFormat.Bgra5551: return SharpDX.DXGI.Format.B5G5R5A1_UNorm; #if WINRT case SurfaceFormat.Bgra4444: return SharpDX.DXGI.Format.B4G4R4A4_UNorm; #endif case SurfaceFormat.Dxt1: return SharpDX.DXGI.Format.BC1_UNorm; case SurfaceFormat.Dxt3: return SharpDX.DXGI.Format.BC2_UNorm; case SurfaceFormat.Dxt5: return SharpDX.DXGI.Format.BC3_UNorm; case SurfaceFormat.NormalizedByte2: return SharpDX.DXGI.Format.R8G8_SNorm; case SurfaceFormat.NormalizedByte4: return SharpDX.DXGI.Format.R8G8B8A8_SNorm; case SurfaceFormat.Rgba1010102: return SharpDX.DXGI.Format.R10G10B10A2_UNorm; case SurfaceFormat.Rg32: return SharpDX.DXGI.Format.R16G16_UNorm; case SurfaceFormat.Rgba64: return SharpDX.DXGI.Format.R16G16B16A16_UNorm; case SurfaceFormat.Alpha8: return SharpDX.DXGI.Format.A8_UNorm; case SurfaceFormat.Single: return SharpDX.DXGI.Format.R32_Float; case SurfaceFormat.HalfSingle: return SharpDX.DXGI.Format.R16_Float; case SurfaceFormat.HalfVector2: return SharpDX.DXGI.Format.R16G16_Float; case SurfaceFormat.Vector2: return SharpDX.DXGI.Format.R32G32_Float; case SurfaceFormat.Vector4: return SharpDX.DXGI.Format.R32G32B32A32_Float; case SurfaceFormat.HalfVector4: return SharpDX.DXGI.Format.R16G16B16A16_Float; case SurfaceFormat.HdrBlendable: // TODO: This needs to check the graphics device and // return the best hdr blendable format for the device. return SharpDX.DXGI.Format.R16G16B16A16_Float; case SurfaceFormat.Bgr32: return SharpDX.DXGI.Format.B8G8R8X8_UNorm; case SurfaceFormat.Bgra32: return SharpDX.DXGI.Format.B8G8R8A8_UNorm; } }
public RenderTargetCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, size, mipMap, preferredFormat, true) { this.DepthStencilFormat = preferredDepthFormat; this.MultiSampleCount = preferredMultiSampleCount; this.RenderTargetUsage = usage; throw new NotImplementedException(); }
public PvrtcBitmapContent(int bitsPerPixel) { System.Diagnostics.Debug.Assert(bitsPerPixel == 2 || bitsPerPixel == 4); _bitsPerPixel = bitsPerPixel; _format = _bitsPerPixel == 2 ? SurfaceFormat.RgbaPvrtc2Bpp : SurfaceFormat.RgbaPvrtc4Bpp; }
protected Texture(GraphicsDevice graphicsDevice, SurfaceFormat format) : base(graphicsDevice) { TextureID = -1; Format = format; GetOpenGLTextureFormat(format, out InternalFormat, out PixelFormat, out PixelType); }
public DownSampler(GraphicFactory factory,float width, float height, SurfaceFormat SurfaceFormat = SurfaceFormat.Color,bool mipmap = false) { this.Rectangle = new Rectangle(0,0,(int)width,(int)height); RenderTarget2D = factory.CreateRenderTarget(Rectangle.Width, Rectangle.Height, SurfaceFormat, mipmap); effect = factory.GetEffect("SBlurPost/DownsampleDepth"); }
internal VGSurface(VGDevice device, int width, int height, SurfaceFormat format) : this(device, new RenderTarget2D( device.GraphicsDevice, width, height, false, format, DepthFormat.Depth24Stencil8, device.GraphicsDevice.PresentationParameters.MultiSampleCount, RenderTargetUsage.PreserveContents)) { }
public SBlurPost(float BLUR_AMOUNT = 1, BlurRadiusSize BlurRadiusSize = BlurRadiusSize.Fifteen, SurfaceFormat SurfaceFormat = Microsoft.Xna.Framework.Graphics.SurfaceFormat.Color) : base(PostEffectType.Deferred) { this.BLUR_AMOUNT = BLUR_AMOUNT; this.SurfaceFormat = SurfaceFormat; ImageSamplerState = SamplerState.LinearClamp; this.BlurRadiusSize = BlurRadiusSize; BLUR_RADIUS = (int)BlurRadiusSize; }
public RenderTarget2D (GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage) :base(graphicsDevice, width, height,0, TextureUsage.None, format) { allocateOpenGLTexture(); }
public TrackedRenderTarget2D(int width, int height, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat) : base(Core.GraphicsDevice, width, height, false, preferredFormat, preferredDepthFormat, 0, RenderTargetUsage.PreserveContents) { }
public static RenderTarget2D CreateRenderTarget(GraphicsDevice device, int numberLevels, SurfaceFormat surface, int width, int height) { MultiSampleType type = device.PresentationParameters.MultiSampleType; // If the card can't use the surface format if (!GraphicsAdapter.DefaultAdapter.CheckDeviceFormat( DeviceType.Hardware, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Format, TextureUsage.None, QueryUsages.None, ResourceType.RenderTarget, surface)) { // Fall back to current display format surface = device.DisplayMode.Format; } // Or it can't accept that surface format // with the current AA settings else if (!GraphicsAdapter.DefaultAdapter.CheckDeviceMultiSampleType( DeviceType.Hardware, surface, device.PresentationParameters.IsFullScreen, type)) { // Fall back to no antialiasing type = MultiSampleType.None; } /*int width, height; * * // See if we can use our buffer size as our texture * CheckTextureSize(device.PresentationParameters.BackBufferWidth, * device.PresentationParameters.BackBufferHeight, * out width, out height);*/ // Create our render target return(new RenderTarget2D(device, width, height, numberLevels, surface, type, 0, RenderTargetUsage.PreserveContents)); }
/// <summary> /// Initializes a new instance of the <see cref="RenderTargetCube"/> class. /// </summary> /// <param name="graphicsDevice">The graphics device.</param> /// <param name="size">The width and height of a texture cube face in pixels.</param> /// <param name="mipMap"><see langword="true"/> to generate a full mipmap chain; otherwise <see langword="false"/>.</param> /// <param name="preferredFormat">The preferred format of the surface.</param> /// <param name="preferredDepthFormat">The preferred format of the depth-stencil buffer.</param> /// <param name="preferredMultiSampleCount">The preferred number of multisample locations.</param> /// <param name="usage">The usage mode of the render target.</param> public RenderTargetCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, size, mipMap, QuerySelectedFormat(graphicsDevice, preferredFormat), true) { DepthStencilFormat = preferredDepthFormat; MultiSampleCount = preferredMultiSampleCount; RenderTargetUsage = usage; PlatformConstruct(graphicsDevice, mipMap, preferredDepthFormat, preferredMultiSampleCount, usage); }
internal TextureCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat format, bool renderTarget) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } this.GraphicsDevice = graphicsDevice; this.size = size; this._format = format; this._levelCount = mipMap ? CalculateMipLevels(size) : 1; #if DIRECTX _renderTarget = renderTarget; _mipMap = mipMap; // Create texture GetTexture(); #elif PSM //TODO #else this.glTarget = TextureTarget.TextureCubeMap; #if IOS || ANDROID GL.GenTextures(1, ref this.glTexture); #else GL.GenTextures(1, out this.glTexture); #endif GraphicsExtensions.CheckGLError(); GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, mipMap ? (int)TextureMinFilter.LinearMipmapLinear : (int)TextureMinFilter.Linear); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); GraphicsExtensions.CheckGLError(); format.GetGLFormat(out glInternalFormat, out glFormat, out glType); for (int i = 0; i < 6; i++) { TextureTarget target = GetGLCubeFace((CubeMapFace)i); if (glFormat == (PixelFormat)All.CompressedTextureFormats) { throw new NotImplementedException(); } else { #if IOS || ANDROID GL.TexImage2D(target, 0, (int)glInternalFormat, size, size, 0, glFormat, glType, IntPtr.Zero); #else GL.TexImage2D(target, 0, glInternalFormat, size, size, 0, glFormat, glType, IntPtr.Zero); #endif GraphicsExtensions.CheckGLError(); } } if (mipMap) { #if IOS || ANDROID GL.GenerateMipmap(TextureTarget.TextureCubeMap); #else GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.GenerateMipmap, (int)All.True); #endif GraphicsExtensions.CheckGLError(); } #endif }
internal void PlatformCreateRenderTarget(Texture renderTarget, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) { var color = 0; var depth = 0; var stencil = 0; if (preferredMultiSampleCount > 0 && this.framebufferHelper.SupportsBlitFramebuffer) { this.framebufferHelper.GenRenderbuffer(out color); this.framebufferHelper.BindRenderbuffer(color); #if GLES this.framebufferHelper.RenderbufferStorageMultisample(preferredMultiSampleCount, (int)RenderbufferStorage.Rgba8Oes, width, height); #else this.framebufferHelper.RenderbufferStorageMultisample(preferredMultiSampleCount, (int)RenderbufferStorage.Rgba8, width, height); #endif } if (preferredDepthFormat != DepthFormat.None) { var depthInternalFormat = RenderbufferStorage.DepthComponent16; var stencilInternalFormat = (RenderbufferStorage)0; switch (preferredDepthFormat) { case DepthFormat.Depth16: depthInternalFormat = RenderbufferStorage.DepthComponent16; break; #if GLES case DepthFormat.Depth24: if (GraphicsCapabilities.SupportsDepth24) { depthInternalFormat = RenderbufferStorage.DepthComponent24Oes; } else if (GraphicsCapabilities.SupportsDepthNonLinear) { depthInternalFormat = (RenderbufferStorage)0x8E2C; } else { depthInternalFormat = RenderbufferStorage.DepthComponent16; } break; case DepthFormat.Depth24Stencil8: if (GraphicsCapabilities.SupportsPackedDepthStencil) { depthInternalFormat = RenderbufferStorage.Depth24Stencil8Oes; } else { if (GraphicsCapabilities.SupportsDepth24) { depthInternalFormat = RenderbufferStorage.DepthComponent24Oes; } else if (GraphicsCapabilities.SupportsDepthNonLinear) { depthInternalFormat = (RenderbufferStorage)0x8E2C; } else { depthInternalFormat = RenderbufferStorage.DepthComponent16; } stencilInternalFormat = RenderbufferStorage.StencilIndex8; break; } break; #else case DepthFormat.Depth24: depthInternalFormat = RenderbufferStorage.DepthComponent24; break; case DepthFormat.Depth24Stencil8: depthInternalFormat = RenderbufferStorage.Depth24Stencil8; break; #endif } if (depthInternalFormat != 0) { this.framebufferHelper.GenRenderbuffer(out depth); this.framebufferHelper.BindRenderbuffer(depth); this.framebufferHelper.RenderbufferStorageMultisample(preferredMultiSampleCount, (int)depthInternalFormat, width, height); if (preferredDepthFormat == DepthFormat.Depth24Stencil8) { stencil = depth; if (stencilInternalFormat != 0) { this.framebufferHelper.GenRenderbuffer(out stencil); this.framebufferHelper.BindRenderbuffer(stencil); this.framebufferHelper.RenderbufferStorageMultisample(preferredMultiSampleCount, (int)stencilInternalFormat, width, height); } } } } var renderTarget2D = renderTarget as RenderTarget2D; if (renderTarget2D != null) { if (color != 0) { renderTarget2D.glColorBuffer = color; } else { renderTarget2D.glColorBuffer = renderTarget2D.glTexture; } renderTarget2D.glDepthBuffer = depth; renderTarget2D.glStencilBuffer = stencil; } else { throw new NotSupportedException(); } }
public TextureCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat format) : this(graphicsDevice, size, mipMap, format, false) { }
static public SharpDX.DXGI.Format ToFormat(SurfaceFormat format) { switch (format) { case SurfaceFormat.Color: default: return(SharpDX.DXGI.Format.R8G8B8A8_UNorm); case SurfaceFormat.Bgr565: return(SharpDX.DXGI.Format.B5G6R5_UNorm); case SurfaceFormat.Bgra5551: return(SharpDX.DXGI.Format.B5G5R5A1_UNorm); #if WINRT case SurfaceFormat.Bgra4444: return(SharpDX.DXGI.Format.B4G4R4A4_UNorm); #endif case SurfaceFormat.Dxt1: return(SharpDX.DXGI.Format.BC1_UNorm); case SurfaceFormat.Dxt3: return(SharpDX.DXGI.Format.BC2_UNorm); case SurfaceFormat.Dxt5: return(SharpDX.DXGI.Format.BC3_UNorm); case SurfaceFormat.NormalizedByte2: return(SharpDX.DXGI.Format.R8G8_SNorm); case SurfaceFormat.NormalizedByte4: return(SharpDX.DXGI.Format.R8G8B8A8_SNorm); case SurfaceFormat.Rgba1010102: return(SharpDX.DXGI.Format.R10G10B10A2_UNorm); case SurfaceFormat.Rg32: return(SharpDX.DXGI.Format.R16G16_UNorm); case SurfaceFormat.Rgba64: return(SharpDX.DXGI.Format.R16G16B16A16_UNorm); case SurfaceFormat.Alpha8: return(SharpDX.DXGI.Format.A8_UNorm); case SurfaceFormat.Single: return(SharpDX.DXGI.Format.R32_Float); case SurfaceFormat.HalfSingle: return(SharpDX.DXGI.Format.R16_Float); case SurfaceFormat.HalfVector2: return(SharpDX.DXGI.Format.R16G16_Float); case SurfaceFormat.Vector2: return(SharpDX.DXGI.Format.R32G32_Float); case SurfaceFormat.Vector4: return(SharpDX.DXGI.Format.R32G32B32A32_Float); case SurfaceFormat.HalfVector4: return(SharpDX.DXGI.Format.R16G16B16A16_Float); case SurfaceFormat.HdrBlendable: // TODO: This needs to check the graphics device and // return the best hdr blendable format for the device. return(SharpDX.DXGI.Format.R16G16B16A16_Float); case SurfaceFormat.Bgr32: return(SharpDX.DXGI.Format.B8G8R8X8_UNorm); case SurfaceFormat.Bgra32: return(SharpDX.DXGI.Format.B8G8R8A8_UNorm); case SurfaceFormat.ColorSRgb: return(SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb); case SurfaceFormat.Bgr32SRgb: return(SharpDX.DXGI.Format.B8G8R8X8_UNorm_SRgb); case SurfaceFormat.Bgra32SRgb: return(SharpDX.DXGI.Format.B8G8R8A8_UNorm_SRgb); case SurfaceFormat.Dxt1SRgb: return(SharpDX.DXGI.Format.BC1_UNorm_SRgb); case SurfaceFormat.Dxt3SRgb: return(SharpDX.DXGI.Format.BC2_UNorm_SRgb); case SurfaceFormat.Dxt5SRgb: return(SharpDX.DXGI.Format.BC3_UNorm_SRgb); } }
public XNATexture2DImplementation(XFG.GraphicsDevice device, int width, int height, bool genMipmaps, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage) : base(width, height, format, depthFormat, multiSampleCount, usage) { _graphicsDevice = device; _texture2D = new XFG.RenderTarget2D(device, width, height, genMipmaps, XNAHelper.ToXNASurfaceFormat(format), XNAHelper.ToXNADepthFormat(depthFormat), multiSampleCount, XFG.RenderTargetUsage.PlatformContents); }
/// <summary> /// Gets the corresponding GPU texture format for the specified bitmap type. /// </summary> /// <param name="format">Format being retrieved.</param> /// <returns>The GPU texture format of the bitmap type.</returns> public override bool TryGetFormat(out SurfaceFormat format) { if (typeof(T) == typeof(Color)) { format = SurfaceFormat.Color; } else if (typeof(T) == typeof(Bgra4444)) { format = SurfaceFormat.Bgra4444; } else if (typeof(T) == typeof(Bgra5551)) { format = SurfaceFormat.Bgra5551; } else if (typeof(T) == typeof(Bgr565)) { format = SurfaceFormat.Bgr565; } else if (typeof(T) == typeof(Vector4)) { format = SurfaceFormat.Vector4; } else if (typeof(T) == typeof(Vector2)) { format = SurfaceFormat.Vector2; } else if (typeof(T) == typeof(Single)) { format = SurfaceFormat.Single; } else if (typeof(T) == typeof(byte)) { format = SurfaceFormat.Alpha8; } else if (typeof(T) == typeof(Rgba64)) { format = SurfaceFormat.Rgba64; } else if (typeof(T) == typeof(Rgba1010102)) { format = SurfaceFormat.Rgba1010102; } else if (typeof(T) == typeof(Rg32)) { format = SurfaceFormat.Rg32; } else if (typeof(T) == typeof(Byte4)) { format = SurfaceFormat.Color; } else if (typeof(T) == typeof(NormalizedByte2)) { format = SurfaceFormat.NormalizedByte2; } else if (typeof(T) == typeof(NormalizedByte4)) { format = SurfaceFormat.NormalizedByte4; } else if (typeof(T) == typeof(HalfSingle)) { format = SurfaceFormat.HalfSingle; } else if (typeof(T) == typeof(HalfVector2)) { format = SurfaceFormat.HalfVector2; } else if (typeof(T) == typeof(HalfVector4)) { format = SurfaceFormat.HalfVector4; } else { format = SurfaceFormat.Color; return(false); } return(true); }
/// <summary> /// Gets the corresponding GPU texture format for the specified bitmap type. /// </summary> /// <param name="format">Format being retrieved.</param> /// <returns>The GPU texture format of the bitmap type.</returns> public override bool TryGetFormat(out SurfaceFormat format) { format = SurfaceFormat.RgbPvrtc2Bpp; return(true); }
private void PlatformConstruct(int width, int height, bool mipmap, SurfaceFormat format, SurfaceType type, bool shared) { _shared = shared; _mipmap = mipmap; }
protected UOTexture(int width, int height, SurfaceFormat format) : base(Client.Game.GraphicsDevice, width, height, false, format) { Ticks = Time.Ticks + 3000; }
public Texture2D( GraphicsDevice graphicsDevice, int width, int height, bool mipmap, SurfaceFormat format ) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } GraphicsDevice = graphicsDevice; Width = width; Height = height; LevelCount = mipmap ? CalculateMipLevels(width, height) : 1; Format = format; GetGLSurfaceFormat(); Threading.ForceToMainThread(() => { texture = new OpenGLDevice.OpenGLTexture( TextureTarget.Texture2D, Format, LevelCount > 1 ); if (((Width & (Width - 1)) != 0) || ((Height & (Height - 1)) != 0)) { texture.WrapS.Set(TextureAddressMode.Clamp); texture.WrapT.Set(TextureAddressMode.Clamp); } OpenGLDevice.Instance.BindTexture(texture); if (Format == SurfaceFormat.Dxt1 || Format == SurfaceFormat.Dxt3 || Format == SurfaceFormat.Dxt5) { GL.CompressedTexImage2D( TextureTarget.Texture2D, 0, glInternalFormat, Width, Height, 0, ((Width + 3) / 4) * ((Height + 3) / 4) * GetFormatSize(), IntPtr.Zero ); } else { GL.TexImage2D( TextureTarget.Texture2D, 0, glInternalFormat, Width, Height, 0, glFormat, glType, IntPtr.Zero ); } texture.Flush(true); }); }
/// <summary> /// helper for creating a RenderTarget2D /// </summary> /// <param name="width">Width.</param> /// <param name="height">Height.</param> /// <param name="preferredFormat">Preferred format.</param> /// <param name="preferredDepthFormat">Preferred depth format.</param> public static RenderTarget2D Create(int width, int height, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat) { return(new RenderTarget2D(Core.GraphicsDevice, width, height, false, preferredFormat, preferredDepthFormat, 0, RenderTargetUsage.PreserveContents)); }
/// <summary> /// Loads all needed components for the BloomEffect. This effect won't work without calling load /// </summary> /// <param name="graphicsDevice"></param> /// <param name="content"></param> /// <param name="width">initial value for creating the rendertargets</param> /// <param name="height">initial value for creating the rendertargets</param> /// <param name="renderTargetFormat">The intended format for the rendertargets. For normal, non-hdr, applications color or rgba1010102 are fine NOTE: For OpenGL, SurfaceFormat.Color is recommended for non-HDR applications.</param> /// <param name="quadRenderer">if you already have quadRenderer you may reuse it here</param> public void Load(GraphicsDevice graphicsDevice, ContentManager content, int width, int height, SurfaceFormat renderTargetFormat = SurfaceFormat.Color, QuadRenderer quadRenderer = null) { _graphicsDevice = graphicsDevice; UpdateResolution(width, height); //if quadRenderer == null -> new, otherwise not _quadRenderer = quadRenderer ?? new QuadRenderer(graphicsDevice); _renderTargetFormat = renderTargetFormat; //Load the shader parameters and passes for cheap and easy access BinaryReader Reader = new BinaryReader(new FileStream("../../../../Effects/bloom.mgfxo", FileMode.Open)); _bloomEffect = new Effect(graphicsDevice, Reader.ReadBytes((int)Reader.BaseStream.Length)); _bloomInverseResolutionParameter = _bloomEffect.Parameters["InverseResolution"]; _bloomRadiusParameter = _bloomEffect.Parameters["Radius"]; _bloomStrengthParameter = _bloomEffect.Parameters["Strength"]; _bloomStreakLengthParameter = _bloomEffect.Parameters["StreakLength"]; _bloomThresholdParameter = _bloomEffect.Parameters["Threshold"]; //For DirectX / Windows _bloomParameterScreenTexture = _bloomEffect.Parameters["ScreenTexture"]; //If we are on OpenGL it's different, load the other one then! if (_bloomParameterScreenTexture == null) { //for OpenGL / CrossPlatform _bloomParameterScreenTexture = _bloomEffect.Parameters["LinearSampler+ScreenTexture"]; } _bloomPassExtract = _bloomEffect.Techniques["Extract"].Passes[0]; _bloomPassExtractLuminance = _bloomEffect.Techniques["ExtractLuminance"].Passes[0]; _bloomPassDownsample = _bloomEffect.Techniques["Downsample"].Passes[0]; _bloomPassUpsample = _bloomEffect.Techniques["Upsample"].Passes[0]; _bloomPassUpsampleLuminance = _bloomEffect.Techniques["UpsampleLuminance"].Passes[0]; //An interesting blendstate for merging the initial image with the bloom. //BlendStateBloom = new BlendState(); //BlendStateBloom.ColorBlendFunction = BlendFunction.Add; //BlendStateBloom.ColorSourceBlend = Blend.BlendFactor; //BlendStateBloom.ColorDestinationBlend = Blend.BlendFactor; //BlendStateBloom.BlendFactor = new Color(0.5f, 0.5f, 0.5f); //Default threshold. BloomThreshold = 0.8f; //Setup the default preset values. //BloomPreset = BloomPresets.One; SetBloomPreset(BloomPreset); }
public static SpriteFont Create(string name) { Stream stream = typeof(SpriteFont).Assembly.GetManifestResourceStream(name); using (BinReader reader = new BinReader(stream)) { reader.ReadByte(); reader.ReadByte(); reader.ReadByte(); char c = reader.ReadChar(); byte version = reader.ReadByte(); byte flags = reader.ReadByte(); bool compressed = (flags & 0x80) != 0; if (version != 5 && version != 4) { throw new ContentLoadException("Invalid XNB version"); } int xnbLength = reader.ReadInt32(); int numberOfReaders = reader.Read7BitEncodedInt(); for (int i = 0; i < numberOfReaders; i++) { string originalReaderTypeString = reader.ReadString(); reader.ReadInt32(); } int shared = reader.Read7BitEncodedInt(); int typeReaderIndex = reader.Read7BitEncodedInt(); reader.Read7BitEncodedInt(); SurfaceFormat format = (SurfaceFormat)reader.ReadInt32(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); int levelCount = reader.ReadInt32(); int levelDataSizeInBytes = reader.ReadInt32(); byte[] levelData = null; // Don't assign this quite yet... int levelWidth = width >> 0; int levelHeight = height >> 0; levelData = reader.ReadBytes(levelDataSizeInBytes); if (format != SurfaceFormat.Color) { levelData = DecompressDxt3(levelData, levelWidth, levelHeight); levelDataSizeInBytes = levelData.Length; } Texture2D texture = new Texture2D (Client.Game.GraphicsDevice, width, height, false, SurfaceFormat.Color); texture.SetData(levelData); reader.Read7BitEncodedInt(); int glyphCount = reader.ReadInt32(); List <Rectangle> glyphs = new List <Rectangle>(glyphCount); for (int i = 0; i < glyphCount; i++) { int x = reader.ReadInt32(); int y = reader.ReadInt32(); int w = reader.ReadInt32(); int h = reader.ReadInt32(); glyphs.Add(new Rectangle(x, y, w, h)); } reader.Read7BitEncodedInt(); int croppingCount = reader.ReadInt32(); List <Rectangle> croppings = new List <Rectangle>(croppingCount); for (int i = 0; i < croppingCount; i++) { int x = reader.ReadInt32(); int y = reader.ReadInt32(); int w = reader.ReadInt32(); int h = reader.ReadInt32(); croppings.Add(new Rectangle(x, y, w, h)); } reader.Read7BitEncodedInt(); int charCount = reader.ReadInt32(); List <char> charMap = new List <char>(charCount); for (int i = 0; i < charCount; i++) { charMap.Add(reader.ReadChar()); } int lineSpacing = reader.ReadInt32(); float spacing = reader.ReadSingle(); reader.Read7BitEncodedInt(); int kerningCount = reader.ReadInt32(); List <Vector3> kernings = new List <Vector3>(croppingCount); for (int i = 0; i < kerningCount; i++) { float x = reader.ReadSingle(); float y = reader.ReadSingle(); float z = reader.ReadSingle(); kernings.Add(new Vector3(x, y, z)); } char?defaultChar = null; if (reader.ReadBoolean()) { defaultChar = reader.ReadChar(); } return(new SpriteFont(texture, glyphs, croppings, charMap, lineSpacing, spacing, kernings, defaultChar)); } }
private void PlatformConstruct(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat format, bool renderTarget) { _renderTarget = renderTarget; _mipMap = mipMap; // Create texture GetTexture(); }
protected static SurfaceFormat QuerySelectedFormat(GraphicsDevice graphicsDevice, SurfaceFormat preferredFormat) { SurfaceFormat selectedFormat; DepthFormat selectedDepthFormat; int selectedMultiSampleCount; graphicsDevice.Adapter.QueryRenderTargetFormat(graphicsDevice.GraphicsProfile, preferredFormat, DepthFormat.None, 0, out selectedFormat, out selectedDepthFormat, out selectedMultiSampleCount); return(selectedFormat); }
/// <summary> /// Initializes a new instance of the <see cref="RenderTargetCube"/> class. /// </summary> /// <param name="graphicsDevice">The graphics device.</param> /// <param name="size">The width and height of a texture cube face in pixels.</param> /// <param name="mipMap"><see langword="true"/> to generate a full mipmap chain; otherwise <see langword="false"/>.</param> /// <param name="preferredFormat">The preferred format of the surface.</param> /// <param name="preferredDepthFormat">The preferred format of the depth-stencil buffer.</param> public RenderTargetCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat) : this(graphicsDevice, size, mipMap, preferredFormat, preferredDepthFormat, 0, RenderTargetUsage.DiscardContents) { }
internal TextureCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat format, bool renderTarget) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } this.GraphicsDevice = graphicsDevice; this.size = size; this.format = format; this.levelCount = mipMap ? CalculateMipLevels(size) : 1; #if DIRECTX var description = new Texture2DDescription { Width = size, Height = size, MipLevels = levelCount, ArraySize = 6, // A texture cube is a 2D texture array with 6 textures. Format = SharpDXHelper.ToFormat(format), BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.TextureCube }; if (renderTarget) { description.BindFlags |= BindFlags.RenderTarget; if (mipMap) { description.OptionFlags |= ResourceOptionFlags.GenerateMipMaps; } } _texture = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, description); #elif PSM //TODO #else this.glTarget = TextureTarget.TextureCubeMap; #if IOS || ANDROID GL.GenTextures(1, ref this.glTexture); #else GL.GenTextures(1, out this.glTexture); #endif GraphicsExtensions.CheckGLError(); GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, mipMap ? (int)TextureMinFilter.LinearMipmapLinear : (int)TextureMinFilter.Linear); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); GraphicsExtensions.CheckGLError(); format.GetGLFormat(out glInternalFormat, out glFormat, out glType); for (int i = 0; i < 6; i++) { TextureTarget target = GetGLCubeFace((CubeMapFace)i); if (glFormat == (PixelFormat)All.CompressedTextureFormats) { throw new NotImplementedException(); } else { #if IOS || ANDROID GL.TexImage2D(target, 0, (int)glInternalFormat, size, size, 0, glFormat, glType, IntPtr.Zero); #else GL.TexImage2D(target, 0, glInternalFormat, size, size, 0, glFormat, glType, IntPtr.Zero); #endif GraphicsExtensions.CheckGLError(); } } if (mipMap) { #if IOS || ANDROID GL.GenerateMipmap(TextureTarget.TextureCubeMap); #else GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.GenerateMipmap, (int)All.True); #endif GraphicsExtensions.CheckGLError(); } #endif }
/// <summary> /// Gets the corresponding GPU texture format for the specified bitmap type. /// </summary> /// <param name="format">Format being retrieved.</param> /// <returns>The GPU texture format of the bitmap type.</returns> public override bool TryGetFormat(out SurfaceFormat format) { format = SurfaceFormat.Dxt1; return(true); }
public XNATexture2DImplementation(XFG.GraphicsDevice device, int width, int height, bool genMipMaps, SurfaceFormat format) : base(width, height, format) { _graphicsDevice = device; _texture2D = new XFG.Texture2D(device, width, height, genMipMaps, XNAHelper.ToXNASurfaceFormat(format)); }
internal static void GetGLFormat(this SurfaceFormat format, GraphicsDevice graphicsDevice, out PixelInternalFormat glInternalFormat, out PixelFormat glFormat, out PixelType glType) { glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; var supportsSRgb = graphicsDevice.GraphicsCapabilities.SupportsSRgb; switch (format) { case SurfaceFormat.Color: glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; break; case SurfaceFormat.ColorSRgb: if (!supportsSRgb) { goto case SurfaceFormat.Color; } glInternalFormat = (PixelInternalFormat)0x8C40; // PixelInternalFormat.Srgb; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; break; case SurfaceFormat.Bgr565: glInternalFormat = PixelInternalFormat.Rgb; glFormat = PixelFormat.Rgb; glType = PixelType.UnsignedShort565; break; case SurfaceFormat.Bgra4444: #if IOS || ANDROID glInternalFormat = PixelInternalFormat.Rgba; #else glInternalFormat = PixelInternalFormat.Rgba4; #endif glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort4444; break; case SurfaceFormat.Bgra5551: glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort5551; break; case SurfaceFormat.Alpha8: glInternalFormat = PixelInternalFormat.Luminance; glFormat = PixelFormat.Luminance; glType = PixelType.UnsignedByte; break; #if !IOS && !ANDROID && !ANGLE case SurfaceFormat.Dxt1: glInternalFormat = PixelInternalFormat.CompressedRgbS3tcDxt1Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt1SRgb: if (!supportsSRgb) { goto case SurfaceFormat.Dxt1; } glInternalFormat = PixelInternalFormat.CompressedSrgbS3tcDxt1Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt1a: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt3: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt3SRgb: if (!supportsSRgb) { goto case SurfaceFormat.Dxt3; } glInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt5: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt5SRgb: if (!supportsSRgb) { goto case SurfaceFormat.Dxt5; } glInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Single: glInternalFormat = PixelInternalFormat.R32f; glFormat = PixelFormat.Red; glType = PixelType.Float; break; case SurfaceFormat.HalfVector2: glInternalFormat = PixelInternalFormat.Rg16f; glFormat = PixelFormat.Rg; glType = PixelType.HalfFloat; break; // HdrBlendable implemented as HalfVector4 (see http://blogs.msdn.com/b/shawnhar/archive/2010/07/09/surfaceformat-hdrblendable.aspx) case SurfaceFormat.HdrBlendable: case SurfaceFormat.HalfVector4: glInternalFormat = PixelInternalFormat.Rgba16f; glFormat = PixelFormat.Rgba; glType = PixelType.HalfFloat; break; case SurfaceFormat.HalfSingle: glInternalFormat = PixelInternalFormat.R16f; glFormat = PixelFormat.Red; glType = PixelType.HalfFloat; break; case SurfaceFormat.Vector2: glInternalFormat = PixelInternalFormat.Rg32f; glFormat = PixelFormat.Rg; glType = PixelType.Float; break; case SurfaceFormat.Vector4: glInternalFormat = PixelInternalFormat.Rgba32f; glFormat = PixelFormat.Rgba; glType = PixelType.Float; break; case SurfaceFormat.NormalizedByte2: glInternalFormat = PixelInternalFormat.Rg8i; glFormat = PixelFormat.Rg; glType = PixelType.Byte; break; case SurfaceFormat.NormalizedByte4: glInternalFormat = PixelInternalFormat.Rgba8i; glFormat = PixelFormat.Rgba; glType = PixelType.Byte; break; case SurfaceFormat.Rg32: glInternalFormat = PixelInternalFormat.Rg16ui; glFormat = PixelFormat.Rg; glType = PixelType.UnsignedShort; break; case SurfaceFormat.Rgba64: glInternalFormat = PixelInternalFormat.Rgba16ui; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort; break; case SurfaceFormat.Rgba1010102: glInternalFormat = PixelInternalFormat.Rgb10A2ui; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedInt1010102; break; #endif #if ANDROID case SurfaceFormat.Dxt1: // 0x83F0 is the RGB version, 0x83F1 is the RGBA version (1-bit alpha) // XNA uses the RGB version. glInternalFormat = (PixelInternalFormat)0x83F0; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt1SRgb: if (!supportsSRgb) { goto case SurfaceFormat.Dxt1; } glInternalFormat = (PixelInternalFormat)0x8C4C; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt1a: // 0x83F0 is the RGB version, 0x83F1 is the RGBA version (1-bit alpha) glInternalFormat = (PixelInternalFormat)0x83F1; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt3: glInternalFormat = (PixelInternalFormat)0x83F2; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt3SRgb: if (!supportsSRgb) { goto case SurfaceFormat.Dxt3; } glInternalFormat = (PixelInternalFormat)0x8C4E; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt5: glInternalFormat = (PixelInternalFormat)0x83F3; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt5SRgb: if (!supportsSRgb) { goto case SurfaceFormat.Dxt5; } glInternalFormat = (PixelInternalFormat)0x8C4F; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaAtcExplicitAlpha: glInternalFormat = (PixelInternalFormat)All.AtcRgbaExplicitAlphaAmd; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaAtcInterpolatedAlpha: glInternalFormat = (PixelInternalFormat)All.AtcRgbaInterpolatedAlphaAmd; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbEtc1: glInternalFormat = (PixelInternalFormat)0x8D64; // GL_ETC1_RGB8_OES glFormat = (PixelFormat)All.CompressedTextureFormats; break; #endif #if IOS || ANDROID case SurfaceFormat.RgbPvrtc2Bpp: glInternalFormat = (PixelInternalFormat)All.CompressedRgbPvrtc2Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbPvrtc4Bpp: glInternalFormat = (PixelInternalFormat)All.CompressedRgbPvrtc4Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaPvrtc2Bpp: glInternalFormat = (PixelInternalFormat)All.CompressedRgbaPvrtc2Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaPvrtc4Bpp: glInternalFormat = (PixelInternalFormat)All.CompressedRgbaPvrtc4Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; #endif default: throw new NotSupportedException(); } }
public void InitWithBitmap(Bitmap image, All filter) { BitmapData bitmapData = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); _format = SurfaceFormat.Color; InitWithData(bitmapData.Scan0, _format, image.Width, image.Height, new Size(image.Width, image.Height), filter); image.UnlockBits(bitmapData); }