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

select.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 int glRenderMode(int mode) {
00034     GLContext *c = gl_get_context();
00035     int result = 0;
00036 
00037     switch (c->render_mode) {
00038     case TGL_RENDER:
00039         break;
00040     case TGL_SELECT:
00041         if (c->select_overflow) {
00042             result = -c->select_hits;
00043         } else {
00044             result = c->select_hits;
00045         }
00046         c->select_overflow = 0;
00047         c->select_ptr = c->select_buffer;
00048         c->name_stack_size = 0;
00049         break;
00050     default:
00051         assert(0);
00052     }
00053     switch (mode) {
00054     case TGL_RENDER:
00055         c->render_mode = TGL_RENDER;
00056         break;
00057     case TGL_SELECT:
00058         c->render_mode = TGL_SELECT;
00059         assert(c->select_buffer != NULL);
00060         c->select_ptr = c->select_buffer;
00061         c->select_hits = 0;
00062         c->select_overflow = 0;
00063         c->select_hit = NULL;
00064         break;
00065     default:
00066         assert(0);
00067     }
00068     return result;
00069 }
00070 
00071 void glSelectBuffer(int size, unsigned int *buf) {
00072     GLContext *c = gl_get_context();
00073 
00074     assert(c->render_mode != TGL_SELECT);
00075 
00076     c->select_buffer = buf;
00077     c->select_size = size;
00078 }
00079 
00080 void glopInitNames(GLContext *c, GLParam *) {
00081     if (c->render_mode == TGL_SELECT) {
00082         c->name_stack_size = 0;
00083         c->select_hit = NULL;
00084     }
00085 }
00086 
00087 void glopPushName(GLContext *c, GLParam *p) {
00088     if (c->render_mode == TGL_SELECT) {
00089         assert(c->name_stack_size < MAX_NAME_STACK_DEPTH);
00090         c->name_stack[c->name_stack_size++] = p[1].i;
00091         c->select_hit = NULL;
00092     }
00093 }
00094 
00095 void glopPopName(GLContext *c, GLParam *) {
00096     if (c->render_mode == TGL_SELECT) {
00097         assert(c->name_stack_size > 0);
00098         c->name_stack_size--;
00099         c->select_hit = NULL;
00100     }
00101 }
00102 
00103 void glopLoadName(GLContext *c, GLParam *p) {
00104     if (c->render_mode == TGL_SELECT) {
00105         assert(c->name_stack_size > 0);
00106         c->name_stack[c->name_stack_size - 1] = p[1].i;
00107         c->select_hit = NULL;
00108     }
00109 }
00110 
00111 void gl_add_select(GLContext *c, unsigned int zmin, unsigned int zmax) {
00112     unsigned int *ptr;
00113     int n;
00114 
00115     if (!c->select_overflow) {
00116         if (!c->select_hit) {
00117             n = c->name_stack_size;
00118             if ((c->select_ptr - c->select_buffer + 3 + n) > c->select_size) {
00119                 c->select_overflow = 1;
00120             } else {
00121                 ptr = c->select_ptr;
00122                 c->select_hit = ptr;
00123                 *ptr++ = c->name_stack_size;
00124                 *ptr++ = zmin;
00125                 *ptr++ = zmax;
00126                 for (int i = 0; i < n; i++)
00127                     *ptr++ = c->name_stack[i];
00128                 c->select_ptr = ptr;
00129                 c->select_hits++;
00130             }
00131         } else {
00132             if (zmin < c->select_hit[1])
00133                 c->select_hit[1] = zmin;
00134             if (zmax > c->select_hit[2])
00135                 c->select_hit[2] = zmax;
00136         }
00137     }
00138 }
00139 
00140 } // end of namespace TinyGL


Generated on Sat Dec 14 2019 05:00:47 for ResidualVM by doxygen 1.7.1
curved edge   curved edge