//============================================================ public void ConfigureBackBuffer(int width, int height) { _size.Set(width, height); // 释放渲染目标 if (null != _nativeTarget) { _nativeTarget.Dispose(); _nativeTarget = null; } if (null != _nativeDepth) { _nativeDepth.Dispose(); _nativeDepth = null; } // 改变缓冲大小 SwapChainDescription description = _nativeSwap.Description; _nativeSwap.ResizeBuffers(description.BufferCount, width, height, Format.R8G8B8A8_UNorm, SwapChainFlags.None); // 重新创建渲染目标 CreatePrimaryRenderTarget(); CreateDepthBuffer(); // 设置视角 _nativeViewport = new Viewport(0, 0, width, height, 0.0f, 1.0f); _target.NativeViewport = _nativeViewport; _nativeTargetActive = _nativeTarget; _nativeDevice.OutputMerger.SetTargets(_nativeDepth, _nativeTargetActive); _nativeDevice.Rasterizer.SetViewports(_nativeViewport); }
//============================================================ public FDxBufferedTexture ExportTexture(string importFileName) { // 获得图片大小 Bitmap bmp = new Bitmap(importFileName); _size.Set(bmp.Width, bmp.Height); bmp.Dispose(); // 生成目标 Form form = new Form(); FDxDevice3D device = RDxCore.Adapter.CreateDevice(form.Handle, _size.Width, _size.Height); device.ModeWireFrame = false; // 设置几何体 FDxRegion region = new FDxRegion(); // 渲染几何体 FDxTechnique technique = RDxCore.TechniqueConsole.Get(device, "growing"); FDrGrowingGeometry geometry = new FDrGrowingGeometry(); geometry.Device = device; geometry.LoadResource(); // 绘制结果 region.Renderables.Push(geometry); // 设置目标 FDxBufferedTexture texture = new FDxBufferedTexture(); texture.Device = device; texture.Create(_size.Width, _size.Height); // 绘制目标 FDxTexture originTexture = new FDxTexture(); originTexture.Device = device; originTexture.LoadFile(importFileName); geometry.Material.Textures.Push(originTexture); // 绘制目标 FDxTexture importTexture = new FDxTexture(); importTexture.Device = device; importTexture.LoadFile(importFileName); geometry.Material.Textures.Push(importTexture); MemoryStream stream = new MemoryStream(); for (int n = 0; n < _borderCount; n++) { device.SetRenderTarget(texture); // 绘制目标 technique.Draw(region); device.SetRenderTarget(); // 复制渲染目标为开始 //importTexture.CopyFrom(texture); texture.SaveStream(stream); importTexture.LoadStream(stream); } // 保存内容 return(texture); }
//============================================================ // <T>更新属性。</T> //============================================================ public void Update() { // 测试有效区域 SIntRectangle rect = new SIntRectangle(); RBitmap.TestValidRectangle(_bitmap, rect, _validAlpha); // 设置属性 _size.Set(_bitmap.Width, _bitmap.Height); _validLocation.Set(rect.Left, rect.Top); _validSize.Set(rect.Width, rect.Height); }
//============================================================ // <T>打开数据内容。</T> //============================================================ public void Open() { if (null != _image) { _image.Dispose(); _image = null; } _image = new FBitmap(); _image.LoadFile(_fileName); _size.Set(_image.Width, _image.Height); _length = new FileInfo(_fileName).Length; }
//============================================================ // <T>导出资源。</T> //============================================================ public void Merge() { // 计算范围 int clipCount = ClipNotEmptyCount; FRsResourceClip firstClip = FristClip; int frameCount = 0; if (null != firstClip) { frameCount = firstClip.FrameCount; } else { RMoCore.TrackConsole.Write(this, "Merge", "Animatioin is valid, first clip is empty. (code={0})", Code); return; } int width = _size.Width * frameCount; int height = _size.Height * clipCount; // 计算是否合并 using (Bitmap bitmap = new Bitmap(width, height)) { // 合并图片 int y = 0; foreach (FRsResourceClip clip in _clips) { if (clip != null) { if (!clip.Frames.IsEmpty()) { for (int x = 0; x < frameCount; x++) { FRsResourceFrame frame = clip.Frames[x]; int cx = _size.Width * x; int cy = _size.Height * y; if (frame.ValidBitmap != null) { frame.MergeLocation.Set(cx, cy); RBitmap.Copy(frame.ValidBitmap, new SIntRectangle(0, 0, frame.ValidBitmap.Width, frame.ValidBitmap.Height), bitmap, frame.MergeLocation); } } y++; } } } // 存储图片 _mergeFileName = RContent2dManager.ResourceConsole.MergeDirectory + "\\" + Code + ".png"; RDirectory.MakeDirectoriesForFile(_mergeFileName); bitmap.Save(_mergeFileName); _mergeSize.Set(bitmap.Width, bitmap.Height); } }
//============================================================ public void LoadFile(string fileName) { _nativeTexture = Texture2D.FromFile(_device.NativeAdapter, fileName); _size.Set(_nativeTexture.Description.Width, _nativeTexture.Description.Height); _nativeResource = new ShaderResourceView(_device.NativeAdapter, _nativeTexture); }