ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

gfx_tinygl_texture.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/myst3/gfx_tinygl_texture.h"
00024 #include "graphics/tinygl/zblit.h"
00025 
00026 namespace Myst3 {
00027 
00028 TinyGLTexture::TinyGLTexture(const Graphics::Surface *surface) {
00029     width = surface->w;
00030     height = surface->h;
00031     format = surface->format;
00032 
00033     if (format.bytesPerPixel == 4) {
00034         internalFormat = TGL_RGBA;
00035         sourceFormat = TGL_UNSIGNED_BYTE;
00036     } else if (format.bytesPerPixel == 2) {
00037         internalFormat = TGL_RGB;
00038         sourceFormat = TGL_UNSIGNED_BYTE; // UNSIGNED_SHORT_5_6_5 not provided
00039     } else
00040         error("Unknown pixel format");
00041 
00042     tglGenTextures(1, &id);
00043     tglBindTexture(TGL_TEXTURE_2D, id);
00044     tglTexImage2D(TGL_TEXTURE_2D, 0, 3, width, height, 0, internalFormat, sourceFormat, 0);
00045     tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_LINEAR);
00046     tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_LINEAR);
00047 
00048     // NOTE: TinyGL doesn't have issues with white lines so doesn't need use TGL_CLAMP_TO_EDGE
00049     tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_WRAP_S, TGL_REPEAT);
00050     tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_WRAP_T, TGL_REPEAT);
00051     _blitImage = Graphics::tglGenBlitImage();
00052 
00053     update(surface);
00054 }
00055 
00056 TinyGLTexture::~TinyGLTexture() {
00057     tglDeleteTextures(1, &id);
00058     tglDeleteBlitImage(_blitImage);
00059 }
00060 
00061 void TinyGLTexture::update(const Graphics::Surface *surface) {
00062     tglBindTexture(TGL_TEXTURE_2D, id);
00063     tglTexImage2D(TGL_TEXTURE_2D, 0, 3, width, height, 0,
00064             internalFormat, sourceFormat, const_cast<void *>(surface->getPixels())); // TESTME: Not sure if it works.
00065     Graphics::tglUploadBlitImage(_blitImage, *surface, 0, false);
00066 }
00067 
00068 void TinyGLTexture::updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) {
00069     // FIXME: TinyGL does not support partial texture update
00070     update(surface);
00071 }
00072 
00073 Graphics::BlitImage *TinyGLTexture::getBlitTexture() const {
00074     return _blitImage;
00075 }
00076 
00077 } // End of namespace Myst3


Generated on Sat Jul 13 2019 05:01:09 for ResidualVM by doxygen 1.7.1
curved edge   curved edge