~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to source/Irrlicht/CSoftwareTexture.cpp

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
 
2
// This file is part of the "Irrlicht Engine".
 
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
 
4
 
 
5
#include "IrrCompileConfig.h"
 
6
#ifdef _IRR_COMPILE_WITH_SOFTWARE_
 
7
 
 
8
#include "CSoftwareTexture.h"
 
9
#include "os.h"
 
10
 
 
11
namespace irr
 
12
{
 
13
namespace video
 
14
{
 
15
 
 
16
//! constructor
 
17
CSoftwareTexture::CSoftwareTexture(IImage* image, const io::path& name,
 
18
                bool renderTarget, void* mipmapData)
 
19
: ITexture(name), Texture(0), IsRenderTarget(renderTarget)
 
20
{
 
21
        #ifdef _DEBUG
 
22
        setDebugName("CSoftwareTexture");
 
23
        #endif
 
24
 
 
25
        if (image)
 
26
        {
 
27
                OrigSize = image->getDimension();
 
28
                core::dimension2d<u32> optSize=OrigSize.getOptimalSize();
 
29
 
 
30
                Image = new CImage(ECF_A1R5G5B5, OrigSize);
 
31
                image->copyTo(Image);
 
32
 
 
33
                if (optSize == OrigSize)
 
34
                {
 
35
                        Texture = Image;
 
36
                        Texture->grab();
 
37
                }
 
38
                else
 
39
                {
 
40
                        Texture = new CImage(ECF_A1R5G5B5, optSize);
 
41
                        Image->copyToScaling(Texture);
 
42
                }
 
43
        }
 
44
}
 
45
 
 
46
 
 
47
 
 
48
//! destructor
 
49
CSoftwareTexture::~CSoftwareTexture()
 
50
{
 
51
        if (Image)
 
52
                Image->drop();
 
53
 
 
54
        if (Texture)
 
55
                Texture->drop();
 
56
}
 
57
 
 
58
 
 
59
 
 
60
//! lock function
 
61
void* CSoftwareTexture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
 
62
{
 
63
        return Image->lock();
 
64
}
 
65
 
 
66
 
 
67
 
 
68
//! unlock function
 
69
void CSoftwareTexture::unlock()
 
70
{
 
71
        if (Image != Texture)
 
72
        {
 
73
                os::Printer::log("Performance warning, slow unlock of non power of 2 texture.", ELL_WARNING);
 
74
                Image->copyToScaling(Texture);
 
75
        }
 
76
 
 
77
        Image->unlock();
 
78
}
 
79
 
 
80
 
 
81
//! Returns original size of the texture.
 
82
const core::dimension2d<u32>& CSoftwareTexture::getOriginalSize() const
 
83
{
 
84
        return OrigSize;
 
85
}
 
86
 
 
87
 
 
88
//! Returns (=size) of the texture.
 
89
const core::dimension2d<u32>& CSoftwareTexture::getSize() const
 
90
{
 
91
        return Image->getDimension();
 
92
}
 
93
 
 
94
 
 
95
//! returns unoptimized surface
 
96
CImage* CSoftwareTexture::getImage()
 
97
{
 
98
        return Image;
 
99
}
 
100
 
 
101
 
 
102
 
 
103
//! returns texture surface
 
104
CImage* CSoftwareTexture::getTexture()
 
105
{
 
106
        return Texture;
 
107
}
 
108
 
 
109
 
 
110
 
 
111
//! returns driver type of texture (=the driver, who created the texture)
 
112
E_DRIVER_TYPE CSoftwareTexture::getDriverType() const
 
113
{
 
114
        return EDT_SOFTWARE;
 
115
}
 
116
 
 
117
 
 
118
 
 
119
//! returns color format of texture
 
120
ECOLOR_FORMAT CSoftwareTexture::getColorFormat() const
 
121
{
 
122
        return ECF_A1R5G5B5;
 
123
}
 
124
 
 
125
 
 
126
 
 
127
//! returns pitch of texture (in bytes)
 
128
u32 CSoftwareTexture::getPitch() const
 
129
{
 
130
        return Image->getDimension().Width * 2;
 
131
}
 
132
 
 
133
 
 
134
//! Regenerates the mip map levels of the texture. Useful after locking and
 
135
//! modifying the texture
 
136
void CSoftwareTexture::regenerateMipMapLevels(void* mipmapData)
 
137
{
 
138
        // our software textures don't have mip maps
 
139
}
 
140
 
 
141
bool CSoftwareTexture::isRenderTarget() const
 
142
{
 
143
        return IsRenderTarget;
 
144
}
 
145
 
 
146
 
 
147
} // end namespace video
 
148
} // end namespace irr
 
149
 
 
150
#endif // _IRR_COMPILE_WITH_SOFTWARE_
 
151