nTexture2 Class Reference
#include <ntexture2.h>
Inheritance diagram for nTexture2:

Detailed Description
Contains image data used by the gfx api's texture samplers. Textures are normal named, shared resources which are usually loaded from disk. Textures can also be declared as render targets.The following code snip shows the creation of 16bit empty texture and filling it with white pixel:
tex = (nTexture2 *)refGfx2->NewTexture("mytexture"); if (!tex->IsUnloaded()) { int width, height; width = height = 128; // create a 16bit 2D empty texture. tex->SetUsage(nTexture2::CreateEmpty); tex->SetType(nTexture2::TEXTURE_2D); tex->SetWidth(width); tex->SetHeight(height); tex->SetFormat(nTexture2::A1R5G5B5); tex->Load(); // fill the created texture with white pixel. struct nTexture2::LockInfo surf; if (tex->Lock(nTexture2::WriteOnly, 0, surf)) { unsigned short *surface = (unsigned short *)surf.surfPointer; for (unsigned int pixelByte=0; pixelByte < width*height; pixelByte++) surface[pixelByte] = 0xffff; tex->Unlock(0); } }
You also can read pixel of the texture like the following:
struct nTexture2::LockInfo surf; tex->Lock(nTexture2::ReadOnly, 0, surf) ushort *surface = (ushort*)surf.surfPointer; ushort color = surface[x + y*surf.surfPitch]; tex->Unlock(0);
The following code shows that another way of copying the image data of the memory to the created texture:
// create an empty texture like above code. ... // get the surface of the texture nSurface *surface; // get the surface of level 0. tex->GetSurfaceLevel("/tmp/surface", 0, &surface); // copy the imageData which is the source image to the texture surface->LoadFromMemory(imageData, dstFormat, width, height, imagePitch); ...
(C) 2002 RadonLabs GmbH
Definition at line 72 of file ntexture2.h.
Public Types | |
| enum | Type { TEXTURE_NOTYPE, TEXTURE_2D, TEXTURE_3D, TEXTURE_CUBE } |
| texture type More... | |
| enum | Format { NOFORMAT, X8R8G8B8, A8R8G8B8, R5G6B5, A1R5G5B5, A4R4G4B4, P8, G16R16, DXT1, DXT2, DXT3, DXT4, DXT5, R16F, G16R16F, A16B16G16R16F, R32F, G32R32F, A32B32G32R32F, A8 } |
| enum | FileFormat { BMP, JPG, TGA, PNG, DDS, PPM, DIB, HDR, PFM } |
| enum | CubeFace { PosX = 0, NegX, PosY, NegY, PosZ, NegZ } |
| enum | Usage { CreateEmpty = (1<<0), CreateFromRawCompoundFile = (1<<1), CreateFromDDSCompoundFile = (1<<2), RenderTargetColor = (1<<3), RenderTargetDepth = (1<<4), RenderTargetStencil = (1<<5), Dynamic = (1<<6), Video = (1<<7) } |
| enum | LockType { ReadOnly, WriteOnly } |
Public Member Functions | |
| nTexture2 () | |
| constructor | |
| virtual | ~nTexture2 () |
| destructor | |
| void | SetUsage (int useFlags) |
| set combination of usage flags | |
| int | GetUsage () const |
| get usage flags combination | |
| bool | IsRenderTarget () const |
| check usage flags if this is a render target | |
| void | SetCompoundFileData (nFile *file, int filePos, int byteSize) |
| set compound file read data | |
| void | SetType (Type t) |
| set texture type (render target only!) | |
| Type | GetType () const |
| get texture type | |
| void | SetFormat (Format f) |
| set texture's pixel format (render target only!) | |
| Format | GetFormat () const |
| get texture's pixel format | |
| void | SetWidth (int w) |
| set width (render target only!) | |
| int | GetWidth () const |
| get width | |
| void | SetHeight (int h) |
| set height (render target only!) | |
| int | GetHeight () const |
| get height | |
| void | SetDepth (int d) |
| set depth (render target only! oops: 3d render targets?) | |
| int | GetDepth () const |
| get depth | |
| int | GetNumMipLevels () const |
| get number of mipmaps | |
| int | GetBytesPerPixel () const |
| get bytes per pixel (computed from pixel format) | |
| virtual bool | Lock (LockType lockType, int level, LockInfo &lockInfo) |
| lock a 2D texture, returns pointer and pitch | |
| virtual void | Unlock (int level) |
| unlock 2D texture | |
| virtual bool | LockCubeFace (LockType lockType, CubeFace face, int level, LockInfo &lockInfo) |
| lock a cube face | |
| virtual void | UnlockCubeFace (CubeFace face, int level) |
| unlock a cube face | |
| virtual bool | SaveTextureToFile (const nString &filename, FileFormat fileFormat) |
| save data in texture into a file | |
| virtual void | GenerateMipMaps () |
Static Public Member Functions | |
| static Format | StringToFormat (const char *str) |
| convert string to pixel format | |
| static const char * | FormatToString (Format fmt) |
| convert pixel format to string | |
| static Type | StringToType (const char *str) |
| convert string to type | |
| static const char * | TypeToString (Type t) |
| convert type to string | |
Protected Member Functions | |
| void | SetNumMipLevels (int num) |
| set number of mipmaps | |
Protected Attributes | |
| Type | type |
| Format | format |
| ushort | usage |
| ushort | width |
| ushort | height |
| ushort | depth |
| ushort | numMipMaps |
| nFile * | compoundFile |
| int | compoundFilePos |
| int | compoundFileDataSize |
Classes | |
| struct | LockInfo |
Member Enumeration Documentation
|
|
texture type
Reimplemented from nResource. Definition at line 76 of file ntexture2.h. |
|
|
Definition at line 85 of file ntexture2.h. |
|
|
Definition at line 110 of file ntexture2.h. |
|
|
Definition at line 124 of file ntexture2.h. |
|
|
Definition at line 135 of file ntexture2.h. |
|
|
Definition at line 148 of file ntexture2.h. |
Constructor & Destructor Documentation
|
|
constructor
Definition at line 13 of file ntexture2_main.cc. |
|
|
destructor
Definition at line 30 of file ntexture2_main.cc. |
Member Function Documentation
|
|
set combination of usage flags
Definition at line 259 of file ntexture2.h. |
|
|
get usage flags combination
Definition at line 269 of file ntexture2.h. |
|
|
check usage flags if this is a render target
Definition at line 279 of file ntexture2.h. |
|
||||||||||||||||
|
set compound file read data
Definition at line 239 of file ntexture2.h. |
|
|
set texture type (render target only!)
Reimplemented from nResource. Definition at line 289 of file ntexture2.h. |
|
|
get texture type
Reimplemented from nResource. Definition at line 299 of file ntexture2.h. |
|
|
set texture's pixel format (render target only!)
Definition at line 309 of file ntexture2.h. |
|
|
get texture's pixel format
Definition at line 319 of file ntexture2.h. |
|
|
set width (render target only!)
Definition at line 329 of file ntexture2.h. |
|
|
get width
Definition at line 339 of file ntexture2.h. |
|
|
set height (render target only!)
Definition at line 349 of file ntexture2.h. |
|
|
get height
Definition at line 359 of file ntexture2.h. |
|
|
set depth (render target only! oops: 3d render targets?)
Definition at line 369 of file ntexture2.h. |
|
|
get depth
Definition at line 379 of file ntexture2.h. |
|
|
get number of mipmaps
Definition at line 399 of file ntexture2.h. |
|
|
get bytes per pixel (computed from pixel format) Returns the bytes per pixel for the current pixel format. May be incorrect for compressed textures!
Definition at line 413 of file ntexture2.h. |
|
||||||||||||||||
|
lock a 2D texture, returns pointer and pitch Locks a mipmap level of the texture, returns a pointer to the surface data and the surface pitch in the provided lockInfo structure. Definition at line 49 of file ntexture2_main.cc. |
|
|
unlock 2D texture
Reimplemented in nD3D9Texture, and nGLTexture. Definition at line 58 of file ntexture2_main.cc. |
|
||||||||||||||||||||
|
lock a cube face Locks a single surface of a cube texture. Definition at line 68 of file ntexture2_main.cc. |
|
||||||||||||
|
unlock a cube face Unlocks a single surface of a cube texture. Reimplemented in nD3D9Texture, and nGLTexture. Definition at line 79 of file ntexture2_main.cc. |
|
|
convert string to pixel format
Definition at line 501 of file ntexture2.h. |
|
|
convert pixel format to string
Definition at line 468 of file ntexture2.h. |
|
|
convert string to type
Definition at line 553 of file ntexture2.h. |
|
|
convert type to string
Definition at line 536 of file ntexture2.h. |
|
||||||||||||
|
save data in texture into a file Saves the texture to a file Reimplemented in nD3D9Texture. Definition at line 90 of file ntexture2_main.cc. |
|
|
Reimplemented in nD3D9Texture, and nGLTexture. Definition at line 99 of file ntexture2_main.cc. |
|
|
set number of mipmaps
Definition at line 389 of file ntexture2.h. |
Member Data Documentation
|
|
Reimplemented from nResource. Definition at line 222 of file ntexture2.h. |
|
|
Definition at line 223 of file ntexture2.h. |
|
|
Definition at line 224 of file ntexture2.h. |
|
|
Definition at line 225 of file ntexture2.h. |
|
|
Definition at line 226 of file ntexture2.h. |
|
|
Definition at line 227 of file ntexture2.h. |
|
|
Definition at line 228 of file ntexture2.h. |
|
|
Definition at line 229 of file ntexture2.h. |
|
|
Definition at line 230 of file ntexture2.h. |
|
|
Definition at line 231 of file ntexture2.h. |
The documentation for this class was generated from the following files: