/
CNullDriver.cpp
1899 lines (1504 loc) · 47.1 KB
/
CNullDriver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CNullDriver.h"
#include "os.h"
#include "CImage.h"
#include "CAttributes.h"
#include "IReadFile.h"
#include "IWriteFile.h"
#include "IImageLoader.h"
#include "IImageWriter.h"
#include "CColorConverter.h"
#include <stdio.h>
#include "IMaterialRenderer.h"
//! creates a loader which is able to load windows bitmaps
IImageLoader* createImageLoaderBMP();
IImageWriter* createImageWriterBMP();
//! constructor
CNullDriver::CNullDriver(IFileSystem* io, const dimension2d<u32>& screenSize)
: FileSystem(io), ViewPort(0,0,0,0), ScreenSize(screenSize),
PrimitivesDrawn(0), MinVertexCountForVBO(500), TextureCreationFlags(0),
OverrideMaterial2DEnabled(false), AllowZWriteOnTransparent(false)
{
DriverAttributes = new CAttributes();
DriverAttributes->addInt("MaxTextures", _DREAM_MATERIAL_MAX_TEXTURES_);
DriverAttributes->addInt("MaxSupportedTextures", _DREAM_MATERIAL_MAX_TEXTURES_);
DriverAttributes->addInt("MaxLights", getMaximalDynamicLightAmount());
DriverAttributes->addInt("MaxAnisotropy", 1);
// DriverAttributes->addInt("MaxUserClipPlanes", 0);
// DriverAttributes->addInt("MaxAuxBuffers", 0);
DriverAttributes->addInt("MaxMultipleRenderTargets", 1);
DriverAttributes->addInt("MaxIndices", -1);
DriverAttributes->addInt("MaxTextureSize", -1);
// DriverAttributes->addInt("MaxGeometryVerticesOut", 0);
// DriverAttributes->addFloat("MaxTextureLODBias", 0.f);
DriverAttributes->addInt("Version", 1);
// DriverAttributes->addInt("ShaderLanguageVersion", 0);
// DriverAttributes->addInt("AntiAlias", 0);
setFog();
setTextureCreationFlag(ETCF_ALWAYS_32_BIT, true);
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, true);
ViewPort = rectangle<s32>(position2d<s32>(0,0), dimension2di(screenSize));
if (FileSystem)
FileSystem->addRef();
// create surface loader
#ifdef _DREAM_COMPILE_WITH_BMP_LOADER_
SurfaceLoader.push_back(createImageLoaderBMP());
#endif
#ifdef _DREAM_COMPILE_WITH_BMP_WRITER_
SurfaceWriter.push_back(createImageWriterBMP());
#endif
// set ExposedData to 0
memset(&ExposedData, 0, sizeof(ExposedData));
for (u32 i=0; i<EVDF_COUNT; ++i)
FeatureEnabled[i]=true;
InitMaterial2D.AntiAliasing=EAAM_OFF;
InitMaterial2D.Lighting=false;
InitMaterial2D.ZWriteEnable=false;
InitMaterial2D.ZBuffer=ECFN_NEVER;
InitMaterial2D.UseMipMaps=false;
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
{
InitMaterial2D.TextureLayer[i].BilinearFilter=false;
InitMaterial2D.TextureLayer[i].TextureWrapU=ETC_REPEAT;
InitMaterial2D.TextureLayer[i].TextureWrapV=ETC_REPEAT;
}
OverrideMaterial2D=InitMaterial2D;
}
//! destructor
CNullDriver::~CNullDriver()
{
if (DriverAttributes)
DriverAttributes->releaseRef();
if (FileSystem)
FileSystem->releaseRef();
deleteAllTextures();
u32 i;
for (i=0; i<SurfaceLoader.size(); ++i)
SurfaceLoader[i]->releaseRef();
for (i=0; i<SurfaceWriter.size(); ++i)
SurfaceWriter[i]->releaseRef();
// delete material renderers
deleteMaterialRenders();
}
//! Adds an external surface loader to the engine.
void CNullDriver::addExternalImageLoader(IImageLoader* loader)
{
if (!loader)
return;
loader->addRef();
SurfaceLoader.push_back(loader);
}
//! Adds an external surface writer to the engine.
void CNullDriver::addExternalImageWriter(IImageWriter* writer)
{
if (!writer)
return;
writer->addRef();
SurfaceWriter.push_back(writer);
}
//! Retrieve the number of image loaders
u32 CNullDriver::getImageLoaderCount() const
{
return SurfaceLoader.size();
}
//! Retrieve the given image loader
IImageLoader* CNullDriver::getImageLoader(u32 n)
{
if (n < SurfaceLoader.size())
return SurfaceLoader[n];
return 0;
}
//! Retrieve the number of image writers
u32 CNullDriver::getImageWriterCount() const
{
return SurfaceWriter.size();
}
//! Retrieve the given image writer
IImageWriter* CNullDriver::getImageWriter(u32 n)
{
if (n < SurfaceWriter.size())
return SurfaceWriter[n];
return 0;
}
//! deletes all textures
void CNullDriver::deleteAllTextures()
{
// we need to remove previously set textures which might otherwise be kept in the
// last set material member. Could be optimized to reduce state changes.
setMaterial(SMaterial());
for (u32 i=0; i<Textures.size(); ++i)
Textures[i].Surface->releaseRef();
Textures.clear();
}
//! applications must call this method before performing any rendering. returns false if failed.
bool CNullDriver::beginScene(bool backBuffer, bool zBuffer, SColor color,
const SExposedVideoData& videoData, rectangle<s32>* sourceRect)
{
clearFPUException();
PrimitivesDrawn = 0;
return true;
}
//! applications must call this method after performing any rendering. returns false if failed.
bool CNullDriver::endScene()
{
FPSCounter.registerFrame(Timer::getRealTime(), PrimitivesDrawn);
return true;
}
//! Disable a feature of the driver.
void CNullDriver::disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag)
{
FeatureEnabled[feature]=!flag;
}
//! queries the features of the driver, returns true if feature is available
bool CNullDriver::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
{
return false;
}
//! Get attributes of the actual video driver
const IAttributes& CNullDriver::getDriverAttributes() const
{
return *DriverAttributes;
}
//! sets transformation
void CNullDriver::setTransform(E_TRANSFORMATION_STATE state, const matrix4& mat)
{
}
//! Returns the transformation set by setTransform
const matrix4& CNullDriver::getTransform(E_TRANSFORMATION_STATE state) const
{
return TransformationMatrix;
}
//! sets a material
void CNullDriver::setMaterial(const SMaterial& material)
{
}
//! Removes a texture from the texture cache and deletes it, freeing lot of
//! memory.
void CNullDriver::removeTexture(ITexture* texture)
{
if (!texture)
return;
for (u32 i=0; i<Textures.size(); ++i)
{
if (Textures[i].Surface == texture)
{
texture->releaseRef();
Textures.erase(i);
}
}
}
//! Removes all texture from the texture cache and deletes them, freeing lot of
//! memory.
void CNullDriver::removeAllTextures()
{
setMaterial ( SMaterial() );
deleteAllTextures();
}
//! Returns a texture by index
ITexture* CNullDriver::getTextureByIndex(u32 i)
{
if ( i < Textures.size() )
return Textures[i].Surface;
return 0;
}
//! Returns amount of textures currently loaded
u32 CNullDriver::getTextureCount() const
{
return Textures.size();
}
//! Renames a texture
void CNullDriver::renameTexture(ITexture* texture, const path& newName)
{
// we can do a const_cast here safely, the name of the ITexture interface
// is just readonly to prevent the user changing the texture name without invoking
// this method, because the textures will need resorting afterwards
SNamedPath& name = const_cast<SNamedPath&>(texture->getName());
name.setPath(newName);
Textures.sort();
}
//! loads a Texture
ITexture* CNullDriver::getTexture(const path& filename)
{
// Identify textures by their absolute filenames if possible.
const path absolutePath = FileSystem->getAbsolutePath(filename);
ITexture* texture = findTexture(absolutePath);
if (texture)
return texture;
// Then try the raw filename, which might be in an Archive
texture = findTexture(filename);
if (texture)
return texture;
// Now try to open the file using the complete path.
IReadFile* file = FileSystem->createAndOpenFile(absolutePath);
if (!file)
{
// Try to open it using the raw filename.
file = FileSystem->createAndOpenFile(filename);
}
if (file)
{
// Re-check name for actual archive names
texture = findTexture(file->getFileName());
if (texture)
{
file->releaseRef();
return texture;
}
texture = loadTextureFromFile(file);
file->releaseRef();
if (texture)
{
addTexture(texture);
texture->releaseRef(); // drop it because we created it, one grab too much
}
else
Printer::log("Could not load texture", filename, ELL_ERROR);
return texture;
}
else
{
Printer::log("Could not open file of texture", filename, ELL_WARNING);
return 0;
}
}
//! loads a Texture
ITexture* CNullDriver::getTexture(IReadFile* file)
{
ITexture* texture = 0;
if (file)
{
texture = findTexture(file->getFileName());
if (texture)
return texture;
texture = loadTextureFromFile(file);
if (texture)
{
addTexture(texture);
texture->releaseRef(); // drop it because we created it, one grab too much
}
if (!texture)
Printer::log("Could not load texture", file->getFileName(), ELL_WARNING);
}
return texture;
}
//! opens the file and loads it into the surface
ITexture* CNullDriver::loadTextureFromFile(IReadFile* file, const path& hashName )
{
ITexture* texture = 0;
IImage* image = createImageFromFile(file);
if (image)
{
// create texture from surface
texture = createDeviceDependentTexture(image, hashName.size() ? hashName : file->getFileName() );
Printer::log("Loaded texture", file->getFileName());
image->releaseRef();
}
return texture;
}
//! adds a surface, not loaded or created by the Irrlicht Engine
void CNullDriver::addTexture(ITexture* texture)
{
if (texture)
{
SSurface s;
s.Surface = texture;
texture->addRef();
Textures.push_back(s);
// the new texture is now at the end of the texture list. when searching for
// the next new texture, the texture array will be sorted and the index of this texture
// will be changed. to let the order be more consistent to the user, sort
// the textures now already although this isn't necessary:
Textures.sort();
}
}
//! looks if the image is already loaded
ITexture* CNullDriver::findTexture(const path& filename)
{
SSurface s;
SDummyTexture dummy(filename);
s.Surface = &dummy;
s32 index = Textures.binary_search(s);
if (index != -1)
return Textures[index].Surface;
return 0;
}
//! Creates a texture from a loaded IImage.
ITexture* CNullDriver::addTexture(const path& name, IImage* image, void* mipmapData)
{
if ( 0 == name.size() || !image)
return 0;
ITexture* t = createDeviceDependentTexture(image, name, mipmapData);
if (t)
{
addTexture(t);
t->releaseRef();
}
return t;
}
//! creates a Texture
ITexture* CNullDriver::addTexture(const dimension2d<u32>& size,
const path& name, ECOLOR_FORMAT format)
{
if(IImage::isRenderTargetOnlyFormat(format))
{
Printer::log("Could not create ITexture, format only supported for render target textures.", ELL_WARNING);
return 0;
}
if ( 0 == name.size () )
return 0;
IImage* image = new CImage(format, size);
ITexture* t = createDeviceDependentTexture(image, name);
image->releaseRef();
addTexture(t);
if (t)
t->releaseRef();
return t;
}
//! returns a device dependent texture from a software surface (IImage)
//! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
ITexture* CNullDriver::createDeviceDependentTexture(IImage* surface, const path& name, void* mipmapData)
{
return new SDummyTexture(name);
}
//! set or reset special render targets
bool CNullDriver::setRenderTarget(E_RENDER_TARGET target, bool clearTarget,
bool clearZBuffer, SColor color)
{
if (ERT_FRAME_BUFFER==target)
return setRenderTarget(0,clearTarget, clearZBuffer, color);
else
return false;
}
//! sets a render target
bool CNullDriver::setRenderTarget(ITexture* texture, bool clearBackBuffer,
bool clearZBuffer, SColor color)
{
return false;
}
//! Sets multiple render targets
bool CNullDriver::setRenderTarget(const array<IRenderTarget>& texture,
bool clearBackBuffer, bool clearZBuffer, SColor color)
{
return false;
}
//! sets a viewport
void CNullDriver::setViewPort(const rectangle<s32>& area)
{
}
//! gets the area of the current viewport
const rectangle<s32>& CNullDriver::getViewPort() const
{
return ViewPort;
}
//! draws a vertex primitive list
void CNullDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType)
{
if ((iType==EIT_16BIT) && (vertexCount>65536))
Printer::log("Too many vertices for 16bit index type, render artifacts may occur.");
PrimitivesDrawn += primitiveCount;
}
//! draws a vertex primitive list in 2d
void CNullDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType)
{
if ((iType==EIT_16BIT) && (vertexCount>65536))
Printer::log("Too many vertices for 16bit index type, render artifacts may occur.");
PrimitivesDrawn += primitiveCount;
}
//! Draws a 3d line.
void CNullDriver::draw3DLine(const vector3df& start,
const vector3df& end, SColor color)
{
}
//! Draws a 3d triangle.
void CNullDriver::draw3DTriangle(const triangle3df& triangle, SColor color)
{
S3DVertex vertices[3];
vertices[0].Pos=triangle.pointA;
vertices[0].Color=color;
vertices[0].Normal=triangle.getNormal().normalize();
vertices[0].TCoords.set(0.f,0.f);
vertices[1].Pos=triangle.pointB;
vertices[1].Color=color;
vertices[1].Normal=vertices[0].Normal;
vertices[1].TCoords.set(0.5f,1.f);
vertices[2].Pos=triangle.pointC;
vertices[2].Color=color;
vertices[2].Normal=vertices[0].Normal;
vertices[2].TCoords.set(1.f,0.f);
const u16 indexList[] = {0,1,2};
drawVertexPrimitiveList(vertices, 3, indexList, 1, EVT_STANDARD, EPT_TRIANGLES, EIT_16BIT);
}
//! Draws a 3d axis aligned box.
void CNullDriver::draw3DBox(const aabbox3d<f32>& box, SColor color)
{
vector3df edges[8];
box.getEdges(edges);
// TODO: optimize into one big drawIndexPrimitive call.
draw3DLine(edges[5], edges[1], color);
draw3DLine(edges[1], edges[3], color);
draw3DLine(edges[3], edges[7], color);
draw3DLine(edges[7], edges[5], color);
draw3DLine(edges[0], edges[2], color);
draw3DLine(edges[2], edges[6], color);
draw3DLine(edges[6], edges[4], color);
draw3DLine(edges[4], edges[0], color);
draw3DLine(edges[1], edges[0], color);
draw3DLine(edges[3], edges[2], color);
draw3DLine(edges[7], edges[6], color);
draw3DLine(edges[5], edges[4], color);
}
//! draws an 2d image
void CNullDriver::draw2DImage(const ITexture* texture, const position2d<s32>& destPos)
{
if (!texture)
return;
draw2DImage(texture,destPos, rectangle<s32>(position2d<s32>(0,0),
dimension2di(texture->getOriginalSize())));
}
//! draws a set of 2d images, using a color and the alpha channel of the
//! texture if desired. The images are drawn beginning at pos and concatenated
//! in one line. All drawings are clipped against clipRect (if != 0).
//! The subtextures are defined by the array of sourceRects and are chosen
//! by the indices given.
void CNullDriver::draw2DImageBatch(const ITexture* texture,
const position2d<s32>& pos,
const array<rectangle<s32> >& sourceRects,
const array<s32>& indices,
s32 kerningWidth,
const rectangle<s32>* clipRect, SColor color,
bool useAlphaChannelOfTexture)
{
position2d<s32> target(pos);
for (u32 i=0; i<indices.size(); ++i)
{
draw2DImage(texture, target, sourceRects[indices[i]],
clipRect, color, useAlphaChannelOfTexture);
target.X += sourceRects[indices[i]].getWidth();
target.X += kerningWidth;
}
}
//! draws a set of 2d images, using a color and the alpha channel of the
//! texture if desired.
void CNullDriver::draw2DImageBatch(const ITexture* texture,
const array<position2d<s32> >& positions,
const array<rectangle<s32> >& sourceRects,
const rectangle<s32>* clipRect,
SColor color,
bool useAlphaChannelOfTexture)
{
const u32 drawCount = min_<u32>(positions.size(), sourceRects.size());
for (u32 i=0; i<drawCount; ++i)
{
draw2DImage(texture, positions[i], sourceRects[i],
clipRect, color, useAlphaChannelOfTexture);
}
}
//! Draws a part of the texture into the rectangle.
void CNullDriver::draw2DImage(const ITexture* texture, const rectangle<s32>& destRect,
const rectangle<s32>& sourceRect, const rectangle<s32>* clipRect,
const SColor* const colors, bool useAlphaChannelOfTexture)
{
if (destRect.isValid())
draw2DImage(texture, position2d<s32>(destRect.UpperLeftCorner),
sourceRect, clipRect, colors?colors[0]:SColor(0xffffffff),
useAlphaChannelOfTexture);
}
//! Draws a 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
void CNullDriver::draw2DImage(const ITexture* texture, const position2d<s32>& destPos,
const rectangle<s32>& sourceRect,
const rectangle<s32>* clipRect, SColor color,
bool useAlphaChannelOfTexture)
{
}
//! Draws the outline of a 2d rectangle
void CNullDriver::draw2DRectangleOutline(const rectanglei& pos, SColor color)
{
draw2DLine(pos.UpperLeftCorner, position2di(pos.LowerRightCorner.X, pos.UpperLeftCorner.Y), color);
draw2DLine(position2di(pos.LowerRightCorner.X, pos.UpperLeftCorner.Y), pos.LowerRightCorner, color);
draw2DLine(pos.LowerRightCorner, position2di(pos.UpperLeftCorner.X, pos.LowerRightCorner.Y), color);
draw2DLine(position2di(pos.UpperLeftCorner.X, pos.LowerRightCorner.Y), pos.UpperLeftCorner, color);
}
//! Draw a 2d rectangle
void CNullDriver::draw2DRectangle(SColor color, const rectangle<s32>& pos, const rectangle<s32>* clip)
{
draw2DRectangle(pos, color, color, color, color, clip);
}
//! Draws a 2d rectangle with a gradient.
void CNullDriver::draw2DRectangle(const rectangle<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
const rectangle<s32>* clip)
{
}
//! Draws a 2d line.
void CNullDriver::draw2DLine(const position2d<s32>& start,
const position2d<s32>& end, SColor color)
{
}
//! Draws a pixel
void CNullDriver::drawPixel(u32 x, u32 y, const SColor & color)
{
}
//! Draws a non filled concyclic regular 2d polyon.
void CNullDriver::draw2DPolygon(position2d<s32> center,
f32 radius, SColor color, s32 count)
{
if (count < 2)
return;
position2d<s32> first;
position2d<s32> a,b;
for (s32 j=0; j<count; ++j)
{
b = a;
f32 p = j / (f32)count * (PI*2);
a = center + position2d<s32>((s32)(sin(p)*radius), (s32)(cos(p)*radius));
if (j==0)
first = a;
else
draw2DLine(a, b, color);
}
draw2DLine(a, first, color);
}
//! returns color format
ECOLOR_FORMAT CNullDriver::getColorFormat() const
{
return ECF_R5G6B5;
}
//! returns screen size
const dimension2d<u32>& CNullDriver::getScreenSize() const
{
return ScreenSize;
}
//! returns the current render target size,
//! or the screen size if render targets are not implemented
const dimension2d<u32>& CNullDriver::getCurrentRenderTargetSize() const
{
return ScreenSize;
}
// returns current frames per second value
s32 CNullDriver::getFPS() const
{
return FPSCounter.getFPS();
}
//! returns amount of primitives (mostly triangles) were drawn in the last frame.
//! very useful method for statistics.
u32 CNullDriver::getPrimitiveCountDrawn( u32 param ) const
{
return (0 == param) ? FPSCounter.getPrimitive() : (1 == param) ? FPSCounter.getPrimitiveAverage() : FPSCounter.getPrimitiveTotal();
}
//! Sets the dynamic ambient light color. The default color is
//! (0,0,0,0) which means it is dark.
//! \param color: New color of the ambient light.
void CNullDriver::setAmbientLight(const SColorf& color)
{
}
//! \return Returns the name of the video driver. Example: In case of the DIRECT3D8
//! driver, it would return "Direct3D8".
const wchar_t* CNullDriver::getName() const
{
return L"Dream NullDevice";
}
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: Frist, draw all geometry. Then use this method, to draw the shadow
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
void CNullDriver::drawStencilShadowVolume(const array<vector3df>& triangles, bool zfail, u32 debugDataVisible)
{
}
//! Fills the stencil shadow with color. After the shadow volume has been drawn
//! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this
//! to draw the color of the shadow.
void CNullDriver::drawStencilShadow(bool clearStencilBuffer,
SColor leftUpEdge, SColor rightUpEdge,
SColor leftDownEdge, SColor rightDownEdge)
{
}
//! deletes all dynamic lights there are
void CNullDriver::deleteAllDynamicLights()
{
Lights.set_used(0);
}
//! adds a dynamic light
s32 CNullDriver::addDynamicLight(const SLight& light)
{
Lights.push_back(light);
return Lights.size() - 1;
}
//! Turns a dynamic light on or off
//! \param lightIndex: the index returned by addDynamicLight
//! \param turnOn: true to turn the light on, false to turn it off
void CNullDriver::turnLightOn(s32 lightIndex, bool turnOn)
{
// Do nothing
}
//! returns the maximal amount of dynamic lights the device can handle
u32 CNullDriver::getMaximalDynamicLightAmount() const
{
return 0;
}
//! Returns current amount of dynamic lights set
//! \return Current amount of dynamic lights set
u32 CNullDriver::getDynamicLightCount() const
{
return Lights.size();
}
//! Returns light data which was previously set by IVideoDriver::addDynamicLight().
//! \param idx: Zero based index of the light. Must be greater than 0 and smaller
//! than IVideoDriver()::getDynamicLightCount.
//! \return Light data.
const SLight& CNullDriver::getDynamicLight(u32 idx) const
{
if ( idx < Lights.size() )
return Lights[idx];
else
return *((SLight*)0);
}
//! Creates a boolean alpha channel of the texture based of an color key.
void CNullDriver::makeColorKeyTexture(ITexture* texture,
SColor color,
bool zeroTexels) const
{
if (!texture)
return;
if (texture->getColorFormat() != ECF_A1R5G5B5 &&
texture->getColorFormat() != ECF_A8R8G8B8 )
{
Printer::log("Error: Unsupported texture color format for making color key channel.", ELL_ERROR);
return;
}
if (texture->getColorFormat() == ECF_A1R5G5B5)
{
u16 *p = (u16*)texture->lock();
if (!p)
{
Printer::log("Could not lock texture for making color key channel.", ELL_ERROR);
return;
}
const dimension2d<u32> dim = texture->getSize();
const u32 pitch = texture->getPitch() / 2;
// color with alpha disabled (i.e. fully transparent)
const u16 refZeroAlpha = (0x7fff & color.toA1R5G5B5());
const u32 pixels = pitch * dim.Height;
for (u32 pixel = 0; pixel < pixels; ++ pixel)
{
// If the color matches the reference color, ignoring alphas,
// set the alpha to zero.
if(((*p) & 0x7fff) == refZeroAlpha)
{
if(zeroTexels)
(*p) = 0;
else
(*p) = refZeroAlpha;
}
++p;
}
texture->unlock();
}
else
{
u32 *p = (u32*)texture->lock();
if (!p)
{
Printer::log("Could not lock texture for making color key channel.", ELL_ERROR);
return;
}
dimension2d<u32> dim = texture->getSize();
u32 pitch = texture->getPitch() / 4;
// color with alpha disabled (fully transparent)
const u32 refZeroAlpha = 0x00ffffff & color.color;
const u32 pixels = pitch * dim.Height;
for (u32 pixel = 0; pixel < pixels; ++ pixel)
{
// If the color matches the reference color, ignoring alphas,
// set the alpha to zero.
if(((*p) & 0x00ffffff) == refZeroAlpha)
{
if(zeroTexels)
(*p) = 0;
else
(*p) = refZeroAlpha;
}
++p;
}
texture->unlock();
}
texture->regenerateMipMapLevels();
}
//! Creates an boolean alpha channel of the texture based of an color key position.
void CNullDriver::makeColorKeyTexture(ITexture* texture,
position2d<s32> colorKeyPixelPos,
bool zeroTexels) const
{
if (!texture)
return;
if (texture->getColorFormat() != ECF_A1R5G5B5 &&
texture->getColorFormat() != ECF_A8R8G8B8 )
{
Printer::log("Error: Unsupported texture color format for making color key channel.", ELL_ERROR);
return;
}
SColor colorKey;
if (texture->getColorFormat() == ECF_A1R5G5B5)
{
u16 *p = (u16*)texture->lock(ETLM_READ_ONLY);
if (!p)
{
Printer::log("Could not lock texture for making color key channel.", ELL_ERROR);
return;
}
u32 pitch = texture->getPitch() / 2;
const u16 key16Bit = 0x7fff & p[colorKeyPixelPos.Y*pitch + colorKeyPixelPos.X];
colorKey = A1R5G5B5toA8R8G8B8(key16Bit);
}
else
{
u32 *p = (u32*)texture->lock(ETLM_READ_ONLY);
if (!p)
{
Printer::log("Could not lock texture for making color key channel.", ELL_ERROR);
return;
}
u32 pitch = texture->getPitch() / 4;
colorKey = 0x00ffffff & p[colorKeyPixelPos.Y*pitch + colorKeyPixelPos.X];
}
texture->unlock();
makeColorKeyTexture(texture, colorKey, zeroTexels);
}
//! Creates a normal map from a height map texture.
//! \param amplitude: Constant value by which the height information is multiplied.
void CNullDriver::makeNormalMapTexture(ITexture* texture, f32 amplitude) const
{
if (!texture)
return;