public Texture2D(int Width, int Height, byte[] Data) { this.Width = Width; this.Height = Height; this.TexWidth_ = Width - 1; this.TexHeight_ = Height - 1; Pixels_ = new Colorf[Height][]; PixelsVec_ = new Vector <double> [Width * Height]; for (var Y = 0; Y < Height; ++Y) { Pixels_[Y] = new Colorf[Width]; for (var X = 0; X < Width; ++X) { var Index = (Y * Width + X) << 2; Pixels_[Y][X] = new Colorf(Data[Index + 2] / 255.0f, Data[Index + 1] / 255.0f, Data[Index + 0] / 255.0f, Data[Index + 3] / 255.0f); PixelsVec_[Index >> 2] = new Vector <double>(new double[] { Data[Index + 2] / 255.0d, Data[Index + 1] / 255.0d, Data[Index + 0] / 255.0d, Data[Index + 3] / 255.0d }); } } unsafe { PixelsVecPointer_ = (double *)Unsafe.AsPointer(ref PixelsVec_[0]); } WarpMode_ = TextureWarpMode.Repeat; BorderColor_ = Colorf.Black; FilterMode_ = TextureFilterMode.Linear; }
internal RenderTarget(IntVector2 size, TextureFilterMode textureFilterMode) { Size = size; ColorTexture = GL.GenTexture(); _fbo = GL.Ext.GenFramebuffer(); ResetFbo(textureFilterMode); }
public LiyfSoftRender() { InitializeComponent(); mFrameBuff = new Bitmap(this.MaximumSize.Width, this.MaximumSize.Height); mFrameGraphics = Graphics.FromImage(mFrameBuff); mZBuff = new float[this.MaximumSize.Width, this.MaximumSize.Height]; mCamera = new Camera(new Vector3D(0, 0, 0, 1), new Vector3D(0, 0, 1, 1), new Vector3D(0, 1, 0, 1), (float)(System.Math.PI / 4f), (this.MaximumSize.Width / (float)this.MaximumSize.Height), 1f, 500f ); Image imge = Image.FromFile("../../Texture/timg.jpg"); mTexture = new Bitmap(imge, 256, 256); mFilterMode = TextureFilterMode.Bilinear; mMesh = new Mesh(pointList, indexs, vertColors, uvs); System.Timers.Timer mainTimer = new System.Timers.Timer(1000 / 30f); mainTimer.Elapsed += new System.Timers.ElapsedEventHandler(Tick); mainTimer.AutoReset = true; mainTimer.Enabled = true; mainTimer.Start(); }
/// <summary> /// Constructor initializes a Texture from a pixelData byte buffer, width and height in pixels and <see cref="ImagePixelFormat"/>. /// </summary> /// <param name="pixelData">The raw pixelData byte buffer that makes up the texture.</param> /// <param name="width">Width in pixels.</param> /// <param name="height">Height in pixels.</param> /// <param name="colorFormat">Provides additional information about pixel encoding.</param> /// <param name="generateMipMaps">Defines if mipmaps are created.</param> /// <param name="filterMode">Defines the filter mode <see cref="TextureFilterMode"/>.</param> /// <param name="wrapMode">Defines the wrapping mode <see cref="TextureWrapMode"/>.</param> public Texture(byte[] pixelData, int width, int height, ImagePixelFormat colorFormat, bool generateMipMaps = true, TextureFilterMode filterMode = TextureFilterMode.Linear, TextureWrapMode wrapMode = TextureWrapMode.Repeat) { SessionUniqueIdentifier = Suid.GenerateSuid(); _imageData = new ImageData(pixelData, width, height, colorFormat); DoGenerateMipMaps = generateMipMaps; FilterMode = filterMode; WrapMode = wrapMode; }
public Texture2D(string path, TextureWrapMode wrapMode, TextureFilterMode filterMode) { texture = GL.GenTexture(); Bitmap bitmap = new Bitmap(path); Rectangle rectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height); BitmapData bitmap_data = bitmap.LockBits(rectangle, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); TextureMagFilter magFilter; TextureMinFilter minFilter; switch (filterMode) { case TextureFilterMode.Nearest: magFilter = TextureMagFilter.Nearest; minFilter = TextureMinFilter.Nearest; break; case TextureFilterMode.Linear: magFilter = TextureMagFilter.Linear; minFilter = TextureMinFilter.Linear; break; case TextureFilterMode.NearestMipmap: magFilter = TextureMagFilter.Nearest; minFilter = TextureMinFilter.NearestMipmapNearest; break; case TextureFilterMode.LinearMipmap: magFilter = TextureMagFilter.Linear; minFilter = TextureMinFilter.LinearMipmapLinear; break; default: magFilter = TextureMagFilter.Nearest; minFilter = TextureMinFilter.Nearest; break; } Bind(0); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmap.Width, bitmap.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bitmap_data.Scan0); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)minFilter); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)magFilter); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)wrapMode); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)wrapMode); if (filterMode == TextureFilterMode.NearestMipmap || filterMode == TextureFilterMode.LinearMipmap) { GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); } Unbind(0); bitmap.UnlockBits(bitmap_data); }
public Vector4 Tex2D(Vector2 texcoord, TextureFilterMode textureFilterMode) { if (textureFilterMode == TextureFilterMode.Point) { return(PointSample(texcoord)); } return(BilinearFiltering(texcoord)); //TODO trilinear }
private uint _showTrisCount; //测试数据 public SoftRendererDemo() { //初始化窗体 InitializeComponent(); try { //载入贴图 Image img = Image.FromFile("../../Texture/texture.jpg"); //转换成位图 _texture = new Bitmap(img, 256, 256); } catch (Exception) { _texture = new Bitmap(256, 256); initTexture(); } //设置渲染模式 _currentMode = RenderMode.Textured; //设置灯光开闭 _lightMode = LightMode.OFF; //设置采样方式 _textureFilterMode = TextureFilterMode.Point; //初始化帧缓冲 _frameBuff = new Bitmap(this.MaximumSize.Width, this.MaximumSize.Height); _frameG1 = Graphics.FromImage(_frameBuff); _zBuff = new float[this.MaximumSize.Height, this.MaximumSize.Width]; //环境光颜色 _ambientColor = new RenderData.Color(1, 1, 1); //加载数据 _mesh = new Mesh(CubeTestData.pointList, CubeTestData.indexs, CubeTestData.uvs, CubeTestData.vertColors, CubeTestData.norlmas, CubeTestData.mat); //光源 Vector3D lightPos = new Vector3D(50, 0, 0); RenderData.Color lightColor = new RenderData.Color(1, 1, 1); _light = new Light(lightPos, lightColor); //相机 Vector3D cameraPos = new Vector3D(0, 0, 0, 1); Vector3D cameraLookAt = new Vector3D(0, 0, 1, 1); Vector3D cameraUp = new Vector3D(0, 1, 0, 0); float cameraFov = (float)System.Math.PI / 4; float cameraAspect = MaximumSize.Width / (float)MaximumSize.Height; float cameraZn = 1f; float cameraZf = 500f; _camera = new Camera(cameraPos, cameraLookAt, cameraUp, cameraFov, cameraAspect, cameraZn, cameraZf); //定时刷新任务 System.Timers.Timer mainTimer = new System.Timers.Timer(1000 / 60f); mainTimer.Elapsed += new ElapsedEventHandler(Tick); mainTimer.AutoReset = true; mainTimer.Enabled = true; mainTimer.Start(); }
private void ReadGameCubeData(BinaryReader binaryReader) { binaryReader.BaseStream.Position += 2; byte addressMode = binaryReader.ReadByte(); addressModeU = (TextureAddressMode)((addressMode & 0xF0) >> 4); addressModeV = (TextureAddressMode)(addressMode & 0x0F); filterMode = (TextureFilterMode)binaryReader.ReadByte(); gcnUnknown1 = Shared.Switch(binaryReader.ReadInt32()); gcnUnknown2 = Shared.Switch(binaryReader.ReadInt32()); gcnUnknown3 = Shared.Switch(binaryReader.ReadInt32()); gcnUnknown4 = Shared.Switch(binaryReader.ReadInt32()); textureName = ReadString(binaryReader); alphaName = ReadString(binaryReader); if (ReadFileMethods.treatStuffAsByteArray) { sectionData = binaryReader.ReadBytes((int)(sectionSize - (binaryReader.BaseStream.Position - startSectionPosition))); return; } rasterFormatFlags = (TextureRasterFormat)Shared.Switch(binaryReader.ReadInt32()); width = Shared.Switch(binaryReader.ReadInt16()); height = Shared.Switch(binaryReader.ReadInt16()); bitDepth = binaryReader.ReadByte(); mipMapCount = binaryReader.ReadByte(); type = binaryReader.ReadByte(); compression = binaryReader.ReadByte(); int palleteSize = ((rasterFormatFlags & TextureRasterFormat.RASTER_PAL4) != 0) ? 0x80 / 4 : ((rasterFormatFlags & TextureRasterFormat.RASTER_PAL8) != 0) ? 0x400 / 4 : 0; if (palleteSize != 0) { palette = new Color[palleteSize]; for (int i = 0; i < palleteSize; i++) { palette[i] = new Color(binaryReader.ReadInt32()); } } mipMaps = new MipMapEntry[mipMapCount]; for (int i = 0; i < mipMapCount; i++) { int dataSize = Shared.Switch(binaryReader.ReadInt32()); byte[] data = binaryReader.ReadBytes(dataSize); mipMaps[i] = new MipMapEntry(dataSize, data); } }
/// <summary> /// 根据uv值对一个位图进行采样 /// /// 采用Clamp模式对位图进行采样(即当uv大于1或小于0时,直接进行截断) /// </summary> /// <param name="texture2D"></param> /// <param name="u"></param> /// <param name="v"></param> /// <returns></returns> public static Color01 Tex2D( Bitmap texture2D, float u, float v, TextureFilterMode filterMode = TextureFilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Clamp) { // 根据纹理采样模式设置uv switch (wrapMode) { case TextureWrapMode.Clamp: // 采用Clamp模式,直接对uv进行截断 u = MathF.Clamp01(u); v = MathF.Clamp01(v); break; case TextureWrapMode.Repeat: // 采用Repeat模式,uv只取小数点部位 u = MathF.Frac(u); v = MathF.Frac(v); break; } Color01 finalColor = Color01.White; // 根据纹理过滤模式设置当前uv点的像素颜色 switch (filterMode) { case TextureFilterMode.Point: // 点采样模式(最近邻采样), // 选取距离当前采样点(u,v)最近的纹素作为当前像素的颜色 int tx = (int)(u * (texture2D.Width - 1)); int ty = (int)(v * (texture2D.Height - 1)); tx = MathF.Clamp(tx, 0, texture2D.Width); ty = MathF.Clamp(ty, 0, texture2D.Height); Color color = texture2D.GetPixel(tx, ty); finalColor = Color01.FromColor(color); break; case TextureFilterMode.Bilinear: // 双线性采样 // (不开启MipMap时,会作用于Level 0(即原始图片大小), // 开启后会选择图片大小与3D图形大小最相近的一层) // 选取与当前采样区域邻近的四个纹素的均值作为本次采样的结果 break; } return(finalColor); }
/// <summary> /// Initialize a Texture from an existing IImageData. The input IImageData will be copied into this Texture via <seealso cref="Blt"/> command. /// </summary> /// <param name="imageData">The existing <see cref="IImageData"/> that will be copied to initialize a Texture instance.</param> /// <param name="generateMipMaps">Defines if mipmaps are created.</param> /// <param name="filterMode">Defines the filter mode <see cref="TextureFilterMode"/>.</param> /// <param name="wrapMode">Defines the wrapping mode <see cref="TextureWrapMode"/>.</param> public Texture(IImageData imageData, bool generateMipMaps = true, TextureFilterMode filterMode = TextureFilterMode.Linear, TextureWrapMode wrapMode = TextureWrapMode.Repeat) { SessionUniqueIdentifier = Suid.GenerateSuid(); _imageData = new ImageData( new byte[imageData.Width * imageData.Height * imageData.PixelFormat.BytesPerPixel], imageData.Width, imageData.Height, imageData.PixelFormat); _imageData.Blt(0, 0, imageData); DoGenerateMipMaps = generateMipMaps; FilterMode = filterMode; WrapMode = wrapMode; }
/// <summary> /// Creates a new instance of type "WritableTexture". /// </summary> /// <param name="texType">Defines the type of the render texture.</param> /// <param name="colorFormat">The color format of the texture, <see cref="ImagePixelFormat"/></param> /// <param name="width">Width in px.</param> /// <param name="height">Height in px.</param> /// <param name="generateMipMaps">Defines if mipmaps are created.</param> /// <param name="filterMode">Defines the filter mode <see cref="TextureFilterMode"/>.</param> /// <param name="wrapMode">Defines the wrapping mode <see cref="TextureWrapMode"/>.</param> /// <param name="compareMode">The textures compare mode. If uncertain, leaf on NONE, this is only important for depth (shadow) textures (<see cref="TextureCompareMode"/>).</param> /// <param name="compareFunc">The textures compare function. If uncertain, leaf on LEESS, this is only important for depth (shadow) textures and if the CompareMode isn't NONE (<see cref="Compare"/>)</param> public WritableTexture(RenderTargetTextureTypes texType, ImagePixelFormat colorFormat, int width, int height, bool generateMipMaps = true, TextureFilterMode filterMode = TextureFilterMode.Linear, TextureWrapMode wrapMode = TextureWrapMode.Repeat, TextureCompareMode compareMode = TextureCompareMode.None, Compare compareFunc = Compare.Less) { SessionUniqueIdentifier = Suid.GenerateSuid(); PixelFormat = colorFormat; Width = width; Height = height; DoGenerateMipMaps = generateMipMaps; FilterMode = filterMode; WrapMode = wrapMode; TextureType = texType; CompareMode = compareMode; CompareFunc = compareFunc; }
protected override void readStruct(Stream stream) { using BinaryReader reader = new BinaryReader(stream); filterMode = EnumUtils.intToEnum <TextureFilterMode>(reader.ReadByte()); byte addressing = reader.ReadByte(); uAddressingMode = EnumUtils.intToEnum <TextureAddressingMode>(addressing & 0xf); vAddressingMode = EnumUtils.intToEnum <TextureAddressingMode>(addressing >> 4); UInt16 flags = reader.ReadUInt16(); useMipLevels = (flags & 1) > 0; // more flags are not known yet }
public SamplerState() { Filter = TextureFilter.Linear; AddressU = TextureAddressMode.Wrap; AddressV = TextureAddressMode.Wrap; AddressW = TextureAddressMode.Wrap; BorderColor = Color.White; MaxAnisotropy = 4; MaxMipLevel = 0; MipMapLevelOfDetailBias = 0.0f; ComparisonFunction = CompareFunction.Never; FilterMode = TextureFilterMode.Default; }
public float alpha; //旋转角 public void InitDevice(int _width, int _height) { this.width = _width; this.height = _height; texWidth = 256; texHeight = 256; renderState = RenderState.COLOR; textureFilterMode = TextureFilterMode.POINT; lightMode = LightMode.ON; light = new Light(new Vector3(50, 0, 0, 1), new Color(0.3f, 0.3f, 0.3f), new Color(1, 1, 1), new Color(1, 1, 1)); camera = new Camera(new Vector3(3.5f, 0, 0, 1), new Vector3(0, 0, 0, 1), new Vector3(0, 0, 1, 1), (float)Math.PI * 0.5f, ((float)_width) / ((float)_height), 1f, 500f); ts = new Transform(_width, _height); if (renderState == RenderState.TEXTURE) { InitTexture(texWidth, texHeight); } //缓冲及画板 frameBuffer = new Bitmap(_width, _height); Gframe = Graphics.FromImage(frameBuffer); zBuffer = new float[_width, _height]; //双缓存区 dc = new BufferedGraphicsContext(); backBuffer = dc.Allocate(Gframe, new Rectangle(new Point(0, 0), new Size(800, 600))); //输入立方体的信息,包括法向量 mesh = new Vectex[8] { new Vectex(1, -1, 1, 1, 0, 0, 1, 0.2f, 0.2f, 1), new Vectex(-1, -1, 1, 1, 0, 1, 0.2f, 1f, 0.2f, 1), new Vectex(-1, 1, 1, 1, 1, 1, 0.2f, 0.2f, 1, 1), new Vectex(1, 1, 1, 1, 1, 0, 1, 0.2f, 1, 1), new Vectex(1, -1, -1, 1, 0, 0, 1, 1, 0.2f, 1), new Vectex(-1, -1, -1, 1, 0, 1, 0.2f, 1, 1, 1), new Vectex(-1, 1, -1, 1, 1, 1, 1, 0.3f, 0.3f, 1), new Vectex(1, 1, -1, 1, 1, 0, 0.2f, 1, 0.3f, 1), }; for (int i = 0; i < 8; i++) { //直接将顶点的位置方向作为其法向方向。 mesh[i].nomal = Vector3.Colone(mesh[i].pos); mesh[i].nomal.Normalized(); } alpha = 1f; }
internal static TextureMinFilter ToMinFilter(TextureFilterMode filterMode) { switch (filterMode) { case TextureFilterMode.Nearest: return(TextureMinFilter.Nearest); case TextureFilterMode.Linear: return(TextureMinFilter.Linear); default: throw new ArgumentException(); } }
private SamplerState(SamplerState cloneSource) { Name = cloneSource.Name; _filter = cloneSource._filter; _addressU = cloneSource._addressU; _addressV = cloneSource._addressV; _addressW = cloneSource._addressW; _borderColor = cloneSource._borderColor; _maxAnisotropy = cloneSource._maxAnisotropy; _maxMipLevel = cloneSource._maxMipLevel; _mipMapLevelOfDetailBias = cloneSource._mipMapLevelOfDetailBias; _comparisonFunction = cloneSource._comparisonFunction; _filterMode = cloneSource._filterMode; }
protected TextureLoadingParameters(IEnumerable <string> filePaths, TextureWrapMode wrapS, TextureWrapMode wrapT, TextureFilterMode minFilter, TextureFilterMode magFilter) : base(filePaths) { if (filePaths.Count() != 1) { Log.WriteLine("A texture resource must have exactly one file.", LogType.Error); return; } WrapS = wrapS; WrapT = wrapT; MinFilter = minFilter; MagFilter = magFilter; }
internal void ResetFbo(TextureFilterMode textureFilterMode) { GL.BindTexture(TextureTarget.Texture2D, ColorTexture); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, Size.X, Size.Y, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); int filter; switch (textureFilterMode) { case TextureFilterMode.Smooth: filter = (int)TextureMagFilter.Linear; break; case TextureFilterMode.Sharp: filter = (int)TextureMagFilter.Nearest; break; default: throw new ArgumentOutOfRangeException(nameof(textureFilterMode), textureFilterMode, null); } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, filter); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, filter); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)OpenTK.Graphics.OpenGL.TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)OpenTK.Graphics.OpenGL.TextureWrapMode.ClampToEdge); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, _fbo); GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, ColorTexture, 0); FramebufferErrorCode errorCode = GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt); if (errorCode != FramebufferErrorCode.FramebufferComplete) { Engine.Get.Debug.Error($"Failed to create render target: {errorCode}"); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); GL.Ext.DeleteFramebuffer(_fbo); return; } GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); GL.BindTexture(TextureTarget.Texture2D, 0); }
public TextureStruct_0001 Read(BinaryReader binaryReader) { sectionIdentifier = Section.Struct; sectionSize = binaryReader.ReadInt32(); renderWareVersion = binaryReader.ReadInt32(); filterMode = (TextureFilterMode)binaryReader.ReadByte(); byte addressMode = binaryReader.ReadByte(); addressModeU = (TextureAddressMode)((addressMode & 0xF0) >> 4); addressModeV = (TextureAddressMode)(addressMode & 0x0F); useMipLevels = binaryReader.ReadUInt16(); return(this); }
public SamplerStateDesc(SamplerStateTypes type) { switch (type) { case SamplerStateTypes.Point_Wrap: filterMin = TextureFilterMode.Nearest; filterMinMiped = TextureFilterMode.Nearest; filterMag = TextureFilterMode.Nearest; addressU = TextureWrapMode.Repeat; addressV = TextureWrapMode.Repeat; addressW = TextureWrapMode.Repeat; break; case SamplerStateTypes.Point_Clamp: filterMin = TextureFilterMode.Nearest; filterMinMiped = TextureFilterMode.Nearest; filterMag = TextureFilterMode.Nearest; addressU = TextureWrapMode.ClampToEdge; addressV = TextureWrapMode.ClampToEdge; addressW = TextureWrapMode.ClampToEdge; break; case SamplerStateTypes.Linear_Wrap: filterMin = TextureFilterMode.Linear; filterMinMiped = TextureFilterMode.Linear; filterMag = TextureFilterMode.Linear; addressU = TextureWrapMode.Repeat; addressV = TextureWrapMode.Repeat; addressW = TextureWrapMode.Repeat; break; case SamplerStateTypes.Linear_Clamp: filterMin = TextureFilterMode.Linear; filterMinMiped = TextureFilterMode.Linear; filterMag = TextureFilterMode.Linear; addressU = TextureWrapMode.ClampToEdge; addressV = TextureWrapMode.ClampToEdge; addressW = TextureWrapMode.ClampToEdge; break; default: Debug.ThrowError("SamplerStateDesc", "Unsuported SamplerStateType"); break; } }
internal Texture2D(Bitmap bitmap, TextureWrapMode wrapS, TextureWrapMode wrapT, TextureFilterMode minFilter, TextureFilterMode magFilter, int textureID) { this.textureID = textureID; this.bitmap = bitmap; this.wrapS = wrapS; this.wrapT = wrapT; this.hasDirtyWrap = false; this.minFilter = minFilter; this.magFilter = magFilter; this.textureCoordinates = Texture.GetDefaultTextureCoordinates(); this.hasDirtyFilter = false; this.hasDirtyData = false; }
private void ReadPS2Data(BinaryReader binaryReader) { filterMode = (TextureFilterMode)binaryReader.ReadByte(); byte addressMode = binaryReader.ReadByte(); addressModeU = (TextureAddressMode)((addressMode & 0xF0) >> 4); addressModeV = (TextureAddressMode)(addressMode & 0x0F); binaryReader.BaseStream.Position += 2; binaryReader.ReadInt32(); textureName = new String_0002().Read(binaryReader).stringString; binaryReader.ReadInt32(); alphaName = new String_0002().Read(binaryReader).stringString; binaryReader.ReadInt32(); int sizeOfdata = binaryReader.ReadInt32(); binaryReader.ReadInt32(); sectionData = binaryReader.ReadBytes(sizeOfdata); }
private uint _showTrisCount; //测试数据,记录当前显示的三角形数 public SoftRendererDemo() { //VectorMatrixTestCase.Test(); InitializeComponent(); try { System.Drawing.Image img = System.Drawing.Image.FromFile("../../Texture/texture.jpg"); _texture = new Bitmap(img, 256, 256); } catch (Exception) { _texture = new Bitmap(256, 256); initTexture(); } // _currentMode = RenderMode.Textured; _lightMode = LightMode.On; _textureFilterMode = TextureFilterMode.Bilinear; // _frameBuff = new Bitmap(this.MaximumSize.Width, this.MaximumSize.Height); _frameG = Graphics.FromImage(_frameBuff); _zBuff = new float[this.MaximumSize.Height, this.MaximumSize.Width]; _ambientColor = new RenderData.Color(1f, 1f, 1f); _mesh = new Mesh(CubeTestData.pointList, CubeTestData.indexs, CubeTestData.uvs, CubeTestData.vertColors, CubeTestData.norlmas, QuadTestData.mat); //_mesh = new Mesh(QuadTestData.pointList, QuadTestData.indexs, QuadTestData.uvs, QuadTestData.vertColors, QuadTestData.norlmas, QuadTestData.mat); //打开注释可以切换mesh //定义光照 _light = new Light(new Vector3D(50, 0, 0), new RenderData.Color(1, 1, 1)); //定义相机 _camera = new Camera(new Vector3D(0, 0, 0, 1), new Vector3D(0, 0, 1, 1), new Vector3D(0, 1, 0, 0), (float)System.Math.PI / 4, this.MaximumSize.Width / (float)this.MaximumSize.Height, 1f, 500f); System.Timers.Timer mainTimer = new System.Timers.Timer(1000 / 60f); mainTimer.Elapsed += new ElapsedEventHandler(Tick); mainTimer.AutoReset = true; mainTimer.Enabled = true; mainTimer.Start(); // }
private float[,] _zBuff; //z缓冲,用来做深度测试 #endregion Fields #region Constructors public SoftRendererDemo() { //VectorMatrixTestCase.Test(); InitializeComponent(); try { System.Drawing.Image img = System.Drawing.Image.FromFile("../../Texture/texture.jpg"); _texture = new Bitmap(img, 256, 256); } catch(Exception) { _texture = new Bitmap(256, 256); initTexture(); } // _currentMode = RenderMode.Textured; _lightMode = LightMode.On; _textureFilterMode = TextureFilterMode.Bilinear; // _frameBuff = new Bitmap(this.MaximumSize.Width, this.MaximumSize.Height); _frameG = Graphics.FromImage(_frameBuff); _zBuff = new float[this.MaximumSize.Height, this.MaximumSize.Width]; _ambientColor = new RenderData.Color(1f, 1f, 1f); _mesh = new Mesh(CubeTestData.pointList, CubeTestData.indexs, CubeTestData.uvs, CubeTestData.vertColors, CubeTestData.norlmas, QuadTestData.mat); //_mesh = new Mesh(QuadTestData.pointList, QuadTestData.indexs, QuadTestData.uvs, QuadTestData.vertColors, QuadTestData.norlmas, QuadTestData.mat); //打开注释可以切换mesh //定义光照 _light = new Light(new Vector3D(50, 0, 0), new RenderData.Color(1, 1, 1)); //定义相机 _camera = new Camera(new Vector3D(0, 0, 0, 1), new Vector3D(0, 0, 1, 1), new Vector3D(0, 1, 0, 0), (float)System.Math.PI / 4, this.MaximumSize.Width / (float)this.MaximumSize.Height, 1f, 500f); System.Timers.Timer mainTimer = new System.Timers.Timer(1000 / 60f); mainTimer.Elapsed += new ElapsedEventHandler(Tick); mainTimer.AutoReset = true; mainTimer.Enabled = true; mainTimer.Start(); // }
#pragma warning disable CS0246 // 未能找到类型或命名空间名“All”(是否缺少 using 指令或程序集引用?) public static All TranslateTextureFilterModeMag(TextureFilterMode filterMode) #pragma warning restore CS0246 // 未能找到类型或命名空间名“All”(是否缺少 using 指令或程序集引用?) { switch (filterMode) { case TextureFilterMode.Point: return(All.Nearest); case TextureFilterMode.Linear: return(All.Linear); case TextureFilterMode.Anisotropic: return(All.Linear); case TextureFilterMode.PointMipLinear: return(All.Nearest); case TextureFilterMode.LinearMipPoint: return(All.Nearest); case TextureFilterMode.MinPointMagLinearMipPoint: return(All.Linear); case TextureFilterMode.MinPointMagLinearMipLinear: return(All.Linear); case TextureFilterMode.MinLinearMagPointMipPoint: return(All.Nearest); case TextureFilterMode.MinLinearMagPointMipLinear: return(All.Nearest); default: throw new InvalidOperationException("Unsupported texture filter mode."); } }
public void SetFilter(TextureFilterMode mode) { //FIXME:not used //Debug.Assert(false); }
private void ReadNormalData(BinaryReader binaryReader, int endOfSectionPosition) { filterMode = (TextureFilterMode)binaryReader.ReadByte(); byte addressMode = binaryReader.ReadByte(); addressModeU = (TextureAddressMode)((addressMode & 0xF0) >> 4); addressModeV = (TextureAddressMode)(addressMode & 0x0F); binaryReader.BaseStream.Position += 2; textureName = ReadString(binaryReader); alphaName = ReadString(binaryReader); rasterFormatFlags = (TextureRasterFormat)binaryReader.ReadInt32(); hasAlpha = binaryReader.ReadInt32() != 0; width = binaryReader.ReadInt16(); height = binaryReader.ReadInt16(); bitDepth = binaryReader.ReadByte(); mipMapCount = binaryReader.ReadByte(); type = binaryReader.ReadByte(); compression = binaryReader.ReadByte(); if (platformType == 5) { totalMipMapDataSize = binaryReader.ReadInt32(); } int palleteSize = ((rasterFormatFlags & TextureRasterFormat.RASTER_PAL4) != 0) ? 0x80 / 4 : ((rasterFormatFlags & TextureRasterFormat.RASTER_PAL8) != 0) ? 0x400 / 4 : 0; if (palleteSize != 0) { palette = new Color[palleteSize]; for (int i = 0; i < palleteSize; i++) { palette[i] = new Color(binaryReader.ReadInt32()); } } int passedSize = 0; mipMaps = new MipMapEntry[mipMapCount]; for (int i = 0; i < mipMapCount; i++) { int dataSize = 0; if (platformType == 8) { dataSize = binaryReader.ReadInt32(); } else if (platformType == 5) { dataSize = BiggestPowerOfTwoUnder(totalMipMapDataSize - passedSize); } byte[] data = binaryReader.ReadBytes(dataSize); mipMaps[i] = new MipMapEntry(dataSize, data); passedSize += dataSize; } }
public TextureLoadingParameters(IEnumerable <string> filePaths, TextureWrapMode wrapMode, TextureFilterMode filterMode) : this(filePaths, wrapMode, wrapMode, filterMode, filterMode) { }
public Texture2D(string path, TextureFilterMode filterMode) : this(path, TextureWrapMode.ClampToBorder, filterMode) { }
/// <summary> /// Set filtering mode. /// </summary> private void SetFilterMode(TextureFilterMode filter) { Runtime.ValidateRefCounted(this); Texture_SetFilterMode(handle, filter); }
internal static extern void Texture_SetFilterMode(IntPtr handle, TextureFilterMode filter);