Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

kiba

Alter Hase

  • »kiba« ist der Autor dieses Themas

Beiträge: 327

Wohnort: NRW

Beruf: Azubi: Fach-Info. Anw.

  • Private Nachricht senden

11

26.04.2009, 16:59

Hab die funktion mal so gemacht.
Hoffe mal es ist alle richtig.

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
inline int CeilPoT( int x ){
    --x;
    x |= x >> 1;
    x |= x >> 2;
    x |= x >> 4;
    x |= x >> 8;
    x |= x >> 16;
    ++x;

    return x;
}

inline int getMipMapLoD(int w,int h){
    int lvl = 0;
    while(w > 0 || h > 0){
        w /= 2;
        h /= 2;
        lvl++;
    }
    return lvl;
}

Surface::loadFile(const char filename){
  //load file [...]

  this->width = ilGetInteger(IL_IMAGE_WIDTH);
  this->height = ilGetInteger(IL_IMAGE_HEIGHT);

  this->mipwidth = CeilPoT(this->width);
  this->mipheight = CeilPoT(this->height);
  this->miplod = getMipMapLoD(this->mipwidth,this->mipheight);
  this->psize = this->mipwidth*this->mipheight*ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
  this->pixels = new ubyte[this->psize];
  ubyte* copydata = ilGetData();
  uint copysize = ilGetInteger(IL_IMAGE_WIDTH)*ilGetInteger(IL_IMAGE_HEIGHT)*ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
  if (copydata){
    for(size_t i = 0;i < this->psize;i++){
      if(i < copysize)
        this->pixels[i] = copydata[i];
      else{
        this->pixels[i] = 0;
    }
  }
 }
}

int main()
{
    int width = 500;
    int height = 112;

    cout << CeilPoT(width) << "," << CeilPoT(height) << endl; //=> 512,128

    cout << getMipMapLoD(CeilPoT(width),CeilPoT(height)) << endl; //=> 10


    return 0;
}

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

12

26.04.2009, 17:55

Naja... Du musst halt noch die Bilddaten für alle Layer erzeugen, d.h. ggf auf die neue Dimension skalieren und dann für jede Mipmap resamplen. Die Anzahl der Mipmaplevels kannst du so berechnen:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
uint32 PixelFormatUtils::GetMipMapLevels( uint32 width, uint32 height, uint32 depth )
{
    uint32 count = 0;
    uint32 mip = ::Max( width, ::Max( height, depth ) );

    while ( mip > 0 )
    {
        mip >>= 1;
        ++count;
    }

    return count;
}