Converts a 3D texture to a 2D render target for pixel editing and manipulation.
Takes textureHandle (3D texture from b3dLoadMesh, b3dBakeMesh, or BBR_LoadTexture3D).
Returns 2D render target handle (for use with b2d drawing functions) or -1 on failure.
3D Graphics
Parameters & Returns
Parameters
textureHandleInt
Returns
Int
Quick Summary
Converts a 3D texture to a 2D render target for pixel editing and manipulation.
Takes textureHandle (3D texture from b3dLoadMesh, b3dBakeMesh, or BBR_LoadTexture3D).
Returns 2D render target handle (for use with b2d drawing functions) or -1 on failure.
Technical Exegesis...
Converts a 3D texture to a 2D render target for pixel editing and manipulation. Takes textureHandle (3D texture from b3dLoadMesh, b3dBakeMesh, or BBR_LoadTexture3D). Returns 2D render target handle (for use with b2d drawing functions) or -1 on failure. Validates texture handle in range. Gets Texture3D from g_textures array. Reads texture pixel data from GPU using ReadTextureFromGPU helper (creates staging buffer, copies GPU texture to staging, maps to CPU memory, reads RGBA pixels).
Converts a 3D texture to a 2D render target for pixel editing and manipulation. Takes textureHandle (3D texture from b3dLoadMesh, b3dBakeMesh, or BBR_LoadTexture3D). Returns 2D render target handle (for use with b2d drawing functions) or -1 on failure. Validates texture handle in range. Gets Texture3D from g_textures array. Reads texture pixel data from GPU using ReadTextureFromGPU helper (creates staging buffer, copies GPU texture to staging, maps to CPU memory, reads RGBA pixels). Creates b2d render target with b2dCreateRenderTarget (same dimensions as texture). Uploads pixel data to render target using b2dUploadPixelData. Returns render target handle. Returns -1 if: invalid texture handle, GPU read fails (DirectX error), render target creation fails (out of memory), upload fails.
This function bridges 3D and 2D graphics systems for texture editing. Texture download from GPU is expensive operation (GPU->CPU transfer, synchronization stall). Use sparingly - not every frame. Returned render target is editable: use b2dSetRenderTarget, b2dDrawImage, b2dDrawRect, b2dDrawText, BBR_DrawLine, etc. to modify. After editing, convert back with b3dImageToTexture and assign to entity with b3dSetEntityBaseTexture. Common workflow: (1) texHandle = b3dGetBaseTexture(entity), (2) img = b3dTextureToImage(texHandle), (3) b2dSetRenderTarget(img), (4) b2dDrawText("Graffiti", x, y), (5) b2dSetRenderTarget(0), (6) newTex = b3dImageToTexture(img), (7) b3dSetEntityBaseTexture(entity, newTex). Use cases: dynamic decals (bullet holes, paint splatters), damage textures (scratches, dents), procedural details (add noise, weathering), UV layout debugging (visualize UV islands), texture previews (render to UI). Pixel format: RGBA 8-bit per channel (4 bytes per pixel). Render target created with same dimensions - no scaling. For large textures (4096x4096), consider downsampling before editing (memory intensive). Alternative for frequent updates: keep texture in staging buffer (CPU-accessible), avoid repeated downloads. Render targets support alpha blending, color keys, all b2d operations.