Converts a 2D render target to a 3D texture resource for use in mesh materials.
Takes imageHandle (2D render target created with b2dCreateRenderTarget or b2dLoadImage).
Returns 3D texture handle or -1 on failure.
3D Graphics
Parameters & Returns
Parameters
imageHandleInt
Returns
Int
Quick Summary
Converts a 2D render target to a 3D texture resource for use in mesh materials.
Takes imageHandle (2D render target created with b2dCreateRenderTarget or b2dLoadImage).
Returns 3D texture handle or -1 on failure.
Technical Exegesis...
Converts a 2D render target to a 3D texture resource for use in mesh materials. Takes imageHandle (2D render target created with b2dCreateRenderTarget or b2dLoadImage). Returns 3D texture handle or -1 on failure. Reads pixel data from b2d image using b2dReadPixelData (allocates buffer, copies RGBA pixels). Creates new Texture3D structure with image dimensions. Allocates D3D12 texture resource (DXGI_FORMAT_R8G8B8A8_UNORM, DEFAULT heap for GPU-only access).
Converts a 2D render target to a 3D texture resource for use in mesh materials. Takes imageHandle (2D render target created with b2dCreateRenderTarget or b2dLoadImage). Returns 3D texture handle or -1 on failure. Reads pixel data from b2d image using b2dReadPixelData (allocates buffer, copies RGBA pixels). Creates new Texture3D structure with image dimensions. Allocates D3D12 texture resource (DXGI_FORMAT_R8G8B8A8_UNORM, DEFAULT heap for GPU-only access). Creates intermediate upload buffer (UPLOAD heap for CPU->GPU transfer). Maps upload buffer, copies pixel data. Records copy command (CopyTextureRegion from upload to texture). Executes command list, waits for GPU completion. Transitions texture to PIXEL_SHADER_RESOURCE state. Creates SRV descriptor for shader access. Adds texture to g_textures array. Frees allocated pixel buffer. Returns texture handle. Returns -1 if: invalid image handle, pixel read fails, GPU resource allocation fails, upload fails.
This function completes the 2D->3D texture editing workflow. After editing render target with b2d drawing functions, upload back to GPU as 3D texture for mesh rendering. Created texture is GPU resource (not CPU-accessible) - can't modify directly, must convert to image first. Texture lifecycle: create once, use many frames (persistent in g_textures). Use with b3dSetEntityBaseTexture to assign to entity material. Common workflow: (1) img = b2dCreateRenderTarget(512, 512, ...), (2) b2dSetRenderTarget(img), (3) b2dCls(), (4) b2dDrawRect/Circle/Text/Image for procedural texture, (5) b2dSetRenderTarget(0), (6) tex = b3dImageToTexture(img), (7) b3dSetEntityBaseTexture(entity, tex). Use cases: procedural textures (noise, patterns, gradients), dynamic UI elements on 3D objects (health bars on nameplates), custom terrain splatmaps, lightmap baking, particle textures, font atlases. Upload is expensive (CPU->GPU transfer, command list execution, GPU sync). Batch multiple texture creates when possible. Pixel format: RGBA 8-bit, same as render target. Texture dimensions: power-of-2 recommended for mipmapping (though not required in D3D12). No mipmap generation - texture has single LOD level. For mipmaps, use external tool or implement mipmap chain generation. Textures consume VRAM - monitor usage with Get3DDevice()->GetAdapterDesc(). Alternative: use texture arrays for sets of related textures.