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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "tetraedge/tetraedge.h"
#include "tetraedge/te/te_3d_texture.h"
#include "tetraedge/te/te_3d_texture_opengl.h"
#include "tetraedge/te/te_3d_texture_tinygl.h"
#include "tetraedge/te/te_resource_manager.h"
#include "tetraedge/te/te_renderer.h"
namespace Tetraedge {
Te3DTexture::Te3DTexture() : _createdTexture(false),
_numFrames(1), _frameRate(0), _format(TeImage::INVALID) {
}
Te3DTexture::~Te3DTexture() {
}
bool Te3DTexture::hasAlpha() const {
TeImage::Format format = getFormat();
return (format == TeImage::RGBA8 || format == 9
|| format == 0xb || format == 1 || format == 0);
}
/*static*/
TeIntrusivePtr<Te3DTexture> Te3DTexture::load2(const Common::Path &path, uint size) {
Common::Path fullPath = path.append(".3dtex");
TeResourceManager *resMgr = g_engine->getResourceManager();
if (!resMgr->exists(fullPath)) {
TeIntrusivePtr<Te3DTexture> retval(makeInstance());
retval->load(path);
retval->setAccessName(fullPath);
resMgr->addResource(retval.get());
return retval;
} else {
return resMgr->getResourceOrMakeInstance<Te3DTexture>(fullPath);
}
}
bool Te3DTexture::load(const Common::Path &path) {
TeResourceManager *resmgr = g_engine->getResourceManager();
Common::Path resPath = path;
TeIntrusivePtr<TeImage> img = resmgr->getResource<TeImage>(resPath);
load(*img);
setAccessName(resPath.append(".3dtex"));
return true;
}
/*static*/
TeVector2s32 Te3DTexture::optimisedSize(const TeVector2s32 &size) {
//
// Note: When we enabled optimized sizes it leaves artifacts around movies
// etc unless the render size is exactly 800x600.
//
// This probably means there is a rounding error somewhere else, just leave
// off for now.
//
if (g_engine->getDefaultScreenWidth() != 800)
return size;
// The maths here is a bit funky but it just picks the nearest power of 2 (up)
int xsize = size._x - 1;
int ysize = size._y - 1;
xsize = (int)xsize >> 1 | xsize;
xsize = (int)xsize >> 2 | xsize;
xsize = (int)xsize >> 4 | xsize;
xsize = (int)xsize >> 8 | xsize;
int v1 = ((int)xsize >> 0x10 | xsize) + 1;
if (v1 < 8) {
v1 = 8;
}
ysize = (int)ysize >> 1 | ysize;
ysize = (int)ysize >> 2 | ysize;
ysize = (int)ysize >> 4 | ysize;
ysize = (int)ysize >> 8 | ysize;
int v2 = ((int)ysize >> 0x10 | ysize) + 1;
if (v2 < 8) {
v2 = 8;
}
return TeVector2s32(v1, v2);
}
/*static*/
Te3DTexture *Te3DTexture::makeInstance() {
Graphics::RendererType r = g_engine->preferredRendererType();
#if defined(USE_OPENGL_GAME)
if (r == Graphics::kRendererTypeOpenGL)
return new Te3DTextureOpenGL();
#endif
#if defined(USE_TINYGL)
if (r == Graphics::kRendererTypeTinyGL)
return new Te3DTextureTinyGL();
#endif
error("Couldn't create Te3DTexture for selected renderer");
}
} // end namespace Tetraedge
|