doom3-bfg/neo/ui/RenderWindow.cpp

239 lines
6.5 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-11-26 18:58:24 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
2012-11-26 18:58:24 +00:00
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#pragma hdrstop
#include "precompiled.h"
2012-11-26 18:58:24 +00:00
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "RenderWindow.h"
// NO LONGER SUPPORTED!
//
// D3 could render a 3D model in a subrect of a full screen
// GUI for the main menus, but we have cut that ability so
// we don't need to deal with offset viewports on all platforms.
idRenderWindow::idRenderWindow( idUserInterfaceLocal* g ) : idWindow( g )
{
2012-11-26 18:58:24 +00:00
gui = g;
CommonInit();
}
idRenderWindow::~idRenderWindow()
{
renderSystem->FreeRenderWorld( world );
2012-11-26 18:58:24 +00:00
}
void idRenderWindow::CommonInit()
{
2012-11-26 18:58:24 +00:00
world = renderSystem->AllocRenderWorld();
needsRender = true;
lightOrigin = idVec4( -128.0f, 0.0f, 0.0f, 1.0f );
lightColor = idVec4( 1.0f, 1.0f, 1.0f, 1.0f );
2012-11-26 18:58:24 +00:00
modelOrigin.Zero();
viewOffset = idVec4( -128.0f, 0.0f, 0.0f, 1.0f );
2012-11-26 18:58:24 +00:00
modelAnim = NULL;
animLength = 0;
animEndTime = -1;
modelDef = -1;
updateAnimation = true;
}
void idRenderWindow::BuildAnimation( int time )
{
if( !updateAnimation )
{
2012-11-26 18:58:24 +00:00
return;
}
if( animName.Length() && animClass.Length() )
{
2012-11-26 18:58:24 +00:00
worldEntity.numJoints = worldEntity.hModel->NumJoints();
worldEntity.joints = ( idJointMat* )Mem_Alloc16( SIMD_ROUND_JOINTS( worldEntity.numJoints ) * sizeof( *worldEntity.joints ), TAG_JOINTMAT );
2012-11-26 18:58:24 +00:00
modelAnim = gameEdit->ANIM_GetAnimFromEntityDef( animClass, animName );
if( modelAnim )
{
2012-11-26 18:58:24 +00:00
animLength = gameEdit->ANIM_GetLength( modelAnim );
animEndTime = time + animLength;
}
}
updateAnimation = false;
2012-11-26 18:58:24 +00:00
}
void idRenderWindow::PreRender()
{
if( needsRender )
{
2012-11-26 18:58:24 +00:00
world->InitFromMap( NULL );
idDict spawnArgs;
spawnArgs.Set( "classname", "light" );
spawnArgs.Set( "name", "light_1" );
spawnArgs.Set( "origin", lightOrigin.ToVec3().ToString() );
spawnArgs.Set( "_color", lightColor.ToVec3().ToString() );
2012-11-26 18:58:24 +00:00
gameEdit->ParseSpawnArgsToRenderLight( &spawnArgs, &rLight );
lightDef = world->AddLightDef( &rLight );
if( !modelName[0] )
{
2012-11-26 18:58:24 +00:00
common->Warning( "Window '%s' in gui '%s': no model set", GetName(), GetGui()->GetSourceFile() );
}
memset( &worldEntity, 0, sizeof( worldEntity ) );
spawnArgs.Clear();
spawnArgs.Set( "classname", "func_static" );
spawnArgs.Set( "model", modelName );
spawnArgs.Set( "origin", modelOrigin.c_str() );
2012-11-26 18:58:24 +00:00
gameEdit->ParseSpawnArgsToRenderEntity( &spawnArgs, &worldEntity );
if( worldEntity.hModel )
{
2012-11-26 18:58:24 +00:00
idVec3 v = modelRotate.ToVec3();
worldEntity.axis = v.ToMat3();
worldEntity.shaderParms[0] = 1;
worldEntity.shaderParms[1] = 1;
worldEntity.shaderParms[2] = 1;
worldEntity.shaderParms[3] = 1;
modelDef = world->AddEntityDef( &worldEntity );
}
needsRender = false;
}
}
void idRenderWindow::Render( int time )
{
2012-11-26 18:58:24 +00:00
rLight.origin = lightOrigin.ToVec3();
rLight.shaderParms[SHADERPARM_RED] = lightColor.x();
rLight.shaderParms[SHADERPARM_GREEN] = lightColor.y();
rLight.shaderParms[SHADERPARM_BLUE] = lightColor.z();
world->UpdateLightDef( lightDef, &rLight );
if( worldEntity.hModel )
{
if( updateAnimation )
{
BuildAnimation( time );
2012-11-26 18:58:24 +00:00
}
if( modelAnim )
{
if( time > animEndTime )
{
2012-11-26 18:58:24 +00:00
animEndTime = time + animLength;
}
gameEdit->ANIM_CreateAnimFrame( worldEntity.hModel, modelAnim, worldEntity.numJoints, worldEntity.joints, animLength - ( animEndTime - time ), vec3_origin, false );
2012-11-26 18:58:24 +00:00
}
worldEntity.axis = idAngles( modelRotate.x(), modelRotate.y(), modelRotate.z() ).ToMat3();
world->UpdateEntityDef( modelDef, &worldEntity );
2012-11-26 18:58:24 +00:00
}
}
void idRenderWindow::Draw( int time, float x, float y )
{
2012-11-26 18:58:24 +00:00
PreRender();
Render( time );
2012-11-26 18:58:24 +00:00
memset( &refdef, 0, sizeof( refdef ) );
refdef.vieworg = viewOffset.ToVec3();;
//refdef.vieworg.Set(-128, 0, 0);
2012-11-26 18:58:24 +00:00
refdef.viewaxis.Identity();
refdef.shaderParms[0] = 1;
refdef.shaderParms[1] = 1;
refdef.shaderParms[2] = 1;
refdef.shaderParms[3] = 1;
2012-11-26 18:58:24 +00:00
refdef.fov_x = 90;
refdef.fov_y = 2 * atan( ( float )drawRect.h / drawRect.w ) * idMath::M_RAD2DEG;
2012-11-26 18:58:24 +00:00
refdef.time[0] = time;
refdef.time[1] = time;
world->RenderScene( &refdef );
2012-11-26 18:58:24 +00:00
}
void idRenderWindow::PostParse()
{
2012-11-26 18:58:24 +00:00
idWindow::PostParse();
}
//
//
idWinVar* idRenderWindow::GetWinVarByName( const char* _name, bool fixup, drawWin_t** owner )
{
//
if( idStr::Icmp( _name, "model" ) == 0 )
{
2012-11-26 18:58:24 +00:00
return &modelName;
}
if( idStr::Icmp( _name, "anim" ) == 0 )
{
2012-11-26 18:58:24 +00:00
return &animName;
}
if( idStr::Icmp( _name, "lightOrigin" ) == 0 )
{
2012-11-26 18:58:24 +00:00
return &lightOrigin;
}
if( idStr::Icmp( _name, "lightColor" ) == 0 )
{
2012-11-26 18:58:24 +00:00
return &lightColor;
}
if( idStr::Icmp( _name, "modelOrigin" ) == 0 )
{
2012-11-26 18:58:24 +00:00
return &modelOrigin;
}
if( idStr::Icmp( _name, "modelRotate" ) == 0 )
{
2012-11-26 18:58:24 +00:00
return &modelRotate;
}
if( idStr::Icmp( _name, "viewOffset" ) == 0 )
{
2012-11-26 18:58:24 +00:00
return &viewOffset;
}
if( idStr::Icmp( _name, "needsRender" ) == 0 )
{
2012-11-26 18:58:24 +00:00
return &needsRender;
}
//
//
return idWindow::GetWinVarByName( _name, fixup, owner );
//
2012-11-26 18:58:24 +00:00
}
bool idRenderWindow::ParseInternalVar( const char* _name, idTokenParser* src )
{
if( idStr::Icmp( _name, "animClass" ) == 0 )
{
ParseString( src, animClass );
2012-11-26 18:58:24 +00:00
return true;
}
return idWindow::ParseInternalVar( _name, src );
2012-11-26 18:58:24 +00:00
}