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

specbuf.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 /*
00024  * This file is based on, or a modified version of code from TinyGL (C) 1997-1998 Fabrice Bellard,
00025  * which is licensed under the zlib-license (see LICENSE).
00026  * It also has modifications by the ResidualVM-team, which are covered under the GPLv2 (or later).
00027  */
00028 
00029 #include "graphics/tinygl/zgl.h"
00030 
00031 namespace TinyGL {
00032 
00033 static void calc_buf(GLSpecBuf *buf, const float shininess) {
00034     float val, inc;
00035     val = 0.0f;
00036     inc = 1.0f / SPECULAR_BUFFER_SIZE;
00037     for (int i = 0; i <= SPECULAR_BUFFER_SIZE; i++) {
00038         buf->buf[i] = pow(val, shininess);
00039         val += inc;
00040     }
00041 }
00042 
00043 GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i, const float shininess) {
00044     GLSpecBuf *found, *oldest;
00045     found = oldest = c->specbuf_first;
00046     while (found && found->shininess_i != shininess_i) {
00047         if (found->last_used < oldest->last_used) {
00048             oldest = found;
00049         }
00050         found = found->next;
00051     }
00052     if (found) {
00053         found->last_used = c->specbuf_used_counter++;
00054         return found;
00055     }
00056     if (!oldest || c->specbuf_num_buffers < MAX_SPECULAR_BUFFERS) {
00057         // create new buffer
00058         GLSpecBuf *buf = (GLSpecBuf *)gl_malloc(sizeof(GLSpecBuf));
00059         if (!buf)
00060             error("could not allocate specular buffer");
00061         c->specbuf_num_buffers++;
00062         buf->next = c->specbuf_first;
00063         c->specbuf_first = buf;
00064         buf->last_used = c->specbuf_used_counter++;
00065         buf->shininess_i = shininess_i;
00066         calc_buf(buf, shininess);
00067         return buf;
00068     }
00069     //overwrite the lru buffer
00070     oldest->shininess_i = shininess_i;
00071     oldest->last_used = c->specbuf_used_counter++;
00072     calc_buf(oldest, shininess);
00073     return oldest;
00074 }
00075 
00076 void specbuf_cleanup(GLContext *c) {
00077     GLSpecBuf *buf, *next;
00078     buf = c->specbuf_first;
00079     for (int i = 0; i < c->specbuf_num_buffers; ++i) {
00080         next = buf->next;
00081         gl_free(buf);
00082         buf = next;
00083     }
00084 }
00085 
00086 } // end of namespace TinyGL


Generated on Sat May 25 2019 05:00:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge