00001 #include "MercuryDynTex.h" 00002 #include "MercuryDisplay.h" 00003 #include "MercuryScreen.h" 00004 #include "MercuryTextureManager.h" 00005 00006 //Yuck! this is only temporary for ripping 00007 00008 //#include <windows.h> 00009 //#include <GL/gl.h> 00010 00011 //A Dyntex lives two lives, either as a single texture or a cube texture 00012 00013 MercuryDynTex::MercuryDynTex() 00014 { 00015 m_pAtt = NULL; 00016 MercuryObject::MercuryObject(); 00017 } 00018 00019 void MercuryDynTex::Init() 00020 { 00021 MercuryObject::Init(); 00022 Camera.Init(); 00023 Camera.SetName( GetName() + "Camera" ); 00024 Camera.SetPosition( MercuryPoint( 0,0,0 ) ); 00025 Camera.SetTarget( MercuryPoint( 0,0,-1 ) ); 00026 Camera.SetUp( MercuryPoint( 0,1,0 ) ); 00027 m_bOrtho = false; 00028 } 00029 00030 void MercuryDynTex::Update( const float dTime ) 00031 { 00032 Camera.Update( dTime); 00033 MercuryObject::Update( dTime ); 00034 } 00035 00036 void MercuryDynTex::Prerender() 00037 { 00038 /* 00039 if (m_pAtt->GetMapping() == CUBE) 00040 { 00041 Camera.SetTarget( MercuryPoint( 1,0,0 ) ); 00042 Camera.Render(); 00043 MercuryObject::Prerender(); 00044 00045 Camera.SetTarget( MercuryPoint( -1,0,0 ) ); 00046 Camera.Render(); 00047 MercuryObject::Prerender(); 00048 00049 Camera.SetTarget( MercuryPoint( 0,1,0 ) ); 00050 Camera.Render(); 00051 MercuryObject::Prerender(); 00052 00053 Camera.SetTarget( MercuryPoint( 0,-1,0 ) ); 00054 Camera.Render(); 00055 MercuryObject::Prerender(); 00056 00057 Camera.SetTarget( MercuryPoint( 0,0,1 ) ); 00058 Camera.Render(); 00059 MercuryObject::Prerender(); 00060 00061 Camera.SetTarget( MercuryPoint( 0,0,-1 ) ); 00062 Camera.Render(); 00063 MercuryObject::Prerender(); 00064 } 00065 else 00066 { 00067 Camera.Render(); 00068 MercuryObject::Prerender(); 00069 } 00070 00071 //YUCK! Too bad we can't preserve the frustum cull stuff safely 00072 if( ((MercuryObject*)m_parentObject)->IsTypeOf( "MercuryScreen" ) ) 00073 ((MercuryScreen*)m_parentObject)->GetCamera()->Render(); 00074 */ 00075 00076 // MercuryDisplay C; 00077 00078 // C. 00079 // C.Ortho( 0,0,1,1,0,10 ); 00080 /* 00081 if (m_pAtt->GetMapping() != CUBE) 00082 { 00083 Camera.Render(); 00084 MercuryObject::Prerender(); 00085 // DISPLAY->BeginRenderToDynamicTexture(m_pAtt); 00086 if( m_bOrtho ) 00087 { 00088 //Tricky -- we flip the z direction so + z's are visible 00089 DISPLAY->Ortho( m_fLX,m_fHX,m_fHY,m_fLY,-m_fLZ,-m_fHZ ); 00090 DISPLAY->SendProjectionMatrixData(); 00091 } 00092 // DISPLAY->ToggleZBufferWrite( true ); 00093 // DISPLAY->EnableDepthTest(); 00094 Camera.Render(); 00095 MercuryObject::CustomRender(); 00096 00097 // DISPLAY->EndRenderToDynamicTexture(); 00098 00099 00100 00101 //YUCK! Too bad we can't preserve the frustum cull stuff safely 00102 if( m_parentObject ) 00103 if( ((MercuryObject*)m_parentObject)->IsTypeOf( "MercuryScreen" ) ) 00104 ((MercuryScreen*)m_parentObject)->GetCamera()->Render(); 00105 } 00106 else 00107 { 00108 00109 Camera.SetTarget( MercuryPoint( 1,0,0 ) ); 00110 Camera.Render(); 00111 MercuryObject::Prerender(); 00112 // DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 0); 00113 Camera.Render(); 00114 MercuryObject::CustomRender(); 00115 // DISPLAY->EndRenderToDynamicCubeTexture(); 00116 00117 Camera.SetTarget( MercuryPoint( -1,0,0 ) ); 00118 Camera.Render(); 00119 MercuryObject::Prerender(); 00120 // DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 1); 00121 Camera.Render(); 00122 MercuryObject::CustomRender(); 00123 // DISPLAY->EndRenderToDynamicCubeTexture(); 00124 00125 Camera.SetTarget( MercuryPoint( 0,1,0 ) ); 00126 Camera.Render(); 00127 MercuryObject::Prerender(); 00128 // DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 2); 00129 Camera.Render(); 00130 MercuryObject::CustomRender(); 00131 // DISPLAY->EndRenderToDynamicCubeTexture(); 00132 00133 Camera.SetTarget( MercuryPoint( 0,-1,0 ) ); 00134 Camera.Render(); 00135 MercuryObject::Prerender(); 00136 // DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 3); 00137 Camera.Render(); 00138 MercuryObject::CustomRender(); 00139 // DISPLAY->EndRenderToDynamicCubeTexture(); 00140 00141 Camera.SetTarget( MercuryPoint( 0,0,1 ) ); 00142 Camera.Render(); 00143 MercuryObject::Prerender(); 00144 DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 4); 00145 Camera.Render(); 00146 MercuryObject::CustomRender(); 00147 DISPLAY->EndRenderToDynamicCubeTexture(); 00148 00149 00150 Camera.SetTarget( MercuryPoint( 0,0,-1 ) ); 00151 Camera.Render(); 00152 MercuryObject::Prerender(); 00153 DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 5); 00154 Camera.Render(); 00155 MercuryObject::CustomRender(); 00156 DISPLAY->EndRenderToDynamicCubeTexture(); 00157 } 00158 */ 00159 } 00160 00161 void MercuryDynTex::CustomRender() 00162 { 00163 /* 00164 if (m_pAtt->GetMapping() != CUBE) 00165 { 00166 DISPLAY->BeginRenderToDynamicTexture(m_pAtt); 00167 Camera.Render(); 00168 MercuryObject::CustomRender(); 00169 DISPLAY->EndRenderToDynamicTexture(); 00170 00171 //YUCK! Too bad we can't preserve the frustum cull stuff safely 00172 if( ((MercuryObject*)m_parentObject)->IsTypeOf( "MercuryScreen" ) ) 00173 ((MercuryScreen*)m_parentObject)->GetCamera()->Render(); 00174 } 00175 */ 00176 /* 00177 if (m_pAtt->GetMapping() == CUBE) 00178 { 00179 00180 Camera.SetTarget( MercuryPoint( 1,0,0 ) ); 00181 DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 0); 00182 Camera.Render(); 00183 MercuryObject::CustomRender(); 00184 DISPLAY->EndRenderToDynamicCubeTexture(); 00185 00186 Camera.SetTarget( MercuryPoint( -1,0,0 ) ); 00187 DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 1); 00188 Camera.Render(); 00189 MercuryObject::CustomRender(); 00190 DISPLAY->EndRenderToDynamicCubeTexture(); 00191 00192 Camera.SetTarget( MercuryPoint( 0,1,0 ) ); 00193 DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 2); 00194 Camera.Render(); 00195 MercuryObject::CustomRender(); 00196 DISPLAY->EndRenderToDynamicCubeTexture(); 00197 00198 Camera.SetTarget( MercuryPoint( 0,-1,0 ) ); 00199 DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 3); 00200 Camera.Render(); 00201 MercuryObject::CustomRender(); 00202 DISPLAY->EndRenderToDynamicCubeTexture(); 00203 00204 Camera.SetTarget( MercuryPoint( 0,0,1 ) ); 00205 DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 4); 00206 Camera.Render(); 00207 MercuryObject::CustomRender(); 00208 DISPLAY->EndRenderToDynamicCubeTexture(); 00209 00210 00211 Camera.SetTarget( MercuryPoint( 0,0,-1 ) ); 00212 Camera.Render(); 00213 MercuryObject::Prerender(); 00214 00215 DISPLAY->BeginRenderToDynamicCubeTexture(m_pAtt, 5); 00216 Camera.Render(); 00217 MercuryObject::CustomRender(); 00218 DISPLAY->EndRenderToDynamicCubeTexture(); 00219 } 00220 else 00221 { 00222 DISPLAY->BeginRenderToDynamicTexture(m_pAtt); 00223 Camera.Render(); 00224 MercuryObject::CustomRender(); 00225 DISPLAY->EndRenderToDynamicTexture(); 00226 } 00227 00228 //YUCK! Too bad we can't preserve the frustum cull stuff safely 00229 if( ((MercuryObject*)m_parentObject)->IsTypeOf( "MercuryScreen" ) ) 00230 ((MercuryScreen*)m_parentObject)->GetCamera()->Render(); 00231 */ 00232 } 00233 00234 void MercuryDynTex::AttachToVBO( int iVBO ) 00235 { 00236 if( m_pAtt ) 00237 m_pAtt->MakeAttachToVBO( iVBO ); 00238 } 00239 00240 void MercuryDynTex::AttachTexture( const MString & t ) 00241 { 00242 /* 00243 if (t.substr(0, 7) == "DYNTEX:") 00244 { 00245 */ 00246 //XXX FIX ME 00247 // m_pAtt = TEXTMAN->Load( t ); 00248 /* 00249 } 00250 else if (t.substr(0, 8) == "DYNCUBE:") 00251 { 00252 m_pAtt = TEXTMAN->Load( t ); 00253 } 00254 */ 00255 } 00256 00257 00258 #include "MercuryObjectFactory.h" 00259 REGISTER_OBJECT_TYPE( MercuryDynTex ); 00260 00261 /* 00262 * Copyright (c) 2007, Charles Lohr 00263 * All rights reserved. 00264 * 00265 * Redistribution and use in source and binary forms, with or 00266 * without modification, are permitted provided that the following 00267 * conditions are met: 00268 * - Redistributions of source code must retain the above 00269 * copyright notice, this list of conditions and the following disclaimer. 00270 * - Redistributions in binary form must reproduce the above copyright 00271 * notice, this list of conditions and the following disclaimer in 00272 * the documentation and/or other materials provided with the distribution. 00273 * - Neither the name of the Mercury Engine nor the names of its 00274 * contributors may be used to endorse or promote products derived from 00275 * this software without specific prior written permission. 00276 * 00277 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00278 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00279 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00280 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00281 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00282 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00283 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00284 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00285 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00286 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00287 */ 00288 00289