newspeoplefor developersdocumentationdownloads

nTexture2 Class Reference

#include <ntexture2.h>

Inheritance diagram for nTexture2:

nResource nRoot nObject nNode nReferenced nSignalEmitter nD3D9Texture nGLTexture List of all members.

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
nFilecompoundFile
int compoundFilePos
int compoundFileDataSize

Classes

struct  LockInfo

Member Enumeration Documentation

enum nTexture2::Type
 

texture type

Enumerator:
TEXTURE_NOTYPE 
TEXTURE_2D 
TEXTURE_3D 
TEXTURE_CUBE 

Reimplemented from nResource.

Definition at line 76 of file ntexture2.h.

enum nTexture2::Format
 

Enumerator:
NOFORMAT 
X8R8G8B8 
A8R8G8B8 
R5G6B5 
A1R5G5B5 
A4R4G4B4 
P8 
G16R16 
DXT1 
DXT2 
DXT3 
DXT4 
DXT5 
R16F 
G16R16F 
A16B16G16R16F 
R32F 
G32R32F 
A32B32G32R32F 
A8 

Definition at line 85 of file ntexture2.h.

enum nTexture2::FileFormat
 

Enumerator:
BMP 
JPG 
TGA 
PNG 
DDS 
PPM 
DIB 
HDR 
PFM 

Definition at line 110 of file ntexture2.h.

enum nTexture2::CubeFace
 

Enumerator:
PosX 
NegX 
PosY 
NegY 
PosZ 
NegZ 

Definition at line 124 of file ntexture2.h.

enum nTexture2::Usage
 

Enumerator:
CreateEmpty 
CreateFromRawCompoundFile 
CreateFromDDSCompoundFile 
RenderTargetColor 
RenderTargetDepth 
RenderTargetStencil 
Dynamic 
Video 

Definition at line 135 of file ntexture2.h.

enum nTexture2::LockType
 

Enumerator:
ReadOnly 
WriteOnly 

Definition at line 148 of file ntexture2.h.


Constructor & Destructor Documentation

nTexture2::nTexture2  ) 
 

constructor

Definition at line 13 of file ntexture2_main.cc.

nTexture2::~nTexture2  )  [virtual]
 

destructor

Definition at line 30 of file ntexture2_main.cc.


Member Function Documentation

void nTexture2::SetUsage int  useFlags  )  [inline]
 

set combination of usage flags

Definition at line 259 of file ntexture2.h.

int nTexture2::GetUsage  )  const [inline]
 

get usage flags combination

Definition at line 269 of file ntexture2.h.

bool nTexture2::IsRenderTarget  )  const [inline]
 

check usage flags if this is a render target

Definition at line 279 of file ntexture2.h.

void nTexture2::SetCompoundFileData nFile file,
int  filePos,
int  byteSize
[inline]
 

set compound file read data

Definition at line 239 of file ntexture2.h.

void nTexture2::SetType Type  t  )  [inline]
 

set texture type (render target only!)

Reimplemented from nResource.

Definition at line 289 of file ntexture2.h.

nTexture2::Type nTexture2::GetType  )  const [inline]
 

get texture type

Reimplemented from nResource.

Definition at line 299 of file ntexture2.h.

void nTexture2::SetFormat Format  f  )  [inline]
 

set texture's pixel format (render target only!)

Definition at line 309 of file ntexture2.h.

nTexture2::Format nTexture2::GetFormat  )  const [inline]
 

get texture's pixel format

Definition at line 319 of file ntexture2.h.

void nTexture2::SetWidth int  w  )  [inline]
 

set width (render target only!)

Definition at line 329 of file ntexture2.h.

int nTexture2::GetWidth  )  const [inline]
 

get width

Definition at line 339 of file ntexture2.h.

void nTexture2::SetHeight int  h  )  [inline]
 

set height (render target only!)

Definition at line 349 of file ntexture2.h.

int nTexture2::GetHeight  )  const [inline]
 

get height

Definition at line 359 of file ntexture2.h.

void nTexture2::SetDepth int  d  )  [inline]
 

set depth (render target only! oops: 3d render targets?)

Definition at line 369 of file ntexture2.h.

int nTexture2::GetDepth  )  const [inline]
 

get depth

Definition at line 379 of file ntexture2.h.

int nTexture2::GetNumMipLevels  )  const [inline]
 

get number of mipmaps

Definition at line 399 of file ntexture2.h.

int nTexture2::GetBytesPerPixel  )  const [inline]
 

get bytes per pixel (computed from pixel format)

Returns the bytes per pixel for the current pixel format. May be incorrect for compressed textures!

  • 17-Jun-05 kims Added 'A8' to return its bytes per pixel.

Definition at line 413 of file ntexture2.h.

bool nTexture2::Lock LockType  lockType,
int  level,
LockInfo lockInfo
[virtual]
 

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.

void nTexture2::Unlock int  level  )  [virtual]
 

unlock 2D texture

Reimplemented in nD3D9Texture, and nGLTexture.

Definition at line 58 of file ntexture2_main.cc.

bool nTexture2::LockCubeFace LockType  lockType,
CubeFace  face,
int  level,
LockInfo lockInfo
[virtual]
 

lock a cube face

Locks a single surface of a cube texture.

Definition at line 68 of file ntexture2_main.cc.

void nTexture2::UnlockCubeFace CubeFace  face,
int  level
[virtual]
 

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.

nTexture2::Format nTexture2::StringToFormat const char *  str  )  [inline, static]
 

convert string to pixel format

Definition at line 501 of file ntexture2.h.

const char * nTexture2::FormatToString Format  fmt  )  [inline, static]
 

convert pixel format to string

Definition at line 468 of file ntexture2.h.

nTexture2::Type nTexture2::StringToType const char *  str  )  [inline, static]
 

convert string to type

Definition at line 553 of file ntexture2.h.

const char * nTexture2::TypeToString Type  t  )  [inline, static]
 

convert type to string

Definition at line 536 of file ntexture2.h.

bool nTexture2::SaveTextureToFile const nString filename,
FileFormat  fileFormat
[virtual]
 

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.

void nTexture2::GenerateMipMaps  )  [virtual]
 

  • Feb-04 Kim, H.W. added to support ngameswf.

Reimplemented in nD3D9Texture, and nGLTexture.

Definition at line 99 of file ntexture2_main.cc.

void nTexture2::SetNumMipLevels int  num  )  [inline, protected]
 

set number of mipmaps

Definition at line 389 of file ntexture2.h.


Member Data Documentation

Type nTexture2::type [protected]
 

Reimplemented from nResource.

Definition at line 222 of file ntexture2.h.

Format nTexture2::format [protected]
 

Definition at line 223 of file ntexture2.h.

ushort nTexture2::usage [protected]
 

Definition at line 224 of file ntexture2.h.

ushort nTexture2::width [protected]
 

Definition at line 225 of file ntexture2.h.

ushort nTexture2::height [protected]
 

Definition at line 226 of file ntexture2.h.

ushort nTexture2::depth [protected]
 

Definition at line 227 of file ntexture2.h.

ushort nTexture2::numMipMaps [protected]
 

Definition at line 228 of file ntexture2.h.

nFile* nTexture2::compoundFile [protected]
 

Definition at line 229 of file ntexture2.h.

int nTexture2::compoundFilePos [protected]
 

Definition at line 230 of file ntexture2.h.

int nTexture2::compoundFileDataSize [protected]
 

Definition at line 231 of file ntexture2.h.


The documentation for this class was generated from the following files:

Copyright © 1999-2005 by the contributing authors. Ideas, requests, problems: Send feedback.