Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
render2d.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19 /***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/render2d.cpp $*
26 * *
27 * $Org Author:: Byon_g $Modtime:: 1/24/01 3:54p $*
28 * *
29 * Author : Kenny Mitchell *
30 * *
31 * $Modtime:: 08/05/02 2:40p $*
32 * *
33 * $Revision:: 48 $*
34 * *
35 * 06/26/02 KM Matrix name change to avoid MAX conflicts *
36 * 08/05/02 KM Texture class redesign
37 *---------------------------------------------------------------------------------------------*
38 * Functions: *
39 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
40
41#include "render2d.h"
42#include "mutex.h"
43#include "ww3d.h"
44#include "refcount.h"
45#include "font3d.h"
46#include "rect.h"
47#include "texture.h"
48#include "matrix4.h"
49#include "matrix3d.h"
50#include "dx8wrapper.h"
51#include "dx8indexbuffer.h"
52#include "dx8vertexbuffer.h"
53#include "sortingrenderer.h"
54#include "vertmaterial.h"
55#include "dx8fvf.h"
56#include "dx8caps.h"
57#include "wwprofile.h"
58#include "wwmemlog.h"
59#include "assetmgr.h"
60
61//#pragma optimize("", off)
62//#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
63
65
66
67/*
68** Render2DClass
69*/
86
91
93{
94 ScreenResolution = screen;
95#if 0
96 // Fool into pixel doubling - Byon..
97 if ( screen.Width() >= 1280 ) {
98 ScreenResolution.Scale( 0.5f );
99 }
100// ScreenResolution = RectClass( 0, 0, 800, 600 );
101#endif
102}
103
119
121{
122 Vertices.Reset_Active();
123 UVCoordinates.Reset_Active();
124 Colors.Reset_Active();
125 Indices.Reset_Active();
126
127 Update_Bias(); // Keep the bias updated
128}
129
134
135void Render2DClass::Set_Texture( const char * filename)
136{
138 Set_Texture( tex );
139 if ( tex != NULL ) {
140 SET_REF_OWNER( tex );
141 tex->Release_Ref();
142 }
143}
144
147{
148 IsGrayScale = b;
149}
150
152{
153 IsGrayScale = false;
154 if (b) {
156 Shader.Set_Src_Blend_Func( ShaderClass::SRCBLEND_SRC_ALPHA );
157 }
158 else {
159 Shader.Set_Src_Blend_Func( ShaderClass::SRCBLEND_ONE);
160 Shader.Set_Dst_Blend_Func( ShaderClass::DSTBLEND_ZERO );
161 }
162}
163
165{
166 IsGrayScale = false;
167
168 if (b) {
169 Shader.Set_Dst_Blend_Func( ShaderClass::DSTBLEND_ONE );
170 Shader.Set_Src_Blend_Func( ShaderClass::SRCBLEND_ONE );
171 }
172 else {
173 Shader.Set_Src_Blend_Func( ShaderClass::SRCBLEND_ONE);
174 Shader.Set_Dst_Blend_Func( ShaderClass::DSTBLEND_ZERO );
175 }
176}
177
179{
180 if (b) {
181 Shader.Set_Texturing( ShaderClass::TEXTURING_ENABLE );
182 }
183 else {
184 Shader.Set_Texturing( ShaderClass::TEXTURING_DISABLE );
185 }
186}
187
189{
190 // default range is (-1,1)-(1,-1)
191 CoordinateScale.X = 2 / range.Width();
192 CoordinateScale.Y = -2 / range.Height();
193 CoordinateOffset.X = -(CoordinateScale.X * range.Left) - 1;
194 CoordinateOffset.Y = -(CoordinateScale.Y * range.Top) + 1;
195
196 Update_Bias();
197}
198
200{
201
203
204 if ( WW3D::Is_Screen_UV_Biased() ) { // Global bais setting
205 Vector2 bais_add( -0.5f ,-0.5f ); // offset by -0.5,-0.5 in pixels
206
207 // Convert from pixels to (-1,1)-(1,-1) units
208 bais_add.X = bais_add.X / (Get_Screen_Resolution().Width() * 0.5f);
209 bais_add.Y = bais_add.Y / (Get_Screen_Resolution().Height() * -0.5f);
210
211 BiasedCoordinateOffset += bais_add;
212 }
213}
214
215#if 0
217{
218 Vector2 out;
219
220 // Convert to (-1,1)-(1,-1)
223
224 // Convert to pixels
225 out.X = (out.X + 1.0f) * (Get_Screen_Resolution().Width() * 0.5f);
226 out.Y = (out.Y - 1.0f) * (Get_Screen_Resolution().Height() * -0.5f);
227
228 // Round to nearest pixel
229 out.X = WWMath::Floor( out.X + 0.5f );
230 out.Y = WWMath::Floor( out.Y + 0.5f );
231
232 // Bias
233 if ( WW3D::Is_Screen_UV_Biased() ) { // Global bais setting
234 out.X -= 0.5f;
235 out.Y -= 0.5f;
236 }
237
238
239 // Convert back to (-1,1)-(1,-1)
240 out.X = out.X / (Get_Screen_Resolution().Width() * 0.5f) - 1.0f;
241 out.Y = out.Y / (Get_Screen_Resolution().Height() * -0.5f) + 1.0f;
242
243 return out;
244}
245#else
246/*
247** Convert Vert must convert from the convention defined by Set_Coordinate_Range
248** into the convention (-1,1)-(1,-1), which is needed by the renderer.
249// NOPE ** In addition, it rounds all coordinates off to the nearest pixel
250** Also, it offsets the coordinates as need for Screen_UV_Bias
251*/
252void Render2DClass::Convert_Vert( Vector2 & vert_out, const Vector2 & vert_in )
253{
254 // Convert to (-1,1)-(1,-1)
255 vert_out.X = vert_in.X * CoordinateScale.X + BiasedCoordinateOffset.X;
256 vert_out.Y = vert_in.Y * CoordinateScale.Y + BiasedCoordinateOffset.Y;
257}
258
259void Render2DClass::Convert_Vert( Vector2 & vert_out, float x_in, float y_in )
260{
261 // Convert to (-1,1)-(1,-1)
262 vert_out.X = x_in * CoordinateScale.X + BiasedCoordinateOffset.X;
263 vert_out.Y = y_in * CoordinateScale.Y + BiasedCoordinateOffset.Y;
264}
265
266#endif
267
268void Render2DClass::Move( const Vector2 & move ) // Move all verts
269{
270 Vector2 scaled_move;
271 scaled_move.X = move.X * CoordinateScale.X;
272 scaled_move.Y = move.Y * CoordinateScale.Y;
273 for ( int i = 0; i < Vertices.Count(); i++ ) {
274 Vertices[i] += scaled_move;
275 }
276}
277
278void Render2DClass::Force_Alpha( float alpha ) // Force all alphas
279{
280 unsigned long a = (unsigned)(WWMath::Clamp( alpha, 0, 1 ) * 255.0f);
281 a <<= 24;
282 for ( int i = 0; i < Colors.Count(); i++ ) {
283 Colors[i] = (Colors[i] & 0x00FFFFFF) | a;
284 }
285}
286
287
288void Render2DClass::Force_Color( int color ) // Force all alphas
289{
290 for ( int i = 0; i < Colors.Count(); i++ ) {
291 Colors[i] = color;
292 }
293}
294
295
296/*
297** Internal Add Quad Elements
298** Caller must mutex lock
299*/
300void Render2DClass::Internal_Add_Quad_Vertices( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3 )
301{
302 Convert_Vert( *Vertices.Uninitialized_Add(), v0 );
303 Convert_Vert( *Vertices.Uninitialized_Add(), v1 );
304 Convert_Vert( *Vertices.Uninitialized_Add(), v2 );
305 Convert_Vert( *Vertices.Uninitialized_Add(), v3 );
306}
307
309{
310 Convert_Vert( *Vertices.Uninitialized_Add(), screen.Left, screen.Top );
311 Convert_Vert( *Vertices.Uninitialized_Add(), screen.Left, screen.Bottom );
312 Convert_Vert( *Vertices.Uninitialized_Add(), screen.Right, screen.Top );
313 Convert_Vert( *Vertices.Uninitialized_Add(), screen.Right, screen.Bottom );
314
315}
316
318{
319 Vector2* uvs;
320
321 uvs=UVCoordinates.Uninitialized_Add();
322 uvs->X = uv.Left; uvs->Y = uv.Top;
323 uvs=UVCoordinates.Uninitialized_Add();
324 uvs->X = uv.Left; uvs->Y = uv.Bottom;
325 uvs=UVCoordinates.Uninitialized_Add();
326 uvs->X = uv.Right; uvs->Y = uv.Top;
327 uvs=UVCoordinates.Uninitialized_Add();
328 uvs->X = uv.Right; uvs->Y = uv.Bottom;
329
330}
331
333{
334 unsigned long* colors;
335
336 colors=Colors.Uninitialized_Add();
337 *colors=color;
338 colors=Colors.Uninitialized_Add();
339 *colors=color;
340 colors=Colors.Uninitialized_Add();
341 *colors=color;
342 colors=Colors.Uninitialized_Add();
343 *colors=color;
344}
345
346void Render2DClass::Internal_Add_Quad_VColors( unsigned long color1, unsigned long color2 )
347{
348 unsigned long* colors;
349
350 colors=Colors.Uninitialized_Add();
351 *colors=color1;
352 colors=Colors.Uninitialized_Add();
353 *colors=color2;
354 colors=Colors.Uninitialized_Add();
355 *colors=color1;
356 colors=Colors.Uninitialized_Add();
357 *colors=color2;
358
359}
360
361void Render2DClass::Internal_Add_Quad_HColors( unsigned long color1, unsigned long color2 )
362{
363 unsigned long* colors;
364
365 colors=Colors.Uninitialized_Add();
366 *colors=color1;
367 colors=Colors.Uninitialized_Add();
368 *colors=color1;
369 colors=Colors.Uninitialized_Add();
370 *colors=color2;
371 colors=Colors.Uninitialized_Add();
372 *colors=color2;
373}
374
375
376void Render2DClass::Internal_Add_Quad_Indicies( int start_vert_index, bool backfaced )
377{
378 unsigned short * indices;
379
380 if (backfaced ^ (CoordinateScale.X * CoordinateScale.Y > 0)) {
381 indices=Indices.Uninitialized_Add();
382 *indices = start_vert_index + 1;
383 indices=Indices.Uninitialized_Add();
384 *indices = start_vert_index + 0;
385 indices=Indices.Uninitialized_Add();
386 *indices = start_vert_index + 2;
387
388 indices=Indices.Uninitialized_Add();
389 *indices = start_vert_index + 1;
390 indices=Indices.Uninitialized_Add();
391 *indices = start_vert_index + 2;
392 indices=Indices.Uninitialized_Add();
393 *indices = start_vert_index + 3;
394 } else {
395 indices=Indices.Uninitialized_Add();
396 *indices = start_vert_index + 0;
397 indices=Indices.Uninitialized_Add();
398 *indices = start_vert_index + 1;
399 indices=Indices.Uninitialized_Add();
400 *indices = start_vert_index + 2;
401
402 indices=Indices.Uninitialized_Add();
403 *indices = start_vert_index + 2;
404 indices=Indices.Uninitialized_Add();
405 *indices = start_vert_index + 1;
406 indices=Indices.Uninitialized_Add();
407 *indices = start_vert_index + 3;
408 }
409
410}
411
412
413void Render2DClass::Add_Quad( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3, const RectClass & uv, unsigned long color )
414{
416 Internal_Add_Quad_Vertices( v0, v1, v2, v3 );
419}
420
421void Render2DClass::Add_Quad_Backfaced( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3, const RectClass & uv, unsigned long color )
422{
423 Internal_Add_Quad_Indicies( Vertices.Count(), true );
424 Internal_Add_Quad_Vertices( v0, v1, v2, v3 );
427}
428
429void Render2DClass::Add_Quad_VGradient( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3, const RectClass & uv, unsigned long top_color, unsigned long bottom_color )
430{
432 Internal_Add_Quad_Vertices( v0, v1, v2, v3 );
434 Internal_Add_Quad_VColors( top_color, bottom_color );
435}
436
437void Render2DClass::Add_Quad_HGradient( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3, const RectClass & uv, unsigned long left_color, unsigned long right_color )
438{
440 Internal_Add_Quad_Vertices( v0, v1, v2, v3 );
442 Internal_Add_Quad_HColors( left_color, right_color );
443}
444
445
446void Render2DClass::Add_Quad_VGradient( const RectClass & screen, unsigned long top_color, unsigned long bottom_color )
447{
450 Internal_Add_Quad_UVs( RectClass( 0,0,1,1 ) );
451 Internal_Add_Quad_VColors( top_color, bottom_color );
452}
453
454void Render2DClass::Add_Quad_HGradient( const RectClass & screen, unsigned long left_color, unsigned long right_color )
455{
458 Internal_Add_Quad_UVs( RectClass( 0,0,1,1 ) );
459 Internal_Add_Quad_HColors( left_color, right_color );
460}
461
462
463void Render2DClass::Add_Quad( const RectClass & screen, const RectClass & uv, unsigned long color )
464{
469}
470
471void Render2DClass::Add_Quad( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3, unsigned long color )
472{
474 Internal_Add_Quad_Vertices( v0, v1, v2, v3 );
475 Internal_Add_Quad_UVs( RectClass( 0,0,1,1 ) );
477}
478
479void Render2DClass::Add_Quad( const RectClass & screen, unsigned long color )
480{
483 Internal_Add_Quad_UVs( RectClass( 0,0,1,1 ) );
485}
486
487/*
488** Add Tri
489*/
490void Render2DClass::Add_Tri( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & uv0, const Vector2 & uv1, const Vector2 & uv2, unsigned long color )
491{
492 int old_vert_count = Vertices.Count();
493
494 // Add the verticies (translated to new coordinates)
495#if 0
496 Vertices.Add( Convert_Vert( v0 ), new_vert_count );
497 Vertices.Add( Convert_Vert( v1 ), new_vert_count );
498 Vertices.Add( Convert_Vert( v2 ), new_vert_count );
499#else
500 Convert_Vert( *Vertices.Uninitialized_Add(), v0 );
501 Convert_Vert( *Vertices.Uninitialized_Add(), v1 );
502 Convert_Vert( *Vertices.Uninitialized_Add(), v2 );
503
504#endif
505
506 // Add the uv coordinates
507
508 *UVCoordinates.Uninitialized_Add()=uv0;
509 *UVCoordinates.Uninitialized_Add()=uv1;
510 *UVCoordinates.Uninitialized_Add()=uv2;
511
512 // Add the colors
513 *Colors.Uninitialized_Add()=color;
514 *Colors.Uninitialized_Add()=color;
515 *Colors.Uninitialized_Add()=color;
516
517 // Add the faces
518 *Indices.Uninitialized_Add()=old_vert_count + 0;
519 *Indices.Uninitialized_Add()=old_vert_count + 1;
520 *Indices.Uninitialized_Add()=old_vert_count + 2;
521
522}
523
524void Render2DClass::Add_Line( const Vector2 & a, const Vector2 & b, float width, unsigned long color )
525{
526 Add_Line( a, b, width, RectClass( 0,0,1,1 ), color );
527}
528
529void Render2DClass::Add_Line( const Vector2 & a, const Vector2 & b, float width, const RectClass & uv, unsigned long color )
530{
531 Vector2 corner_offset = a - b; // get line relative to b
532 float temp = corner_offset.X; // Rotate 90
533 corner_offset.X = corner_offset.Y;
534 corner_offset.Y = -temp;
535 corner_offset.Normalize(); // scale to length width/2
536 corner_offset *= width / 2;
537
538 Add_Quad( a - corner_offset, a + corner_offset, b - corner_offset, b + corner_offset, uv, color );
539 //Add_Quad_HGradient(RectClass( a.X -corner_offset.X ,a.Y,b.X,b.Y ), color, color2);
540 //Add_Quad_HGradient( const RectClass & screen, unsigned long left_color, unsigned long right_color );
541}
542
543
544void Render2DClass::Add_Line( const Vector2 & a, const Vector2 & b, float width, unsigned long color, unsigned long color2 )
545{
546 Add_Line( a, b, width, RectClass( 0,0,1,1 ), color, color2 );
547}
548
549void Render2DClass::Add_Line( const Vector2 & a, const Vector2 & b, float width, const RectClass & uv, unsigned long color , unsigned long color2)
550{
551 Vector2 corner_offset = a - b; // get line relative to b
552 float temp = corner_offset.X; // Rotate 90
553 corner_offset.X = corner_offset.Y;
554 corner_offset.Y = -temp;
555 corner_offset.Normalize(); // scale to length width/2
556 corner_offset *= width / 2;
557
558 Add_Quad_HGradient( a - corner_offset, a + corner_offset, b - corner_offset, b + corner_offset, uv, color,color2);
559 //Add_Quad_HGradient(RectClass( a.X -corner_offset.X ,a.Y,b.X,b.Y ), color, color2);
560}
561
562
563void Render2DClass::Add_Rect( const RectClass & rect, float border_width, uint32 border_color, uint32 fill_color )
564{
565 //
566 // First add the outline
567 //
568 if( border_width > 0 )
569 Add_Outline( rect, border_width, border_color );
570
571 //
572 // Next, fill the contents
573 //
574 RectClass fill_rect = rect;
575 if( border_width > 0 )
576 {
577 fill_rect.Left += border_width + 1;
578 fill_rect.Top += border_width + 1;
579 fill_rect.Right -= border_width - 1;
580 fill_rect.Bottom -= border_width - 1;
581 }
582 Add_Quad (fill_rect, fill_color);
583 return ;
584}
585
586void Render2DClass::Add_Outline( const RectClass & rect, float width, unsigned long color )
587{
588 Add_Outline( rect, width, RectClass( 0,0,1,1 ), color );
589}
590
591void Render2DClass::Add_Outline( const RectClass & rect, float width, const RectClass & uv, unsigned long color )
592{
593 //
594 // Pretty straight forward, simply add the four side of the rectangle as lines.
595 //
598 Add_Line (Vector2 (rect.Left + 1, rect.Bottom), Vector2 (rect.Left + 1, rect.Top + 1), width, color);
599 Add_Line (Vector2 (rect.Left, rect.Top + 1), Vector2 (rect.Right - 1, rect.Top + 1), width, color);
600 Add_Line (Vector2 (rect.Right, rect.Top), Vector2 (rect.Right, rect.Bottom - 1), width, color);
601 Add_Line (Vector2 (rect.Right, rect.Bottom), Vector2 (rect.Left + 1, rect.Bottom), width, color);
602}
603
605{
606 if ( !Indices.Count() || IsHidden) {
607 return;
608 }
609
610 // save the view and projection matrices since we're nuking them
611 Matrix4x4 view,proj;
612 Matrix4x4 identity(true);
613
614 DX8Wrapper::Get_Transform(D3DTS_VIEW,view);
615 DX8Wrapper::Get_Transform(D3DTS_PROJECTION,proj);
616
617 //
618 // Configure the viewport for entire screen
619 //
620 int width, height, bits;
621 bool windowed;
622 WW3D::Get_Device_Resolution( width, height, bits, windowed );
623 D3DVIEWPORT8 vp = { 0 };
624 vp.X = 0;
625 vp.Y = 0;
626 vp.Width = width;
627 vp.Height = height;
628 vp.MinZ = 0;
629 vp.MaxZ = 1;
632
635 REF_PTR_RELEASE(vm);
636
639 DX8Wrapper::Set_Transform(D3DTS_PROJECTION,identity);
640
642 {
644 const FVFInfoClass &fi=vb.FVF_Info();
645 unsigned char *va=(unsigned char*)Lock.Get_Formatted_Vertex_Array();
646 int i;
647
648 for (i=0; i<Vertices.Count(); i++)
649 {
650 Vector3 temp(Vertices[i].X,Vertices[i].Y,ZValue);
651 *(Vector3*)(va+fi.Get_Location_Offset())=temp;
652 *(unsigned int*)(va+fi.Get_Diffuse_Offset())=Colors[i];
653 *(Vector2*)(va+fi.Get_Tex_Offset(0))=UVCoordinates[i];
654 va+=fi.Get_FVF_Size();
655 }
656 }
657
659 try {
661 unsigned short *mem=Lock.Get_Index_Array();
662 for (int i=0; i<Indices.Count(); i++)
663 mem[i]=Indices[i];
664
666 } catch(...) {
668 }
669
672
673 if (IsGrayScale)
674 { //special case added to draw grayscale non-alpha blended images.
676 DX8Wrapper::Apply_Render_State_Changes(); //force update of all regular W3D states.
677 if (DX8Wrapper::Get_Current_Caps()->Support_Dot3())
678 { //Override W3D states with customizations for grayscale
679 DX8Wrapper::Set_DX8_Render_State(D3DRS_TEXTUREFACTOR, 0x80A5CA8E);
680 DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG0, D3DTA_TFACTOR | D3DTA_ALPHAREPLICATE);
681 DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
682 DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR | D3DTA_ALPHAREPLICATE);
683 DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLOROP, D3DTOP_MULTIPLYADD);
684
685 DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG1, D3DTA_CURRENT);
686 DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG2, D3DTA_TFACTOR);
687 DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3);
688 }
689 else
690 { //doesn't have DOT3 blend mode so fake it another way.
691 DX8Wrapper::Set_DX8_Render_State(D3DRS_TEXTUREFACTOR, 0x60606060);
692 DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
693 DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
694 DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
695 }
696 }
697 else
699 DX8Wrapper::Draw_Triangles(0,Indices.Count()/3,0,Vertices.Count());
700
701 DX8Wrapper::Set_Transform(D3DTS_VIEW,view);
702 DX8Wrapper::Set_Transform(D3DTS_PROJECTION,proj);
703 if (IsGrayScale)
704 ShaderClass::Invalidate(); //force both stages to be reset.
705
706}
707
708
709/*
710** Render2DTextClass
711*/
713 Location(0.0f,0.0f),
714 Cursor(0.0f,0.0f),
715 Font(NULL),
716 WrapWidth(0),
717 ClipRect(0, 0, 0, 0),
718 IsClippedEnabled(false)
719{
720 Set_Coordinate_Range( RectClass( -320, -240, 320, 240 ) );
721 Set_Font( font );
722
723 Reset();
724}
725
730
732{
734 Cursor = Location;
735 WrapWidth = 0;
736 DrawExtents = RectClass( 0,0,0,0 );
737 TotalExtents = RectClass( 0,0,0,0 );
738 ClipRect.Set (0, 0, 0, 0);
739 IsClippedEnabled = false;
740}
741
743{
744 REF_PTR_SET(Font,font);
745
746 if ( Font != NULL ) {
747 Set_Texture( Font->Peek_Texture() );
748
749 #define BLOCK_CHAR 0
750 BlockUV = Font->Char_UV( BLOCK_CHAR );
751 // Inset it a bit to be sure we have no edge problems
752 BlockUV.Inflate( Vector2(-BlockUV.Width()/4, -BlockUV.Height()/4) );
753 }
754}
755
756
757/*
758**
759*/
760void Render2DTextClass::Draw_Char( WCHAR ch, unsigned long color )
761{
762 float char_spacing = Font->Char_Spacing( ch );
763 float char_height = Font->Char_Height();
764
765 //
766 // Check to see if this character is clipped
767 //
768 bool is_clipped = false;
769 if ( IsClippedEnabled &&
770 (Cursor.X < ClipRect.Left ||
771 Cursor.X + char_spacing > ClipRect.Right ||
772 Cursor.Y < ClipRect.Top ||
773 Cursor.Y + char_height > ClipRect.Bottom))
774 {
775 is_clipped = true;
776 }
777
778 if ( ch != (WCHAR)' ' && !is_clipped ) {
779 RectClass screen( Cursor.X, Cursor.Y, Cursor.X + Font->Char_Width(ch), Cursor.Y + char_height );
780
783 Internal_Add_Quad_UVs( Font->Char_UV( ch ) );
785
786 DrawExtents += screen;
787 TotalExtents += screen;
788 }
789 Cursor.X += char_spacing;
790}
791
792void Render2DTextClass::Draw_Text( const char * text, unsigned long color )
793{
795 WideStringClass wide(0,true);
796 wide.Convert_From( text );
797 Draw_Text( wide, color );
798}
799
800void Render2DTextClass::Draw_Text( const WCHAR * text, unsigned long color )
801{
803
804 // Reset the Extents
805 DrawExtents = RectClass( Location, Location );
806 if ( TotalExtents.Width() == 0 ) {
807 TotalExtents = RectClass( Location, Location );
808 }
809
810 while (*text) {
811 WCHAR ch = *text++;
812
813 // Check to see if we need to move to a newline or not
814 bool wrap = ( ch == (WCHAR)'\n' );
815
816 // if the current char is a space, and the next word length puts us past our Width, wrap
817 if ( ch == (WCHAR)' ' && WrapWidth > 0 ) {
818 const WCHAR * word = text;
819 float word_width = Font->Char_Spacing(ch);
820 while ( (*word != (WCHAR)0) && (*word > (WCHAR)' ') ) {
821 word_width += Font->Char_Spacing(*word++);
822 }
823 wrap = ( (Cursor.X + word_width) >= (Location.X + WrapWidth) );
824 }
825
826 if ( wrap ) {
827 Cursor.Y += Font->Char_Height();
828 Cursor.X = Location.X;
829 } else {
830
831 // Draw char at cursor, update cursor and extents
832 Draw_Char( ch, color );
833 }
834 }
835}
836
837void Render2DTextClass::Draw_Block( const RectClass & screen, unsigned long color )
838{
841 Internal_Add_Quad_UVs( BlockUV );
843
844 TotalExtents += screen;
845}
846
848{
849 Vector2 extent (0, Font->Char_Height());
850
851 if (text) {
852 while (*text) {
853 WCHAR ch = *text++;
854
855 if ( ch != (WCHAR)'\n' ) {
856 extent.X += Font->Char_Spacing( ch );
857 }
858 }
859 }
860
861 return extent;
862}
863
#define NULL
Definition BaseType.h:92
unsigned long uint32
Definition bittype.h:46
@ false
Definition bool.h:59
static void Set_World_Identity()
static void Set_Vertex_Buffer(const VertexBufferClass *vb, unsigned stream=0)
static void Set_Texture(unsigned stage, TextureBaseClass *texture)
static void Set_View_Identity()
static const DX8Caps * Get_Current_Caps()
Definition dx8wrapper.h:536
static void Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTURESTAGESTATETYPE state, unsigned value)
Definition dx8wrapper.h:899
static void Set_Index_Buffer(const IndexBufferClass *ib, unsigned short index_base_offset)
static void Draw_Triangles(unsigned buffer_type, unsigned short start_index, unsigned short polygon_count, unsigned short min_vertex_index, unsigned short vertex_count)
static void Set_Viewport(CONST D3DVIEWPORT8 *pViewport)
static void Set_Material(const VertexMaterialClass *material)
static void Set_Shader(const ShaderClass &shader)
static void Get_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4 &m)
static void Set_Transform(D3DTRANSFORMSTATETYPE transform, const Matrix4x4 &m)
static void Apply_Render_State_Changes()
static void Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value)
Definition dx8wrapper.h:874
VertexFormatXYZNDUV2 * Get_Formatted_Vertex_Array()
const FVFInfoClass & FVF_Info() const
unsigned Get_Tex_Offset(unsigned int n) const
Definition dx8fvf.h:274
unsigned Get_FVF_Size() const
Definition dx8fvf.h:280
unsigned Get_Diffuse_Offset() const
Definition dx8fvf.h:277
unsigned Get_Location_Offset() const
Definition dx8fvf.h:269
float Char_Spacing(WCHAR ch) const
Definition font3d.h:184
float Char_Height(void) const
Definition font3d.h:185
float Left
Definition rect.h:50
float Height(void) const
Definition rect.h:69
float Top
Definition rect.h:51
float Bottom
Definition rect.h:53
float Width(void) const
Definition rect.h:68
float Right
Definition rect.h:52
WWINLINE void Release_Ref(void) const
Definition refcount.h:146
void Enable_Additive(bool b)
Definition render2d.cpp:164
void Enable_Grayscale(bool b)
added for generals to draw disabled button states - MW
Definition render2d.cpp:146
TextureClass * Texture
Definition render2d.h:170
void Internal_Add_Quad_UVs(const RectClass &uv)
Definition render2d.cpp:317
void Render(void)
Definition render2d.cpp:604
void Add_Rect(const RectClass &rect, float border_width=1.0F, uint32 border_color=0xFF000000, uint32 fill_color=0xFFFFFFFF)
Definition render2d.cpp:563
void Internal_Add_Quad_Colors(unsigned long color)
Definition render2d.cpp:332
void Move(const Vector2 &a)
Definition render2d.cpp:268
Vector2 PreAllocatedUVCoordinates[60]
Definition render2d.h:177
void Add_Quad(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &v3, const RectClass &uv, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:413
void Set_Coordinate_Range(const RectClass &range)
Definition render2d.cpp:188
void Update_Bias(void)
Definition render2d.cpp:199
static void Set_Screen_Resolution(const RectClass &screen)
Definition render2d.cpp:92
void Add_Outline(const RectClass &rect, float width=1.0F, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:586
Vector2 CoordinateOffset
Definition render2d.h:168
DynamicVectorClass< unsigned short > Indices
Definition render2d.h:172
void Enable_Alpha(bool b)
Definition render2d.cpp:151
void Internal_Add_Quad_Indicies(int start_vert_index, bool backfaced=false)
Definition render2d.cpp:376
void Force_Color(int color)
Definition render2d.cpp:288
Vector2 PreAllocatedVertices[60]
Definition render2d.h:175
void Internal_Add_Quad_Vertices(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &v3)
Definition render2d.cpp:300
void Add_Quad_Backfaced(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &v3, const RectClass &uv, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:421
DynamicVectorClass< Vector2 > UVCoordinates
Definition render2d.h:176
void Add_Quad_VGradient(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &v3, const RectClass &uv, unsigned long top_color, unsigned long bottom_color)
Definition render2d.cpp:429
Vector2 CoordinateScale
Definition render2d.h:167
unsigned long PreAllocatedColors[60]
Definition render2d.h:179
static const RectClass & Get_Screen_Resolution(void)
Definition render2d.h:164
void Set_Texture(TextureClass *tex)
Definition render2d.cpp:130
DynamicVectorClass< Vector2 > Vertices
Definition render2d.h:174
bool IsGrayScale
Definition render2d.h:181
unsigned short PreAllocatedIndices[60]
Definition render2d.h:173
Vector2 BiasedCoordinateOffset
Definition render2d.h:169
void Add_Line(const Vector2 &a, const Vector2 &b, float width, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:524
virtual void Reset(void)
Definition render2d.cpp:120
void Add_Quad_HGradient(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &v3, const RectClass &uv, unsigned long left_color, unsigned long right_color)
Definition render2d.cpp:437
void Internal_Add_Quad_VColors(unsigned long color1, unsigned long color2)
Definition render2d.cpp:346
void Add_Tri(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &uv0, const Vector2 &uv1, const Vector2 &uv2, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:490
Render2DClass(TextureClass *tex=NULL)
Definition render2d.cpp:70
DynamicVectorClass< unsigned long > Colors
Definition render2d.h:178
void Internal_Add_Quad_HColors(unsigned long color1, unsigned long color2)
Definition render2d.cpp:361
virtual ~Render2DClass(void)
Definition render2d.cpp:87
void Force_Alpha(float alpha)
Definition render2d.cpp:278
ShaderClass Shader
Definition render2d.h:171
static RectClass ScreenResolution
Definition render2d.h:184
void Enable_Texturing(bool b)
Definition render2d.cpp:178
static ShaderClass Get_Default_Shader(void)
Definition render2d.cpp:105
Vector2 Convert_Vert(const Vector2 &v)
void Set_Font(Font3DInstanceClass *font)
Definition render2d.cpp:742
void Draw_Block(const RectClass &screen, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:837
virtual void Reset(void)
Definition render2d.cpp:731
Render2DTextClass(Font3DInstanceClass *font=NULL)
Definition render2d.cpp:712
Vector2 Get_Text_Extents(const WCHAR *text)
Definition render2d.cpp:847
void Draw_Text(const char *text, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:792
void Set_Texturing(TexturingType x)
Definition shader.h:335
@ GRADIENT_MODULATE
Definition shader.h:193
static ShaderClass _PresetOpaqueShader
Definition shader.h:365
void Set_Src_Blend_Func(SrcBlendFuncType x)
Definition shader.h:334
static void Invalidate()
Definition shader.h:346
@ PASS_ALWAYS
Definition shader.h:110
@ FOG_DISABLE
Definition shader.h:183
void Set_Depth_Compare(DepthCompareType x)
Definition shader.h:323
void Set_Depth_Mask(DepthMaskType x)
Definition shader.h:324
void Set_Primary_Gradient(PriGradientType x)
Definition shader.h:332
@ TEXTURING_DISABLE
Definition shader.h:219
@ TEXTURING_ENABLE
Definition shader.h:220
void Set_Fog_Func(FogFuncType x)
Definition shader.h:331
@ DEPTH_WRITE_DISABLE
Definition shader.h:116
void Set_Dst_Blend_Func(DstBlendFuncType x)
Definition shader.h:330
@ SRCBLEND_SRC_ALPHA
Definition shader.h:212
@ SRCBLEND_ONE
Definition shader.h:211
@ DSTBLEND_ZERO
Definition shader.h:172
@ DSTBLEND_ONE_MINUS_SRC_ALPHA
Definition shader.h:177
@ DSTBLEND_ONE
Definition shader.h:173
WWINLINE void Normalize(void)
Definition vector2.h:331
float Y
Definition vector2.h:79
float X
Definition vector2.h:74
static VertexMaterialClass * Get_Preset(PresetType type)
virtual TextureClass * Get_Texture(const char *filename, MipCountType mip_level_count=MIP_LEVELS_ALL, WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN, bool allow_compression=true, TextureBaseClass::TexAssetType type=TextureBaseClass::TEX_REGULAR, bool allow_reduction=true)
static WW3DAssetManager * Get_Instance(void)
Definition assetmgr.h:205
static void Get_Device_Resolution(int &set_w, int &set_h, int &get_bits, bool &get_windowed)
Definition ww3d.cpp:670
static bool Is_Screen_UV_Biased(void)
Definition ww3d.h:223
static float Clamp(float val, float min=0.0f, float max=1.0f)
Definition wwmath.h:208
static float Floor(float val)
Definition wwmath.h:153
bool Convert_From(const char *text)
int IndexBufferExceptionFunc(void)
const unsigned dynamic_fvf_type
@ BUFFER_TYPE_DYNAMIC_DX8
Definition dx8wrapper.h:90
else return(RetVal)
#define SET_REF_OWNER(P)
Definition refcount.h:63
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
#define REF_PTR_SET(dst, src)
Definition refcount.h:79
#define BLOCK_CHAR
@ MIP_LEVELS_1
@ MEM_GEOMETRY
Definition wwmemlog.h:59
#define WWMEMLOG(category)
Definition wwmemlog.h:183