Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pipelined_texture.cpp
Go to the documentation of this file.
1 #include "pipelined_texture.h"
2 
5 {
6  return data;
7 }
8 
10 {
11  //Had to duplicate the Texture::Original() function otherwise VC++ 6 would not compile anymore
12  //reporting an undefined reference to Texture::Original()
13  if (original)
14  return original->Original();
15  else
16  return this;
17 }
18 
19 void PipelinedTexture::endMutate( int xoffset, int yoffset, int width, int height )
20 {
21  GFXTransferSubTexture( data, name, xoffset, yoffset, width, height, TEXTURE_2D );
22 }
23 
24 PipelinedTexture::PipelinedTexture( unsigned int width, unsigned int height, unsigned char *current,
25  unsigned char *last ) : Texture()
26 {
27  this->sizeX = width;
28  this->sizeY = height;
29  this->clone = 0;
31  mode = _24BITRGBA;
32  data = new unsigned char[4*width*height];
33  stage = 0;
34  original = NULL;
35  refcount = 0;
38  GFXCreateTexture( sizeX, sizeY, (mode == _24BITRGBA) ? RGBA32 : ( (mode == _8BIT) ? PALETTE8 : RGB32 ), &name, NULL,
39  (stage == 1) ? 0 : 1 );
40  GFXCreateTexture( sizeX,
41  sizeY,
42  (mode == _24BITRGBA) ? RGBA32 : ( (mode == _8BIT) ? PALETTE8 : RGB32 ),
43  &this->current,
44  NULL,
45  (stage == 1) ? 0 : 1 );
46  GFXCreateTexture( sizeX,
47  sizeY,
48  (mode == _24BITRGBA) ? RGBA32 : ( (mode == _8BIT) ? PALETTE8 : RGB32 ),
49  &this->last,
50  NULL,
51  (stage == 1) ? 0 : 1 );
52  if (current)
53  GFXTransferTexture( current, this->current, sizeX, sizeY,
54  (mode == _24BITRGBA) ? RGBA32 : ( (mode == _8BIT) ? PALETTE8 : RGB32 ), TEXTURE_2D );
55  if (last)
56  GFXTransferTexture( last, this->last, sizeX, sizeY,
57  (mode == _24BITRGBA) ? RGBA32 : ( (mode == _8BIT) ? PALETTE8 : RGB32 ), TEXTURE_2D );
58 }
59 
61 {
62  GFXSelectTexture( current, stage );
63 }
65 {
66  GFXSelectTexture( last, 0 );
67 }
69 {
70  GFXSelectTexture( current, stage );
71  GFXSelectTexture( last, (stage == 1) ? 0 : 1 );
72 }
74 {
75  stage = (stage+1)%2;
76  int tmp = name;
77  name = last;
78  last = current;
79  current = tmp;
80  if (clone) {
81  clone--;
82  GFXCreateTexture( sizeX, sizeY, (mode == _24BITRGBA) ? RGBA32 : ( (mode == _8BIT) ? PALETTE8 : RGB32 ), &name, NULL,
83  (stage == 1) ? 0 : 1 );
84  }
85 }
86 
88 {
89  PipelinedTexture *retval = new PipelinedTexture();
90  *retval = *this;
91  retval->last = last;
92  retval->current = current;
93  retval->clone = 2;
94  int bpp = (mode == _24BITRGBA) ? 4 : ( (mode == _8BIT) ? 1 : 3 );
95  retval->data = new unsigned char[sizeX*sizeY*bpp];
96  memcpy( retval->data, data, bpp*sizeof (unsigned char)*sizeX*sizeY );
97  GFXCreateTexture( sizeX, sizeY, (mode == _24BITRGBA) ? RGBA32 : ( (mode == _8BIT) ? PALETTE8 : RGB32 ), &name, NULL,
98  (stage == 1) ? 0 : 1, BILINEAR, TEXTURE2D );
99  GFXTransferTexture( retval->data,
100  name,
101  sizeX,
102  sizeY,
103  (mode == _24BITRGBA) ? RGBA32 : ( (mode == _8BIT) ? PALETTE8 : RGB32 ),
104  TEXTURE_2D );
105  return retval;
106 }
107 
109 {
110  if (clone < 2)
111  GFXDeleteTexture( current );
112  if (!clone)
113  GFXDeleteTexture( last );
115 }
116