public static H1GpuMemoryPageTexture3D CreatePage(H1GpuMemoryChunk owner, H1Texture3D.Description desc) { H1GpuMemoryPageTexture3D newTexture3D = new H1GpuMemoryPageTexture3D(owner); // convert texture1D description to appropriate input parameters to create texture1D H1PixelFormat format = desc.Format; Int32 width = Convert.ToInt32(desc.Width); Int32 height = Convert.ToInt32(desc.Height); Int32 depthOrArraySize = Convert.ToInt32(desc.Depth); H1OptionalParametersForTexture options = null; if (desc.MipLevels != 1) // if there is any optional property to apply { options = new H1OptionalParametersForTexture() { MipLevels = Convert.ToUInt16(desc.MipLevels), }; } if (!newTexture3D.CreatePage(format, width, height, depthOrArraySize, options)) { return(null); } return(newTexture3D); }
// static method for more general creat page for texture resided in GPU memory protected virtual Boolean CreatePage(H1PixelFormat format, Int32 width, Int32 height, Int32 depthOrArraySize, H1OptionalParametersForTexture options = null) { // invalid call for create page if (Owner.PageType != H1GpuMemoryPageType.Normal) { return(false); } // create resource encapsulated GPU API layer H1HeapType heapType = H1HeapType.Unknown; H1ResourceStates usage = H1ResourceStates.Invalid; if (Owner.Type != H1GpuMemoryType.GpuWritable) { // invalid gpu memory type // CpuWritable type should be H1GpuMemoryPageSegmented type return(false); } // GPU-writable heapType = H1HeapType.Default; H1GpuResourceDesc resourceDesc = new H1GpuResourceDesc(); resourceDesc.Alignment = 0; // depends on GDI decision for choosing appropriate alignment resourceDesc.Width = Convert.ToUInt32(width); resourceDesc.Height = Convert.ToUInt32(height); resourceDesc.DepthOrArraySize = Convert.ToUInt16(depthOrArraySize); resourceDesc.Format = format; // these description properties are default values resourceDesc.SampleDesc.Count = 1; resourceDesc.SampleDesc.Quality = 0; resourceDesc.Layout = H1TextureLayout.RowMajor; resourceDesc.MipLevels = 1; // apply optional parameters if (options != null) { resourceDesc.Flags = options.ResourceFlags; usage = options.ResourceStates; // resource description optional parameters resourceDesc.MipLevels = options.MipLevels; resourceDesc.Layout = options.Layout; // struct copy (shallow copy should be occurred) resourceDesc.SampleDesc = options.SampleDesc; } // create new page resource //if (!Resource.CreateResource(heapType, resourceDesc, usage)) { return(false); } //return true; }