/// <summary> /// Creates an empty texture. /// </summary> /// <param name="width">Width of texture in pixel.</param> /// <param name="height">Height of texture in pixel.</param> /// <param name="mipLevels">Number of mip levels.</param> /// <param name="format">Format to use for texture.</param> /// <param name="usage">Special texture usage.</param> /// <returns>New texture.</returns> public ITexture2d Create(int width, int height, int mipLevels, Purple.Graphics.Format format, Purple.Graphics.TextureUsage usage) { ITexture2d tex = textureLoader.Create(width, height, mipLevels, format, usage); textures.Add(new WeakReference(tex)); return(tex); }
/// <summary> /// Creates a new text object. /// </summary> /// <param name="texture">The texture object to render the text into.</param> /// <param name="font">The font to use for rendering the text.</param> /// <param name="color">The color of the text.</param> public Text(ITexture2d texture, Font font, int color) { bitmap = new Bitmap(texture.Description.Width, texture.Description.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); this.texture = texture; this.font = font; this.Color = color; format = new StringFormat(StringFormat.GenericDefault); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// Creates a new overlay element. /// </summary> /// <param name="normal">The image to use for normal state.</param> /// <param name="pressed">The image to use for pressed state.</param> /// <param name="hover">The image to use for mouseOver state.</param> /// <param name="disabled">The image to use for disabled state.</param> public Overlay(ITexture2d normal, ITexture2d pressed, ITexture2d hover, ITexture2d disabled) : base(normal) { buttonLogic = new ThinButtonLogic(); this.normal = normal; this.pressed = pressed; this.hover = hover; this.disabled = disabled; }
/// <summary> /// Creates a new subTexture. /// </summary> /// <param name="parent">The parent texture to split up.</param> /// <param name="index">The current index of the subTexture to create.</param> /// <param name="totalNum">Total number of subTextures.</param> /// <param name="columns">The number of columns.</param> /// <returns>The subTexture.</returns> public static SubTexture Create(ITexture2d parent, int index, int totalNum, int columns) { int column = index % columns; int row = index / columns; int rows = (totalNum + columns - 1) / columns; return(new SubTexture(new System.Drawing.RectangleF( (float)column / columns, (float)row / rows, 1.0f / columns, 1.0f / rows), parent)); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// Create a new guiSlider object. /// </summary> /// <param name="normal">The standard texture.</param> /// <param name="hovered">The texture used if the slider is hovered.</param> /// <param name="pressed">The texture used if the slider is pressed.</param> /// <param name="disabled">The texture used if the slider is disabled.</param> public GuiSlider(ITexture2d normal, ITexture2d hovered, ITexture2d pressed, ITexture2d disabled) : base(normal) { this.textureNormal = normal; this.textureHovered = hovered; this.texturePressed = pressed; this.textureDisabled = disabled; this.Direction = Direction.Left; }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Initializes the image with a given texture. /// </summary> /// <param name="texture">Texture to initialize image with.</param> protected void Init(ITexture2d texture) { if (texture == null) { throw new ArgumentNullException("texture"); } quad = (IExtendedQuad)QuadFactory.Instance.CreateQuad(); quad.Texture = texture; quad.Size = quad.TextureSize; }
/// <summary> /// Default construcor /// </summary> public SpherePlanetHomogenousProceduralTerrainRenderer( ) { m_Renderer = new SpherePlanetTerrainPatchRenderer( this ); m_Technique = new SpherePlanetPackTextureTechnique( this ); m_PackTexture = ( ITexture2d )AssetManager.Instance.Load( "Terrain\\dirt0.jpg", new TextureLoadParameters( true ) ); m_LookupTexture = RbGraphics.Factory.CreateTexture2d( ); Texture2dData lookupData = new Texture2dData( 1, 1, TextureFormat.R8G8B8 ); m_LookupTexture.Create( lookupData, true ); }
/// <summary> /// Loads all image files that match fileName??.extension. /// </summary> /// <param name="fileName">The name of the file without the index number.</param> /// <returns>The loaded textures.</returns> public ITexture2d[] LoadTextures(string fileName) { string[] files = GetAnimationFiles(fileName); ITexture2d[] textures = new ITexture2d[files.Length]; for (int i = 0; i < files.Length; i++) { textures[i] = Load(files[i]); } return(textures); }
/// <summary> /// Default constructor. Creates a background thread to process new texture requests /// </summary> public TerrainTypeTextureBuilder( TerrainTypeList terrainTypes ) { Arguments.CheckNotNull( terrainTypes , "terrainTypes"); m_Worker = new BackgroundWorker( ); m_Worker.DoWork += ProcessRequest; m_Worker.RunWorkerCompleted += RequestComplete; m_LookupTexture = RbGraphics.Factory.CreateTexture2d( ); m_PackTexture = RbGraphics.Factory.CreateTexture2d( ); TerrainTypes = terrainTypes; }
/// <summary> /// Initializes the GuiScrollList with a vertain number of text images. /// </summary> /// <param name="items">The text items to display.</param> /// <param name="width">The width of one text item.</param> /// <param name="height">The height of one text item.</param> /// <param name="font">The font to use for the text.</param> /// <param name="textColor">The color of the text.</param> /// <param name="outlineColor">The color of the outline or 0.</param> public void InitImages(string[] items, int width, int height, System.Drawing.Font font, int textColor, int outlineColor) { ITexture2d texture = Text.Create(items, width, height, font, textColor, outlineColor); SubTexture[] textures = SubTexture.Create(texture, items.Length, 1); images = new Image[textures.Length]; for (int i = 0; i < textures.Length; i++) { images[i] = new Image(textures[i]); } Init(images); SetSize(images[0].Size); }
private IList LoadLightMaps(IList quakeLightMaps) { IList lightMaps = new ArrayList(); foreach (QuakeLightMap lightMap in quakeLightMaps) { Stream lightMapStream = new MemoryStream(lightMap.image); ITexture2d lm = LoadRaw(lightMapStream, 128, 128, 1, Format.R8G8B8); lightMaps.Add(lm); lightMapStream.Close(); } return(lightMaps); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// Creates a new text object. /// </summary> /// <param name="width">Size of texture to create.</param> /// <param name="height">Size of texture to create.</param> /// <param name="font">The font to use for rendering the text.</param> /// <param name="color">The color of the text.</param> public Text(int width, int height, Font font, int color) { if (width <= 0 || height <= 0) { throw new ArgumentException("Size of Text is invalid! (" + width + ":" + height + ")"); } bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); this.texture = TextureManager.Instance.Create(width, height, 1, Format.A8R8G8B8, TextureUsage.Normal); //dynamic? this.font = font; this.Color = color; format = new StringFormat(StringFormat.GenericDefault); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Updates the particle system. /// </summary> /// <param name="deltaTime">The time since the last update.</param> public override void Update(float deltaTime) { UpdateAge(deltaTime); // delete dead particles FixedRoundBuffer buffer = particles as FixedRoundBuffer; while (buffer.Count > 0 && !(buffer[0] as IParticle).IsAlive) { buffer.RemoveFirst(); } UpdateParticles(deltaTime); EmitParticles(deltaTime); ITexture2d texture = Texture; if (particles.Count >= 2) { // update streams PositionStream posStream = (PositionStream)vertexUnit[typeof(PositionStream)]; ColorStream colorStream = (ColorStream)vertexUnit[typeof(ColorStream)]; TextureStream textureStream = (TextureStream)vertexUnit[typeof(TextureStream)]; // Update all particles for (int i = 0; i < particles.Count; i++) { int offset = i * 2; IParticle particle = particles[i] as IParticle; IParticle3d particle3d = particles[i] as IParticle3d; if (particle3d != null) { Vector3 position = particle3d.Position; posStream[offset] = position + particle.Size.X * (particle as IParticleOrientation).Orientation; posStream[offset + 1] = position - particle.Size.X * (particle as IParticleOrientation).Orientation; } IParticleColor particleColor = particles[i] as IParticleColor; if (particleColor != null) { colorStream[offset] = particleColor.Color; colorStream[offset + 1] = particleColor.Color; } float tx = texture.TextureCoordinates.Left + texture.TextureCoordinates.Width * particle.Age / particle.LifeTime; textureStream[offset] = new Vector2(tx, texture.TextureCoordinates.Top); textureStream[offset + 1] = new Vector2(tx, texture.TextureCoordinates.Bottom); } posStream.Upload(); colorStream.Upload(); textureStream.Upload(); } }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// Creates a new GuiScrollList element. /// </summary> public GuiScrollList(int totalNum, int columns, ITexture2d normal, ITexture2d hover, ITexture2d selected) { isInfinite = false; SubTexture[] subTexturesNormal = SubTexture.Create(normal, totalNum, columns); SubTexture[] subTexturesHover = SubTexture.Create(hover, totalNum, columns); SubTexture[] subTexturesSelected = SubTexture.Create(selected, totalNum, columns); Button[] buttons = new Button[subTexturesNormal.Length]; for (int i = 0; i < buttons.Length; i++) { buttons[i] = new Button(subTexturesNormal[i], subTexturesSelected[i], subTexturesHover[i]); } Init(images); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// Creates a new GuiListBox object. /// </summary> /// <param name="items">The number of items.</param> /// <param name="background">The background texture.</param> /// <param name="hover">The hover texture.</param> /// <param name="selected">The selected texture.</param> public GuiListBox(int items, ITexture2d background, ITexture2d hover, ITexture2d selected) { this.background = background; this.hover = hover; this.selected = selected; this.images = new Image[items]; states = new ButtonState[items]; for (int i = 0; i < images.Length; i++) { SubTexture subTexture = SubTexture.Create(background, i, items, 1); images[i] = new Image(subTexture); images[i].Position = Vector2.MultiplyElements(images[i].Size, new Vector2(0.0f, i)); this.Children.Add(images[i]); } this.size = Vector2.MultiplyElements(images[0].Size, new Vector2(1, items)); }
/// <summary> /// Loads the standard mouse cursor. /// </summary> /// <returns>The standard mouse cursor.</returns> private IImage LoadMouseCursor() { using (Purple.Profiling.Profiler.Instance.Sample("LoadMouseCursor")) { if (GraphicsEngine.Initialized) { string name = "Purple/Input/Cursor.png"; ITexture2d texture = TextureManager.Instance.Load(Purple.IO.ResourceFileSystem.Instance.Open(name)); IImage img = new Image(texture); img.Position = new Purple.Math.Vector2(0.5f, 0.5f); return(img); } else { return(null); } } }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// Creates a new instance of a <see cref="Button"/>. /// </summary> /// <param name="normal">The image to use for normal state.</param> /// <param name="pressed">The image to use for pressed state.</param> /// <param name="hover">The image to use for mouseOver state.</param> /// <param name="disabled">The image to use for disabled state.</param> public Button(ITexture2d normal, ITexture2d pressed, ITexture2d hover, ITexture2d disabled) : base(normal) { if (normal == null) { throw new ArgumentNullException("normal"); } if (pressed == null) { throw new ArgumentNullException("pressed"); } this.normal = normal; this.pressed = pressed; this.disabled = disabled; this.hover = hover; buttonState = ButtonState.Normal; }
/// <summary> /// loads a texture from a stream containing raw bitmap data /// </summary> /// <param name="stream">stream to load from</param> /// <param name="width">width of texture</param> /// <param name="height">height of texture</param> /// <param name="mipLevels">number of MipMap level</param> /// <param name="format">format of texture</param> /// <returns>texture object</returns> private ITexture2d LoadRaw(Stream stream, int width, int height, int mipLevels, Purple.Graphics.Format format) { int countBytes = width * height * Purple.Graphics.GraphicsEngine.BitsPerPixel(format) / 8; byte[] data = new Byte[countBytes]; stream.Read(data, 0, countBytes); System.Drawing.Bitmap bitmap; // pin array System.Runtime.InteropServices.GCHandle handle = System.Runtime.InteropServices.GCHandle.Alloc(data); System.IntPtr ptr = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(data, 0); bitmap = new System.Drawing.Bitmap(width, height, width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, ptr); ITexture2d tex = TextureManager.Instance.Create(width, height, 1, Format.A8R8G8B8, TextureUsage.Normal); tex.CopyBitmap(bitmap, new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Point.Empty); bitmap.Dispose(); handle.Free(); return(tex); }
/// <summary> /// Creates a certain number of subTextures by splitting up a texture into regions of same size. /// </summary> /// <param name="parent">The parent texture to split up.</param> /// <param name="totalNum">Total number of subTextures.</param> /// <param name="columns">The number of columns.</param> /// <returns>The array of subTextures.</returns> public static SubTexture[] Create(ITexture2d parent, int totalNum, int columns) { SubTexture[] subTextures = new SubTexture[totalNum]; int rows = (totalNum + columns - 1) / columns; float stepX = 1.0f / columns; float stepY = 1.0f / rows; for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { int index = x + y * columns; if (index >= totalNum) { return(subTextures); } subTextures[index] = new SubTexture(new System.Drawing.RectangleF(stepX * x, stepY * y, stepX, stepY), parent); } } return(subTextures); }
private IList LoadTextures(IList quakeTextures) { ArrayList textures = new ArrayList(); TextureManager textureManager = TextureManager.Instance; IFileSystem fs = textureManager.FileSystem; string path = ""; foreach (QuakeTexture tex in quakeTextures) { path = StringHelper.Convert(tex.strName); string fileName = Purple.IO.Path.GetFileName(path); //fileName = fileName.Replace("textures/", ""); string directory = Purple.IO.Path.GetFolder(path); if (fs.ExistsDirectory(directory)) { string[] matchingFiles = fs.GetFiles(directory, fileName + ".*"); if (matchingFiles.Length != 0) { string matchingFile = matchingFiles[0]; Stream imageStream = fs.Open(matchingFile); ITexture2d lt = textureManager.Load(imageStream); textures.Add(lt); imageStream.Close(); } else { Log.Spam("Couldn't load texture: " + path); textures.Add(null); } } else { textures.Add(null); Log.Spam("Couldn't load texture: " + path + " because directory doesn't exist: " + directory); } } return(textures); }
/// <summary> /// Loads a texture from a stream. /// </summary> /// <param name="stream">Stream to load texture from.</param> /// <returns>Texture object.</returns> public ITexture2d Load(Stream stream) { Filter resizeFilter = Filter.None; if (autoResize) { resizeFilter = autoResizeFilter; } // HACK - will be replaced by a texture quality handler Format f = format; int w = 0; int h = 0; SurfaceDescription desc = new SurfaceDescription(0, 0, Format.A8R8G8B8); if (textureQuality != 1.0f) { desc = textureLoader.GetSurfaceDescription(stream); } if (textureQuality < 0.7f) { f = Format.Dxt5; } if (textureQuality < 0.1f) { f = Format.Dxt1; } if (this.autoResize == false) { mipLevels = 1; } // HACK - will be replaced by a texture quality handler ITexture2d tex = textureLoader.Load(stream, w, h, mipLevels, f, resizeFilter, this.mipMapFilter, TextureUsage.Normal); textures.Add(new WeakReference(tex)); return(tex); }
public TerrainVisualiserControl( ) { InitializeComponent( ); m_Texture = RbGraphics.Factory.CreateTexture2d( ); IEffect effect = ( IEffect )AssetManager.Instance.Load( @"Effects\Planets\TerrainVisualiser.cgfx" ); m_Technique = new TechniqueSelector( effect, "ShowTerrainPropertiesTechnique" ); terrainDisplay.OnRender += RenderTerrain; resolutionComboBox.Items.Add( "Fit to window" ); resolutionComboBox.Items.Add( 2048 ); resolutionComboBox.Items.Add( 1024 ); resolutionComboBox.Items.Add( 512 ); resolutionComboBox.Items.Add( 256 ); resolutionComboBox.Items.Add( 128 ); resolutionComboBox.Items.Add( 64 ); resolutionComboBox.Items.Add( 32 ); resolutionComboBox.Items.Add( 16 ); resolutionComboBox.Items.Add( 8 ); resolutionComboBox.Items.Add( 4 ); resolutionComboBox.SelectedIndex = 0; }
private bool LoadSkin(string part, string skinName) { using (Stream stream = fileSystem.Open(path + part + skinName + ".skin")) { StreamReader sr = new StreamReader(stream); while (sr.Peek() != -1) { string line = sr.ReadLine(); // test if line contains a path if (line.IndexOf("/") != -1) { int indexComma = line.IndexOf(","); string name = line.Substring(0, indexComma); string fileName = Purple.IO.Path.GetFileName(line.Substring(indexComma + 1)); ITexture2d tex = TextureManager.Instance.Load(modelPath + "/" + fileName); textures.Add(name, tex); } } sr.Close(); return(true); } }
/// <summary> /// Creates a new gui switch object. /// </summary> /// <param name="textureOn">Texture to use if switch is turned on.</param> /// <param name="textureOff">Texture to use if switch is turned off.</param> /// <param name="textureHoverOn">Texture to use if switch is hovered and turned on.</param> /// <param name="textureHoverOff">Texture to use if switch is hovered and turned off.</param> /// <param name="textureDisabledOn">Texture to use if switch is disabled and turned on.</param> /// <param name="textureDisabledOff">Texture to use if switch is disabled and turned off.</param> public GuiSwitch(ITexture2d textureOn, ITexture2d textureOff, ITexture2d textureHoverOn, ITexture2d textureHoverOff, ITexture2d textureDisabledOn, ITexture2d textureDisabledOff) : base(textureOn) { if (textureOn == null) { throw new ArgumentNullException("textureOn"); } if (textureOff == null) { throw new ArgumentNullException("textureOff"); } this.textureOn = textureOn; this.textureOff = textureOff; this.textureDisabledOn = textureDisabledOn; this.textureDissabledOff = textureDisabledOff; this.textureHoverOn = textureHoverOn; this.textureHoverOff = textureHoverOff; buttonLogic = new ButtonLogic(); checkedValue = true; }
/// <summary> /// Saves a texture to a file /// </summary> /// <param name="texture">Texture to save</param> /// <param name="path">Save file path</param> /// <param name="format">Image file format</param> public static void SaveTextureToImageFile( ITexture2d texture, string path, ImageFormat format ) { Image img = CreateBitmapFromTexture( texture ); img.Save( path, format ); }
/// <summary> /// Setup constructor /// </summary> /// <param name="indices">Index buffer</param> /// <param name="technique">Rendering technique</param> /// <param name="textures">Textures</param> public CellGeometryGroup( int[] indices, ITechnique technique, ITexture2d[] textures ) { m_Indices = indices; m_Textures = textures; m_Technique = technique; }
/// <summary> /// Destroys associated buffers /// </summary> public unsafe void Dispose( ) { RenderTargets.RemoveCreatedRenderTarget( this ); if ( m_Texture != null ) { m_Texture.Dispose( ); m_Texture = null; } if ( m_DepthTexture != null ) { m_DepthTexture.Dispose( ); m_DepthTexture = null; } // NOTE: AP: If GL context is no longer available, these delete calls will fail // TODO: AP: Ensure Dispose() is called correctly for all graphics objects prior to application exit try { if ( m_FboHandle != InvalidHandle ) { fixed ( int* fboHandle = &m_FboHandle ) { Gl.glDeleteFramebuffersEXT( 1, ( IntPtr )fboHandle ); } m_FboHandle = InvalidHandle; } if ( m_FboDepthHandle != InvalidHandle ) { fixed ( int* fboHandle = &m_FboDepthHandle ) { Gl.glDeleteRenderbuffersEXT( 1, ( IntPtr )fboHandle ); } m_FboDepthHandle = InvalidHandle; } } catch ( AccessViolationException ex ) { GraphicsLog.Exception( ex, "RenderTarget.Dispose failed - ignoring exception" ); } }
/// <summary> /// Adds a texture to the pack texture /// </summary> /// <param name="texture">Texture to add</param> /// <returns>Returns the rectangle in the pack texture where texture is placed. Returns null if no space could be found for texture</returns> public Rectangle Add( ITexture2d texture ) { return Add( Texture2dUtils.CreateBitmapFromTexture( texture ) ); }
/// <summary> /// Creates a new instance of a <see cref="Button"/>. /// </summary> /// <param name="normal">The image to use for normal state.</param> /// <param name="pressed">The image to use for pressed state.</param> public Button(ITexture2d normal, ITexture2d pressed) : this(normal, pressed, normal, normal) { }
/// <summary> /// Creates an instance of a SubTexture. /// </summary> /// <param name="tc">New texture coordinates in pixels.</param> /// <param name="parentTexture">The texture to create the subTexture from.</param> public SubTexture(Rectangle tc, ITexture2d parentTexture) : this(new RectangleF((float)tc.Left / parentTexture.Root.ImageDescription.Width, (float)tc.Top / parentTexture.Root.ImageDescription.Height, (float)tc.Width / parentTexture.Root.ImageDescription.Width, (float)tc.Height / parentTexture.Root.ImageDescription.Height), parentTexture) { }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// Creates an instance of a SubTexture. /// </summary> /// <param name="textureCoordinates">New texture coordinates relativ to parent texture [0;1].</param> /// <param name="parentTexture">The texture to create the subTexture from.</param> public SubTexture(RectangleF textureCoordinates, ITexture2d parentTexture) { this.parentTexture = parentTexture; this.textureCoordinates = CalcSubCoordinates(textureCoordinates, parentTexture.TextureCoordinates); this.imageDescription = CalcImageDescription(); }
/// <summary> /// Loads a manifest resource into an existing texture /// </summary> /// <param name="texture">Texture to load into</param> /// <param name="name">Resource name</param> /// <param name="generateMipMaps">If true, then mipmaps are generated for the created texture</param> public static void CreateTextureFromImageResource( ITexture2d texture, string name, bool generateMipMaps ) { Stream stream = AppDomainUtils.FindManifestResource( name ); LoadTextureFromImageStream( texture, stream, generateMipMaps ); }
/// <summary> /// Create a new guiSlider object. /// </summary> /// <param name="normal">The standard texture.</param> public GuiSlider(ITexture2d normal) : this(normal, normal, normal, normal) { }
/// <summary> /// Creates a texture from an image file /// </summary> /// <param name="texture">Texture to load into</param> /// <param name="path">Path to image file</param> /// <param name="generateMipMaps">If true, then mipmaps are generated for the created texture</param> public static void LoadTextureFromImageFile( ITexture2d texture, string path, bool generateMipMaps ) { Bitmap bmp = new Bitmap( path ); // Texture2dData texData = CreateTextureDataFromBitmap( bmp ); // texture.Create( texData, generateMipMaps ); texture.Create( bmp, generateMipMaps ); }
/// <summary> /// Creates a bitmap from a texture /// </summary> public static Bitmap CreateBitmapFromTexture( ITexture2d texture ) { Bitmap bmp = texture.ToBitmap( false )[ 0 ]; return bmp; }
/// <summary> /// Creates the underlying texture, accessible via <see cref="Texture"/> /// </summary> /// <param name="generateMipMaps">If true, then the texture gets mip-mapped</param> public void Finish( bool generateMipMaps ) { m_Texture = Texture2dUtils.CreateTextureFromBitmap( m_TextureImage, generateMipMaps ); }
/// <summary> /// Creates a new instance of a <see cref="Button"/>. /// </summary> /// <param name="normal">The image to use for normal state.</param> /// <param name="pressed">The image to use for pressed state.</param> /// <param name="hover">The image to use for mouseOver state.</param> public Button(ITexture2d normal, ITexture2d pressed, ITexture2d hover) : this(normal, pressed, hover, normal) { }
/// <summary> /// Setup constructor /// </summary> /// <param name="technique">Group technique</param> /// <param name="textures">Group textures</param> public GroupMaterial( ITechnique technique, ITexture2d[] textures ) { m_Technique = technique; m_Textures = textures; }
/// <summary> /// Creates a new instance of a <see cref="Button"/>. /// </summary> /// <param name="normal">The image to use for normal state.</param> public Button(ITexture2d normal) : this(normal, normal, normal, normal) { }
/// <summary> /// Creates a cell geometry group /// </summary> /// <returns>New cell geometry group</returns> public EnvironmentGraphicsData.CellGeometryGroup Create( ) { ITechnique technique = m_Material.Technique; ITexture2d[] textures = new ITexture2d[ m_Material.Textures.Length ]; for ( int textureIndex = 0; textureIndex < textures.Length; ++textureIndex ) { textures[ textureIndex ] = m_Material.Textures[ textureIndex ]; } EnvironmentGraphicsData.CellGeometryGroup group = new EnvironmentGraphicsData.CellGeometryGroup( m_Indices.ToArray( ), technique, textures ); return group; }
/// <summary> /// Creates the render target /// </summary> /// <param name="name">Render target name</param> /// <param name="width">Width of the render target</param> /// <param name="height">Height of the render target</param> /// <param name="colourFormat">Format of the render target colour buffer. If this is Undefined, then no colour buffer is created</param> /// <param name="depthBits">Number of bits per element in the depth buffer (0 for no depth buffer)</param> /// <param name="stencilBits">Number of bits per element in the stencil buffer (0 for no stencil buffer)</param> /// <param name="depthBufferAsTexture">If true, then depth buffer storage is created in a texture</param> public unsafe void Create( string name, int width, int height, TextureFormat colourFormat, int depthBits, int stencilBits, bool depthBufferAsTexture ) { // Requires the frame buffer extension if ( !ms_ExtensionPresent ) { throw new ApplicationException( "FBO extension not available - can't create render target" ); } // Generate the frame buffer object fixed ( int* handleMem = &m_FboHandle ) { Gl.glGenFramebuffersEXT( 1, ( IntPtr )handleMem ); } Gl.glBindFramebufferEXT( Gl.GL_FRAMEBUFFER_EXT, m_FboHandle ); GraphicsLog.Assert( Gl.glIsFramebufferEXT( m_FboHandle ) != 0, "Expected FBO handle to be valid" ); // Generate the depth render buffer object if ( depthBits != 0 ) { if ( depthBufferAsTexture ) { // Make sure extension is supported if ( !Gl.IsExtensionSupported( "GL_ARB_depth_texture" ) ) { throw new ApplicationException( "Can't add depth texture to render target - unsupported" ); } Gl.glEnable( Gl.GL_TEXTURE_2D ); // Create the depth texture OpenGlTexture2d texture = ( OpenGlTexture2d )Graphics.Factory.CreateTexture2d( ); switch ( depthBits ) { case 16 : texture.Create( new Texture2dData( width, height, TextureFormat.Depth16 ), false ); break; case 24 : texture.Create( new Texture2dData( width, height, TextureFormat.Depth24 ), false ); break; case 32 : texture.Create( new Texture2dData( width, height, TextureFormat.Depth32 ), false ); break; default : throw new ApplicationException( string.Format( "Unsupported render target depth buffer size of {0} bits", depthBits ) ); } // Add texture parameters (barfs otherwise - incomplete attachements) Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_DEPTH_TEXTURE_MODE, Gl.GL_LUMINANCE ); // Gl.glTexEnvf( Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_REPLACE ); Gl.glTexParameterf( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE ); Gl.glTexParameterf( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE ); Gl.glTexParameterf( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST ); Gl.glTexParameterf( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST ); // Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_COMPARE_MODE, Gl.GL_COMPARE_R_TO_TEXTURE ); // Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_COMPARE_FUNC, Gl.GL_LESS ); Gl.glFramebufferTexture2DEXT( Gl.GL_FRAMEBUFFER_EXT, Gl.GL_DEPTH_ATTACHMENT_EXT, Gl.GL_TEXTURE_2D, texture.TextureHandle, 0 ); m_DepthTexture = texture; } else { fixed ( int* handleMem = &m_FboDepthHandle ) { Gl.glGenFramebuffersEXT( 1, ( IntPtr )handleMem ); } Gl.glBindRenderbufferEXT( Gl.GL_RENDERBUFFER_EXT, m_FboDepthHandle ); Gl.glRenderbufferStorageEXT( Gl.GL_RENDERBUFFER_EXT, Gl.GL_DEPTH_COMPONENT, width, height ); Gl.glFramebufferRenderbufferEXT( Gl.GL_FRAMEBUFFER_EXT, Gl.GL_DEPTH_ATTACHMENT_EXT, Gl.GL_RENDERBUFFER_EXT, m_FboDepthHandle ); } OpenGlRenderer.CheckErrors( ); } // Generate the texture if ( colourFormat != TextureFormat.Undefined ) { // Create a texture OpenGlTexture2d texture = ( OpenGlTexture2d )Graphics.Factory.CreateTexture2d( ); texture.Create( new Texture2dData( width, height, colourFormat ), false ); // Add texture parameters (barfs otherwise - incomplete attachements) Gl.glTexParameterf( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE ); Gl.glTexParameterf( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE ); Gl.glTexParameterf( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR ); Gl.glTexParameterf( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR ); // Bind the texture to the frame buffer (creating it has already bound the texture) Gl.glFramebufferTexture2DEXT( Gl.GL_FRAMEBUFFER_EXT, Gl.GL_COLOR_ATTACHMENT0_EXT, Gl.GL_TEXTURE_2D, texture.TextureHandle, 0 ); OpenGlRenderer.CheckErrors( ); m_Texture = texture; } else { // No color buffer to draw to or read from Gl.glDrawBuffer( Gl.GL_NONE ); Gl.glReadBuffer( Gl.GL_NONE ); } if ( stencilBits != 0 ) { throw new ApplicationException( "OpenGL does not support render targets with stencil buffers - please set stencilBits to 0" ); } // Check if we've succesfully created the frame buffer object int status = Gl.glCheckFramebufferStatusEXT( Gl.GL_FRAMEBUFFER_EXT ); if ( status != Gl.GL_FRAMEBUFFER_COMPLETE_EXT ) { string problem; switch ( status ) { //case Gl.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENTS_EXT : problem = "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENTS_EXT"; break; case Gl.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT : problem = "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT"; break; case Gl.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT : problem = "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT"; break; //case Gl.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT : problem = "GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT"; break; case Gl.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT : problem = "GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT"; break; case Gl.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT : problem = "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT"; break; case Gl.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT : problem = "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT"; break; case Gl.GL_FRAMEBUFFER_UNSUPPORTED_EXT : problem = "GL_FRAMEBUFFER_UNSUPPORTED_EXT"; break; default : problem = "unknown error"; break; } throw new ApplicationException( string.Format( "Failed to create render target ({0}x{1} at {2}, {3} depth bits, {4} stencil bits). GL status = {5} ({6})", width, height, colourFormat, depthBits, stencilBits, status, problem ) ); } else { GraphicsLog.Info( "Created render target ({0}x{1} at {2}, {3} depth bits, {4} stencil bits)", width, height, colourFormat, depthBits, stencilBits ); } m_Name = name; m_Width = width; m_Height = height; Gl.glBindFramebufferEXT( Gl.GL_FRAMEBUFFER_EXT, 0 ); RenderTargets.AddCreatedRenderTarget( this ); }
/// <summary> /// Sets the lookup textures required by the atmosphere renderer /// </summary> /// <param name="scatteringTexture">Lookup table for in- and out-scattering coefficients</param> /// <param name="opticalDepthTexture">Lookup table for optical depth</param> public void SetLookupTextures( ITexture3d scatteringTexture, ITexture2d opticalDepthTexture ) { m_ScatteringTexture = scatteringTexture; m_OpticalDepthTexture = opticalDepthTexture; }
/// <summary> /// Writes a texture to a stream /// </summary> /// <param name="texture">Texture to write</param> /// <param name="stream">Stream to write to</param> /// <param name="writeMipMaps"> /// If true, all the texture's mip-map levels are written to the stream. Otherwise, only the level 0 /// texture is written. /// </param> /// <exception cref="ArgumentNullException">Thrown if texture or stream arguments are null</exception> public static void WriteTextureToStream( ITexture2d texture, Stream stream, bool writeMipMaps ) { Arguments.CheckNotNull( texture, "texture" ); Arguments.CheckNotNull( stream, "stream" ); Texture2dData[] textureDataArray = texture.ToTextureData( writeMipMaps ); using ( BinaryWriter writer = new BinaryWriter( stream ) ) { writer.Write( TextureFileFormatVersion1.TextureFileIdentifier ); TextureFileFormatVersion1.Group headerGroup = new TextureFileFormatVersion1.Group( ); headerGroup.GroupId = GroupIdentifier.TextureHeaderGroup; long startOfHeaderGroup = BeginGroup( writer, headerGroup ); // Write the header TextureFileFormatVersion1.Header header = new TextureFileFormatVersion1.Header( ); header.Dimensions = 2; header.Format = texture.Format; header.TextureDataEntries = textureDataArray.Length; header.Write( writer ); // Write texture data TextureFileFormatVersion1.Group textureDataGroup = new TextureFileFormatVersion1.Group( ); textureDataGroup.GroupId = GroupIdentifier.Texture2dDataGroup; for ( int textureDataIndex = 0; textureDataIndex < textureDataArray.Length; ++textureDataIndex ) { // Write the texture group long startOfTextureGroup = BeginGroup( writer, textureDataGroup ); Texture2dData textureData = textureDataArray[ textureDataIndex ]; // Write texture data writer.Write( textureData.Width ); writer.Write( textureData.Height ); writer.Write( textureData.Bytes ); // Update the texture group EndGroup( writer, startOfTextureGroup ); } // Update group with correct size EndGroup( writer, startOfHeaderGroup ); } }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// Creates a new instance of a <see cref="GuiGauge"/>. /// </summary> /// <param name="texture">The texture to use for the gauge.</param> public GuiGauge(ITexture2d texture) : base(texture) { }
/// <summary> /// Sets the texture to apply /// </summary> /// <param name="texture">Texture to apply</param> public Texture2dSamplerBase( ITexture2d texture ) { m_Texture = texture; }
/// <summary> /// Creates a new instance of an <see cref="Image"/>. /// </summary> /// <param name="texture">Texture to use for quad.</param> public Image(ITexture2d texture) { Init(texture); }
/// <summary> /// Create a new guiSlider object. /// </summary> /// <param name="normal">The standard texture.</param> /// <param name="hovered">The texture used if the slider is hovered.</param> public GuiSlider(ITexture2d normal, ITexture2d hovered) : this(normal, hovered, normal, normal) { }
/// <summary> /// Creates a texture from an image stream /// </summary> /// <param name="texture">Texture to load into</param> /// <param name="stream">Stream containing image data</param> /// <param name="generateMipMaps">If true, then mipmaps are generated for the created texture</param> public static void LoadTextureFromImageStream( ITexture2d texture, Stream stream, bool generateMipMaps ) { Bitmap bmp = new Bitmap( stream ); texture.Create( bmp, generateMipMaps ); }