~openhommdev/openhomm/gui

« back to all changes in this revision

Viewing changes to src/render/hrCache.cpp

  • Committer: Roman Fomin
  • Date: 2010-02-22 15:38:37 UTC
  • Revision ID: rfomin@gmail.com-20100222153837-7idkqlt3dt5br3ny
add border
pcx plugin: alpha channel

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include "hrGL.hpp"
19
19
#include "hrCache.hpp"
20
20
#include "hrSettings.hpp"
 
21
//#include "squish.h"
 
22
 
21
23
 
22
24
typedef void (APIENTRY *pfn_glCompressedTexImage2DARB) (GLenum, GLint, GLenum, GLsizei,
23
25
                                                        GLsizei, GLint, GLsizei, const GLvoid *);
30
32
 
31
33
static const int HR_FILE_SIZE = 0;
32
34
 
33
 
hrCache::hrCache() : target(GL_TEXTURE_2D), format(GL_RGBA)
 
35
hrCache::hrCache() : inc(0), target(GL_TEXTURE_2D), format(GL_RGBA)
34
36
{
35
37
    cache.setMaxCost(1000);
36
38
 
63
65
 
64
66
hrGraphicsItem hrCache::loadItem(const QString &name, bool notDeletable)
65
67
{
66
 
    static int inc = 0;
67
68
    hrCacheKey key = inc++;
68
69
 
69
70
    hrCacheItem *item;
90
91
    return hrGraphicsItem(key, item->countFrames(), item->getSize());
91
92
}
92
93
 
 
94
hrGraphicsItem hrCache::loadItem(const QImage &im)
 
95
{
 
96
    hrCacheKey key = inc++;
 
97
 
 
98
    hrCacheItem *item = new hrCacheItem();
 
99
 
 
100
    item->addFrame(Load(im));
 
101
    item->setSize(im.size());
 
102
 
 
103
    map[key] = item;
 
104
 
 
105
    return hrGraphicsItem(key, item->countFrames(), item->getSize());
 
106
}
 
107
 
93
108
 
94
109
hrCacheItem* hrCache::Load(const QString &name) const
95
110
{
119
134
 
120
135
GLuint hrCache::Load(const QImage &im) const
121
136
{
122
 
    QImage conv = QGLWidget::convertToGLFormat(target == GL_TEXTURE_2D
123
 
                                            ? ImageToPOT(im)
124
 
                                            : im
 
137
    QImage conv;
 
138
    if (target == GL_TEXTURE_2D)
 
139
    {
 
140
        int s = hrgl::NearestGLTextureSize(qMax(im.width(), im.height()));
 
141
        conv = QGLWidget::convertToGLFormat(im.width() == im.height()
 
142
                                            && s == im.width()
 
143
                                            ? im : im.copy(0, 0, s, s)
125
144
                                            );
126
 
    GLuint tx = bindImage(conv.bits()
127
 
                          , conv.width()
128
 
                          , conv.height()
129
 
                          , false
130
 
                          , 0
 
145
    }
 
146
    else
 
147
    {
 
148
        conv = QGLWidget::convertToGLFormat(im);
 
149
    }
 
150
 
 
151
    /*int size = squish::GetStorageRequirements(conv.width()
 
152
                                              , conv.height()
 
153
                                              , squish::kDxt5
 
154
                                              );
 
155
    qint8 *out = new qint8[size];
 
156
    squish::CompressImage(conv.bits()
 
157
                          , conv.width()
 
158
                          , conv.height()
 
159
                          , out
 
160
                          , squish::kColourRangeFit | squish::kDxt5
 
161
                          );*/
 
162
 
 
163
    GLuint tx = bindImage(conv.bits()//out
 
164
                          , conv.width()
 
165
                          , conv.height()
 
166
                          , false//true
 
167
                          , 0//size
131
168
                          );
 
169
 
132
170
    return tx;
133
171
}
134
172
 
323
361
    return param;
324
362
}
325
363
 
326
 
QImage hrCache::ImageToPOT(const QImage &im) const
327
 
{
328
 
    int s = hrgl::NearestGLTextureSize(qMax(im.width(), im.height()));
329
 
    return im.copy(0, 0, s, s);
330
 
}
331
 
 
332
364
void hrCache::checkExtensions()
333
365
{
334
366
    QString extensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));