2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "cpicosurface.h"
26 CPicoSurface::CPicoSurface(picoSurface_t *pSurface)
30 m_pSurface = pSurface;
32 // PicoFixSurfaceNormals( pSurface );
36 m_shader = QERApp_Shader_ForName(GetShaderName());
39 CPicoSurface::~CPicoSurface()
44 void CPicoSurface::Draw(int state, int rflags)
46 Draw(state, m_shader, rflags);
49 void CPicoSurface::Draw(int state, IShader *pShader, int rflags)
53 if( !(rflags & (DRAW_RF_SEL_OUTLINE|DRAW_RF_SEL_FILL|DRAW_RF_XY)) )
55 if(state & DRAW_GL_TEXTURE_2D)
57 g_QglTable.m_pfn_qglBindTexture(GL_TEXTURE_2D, pShader->getTexture()->texture_number);
58 if( (rflags & DRAW_RF_CAM) && (pShader->getFlags() & QER_ALPHAFUNC) ) {
62 g_QglTable.m_pfn_qglColor4f( 1.f, 1.f, 1.f, 1.f ); // identity
64 g_QglTable.m_pfn_qglEnable( GL_ALPHA_TEST );
66 pShader->getAlphaFunc( &nFunc, &fRef );
67 g_QglTable.m_pfn_qglAlphaFunc( nFunc, fRef );
72 //g_QglTable.m_pfn_qglColor3fv( pShader->getTexture()->color );
73 /* g_QglTable.m_pfn_qglEnableClientState(GL_COLOR_ARRAY);*/
76 if( !(state & DRAW_GL_WIRE) && (pShader->getFlags() & QER_CULL) )
78 if( pShader->getCull() == 2 )
80 g_QglTable.m_pfn_qglDisable( GL_CULL_FACE );
81 g_QglTable.m_pfn_qglPolygonMode (GL_FRONT, GL_FILL);
85 g_QglTable.m_pfn_qglCullFace( GL_BACK );
90 switch( PicoGetSurfaceType(m_pSurface) )
92 case PICO_TRIANGLES: g_QglTable.m_pfn_qglBegin(GL_TRIANGLES);
93 for (j=0; j<PicoGetSurfaceNumIndexes(m_pSurface); j++)
95 g_QglTable.m_pfn_qglNormal3fv(PicoGetSurfaceNormal(m_pSurface,PicoGetSurfaceIndex(m_pSurface,j)));
97 if( !(rflags & (DRAW_RF_SEL_OUTLINE|DRAW_RF_SEL_FILL|DRAW_RF_XY)) ) {
98 if(state & DRAW_GL_TEXTURE_2D) {
99 g_QglTable.m_pfn_qglTexCoord2fv(PicoGetSurfaceST(m_pSurface,0,PicoGetSurfaceIndex(m_pSurface,j)));
101 picoByte_t *vertexColor = PicoGetSurfaceColor(m_pSurface,0,PicoGetSurfaceIndex(m_pSurface,j));
102 //% g_QglTable.m_pfn_qglColor4f( vertexColor[ 0 ] / 255.f,
103 //% vertexColor[ 1 ] / 255.f,
104 //% vertexColor[ 2 ] / 255.f,
105 //% vertexColor[ 3 ] / 255.f );
106 g_QglTable.m_pfn_qglColor4ubv( vertexColor );
109 g_QglTable.m_pfn_qglVertex3fv( PicoGetSurfaceXYZ( m_pSurface, PicoGetSurfaceIndex( m_pSurface, j ) ) );
111 g_QglTable.m_pfn_qglEnd();
112 /*g_QglTable.m_pfn_qglVertexPointer( 3, GL_FLOAT, 0, PicoGetSurfaceXYZ( m_pSurface, 0 ) );
113 g_QglTable.m_pfn_qglNormalPointer( GL_FLOAT, 0, PicoGetSurfaceNormal( m_pSurface, 0 ) );
114 if( !(rflags & (DRAW_RF_SEL_OUTLINE|DRAW_RF_SEL_FILL|DRAW_RF_XY)) ) {
115 if( state & DRAW_GL_TEXTURE_2D ) {
116 g_QglTable.m_pfn_qglTexCoordPointer( 2, GL_FLOAT, 0, PicoGetSurfaceST( m_pSurface, 0, 0 ) );
118 g_QglTable.m_pfn_qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, PicoGetSurfaceColor( m_pSurface, 0, 0 ) );
121 g_QglTable.m_pfn_qglDrawElements( GL_TRIANGLES, PicoGetSurfaceNumIndexes( m_pSurface ), GL_UNSIGNED_INT, PicoGetSurfaceIndexes( m_pSurface, 0 ) );*/
123 /*g_QglTable.m_pfn_qglColor3f( 0.f, .5f, 1.f );
124 g_QglTable.m_pfn_qglBegin( GL_LINES );
125 for( int i = 0; i < PicoGetSurfaceNumIndexes( m_pSurface ); i++ ) {
127 VectorMA( PicoGetSurfaceXYZ( m_pSurface, PicoGetSurfaceIndex( m_pSurface, i ) ), .3f, PicoGetSurfaceNormal( m_pSurface, PicoGetSurfaceIndex( m_pSurface, i ) ), outerpoint );
128 g_QglTable.m_pfn_qglVertex3fv( PicoGetSurfaceXYZ( m_pSurface, PicoGetSurfaceIndex( m_pSurface, i ) ) );
129 g_QglTable.m_pfn_qglVertex3fv( outerpoint );
131 g_QglTable.m_pfn_qglEnd();*/
134 default: Sys_Printf( "ERROR: Unsupported Pico Surface Type: %i", PicoGetSurfaceType(m_pSurface) );
138 if( !(rflags & (DRAW_RF_SEL_OUTLINE|DRAW_RF_SEL_FILL|DRAW_RF_XY)) )
140 if( (state & DRAW_GL_TEXTURE_2D) && (rflags & DRAW_RF_CAM) && (pShader->getFlags() & QER_ALPHAFUNC) ) {
141 g_QglTable.m_pfn_qglDisable( GL_ALPHA_TEST );
144 /* if(!(state & DRAW_GL_TEXTURE_2D)) {
145 g_QglTable.m_pfn_qglDisableClientState(GL_COLOR_ARRAY);
148 if( !(state & DRAW_GL_WIRE) && (pShader->getFlags() & QER_CULL) )
150 if( pShader->getCull() == 2 )
152 g_QglTable.m_pfn_qglPolygonMode (GL_FRONT, GL_LINE);
153 g_QglTable.m_pfn_qglEnable( GL_CULL_FACE );
157 g_QglTable.m_pfn_qglCullFace( GL_FRONT );
165 void CPicoSurface::AccumulateBBox()
170 for (i=0; i<PicoGetSurfaceNumVertexes(m_pSurface); i++)
172 p=PicoGetSurfaceXYZ(m_pSurface,i);
173 aabb_extend_by_point(&m_BBox, p);
175 aabb_update_radius(&m_BBox);
178 bool CPicoSurface::TestRay (const ray_t *ray, vec_t *dist) const
181 vec_t start_dist = *dist;
182 vec_t local_dist = *dist;
183 if (aabb_intersect_ray(&m_BBox, ray, &local_dist))
185 switch( PicoGetSurfaceType(m_pSurface) )
188 for (i=0; i<PicoGetSurfaceNumIndexes(m_pSurface); i+=3)
190 local_dist = ray_intersect_triangle(ray, true, PicoGetSurfaceXYZ(m_pSurface,PicoGetSurfaceIndex(m_pSurface,i+2)),
191 PicoGetSurfaceXYZ(m_pSurface,PicoGetSurfaceIndex(m_pSurface,i+1)),
192 PicoGetSurfaceXYZ(m_pSurface,PicoGetSurfaceIndex(m_pSurface,i)));
193 if (local_dist < *dist)
198 Sys_Printf( "ERROR: Unsupported Pico Surface Type: %i", PicoGetSurfaceType(m_pSurface) );
202 return (*dist < start_dist);