doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RenderWindow.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 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 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 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.
25 
26 ===========================================================================
27 */
28 
29 #include "../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "DeviceContext.h"
33 #include "Window.h"
34 #include "UserInterfaceLocal.h"
35 #include "RenderWindow.h"
36 
38  dc = d;
39  gui = g;
40  CommonInit();
41 }
42 
44  gui = g;
45  CommonInit();
46 }
47 
50 }
51 
54  needsRender = true;
55  lightOrigin = idVec4(-128.0f, 0.0f, 0.0f, 1.0f);
56  lightColor = idVec4(1.0f, 1.0f, 1.0f, 1.0f);
57  modelOrigin.Zero();
58  viewOffset = idVec4(-128.0f, 0.0f, 0.0f, 1.0f);
59  modelAnim = NULL;
60  animLength = 0;
61  animEndTime = -1;
62  modelDef = -1;
63  updateAnimation = true;
64 }
65 
66 
68 
69  if (!updateAnimation) {
70  return;
71  }
72 
73  if (animName.Length() && animClass.Length()) {
77  if (modelAnim) {
79  animEndTime = time + animLength;
80  }
81  }
82  updateAnimation = false;
83 
84 }
85 
87  if (needsRender) {
89  idDict spawnArgs;
90  spawnArgs.Set("classname", "light");
91  spawnArgs.Set("name", "light_1");
92  spawnArgs.Set("origin", lightOrigin.ToVec3().ToString());
93  spawnArgs.Set("_color", lightColor.ToVec3().ToString());
96  if ( !modelName[0] ) {
97  common->Warning( "Window '%s' in gui '%s': no model set", GetName(), GetGui()->GetSourceFile() );
98  }
99  memset( &worldEntity, 0, sizeof( worldEntity ) );
100  spawnArgs.Clear();
101  spawnArgs.Set("classname", "func_static");
102  spawnArgs.Set("model", modelName);
103  spawnArgs.Set("origin", modelOrigin.c_str());
105  if ( worldEntity.hModel ) {
107  worldEntity.axis = v.ToMat3();
108  worldEntity.shaderParms[0] = 1;
109  worldEntity.shaderParms[1] = 1;
110  worldEntity.shaderParms[2] = 1;
111  worldEntity.shaderParms[3] = 1;
113  }
114  needsRender = false;
115  }
116 }
117 
118 void idRenderWindow::Render( int time ) {
124  if ( worldEntity.hModel ) {
125  if (updateAnimation) {
126  BuildAnimation(time);
127  }
128  if (modelAnim) {
129  if (time > animEndTime) {
130  animEndTime = time + animLength;
131  }
133  }
136  }
137 }
138 
139 
140 
141 
142 void idRenderWindow::Draw(int time, float x, float y) {
143  PreRender();
144  Render(time);
145 
146  memset( &refdef, 0, sizeof( refdef ) );
148  //refdef.vieworg.Set(-128, 0, 0);
149 
151  refdef.shaderParms[0] = 1;
152  refdef.shaderParms[1] = 1;
153  refdef.shaderParms[2] = 1;
154  refdef.shaderParms[3] = 1;
155 
156  refdef.x = drawRect.x;
157  refdef.y = drawRect.y;
160  refdef.fov_x = 90;
161  refdef.fov_y = 2 * atan((float)drawRect.h / drawRect.w) * idMath::M_RAD2DEG;
162 
163  refdef.time = time;
165 }
166 
169 }
170 
171 //
172 //
173 idWinVar *idRenderWindow::GetWinVarByName(const char *_name, bool fixup, drawWin_t** owner ) {
174 //
175  if (idStr::Icmp(_name, "model") == 0) {
176  return &modelName;
177  }
178  if (idStr::Icmp(_name, "anim") == 0) {
179  return &animName;
180  }
181  if (idStr::Icmp(_name, "lightOrigin") == 0) {
182  return &lightOrigin;
183  }
184  if (idStr::Icmp(_name, "lightColor") == 0) {
185  return &lightColor;
186  }
187  if (idStr::Icmp(_name, "modelOrigin") == 0) {
188  return &modelOrigin;
189  }
190  if (idStr::Icmp(_name, "modelRotate") == 0) {
191  return &modelRotate;
192  }
193  if (idStr::Icmp(_name, "viewOffset") == 0) {
194  return &viewOffset;
195  }
196  if (idStr::Icmp(_name, "needsRender") == 0) {
197  return &needsRender;
198  }
199 
200 //
201 //
202  return idWindow::GetWinVarByName(_name, fixup, owner);
203 //
204 }
205 
206 bool idRenderWindow::ParseInternalVar(const char *_name, idParser *src) {
207  if (idStr::Icmp(_name, "animClass") == 0) {
208  ParseString(src, animClass);
209  return true;
210  }
211  return idWindow::ParseInternalVar(_name, src);
212 }
GLubyte g
Definition: glext.h:4662
renderView_t refdef
Definition: RenderWindow.h:52
idMat3 ToMat3(void) const
Definition: Vector.cpp:195
const idMD5Anim * modelAnim
Definition: RenderWindow.h:56
virtual void FreeRenderWorld(idRenderWorld *rw)=0
int Length()
Definition: Winvar.h:192
void Render(int time)
const char * GetName()
Definition: Window.h:247
const GLdouble * v
Definition: glext.h:2936
virtual qhandle_t AddEntityDef(const renderEntity_t *re)=0
renderLight_t rLight
Definition: RenderWindow.h:55
float x() const
Definition: Winvar.h:576
int Length(void) const
Definition: Str.h:702
virtual bool ParseInternalVar(const char *name, idParser *src)
Definition: Window.cpp:1915
GLenum GLint GLint y
Definition: glext.h:2849
idRenderSystem * renderSystem
const idVec3 & ToVec3() const
Definition: Winvar.h:618
void ParseString(idParser *src, idStr &out)
Definition: Window.cpp:1883
Definition: Vector.h:316
const int SHADERPARM_GREEN
Definition: RenderWorld.h:47
idDeviceContext * dc
Definition: Window.h:425
virtual qhandle_t AddLightDef(const renderLight_t *rlight)=0
idWinVec4 viewOffset
Definition: RenderWindow.h:68
GLuint src
Definition: glext.h:5390
void Set(const char *key, const char *value)
Definition: Dict.cpp:275
void Identity(void)
Definition: Matrix.h:591
GLenum GLint x
Definition: glext.h:2849
virtual void ANIM_CreateAnimFrame(const idRenderModel *model, const idMD5Anim *anim, int numJoints, idJointMat *frame, int time, const idVec3 &offset, bool remove_origin_offset)
int Icmp(const char *text) const
Definition: Str.h:667
idGameEdit * gameEdit
Definition: GameEdit.cpp:668
float shaderParms[MAX_ENTITY_SHADER_PARMS]
Definition: RenderWorld.h:201
idWinVec4 lightOrigin
Definition: RenderWindow.h:64
const int SHADERPARM_BLUE
Definition: RenderWorld.h:48
void BuildAnimation(int time)
static const float M_RAD2DEG
Definition: Math.h:215
virtual ~idRenderWindow()
idRectangle drawRect
Definition: Window.h:373
renderEntity_t worldEntity
Definition: RenderWindow.h:54
virtual idRenderWorld * AllocRenderWorld(void)=0
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup=false, drawWin_t **owner=NULL)
bool updateAnimation
Definition: RenderWindow.h:72
virtual void PostParse()
Definition: Window.cpp:1709
void Zero()
Definition: Winvar.h:611
Definition: Vector.h:808
idWinVec4 lightColor
Definition: RenderWindow.h:65
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
qhandle_t modelDef
Definition: RenderWindow.h:60
virtual const char * c_str() const
Definition: Winvar.h:607
float y
Definition: Rectangle.h:37
idCommon * common
Definition: Common.cpp:206
idJointMat * joints
Definition: RenderWorld.h:135
Definition: Dict.h:65
#define NULL
Definition: Lib.h:88
void Clear(void)
Definition: Dict.cpp:201
void * Mem_Alloc16(const int size)
Definition: Heap.cpp:1107
float shaderParms[MAX_GLOBAL_SHADER_PARMS]
Definition: RenderWorld.h:223
virtual bool InitFromMap(const char *mapName)=0
virtual void UpdateEntityDef(qhandle_t entityHandle, const renderEntity_t *re)=0
idRenderWindow(idUserInterfaceLocal *gui)
idRenderModel * hModel
Definition: RenderWorld.h:81
idWinStr animName
Definition: RenderWindow.h:62
virtual void UpdateLightDef(qhandle_t lightHandle, const renderLight_t *rlight)=0
virtual const idMD5Anim * ANIM_GetAnimFromEntityDef(const char *classname, const char *animname)
float z() const
Definition: Winvar.h:584
const char * ToString(int precision=2) const
Definition: Vector.cpp:221
float x
Definition: Rectangle.h:36
idVec3 vieworg
Definition: RenderWorld.h:215
const int SHADERPARM_RED
Definition: RenderWorld.h:46
idUserInterfaceLocal * gui
Definition: Window.h:427
tuple f
Definition: idal.py:89
idUserInterfaceLocal * GetGui()
Definition: Window.h:225
idWinBool needsRender
Definition: RenderWindow.h:69
virtual int ANIM_GetLength(const idMD5Anim *anim)
idWinStr modelName
Definition: RenderWindow.h:61
float w
Definition: Rectangle.h:38
virtual void ParseSpawnArgsToRenderLight(const idDict *args, renderLight_t *renderLight)
Definition: Light.cpp:80
virtual void RenderScene(const renderView_t *renderView)=0
virtual void ParseSpawnArgsToRenderEntity(const idDict *args, renderEntity_t *renderEntity)
Definition: Entity.cpp:229
virtual int NumJoints(void) const =0
idRenderWorld * world
Definition: RenderWindow.h:53
virtual bool ParseInternalVar(const char *name, idParser *src)
float h
Definition: Rectangle.h:39
idWinVec4 modelRotate
Definition: RenderWindow.h:67
qhandle_t lightDef
Definition: RenderWindow.h:59
virtual void Draw(int time, float x, float y)
virtual void PostParse()
idMat3 viewaxis
Definition: RenderWorld.h:216
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
float shaderParms[MAX_ENTITY_SHADER_PARMS]
Definition: RenderWorld.h:127
float y() const
Definition: Winvar.h:580
idWinVec4 modelOrigin
Definition: RenderWindow.h:66
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup=false, drawWin_t **owner=NULL)
Definition: Window.cpp:1776