~haggai-eran/nux/rtl-rebased

« back to all changes in this revision

Viewing changes to NuxGraphics/IOpenGLBaseTexture.cpp

  • Committer: Jay Taoko
  • Date: 2011-10-21 23:49:15 UTC
  • mfrom: (508.1.2 nux-20)
  • Revision ID: jay.taoko@canonical.com-20111021234915-hnzakb5ndebica8i
* Removed custom Nux types: t_u32, t_s32, t_bool, ...

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
  NUX_IMPLEMENT_OBJECT_TYPE(IOpenGLBaseTexture);
35
35
 
36
36
  IOpenGLBaseTexture::IOpenGLBaseTexture(OpenGLResourceType ResourceType,
37
 
                                          t_u32 Width,
38
 
                                          t_u32 Height,
39
 
                                          t_u32 Depth,
40
 
                                          t_u32 NumMipLevel,
 
37
                                          unsigned int Width,
 
38
                                          unsigned int Height,
 
39
                                          unsigned int Depth,
 
40
                                          unsigned int NumMipLevel,
41
41
                                          BitmapFormat PixelFormat, NUX_FILE_LINE_DECL)
42
42
    : IOpenGLResource(ResourceType, NUX_FILE_LINE_PARAM)
43
43
    , _IsPOT(false)
118
118
    _TextureStates.SetRenderStates();
119
119
  }
120
120
 
121
 
  void IOpenGLBaseTexture::SetFiltering(t_u32 MinFilter, t_u32 MagFilter/*, t_u32 MIP = GL_NEAREST*/)
 
121
  void IOpenGLBaseTexture::SetFiltering(unsigned int MinFilter, unsigned int MagFilter/*, unsigned int MIP = GL_NEAREST*/)
122
122
  {
123
123
    _TextureStates.SetFiltering(MinFilter, MagFilter);
124
124
  }
125
125
 
126
 
  void IOpenGLBaseTexture::SetWrap(t_u32 U, t_u32 V, t_u32 W)
 
126
  void IOpenGLBaseTexture::SetWrap(unsigned int U, unsigned int V, unsigned int W)
127
127
  {
128
128
    _TextureStates.SetWrap(U, V, W);
129
129
  }
133
133
    _TextureStates.SetLOD(MinLod, MaxLod);
134
134
  }
135
135
 
136
 
  void IOpenGLBaseTexture::SetMipLevel(t_u32 MinMip, t_u32 MaxMip)
 
136
  void IOpenGLBaseTexture::SetMipLevel(unsigned int MinMip, unsigned int MaxMip)
137
137
  {
138
138
    _TextureStates.SetMipLevel(MinMip, MaxMip);
139
139
  }
263
263
  }
264
264
 
265
265
 
266
 
  t_s32 GetTextureSize(IOpenGLBaseTexture *pTexture)
 
266
  int GetTextureSize(IOpenGLBaseTexture *pTexture)
267
267
  {
268
268
    GLint unpack_alignment = GPixelFormats[pTexture->_PixelFormat].RowMemoryAlignment;
269
 
    t_u32 halfUnpack = Log2(unpack_alignment);
 
269
    unsigned int halfUnpack = Log2(unpack_alignment);
270
270
 
271
 
    t_u32 TextureSize = 0;
 
271
    unsigned int TextureSize = 0;
272
272
 
273
273
    if (
274
274
      pTexture->_PixelFormat == BITFMT_DXT1 ||
279
279
    {
280
280
      for (int Level = 0; Level < pTexture->GetNumMipLevel(); Level++)
281
281
      {
282
 
        t_u32 Width            = Max<t_u32> (1, pTexture->_Width >> Level);
283
 
        t_u32 Height           = Max<t_u32> (1, pTexture->_Height >> Level);
284
 
        t_u32 WidthInBlocks    = Max<t_u32> ((Width + 3) / 4, 1); // round the width to the upper multiple of 4. DXT blocks are 4x4 texels.
285
 
        t_u32 HeightInBlocks   = Max<t_u32> ((Height + 3) / 4, 1); // round the height to the upper multiple of 4. DXT blocks are 4x4 texels.
 
282
        unsigned int Width            = Max<unsigned int> (1, pTexture->_Width >> Level);
 
283
        unsigned int Height           = Max<unsigned int> (1, pTexture->_Height >> Level);
 
284
        unsigned int WidthInBlocks    = Max<unsigned int> ((Width + 3) / 4, 1); // round the width to the upper multiple of 4. DXT blocks are 4x4 texels.
 
285
        unsigned int HeightInBlocks   = Max<unsigned int> ((Height + 3) / 4, 1); // round the height to the upper multiple of 4. DXT blocks are 4x4 texels.
286
286
 
287
287
        if (pTexture->_PixelFormat == BITFMT_DXT1)
288
288
        {
298
298
    {
299
299
      for (int Level = 0; Level < pTexture->GetNumMipLevel(); Level++)
300
300
      {
301
 
        t_u32 Width             = Max<t_u32> (1, pTexture->_Width >> Level);
302
 
        t_u32 Height            = Max<t_u32> (1, pTexture->_Height >> Level);
303
 
        t_u32 BytePerPixel      = GPixelFormats[pTexture->_PixelFormat].BlockBytes;
304
 
        t_u32 SlicePitch        = (((Width * BytePerPixel + (unpack_alignment - 1)) >> (halfUnpack)) << (halfUnpack)) * Height;
 
301
        unsigned int Width             = Max<unsigned int> (1, pTexture->_Width >> Level);
 
302
        unsigned int Height            = Max<unsigned int> (1, pTexture->_Height >> Level);
 
303
        unsigned int BytePerPixel      = GPixelFormats[pTexture->_PixelFormat].BlockBytes;
 
304
        unsigned int SlicePitch        = (((Width * BytePerPixel + (unpack_alignment - 1)) >> (halfUnpack)) << (halfUnpack)) * Height;
305
305
 
306
306
        TextureSize += SlicePitch;
307
307
      }
316
316
  }
317
317
 
318
318
  void GetTextureDesc(IOpenGLBaseTexture *pTexture,
319
 
                       t_u32 Level,
 
319
                       unsigned int Level,
320
320
                       TEXTURE_DESC *pDesc)
321
321
  {
322
322
    GLint unpack_alignment = GPixelFormats[pTexture->_PixelFormat].RowMemoryAlignment;
323
 
    t_u32 halfUnpack = Log2(unpack_alignment);
 
323
    unsigned int halfUnpack = Log2(unpack_alignment);
324
324
 
325
 
    t_u32 BytePerPixel = 0;
 
325
    unsigned int BytePerPixel = 0;
326
326
 
327
327
    pDesc->PixelFormat = pTexture->_PixelFormat;
328
328
 
333
333
      pTexture->_PixelFormat == BITFMT_DXT4 ||
334
334
      pTexture->_PixelFormat == BITFMT_DXT5)
335
335
    {
336
 
      pDesc->Width            = Max<t_u32> (1, pTexture->_Width >> Level);
337
 
      pDesc->Height           = Max<t_u32> (1, pTexture->_Height >> Level);
338
 
      pDesc->WidthInBlocks    = Max<t_u32> ((pDesc->Width + 3) / 4, 1); // round the width to the upper multiple of 4. DXT blocks are 4x4 texels.
339
 
      pDesc->HeightInBlocks   = Max<t_u32> ((pDesc->Height + 3) / 4, 1); // round the height to the upper multiple of 4. DXT blocks are 4x4 texels.
 
336
      pDesc->Width            = Max<unsigned int> (1, pTexture->_Width >> Level);
 
337
      pDesc->Height           = Max<unsigned int> (1, pTexture->_Height >> Level);
 
338
      pDesc->WidthInBlocks    = Max<unsigned int> ((pDesc->Width + 3) / 4, 1); // round the width to the upper multiple of 4. DXT blocks are 4x4 texels.
 
339
      pDesc->HeightInBlocks   = Max<unsigned int> ((pDesc->Height + 3) / 4, 1); // round the height to the upper multiple of 4. DXT blocks are 4x4 texels.
340
340
 
341
341
      if ( /*pTexture->_Format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||*/
342
342
        pTexture->_PixelFormat == BITFMT_DXT1)
386
386
    }
387
387
    else
388
388
    {
389
 
      pDesc->Width            = Max<t_u32> (1, pTexture->_Width >> Level);
390
 
      pDesc->Height           = Max<t_u32> (1, pTexture->_Height >> Level);
 
389
      pDesc->Width            = Max<unsigned int> (1, pTexture->_Width >> Level);
 
390
      pDesc->Height           = Max<unsigned int> (1, pTexture->_Height >> Level);
391
391
      pDesc->WidthInBlocks    = pDesc->Width;
392
392
      pDesc->HeightInBlocks   = pDesc->Height;
393
393
      BytePerPixel            = GPixelFormats[pTexture->_PixelFormat].BlockBytes;