Debian Codegraph @

third_party/rust/wpf-gpu-raster/src/hwvertexbuffer.rs

raw
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5
6 //-----------------------------------------------------------------------------
7 //
8
9 //
10 // Description:
11 // Contains HW Vertex Buffer and Builder class implementations
12 //
13 //
14 // Notes:
15 //
16 // +--------------------------------------+
17 // | |
18 // | Start Stratum |
19 // 1 | |
20 // | |
21 // +--------------------------------------+
22 // 2 |======================================|
23 // +--------------------------------------+
24 // | / \ / \ |
25 // | / \ / \ |
26 // | A / B \ C / D \ E |
27 // 3 | / \ / \ |
28 // | / \ / \ |
29 // | / \ / \ |
30 // | / \ / \ |
31 // +--------------------------------------+
32 // | \ / \ / |
33 // | \ / \ / |
34 // 4 | F \ G / H \ I / J |
35 // | \ / \ / |
36 // +--------------------------------------+
37 // 5 |======================================|
38 // +--------------------------------------+
39 // 6 |======================================|
40 // +--------------------------------------+
41 // | |
42 // | |
43 // 7 | Stop Stratum |
44 // | |
45 // | |
46 // +--------------------------------------+
47 //
48 //
49 // Strata & complement mode.
50 //
51 // The anti-aliased HW rasterizer produces a series of "strata" where
52 // each strata can be a complex span rendered using lines (#'s 2,5,6) or
53 // a series of trapezoids (#'s 3 & 4.) In normal mode the trapezoid
54 // regions B,D,G,I are filled in.
55 //
56 // Complement mode complicates things. Complex spans are relatively easy
57 // because we get the whole line's worth of data at once. Trapezoids are
58 // more complex because we get B,D,G and I separately. We handle this by
59 // tracking the current stratum and finishing the last incomplete
60 // trapezoid stratum when a new stratum begins. Regions E & J finish
61 // trapezoid strata. We also need to add rectangles at the beginning and
62 // end of the geometry (start and stop) to fill out the complement
63 // region.
64 //
65 // This is implemented like so:
66 //
67 // 1. Strata are generated from top to bottom without gaps.
68 // 2. Before drawing any lines or trapezoids call
69 // PrepareStratum(a, b, fTrapezoid) where a & b are the extent of
70 // the current stratum and fTrapezoid is true if you are drawing
71 // a trapezoid. This will take care of creating the start
72 // stratum and/or finishing a trapezoid stratum if necessary.
73 // 3. When completely done call EndBuildingOutside() which will
74 // close a pending trapezoid and/or produce the stop stratum.
75 //
76 //-----------------------------------------------------------------------------
77
78 const FORCE_TRIANGLES: bool = true;
79
80 //+----------------------------------------------------------------------------
81 //
82 // Constants to control when we stop waffling because the tiles are too
83 // small to make a difference.
84 //
85 // Future Consideration: can produce an excessive number of triangles.
86 // How we mitigate or handle this could be improved. Right now we stop
87 // waffling if the waffle size is less than a quarter-pixel.
88 // Two big improvements that could be made are:
89 // - multipacking very small textures (but note that we cannot rely
90 // on prefiltering to ensure that small screen space means small texture
91 // source)
92 // - clipping primitives to approximately the screen size
93 //
94 //-----------------------------------------------------------------------------
95 //const c_rMinWaffleWidthPixels: f32 = 0.25;
96
97
98 const FLOAT_ZERO: f32 = 0.;
99 const FLOAT_ONE: f32 = 1.;
100
101 //+----------------------------------------------------------------------------
102 //
103 // Class: CHwVertexBuffer and CHwTVertexBuffer<class TVertex>
104 //
105 // Synopsis: This class accumulates geometry data for a primitive
106 //
107 //-----------------------------------------------------------------------------
108
109 use crate::{types::*, geometry_sink::IGeometrySink, aacoverage::c_nShiftSizeSquared, OutputVertex, nullable_ref::Ref};
110
111
112 //+----------------------------------------------------------------------------
113 //
114 // Class: CHwVertexBuffer::Builder
115 //
116 // Synopsis: Base vertex builder class
117 //
118 // Responsibilities:
119 // - Given ordered basic vertex information expand/convert/pass-thru
120 // to vertex buffer (Basic vertex information is minimal vertex
121 // information sent from the caller that may or may not have been
122 // passed thru a tessellator.)
123 // - Choosing vertex format from a minimal required vertex format
124 //
125 // Not responsible for:
126 // - Allocating space in vertex buffer
127 //
128 // Inputs required:
129 // - Key and data to translate input basic vertex info to full vertex data
130 // - Vertex info from tessellation (or other Geometry Generator)
131 // - Vertex buffer to send output to
132 //
133
134 /*pub struct CHwVertexBufferBuilder /* : public IGeometrySink */
135 {
136 /*
137 public:
138
139 static HRESULT Create(
140 MilVertexFormat vfIn,
141 MilVertexFormat vfOut,
142 MilVertexFormatAttribute vfaAntiAliasScaleLocation,
143 __in_ecount_opt(1) CHwPipeline *pPipeline,
144 __in_ecount_opt(1) CD3DDeviceLevel1 *pDevice,
145 __in_ecount(1) CBufferDispenser *pBufferDispenser,
146 __deref_out_ecount(1) CHwVertexBuffer::Builder **ppVertexBufferBuilder
147 );
148
149 virtual ~Builder()
150 {
151 #if DBG
152 Assert(!m_fDbgDestroyed);
153 m_fDbgDestroyed = true;
154 #endif DBG
155 }
156
157 //+------------------------------------------------------------------------
158 //
159 // Member: SetConstantMapping
160 //
161 // Synopsis: Use this method to specify that the given color source for
162 // the given vertex destination is constant (won't differ per
163 // vertex)
164 //
165 //-------------------------------------------------------------------------
166
167 virtual HRESULT SetConstantMapping(
168 MilVertexFormatAttribute mvfaDestination,
169 __in_ecount(1) const CHwConstantColorSource *pConstCS
170 ) PURE;
171
172
173 //+------------------------------------------------------------------------
174 //
175 // Member: FinalizeMappings
176 //
177 // Synopsis: Use this method to let builder know that all mappings have
178 // been sent
179 //
180 //-------------------------------------------------------------------------
181
182 virtual HRESULT FinalizeMappings(
183 ) PURE;
184
185 //+------------------------------------------------------------------------
186 //
187 // Member: SetOutsideBounds
188 //
189 // Synopsis: Enables rendering zero-alpha geometry outside of the input
190 // shape but within the given bounding rectangle, if fNeedInside
191 // isn't true then it doesn't render geometry with full alpha.
192 //
193 //-------------------------------------------------------------------------
194 virtual void SetOutsideBounds(
195 __in_ecount_opt(1) const CMILSurfaceRect *prcBounds,
196 bool fNeedInside
197 ) PURE;
198
199 //+------------------------------------------------------------------------
200 //
201 // Member: HasOutsideBounds
202 //
203 // Synopsis: Returns true if outside bounds have been set.
204 //
205 //-------------------------------------------------------------------------
206 virtual bool HasOutsideBounds() const PURE;
207
208 //+------------------------------------------------------------------------
209 //
210 // Member: BeginBuilding
211 //
212 // Synopsis: This method lets the builder know it should start from a
213 // clean slate
214 //
215 //-------------------------------------------------------------------------
216
217 virtual HRESULT BeginBuilding(
218 ) PURE;
219
220 //+------------------------------------------------------------------------
221 //
222 // Member: EndBuilding
223 //
224 // Synopsis: Use this method to let the builder know that all of the
225 // vertex data has been sent
226 //
227 //-------------------------------------------------------------------------
228
229 virtual HRESULT EndBuilding(
230 __deref_opt_out_ecount(1) CHwVertexBuffer **ppVertexBuffer
231 ) PURE;
232
233 //+------------------------------------------------------------------------
234 //
235 // Member: FlushReset
236 //
237 // Synopsis: Send pending state and geometry to the device and reset
238 // the vertex buffer.
239 //
240 //-------------------------------------------------------------------------
241
242 MIL_FORCEINLINE HRESULT FlushReset()
243 {
244 return FlushInternal(NULL);
245 }
246
247 //
248 // Currently all CHwVertexBuffer::Builder are supposed to be allocated via
249 // a CBufferDispenser.
250 //
251
252 DECLARE_BUFFERDISPENSER_DELETE
253
254 protected:
255
256 Builder()
257 {
258 m_mvfIn = MILVFAttrNone;
259
260 #if DBG
261 m_mvfDbgOut = MILVFAttrNone;
262 #endif
263
264 m_mvfaAntiAliasScaleLocation = MILVFAttrNone;
265
266 m_pPipelineNoRef = NULL;
267 m_pDeviceNoRef = NULL;
268
269 #if DBG
270 m_fDbgDestroyed = false;
271 #endif DBG
272 }
273
274 //+------------------------------------------------------------------------
275 //
276 // Member: FlushInternal
277 //
278 // Synopsis: Send any pending state and geometry to the device.
279 // If the optional argument is NULL then reset the
280 // vertex buffer.
281 // If the optional argument is non-NULL AND we have
282 // not yet flushed the vertex buffer return the vertex
283 // buffer.
284 //
285 //-------------------------------------------------------------------------
286
287 virtual HRESULT FlushInternal(
288 __deref_opt_out_ecount_opt(1) CHwVertexBuffer **ppVertexBuffer
289 ) PURE;
290
291
292 CHwPipeline *m_pPipelineNoRef;
293 CD3DDeviceLevel1 *m_pDeviceNoRef;
294
295 MilVertexFormat m_mvfIn; // Vertex fields that are pre-generated
296
297 #if DBG
298 MilVertexFormat m_mvfDbgOut; // Output format of the vertex
299 #endif
300
301 MilVertexFormat m_mvfGenerated; // Vertex fields that are dynamically
302 // generated by this builder
303
304 MilVertexFormatAttribute m_mvfaAntiAliasScaleLocation; // Vertex field that
305 // contains PPAA
306 // falloff factor
307
308 #if DBG
309 private:
310
311 bool m_fDbgDestroyed; // Used to check single Release pattern
312
313 #endif DBG
314 */
315 }*/
316 #[derive(Default)]
317 pub struct CD3DVertexXYZDUV2 {
318 x: f32,
319 y: f32,
320 //Z: f32,
321 coverage: f32,
322 /*U0: f32, V0: f32,
323 U1: f32, V1: f32,*/
324 }
325 pub type CHwVertexBuffer<'z> = CHwTVertexBuffer<'z, OutputVertex>;
326 #[derive(Default)]
327 pub struct CHwTVertexBuffer<'z, TVertex>
328 {
329 //m_rgIndices: DynArray<WORD>, // Dynamic array of indices
330
331
332 //m_pBuilder: Rc<CHwTVertexBufferBuilder<TVertex>>,
333
334 /*
335 #if DBG
336 public:
337
338 CHwTVertexBuffer()
339 {
340 m_fDbgNonLineSegmentTriangleStrip = false;
341 }
342 #endif
343
344 protected:
345
346 //+------------------------------------------------------------------------
347 //
348 // Member: Reset
349 //
350 // Synopsis: Mark the beginning of a new list of vertices; the existing
351 // list is discarded
352 //
353 //-------------------------------------------------------------------------
354
355 MIL_FORCEINLINE void Reset(
356 __in_ecount(1) Builder *pVBB
357 )
358 {
359 #if DBG
360 m_fDbgNonLineSegmentTriangleStrip = false;
361 #endif
362 m_rgIndices.SetCount(0);
363 m_rgVerticesTriList.SetCount(0);
364 m_rgVerticesTriStrip.SetCount(0);
365 m_rgVerticesLineList.SetCount(0);
366 m_rgVerticesNonIndexedTriList.SetCount(0);
367
368 m_pBuilder = pVBB;
369 }
370
371 //+------------------------------------------------------------------------
372 //
373 // Member: AddNonIndexedTriListVertices
374 //
375 // Synopsis: Reserve space for consecutive vertices and return start
376 // index
377 //
378 //-------------------------------------------------------------------------
379
380 MIL_FORCEINLINE HRESULT AddNonIndexedTriListVertices(
381 UINT uCount,
382 __deref_ecount(uCount) TVertex **ppVertices
383 );
384
385 //+------------------------------------------------------------------------
386 //
387 // Member: AddTriListVertices
388 //
389 // Synopsis: Reserve space for consecutive vertices and return start
390 // index
391 //
392 //-------------------------------------------------------------------------
393
394 MIL_FORCEINLINE HRESULT AddTriListVertices(
395 UINT uDelta,
396 __deref_ecount(uDelta) TVertex **ppVertices,
397 __out_ecount(1) WORD *pwIndexStart
398 );
399
400 //+------------------------------------------------------------------------
401 //
402 // Member: AddTriStripVertices
403 //
404 // Synopsis: Reserve space for consecutive vertices and return start
405 // index
406 //
407 //-------------------------------------------------------------------------
408
409 MIL_FORCEINLINE HRESULT AddTriStripVertices(
410 UINT uCount,
411 __deref_ecount(uCount) TVertex **ppVertices
412 );
413
414 //+------------------------------------------------------------------------
415 //
416 // Member: AddLineListVertices
417 //
418 // Synopsis: Reserve space for consecutive vertices and return start
419 // index
420 //
421 //-------------------------------------------------------------------------
422
423 MIL_FORCEINLINE HRESULT AddLineListVertices(
424 UINT uCount,
425 __deref_ecount(uCount) TVertex **ppVertices
426 );
427
428 public:
429
430 //+------------------------------------------------------------------------
431 //
432 // Member: AddLine implements ILineSink<PointXYA>
433 //
434 // Synopsis: Add a line given two points with x, y, & alpha.
435 //
436 //-------------------------------------------------------------------------
437 HRESULT AddLine(
438 __in_ecount(1) const PointXYA &v0,
439 __in_ecount(1) const PointXYA &v1
440 );
441
442 //+------------------------------------------------------------------------
443 //
444 // Member: AddTriangle implements ITriangleSink<PointXYA>
445 //
446 // Synopsis: Add a triangle given three points with x, y, & alpha.
447 //
448 //-------------------------------------------------------------------------
449
450 HRESULT AddTriangle(
451 __in_ecount(1) const PointXYA &v0,
452 __in_ecount(1) const PointXYA &v1,
453 __in_ecount(1) const PointXYA &v2
454 );
455
456 // Re-introduce parent AddTriangle(WORD,WORD,WORD) into this scope.
457 using CHwVertexBuffer::AddTriangle;
458
459 //+------------------------------------------------------------------------
460 //
461 // Member: AddLineAsTriangleStrip
462 //
463 // Synopsis: Add a horizontal line using a trinagle strip
464 //
465 //-------------------------------------------------------------------------
466 HRESULT AddLineAsTriangleStrip(
467 __in_ecount(1) const TVertex *pBegin, // Begin
468 __in_ecount(1) const TVertex *pEnd // End
469 );
470
471 //+------------------------------------------------------------------------
472 //
473 // Member: SendVertexFormat
474 //
475 // Synopsis: Send contained vertex format to device
476 //
477 //-------------------------------------------------------------------------
478
479 HRESULT SendVertexFormat(
480 __inout_ecount(1) CD3DDeviceLevel1 *pDevice
481 ) const;
482
483 //+------------------------------------------------------------------------
484 //
485 // Member: DrawPrimitive
486 //
487 // Synopsis: Send the geometry data to the device and execute rendering
488 //
489 //-------------------------------------------------------------------------
490
491 HRESULT DrawPrimitive(
492 __inout_ecount(1) CD3DDeviceLevel1 *pDevice
493 ) const;
494
495 protected:
496 //+------------------------------------------------------------------------
497 //
498 // Member: GetNumTriListVertices
499 //
500 // Synopsis: Return current number of vertices
501 //
502 //-------------------------------------------------------------------------
503
504 MIL_FORCEINLINE DWORD GetNumTriListVertices() const
505 {
506 return m_rgVerticesTriList.GetCount();
507 }
508
509 //+------------------------------------------------------------------------
510 //
511 // Member: GetTriListVertices
512 //
513 // Synopsis: Return pointer to beginning of vertex list and their count
514 //
515 //-------------------------------------------------------------------------
516
517 MIL_FORCEINLINE void GetTriListVertices(
518 __deref_out_ecount_full(*puNumVertices) TVertex **ppVertices,
519 __out_ecount(1) UINT * puNumVertices
520 )
521 {
522 *ppVertices = m_rgVerticesTriList.GetDataBuffer();
523 *puNumVertices = m_rgVerticesTriList.GetCount();
524 }
525
526 //+------------------------------------------------------------------------
527 //
528 // Member: GetNumNonIndexedTriListVertices
529 //
530 // Synopsis: Return current number of vertices
531 //
532 //-------------------------------------------------------------------------
533
534 MIL_FORCEINLINE DWORD GetNumNonIndexedTriListVertices() const
535 {
536 return m_rgVerticesNonIndexedTriList.GetCount();
537 }
538
539 //+------------------------------------------------------------------------
540 //
541 // Member: GetNonIndexedTriListVertices
542 //
543 // Synopsis: Return pointer to beginning of vertex list and their count
544 //
545 //-------------------------------------------------------------------------
546
547 MIL_FORCEINLINE void GetNonIndexedTriListVertices(
548 __deref_out_ecount_full(*puNumVertices) TVertex **ppVertices,
549 __out_ecount(1) UINT * puNumVertices
550 )
551 {
552 *ppVertices = m_rgVerticesNonIndexedTriList.GetDataBuffer();
553 *puNumVertices = m_rgVerticesNonIndexedTriList.GetCount();
554 }
555
556 //+------------------------------------------------------------------------
557 //
558 // Member: GetNumTriStripVertices
559 //
560 // Synopsis: Return current number of vertices
561 //
562 //-------------------------------------------------------------------------
563
564 MIL_FORCEINLINE DWORD GetNumTriStripVertices() const
565 {
566 return m_rgVerticesTriStrip.GetCount();
567 }
568
569 //+------------------------------------------------------------------------
570 //
571 // Member: GetTriStripVertices
572 //
573 // Synopsis: Return pointer to beginning of vertex list and their count
574 //
575 //-------------------------------------------------------------------------
576
577 MIL_FORCEINLINE void GetTriStripVertices(
578 __deref_out_ecount_full(*puNumVertices) TVertex **ppVertices,
579 __out_ecount(1) UINT *puNumVertices
580 )
581 {
582 *ppVertices = m_rgVerticesTriStrip.GetDataBuffer();
583 *puNumVertices = m_rgVerticesTriStrip.GetCount();
584 }
585
586 //+------------------------------------------------------------------------
587 //
588 // Member: GetNumLineListVertices
589 //
590 // Synopsis: Return current number of vertices
591 //
592 //-------------------------------------------------------------------------
593
594 MIL_FORCEINLINE DWORD GetNumLineListVertices() const
595 {
596 return m_rgVerticesLineList.GetCount();
597 }
598
599 //+------------------------------------------------------------------------
600 //
601 // Member: GetLineListVertices
602 //
603 // Synopsis: Return pointer to beginning of vertex list and their count
604 //
605 //-------------------------------------------------------------------------
606
607 MIL_FORCEINLINE void GetLineListVertices(
608 __deref_out_ecount_full(*puNumVertices) TVertex **ppVertices,
609 __out_ecount(1) UINT * puNumVertices
610 )
611 {
612 *ppVertices = m_rgVerticesLineList.GetDataBuffer();
613 *puNumVertices = m_rgVerticesLineList.GetCount();
614 }
615
616 //+------------------------------------------------------------------------
617 //
618 // Member: GetLineListVertices
619 //
620 // Synopsis: Return pointer to beginning of vertex list
621 //
622 //-------------------------------------------------------------------------
623
624
625
626 */
627
628 // Dynamic array of vertices for which all allocations are zeroed.
629 // XXX: the zero has been removed
630 //m_rgVerticesTriList: DynArray<TVertex>, // Indexed triangle list vertices
631 //m_rgVerticesNonIndexedTriList: DynArray<TVertex>, // Non-indexed triangle list vertices
632 m_rgVerticesTriList: DynArray<TVertex>, // Triangle strip vertices
633 //m_rgVerticesLineList: DynArray<TVertex>, // Linelist vertices
634
635 m_rgVerticesBuffer: Option<&'z mut [TVertex]>,
636 m_rgVerticesBufferOffset: usize,
637
638 #[cfg(debug_assertions)]
639 // In debug make a note if we add a triangle strip that doesn't have 6 vertices
640 // so that we can ensure that we only waffle 6-vertex tri strips.
641 m_fDbgNonLineSegmentTriangleStrip: bool,
642 subpixel_bias: f32,
643 }
644
645 impl<'z, TVertex: Default> CHwTVertexBuffer<'z, TVertex> {
646 pub fn new(rasterization_truncates: bool, output_buffer: Option<&'z mut [TVertex]>) -> Self {
647 CHwTVertexBuffer::<TVertex> {
648 subpixel_bias: if rasterization_truncates {
649 // 1/512 is 0.5 of a subpixel when using 8 bits of subpixel precision.
650 1./512.
651 } else {
652 0.
653 },
654 m_rgVerticesBuffer: output_buffer,
655 m_rgVerticesBufferOffset: 0,
656 ..Default::default()
657 }
658 }
659
660 pub fn flush_output(&mut self) -> Box<[TVertex]> {
661 std::mem::take(&mut self.m_rgVerticesTriList).into_boxed_slice()
662 }
663
664 pub fn get_output_buffer_size(&self) -> Option<usize> {
665 if self.m_rgVerticesBuffer.is_some() {
666 Some(self.m_rgVerticesBufferOffset)
667 } else {
668 None
669 }
670 }
671 }
672
673 //+----------------------------------------------------------------------------
674 //
675 // Class: CHwTVertexMappings<class TVertex>
676 //
677 // Synopsis: Helper class that knows how to populate a vertex from the
678 // incoming basic per vertex data, like just X and Y
679 //
680 //-----------------------------------------------------------------------------
681 #[derive(Default)]
682 struct CHwTVertexMappings<TVertex>
683 {/*
684 public:
685
686 CHwTVertexMappings();
687
688 void SetPositionTransform(
689 __in_ecount(1) const MILMatrix3x2 &matPositionTransform
690 );
691
692 HRESULT SetConstantMapping(
693 MilVertexFormatAttribute mvfaDestination,
694 __in_ecount(1) const CHwConstantColorSource *pConstCS
695 );
696
697 void PointToUV(
698 __in_ecount(1) const MilPoint2F &ptIn,
699 __bound UINT uIndex,
700 __out_ecount(1) TVertex *pvOut
701 );
702
703 MIL_FORCEINLINE bool AreWaffling() const
704 {
705 return false;
706 }
707
708 private:
709 static const size_t s_numOfVertexTextureCoords
710 = NUM_OF_VERTEX_TEXTURE_COORDS(TVertex);
711 public:
712
713 MilVertexFormat m_mvfMapped;
714
715 MilColorF m_colorStatic;
716
717 MILMatrix3x2 m_matPos2DTransform;
718
719 MILMatrix3x2 m_rgmatPointToUV[s_numOfVertexTextureCoords];
720 CMilPointAndSizeF m_rgSubrect[s_numOfVertexTextureCoords];
721 WaffleModeFlags m_rgWaffleMode[s_numOfVertexTextureCoords];
722
723 */
724 m_vStatic: TVertex,
725 subpixel_bias: f32,
726 }
727
728 impl<TVertex> CHwTVertexBuffer<'_, TVertex> {
729 pub fn Reset(&mut self,
730 /*pVBB: &mut CHwTVertexBufferBuilder<TVertex>*/
731 )
732 {
733 #[cfg(debug_assertions)]
734 {
735 self.m_fDbgNonLineSegmentTriangleStrip = false;
736 }
737
738 //self.m_rgIndices.SetCount(0);
739 //self.m_rgVerticesTriList.SetCount(0);
740 self.m_rgVerticesTriList.SetCount(0);
741 self.m_rgVerticesBufferOffset = 0;
742 //self.m_rgVerticesLineList.SetCount(0);
743 //self.m_rgVerticesNonIndexedTriList.SetCount(0);
744
745 //self.m_pBuilder = pVBB;
746 }
747
748 fn IsEmpty(&self) -> bool
749 {
750 return true
751 // && (self.m_rgIndices.GetCount() == 0)
752 //&& (self.m_rgVerticesLineList.GetCount() == 0)
753 && (self.m_rgVerticesTriList.GetCount() == 0)
754 && self.m_rgVerticesBufferOffset == 0
755 //&& (self.m_rgVerticesNonIndexedTriList.GetCount() == 0);
756 }
757
758 }
759
760 //+----------------------------------------------------------------------------
761 //
762 // Class: CHwTVertexBuffer<class TVertex>::Builder
763 //
764 // Synopsis: Implements CHwVertexBuffer::Builder for a particular vertex
765 // format
766 //
767 //-----------------------------------------------------------------------------
768
769 pub struct CHwTVertexBufferBuilder<'y, 'z, TVertex>
770 {
771 m_mvfIn: MilVertexFormat, // Vertex fields that are pre-generated
772
773 #[cfg(debug_assertions)]
774 m_mvfDbgOut: MilVertexFormat, // Output format of the vertex
775
776 m_mvfGenerated: MilVertexFormat, // Vertex fields that are dyn
777
778 m_mvfaAntiAliasScaleLocation: MilVertexFormatAttribute, // Vertex field that
779 // contains PPAA
780 // falloff factor
781
782 /*
783 public:
784
785 static MilVertexFormat GetOutVertexFormat();
786
787 static HRESULT Create(
788 __in_ecount(1) CHwTVertexBuffer<TVertex> *pVertexBuffer,
789 MilVertexFormat mvfIn,
790 MilVertexFormat mvfOut,
791 MilVertexFormatAttribute mvfaAntiAliasScaleLocation,
792 __inout_ecount(1) CBufferDispenser *pBufferDispenser,
793 __deref_out_ecount(1) typename CHwTVertexBuffer<TVertex>::Builder **ppVertexBufferBuilder
794 );
795
796 HRESULT SetConstantMapping(
797 MilVertexFormatAttribute mvfaDestination,
798 __in_ecount(1) const CHwConstantColorSource *pConstCS
799 );
800
801 void SetTransformMapping(
802 __in_ecount(1) const MILMatrix3x2 &mat2DTransform
803 );
804
805 HRESULT FinalizeMappings(
806 );
807
808 void SetOutsideBounds(
809 __in_ecount_opt(1) const CMILSurfaceRect *prcBounds,
810 bool fNeedInside
811 );
812
813 bool HasOutsideBounds() const
814 {
815 return NeedOutsideGeometry();
816 }
817
818 HRESULT BeginBuilding(
819 );
820
821 HRESULT AddVertex(
822 __in_ecount(1) const MilPoint2F &ptPosition,
823 // In: Vertex coordinates
824 __out_ecount(1) WORD *pIndex
825 // Out: The index of the new vertex
826 );
827
828 HRESULT AddIndexedVertices(
829 UINT cVertices, // In: number of vertices
830 __in_bcount(cVertices*uVertexStride) const void *pVertexBuffer, // In: vertex buffer containing the vertices
831 UINT uVertexStride, // In: size of each vertex
832 MilVertexFormat mvfFormat, // In: format of each vertex
833 UINT cIndices, // In: Number of indices
834 __in_ecount(cIndices) const UINT *puIndexBuffer // In: index buffer
835 );
836
837 HRESULT AddTriangle(
838 DWORD i1, // In: Index of triangle's first vertex
839 DWORD i2, // In: Index of triangle's second vertex
840 DWORD i3 // In: Index of triangle's third vertex
841 );
842
843 HRESULT AddComplexScan(
844 INT nPixelY,
845 // In: y coordinate in pixel space
846 __in_ecount(1) const CCoverageInterval *pIntervalSpanStart
847 // In: coverage segments
848 );
849
850 HRESULT AddParallelogram(
851 __in_ecount(4) const MilPoint2F *rgPosition
852 );
853
854 HRESULT AddTrapezoid(
855 float rPixelYTop, // In: y coordinate of top of trapezoid
856 float rPixelXTopLeft, // In: x coordinate for top left
857 float rPixelXTopRight, // In: x coordinate for top right
858 float rPixelYBottom, // In: y coordinate of bottom of trapezoid
859 float rPixelXBottomLeft, // In: x coordinate for bottom left
860 float rPixelXBottomRight, // In: x coordinate for bottom right
861 float rPixelXLeftDelta, // In: trapezoid expand radius for left edge
862 float rPixelXRightDelta // In: trapezoid expand radius for right edge
863 );
864
865 BOOL IsEmpty();
866
867 HRESULT EndBuilding(
868 __deref_opt_out_ecount(1) CHwVertexBuffer **ppVertexBuffer
869 );
870
871 HRESULT FlushInternal(
872 __deref_opt_out_ecount_opt(1) CHwVertexBuffer **ppVertexBuffer
873 );
874
875 private:
876
877 // Helpers that do AddTrapezoid. Same parameters
878 HRESULT AddTrapezoidStandard( float, float, float, float, float, float, float, float );
879 HRESULT AddTrapezoidWaffle( float, float, float, float, float, float, float, float );
880
881
882
883 HRESULT PrepareStratumSlow(
884 float rStratumTop,
885 float rStratumBottom,
886 bool fTrapezoid,
887 float rTrapezoidLeft,
888 float rTrapezoidRight
889 );
890
891 // Wrap up building of outside geometry.
892 HRESULT EndBuildingOutside();
893
894 DECLARE_BUFFERDISPENSER_NEW(CHwTVertexBuffer<TVertex>::Builder,
895 Mt(CHwTVertexBuffer_Builder));
896
897 Builder(
898 __in_ecount(1) CHwTVertexBuffer<TVertex> *pVertexBuffer
899 );
900
901 HRESULT SetupConverter(
902 MilVertexFormat mvfIn,
903 MilVertexFormat mvfOut,
904 MilVertexFormatAttribute mvfaAntiAliasScaleLocation
905 );
906
907 HRESULT RenderPrecomputedIndexedTriangles(
908 __range(1, SHORT_MAX) UINT cVertices,
909 __in_ecount(cVertices) const TVertex *rgoVertices,
910 __range(1, UINT_MAX) UINT cIndices,
911 __in_ecount(cIndices) const UINT *rguIndices
912 );
913
914
915 // Expands all vertices in the buffer.
916 void ExpandVertices();
917
918 // Has never been successfully used to declare a method or derived type...
919 /* typedef void (CHwTVertexBuffer<TVertex>::Builder::FN_ExpandVertices)(
920 UINT uCount,
921 TVertex *pVertex
922 );*/
923
924 // error C2143: syntax error : missing ';' before '*'
925 // typedef FN_ExpandVertices *PFN_ExpandVertices;
926
927 typedef void (CHwTVertexBuffer<TVertex>::Builder::* PFN_ExpandVertices)(
928 __range(1,UINT_MAX) UINT uCount,
929 __inout_ecount_full(uCount) TVertex *rgVertices
930 );
931
932 //
933 // Table of vertex expansion routines for common expansion cases:
934 // - There are entries for Z, Diffuse, and one set texture coordinates for
935 // a total of eight combinations.
936 // - Additionally there is a second set of entries for anti-aliasing
937 // falloff applied thru diffuse.
938 //
939
940 static const PFN_ExpandVertices sc_pfnExpandVerticesTable[8*2];
941
942 MIL_FORCEINLINE
943 void TransferAndOrExpandVerticesInline(
944 __range(1,UINT_MAX) UINT uCount,
945 __in_ecount(uCount) TVertex const * rgInputVertices,
946 __out_ecount(uCount) TVertex *rgOutputVertices,
947 MilVertexFormat mvfOut,
948 MilVertexFormatAttribute mvfaScaleByFalloff,
949 bool fInputOutputAreSameBuffer,
950 bool fTransformPosition
951 );
952
953 // FN_ExpandVertices ExpandVerticesFast
954 template <MilVertexFormat mvfOut, MilVertexFormatAttribute mvfaScaleByFalloff>
955 void ExpandVerticesFast(
956 __range(1,UINT_MAX) UINT uCount,
957 __inout_ecount_full(uCount) TVertex *rgVertices
958 )
959 {
960 TransferAndOrExpandVerticesInline(
961 uCount,
962 rgVertices,
963 rgVertices,
964 mvfOut,
965 mvfaScaleByFalloff,
966 true, // => fInputOutputAreSameBuffer
967 false // => fTransformPosition
968 );
969 }
970
971 // error C2146: syntax error : missing ';' before identifier 'ExpandVerticesGeneral'
972 // error C2501: 'CHwTVertexBufferBuilder<TVertex>::FN_ExpandVertices' : missing storage-class or type specifiers
973 // FN_ExpandVertices ExpandVerticesGeneral
974 // typename FN_ExpandVertices ExpandVerticesGeneral
975 // error C4346: 'CHwTVertexBufferBuilder<TVertex>::FN_ExpandVertices' : dependent name is not a type
976 // CHwTVertexBufferBuilder<TVertex>::FN_ExpandVertices ExpandVerticesGeneral
977 // Can't define methos here (unless not parameters are used).
978 // typename CHwTVertexBufferBuilder<TVertex>::FN_ExpandVertices ExpandVerticesGeneral
979 // FN_ExpandVertices ExpandVerticesGeneral
980 void ExpandVerticesGeneral(
981 __range(1,UINT_MAX) UINT uCount,
982 __inout_ecount_full(uCount) TVertex *rgVertices
983 )
984 {
985 TransferAndOrExpandVerticesInline(
986 uCount,
987 rgVertices,
988 rgVertices,
989 m_mvfGenerated,
990 m_mvfaAntiAliasScaleLocation,
991 true, // => fInputOutputAreSameBuffer
992 false // => fTransformPosition
993 );
994 }
995
996 void TransferAndExpandVerticesGeneral(
997 __range(1,UINT_MAX) UINT uCount,
998 __in_ecount(uCount) TVertex const *rgInputVertices,
999 __out_ecount_full(uCount) TVertex *rgOutputVertices,
1000 bool fTransformPosition
1001 )
1002 {
1003 TransferAndOrExpandVerticesInline(
1004 uCount,
1005 rgInputVertices,
1006 rgOutputVertices,
1007 m_mvfGenerated,
1008 m_mvfaAntiAliasScaleLocation,
1009 false, // => fInputOutputAreSameBuffer
1010 fTransformPosition // => fTransformPosition
1011 );
1012 }
1013
1014 // FN_ExpandVertices ExpandVerticesInvalid
1015 void ExpandVerticesInvalid(
1016 __range(1,UINT_MAX) UINT uCount,
1017 __inout_ecount_full(uCount) TVertex *rgVertices
1018 )
1019 {
1020 RIP("Invalid ExpandVertices routine.");
1021 }
1022
1023 //+------------------------------------------------------------------------
1024 //
1025 // Member: NeedCoverageGeometry
1026 //
1027 // Synopsis: True if we should create geometry for a particular
1028 // coverage value.
1029 //
1030 //-------------------------------------------------------------------------
1031 bool NeedCoverageGeometry(INT nCoverage) const;
1032
1033
1034
1035
1036
1037 //+------------------------------------------------------------------------
1038 //
1039 // Member: ReinterpretFloatAsDWORD
1040 //
1041 // Synopsis: Quicky helper to convert a float to a DWORD bitwise.
1042 //
1043 //-------------------------------------------------------------------------
1044 static MIL_FORCEINLINE DWORD ReinterpretFloatAsDWORD(float c)
1045 {
1046 return reinterpret_cast<DWORD &>(c);
1047 }
1048
1049 private:
1050 MIL_FORCEINLINE bool AreWaffling() const
1051 {
1052 return m_map.AreWaffling();
1053 }
1054
1055 void ViewportToPackedCoordinates(
1056 __range(1,UINT_MAX / uGroupSize) UINT uGroupCount,
1057 __inout_ecount(uGroupCount * uGroupSize) TVertex *pVertex,
1058 __range(2,6) UINT uGroupSize,
1059 /*__range(0,NUM_OF_VERTEX_TEXTURE_COORDS(TVertex)-1)*/ __bound UINT uIndex
1060 );
1061
1062 void ViewportToPackedCoordinates(
1063 __range(1,UINT_MAX / uGroupSize) UINT uGroupCount,
1064 __inout_ecount(uGroupCount * uGroupSize) TVertex *pVertex,
1065 __range(2,6) UINT uGroupSize
1066 );
1067
1068 template<class TWaffler>
1069 __out_ecount(1) typename TWaffler::ISink *
1070 BuildWafflePipeline(
1071 __out_xcount(NUM_OF_VERTEX_TEXTURE_COORDS(TVertex) * 2) TWaffler *wafflers,
1072 __out_ecount(1) bool &fWafflersUsed
1073 ) const;
1074
1075
1076 template<class TWaffler>
1077 typename TWaffler::ISink *
1078 BuildWafflePipeline(
1079 __out_xcount(NUM_OF_VERTEX_TEXTURE_COORDS(TVertex) * 2) TWaffler *wafflers
1080 ) const
1081 {
1082 bool fNotUsed;
1083 return BuildWafflePipeline(wafflers, fNotUsed);
1084 }*/
1085
1086 m_pVB: &'y mut CHwTVertexBuffer<'z, TVertex>,
1087
1088 //m_pfnExpandVertices: PFN_ExpandVertices, // Method for expanding vertices
1089
1090 //m_rgoPrecomputedTriListVertices: *const TVertex,
1091 //m_cPrecomputedTriListVertices: UINT,
1092
1093 //m_rguPrecomputedTriListIndices: *const UINT,
1094 //m_cPrecomputedTriListIndices: UINT,
1095
1096 //m_map: CHwTVertexMappings<TVertex>,
1097
1098 // This is true if we had to flush the pipeline as we were getting
1099 // geometry rather than just filling up a single vertex buffer.
1100 m_fHasFlushed: bool,
1101
1102 // The next two members control the generation of the zero-alpha geometry
1103 // outside the input geometry.
1104 m_fNeedOutsideGeometry: bool,
1105 m_fNeedInsideGeometry: bool,
1106 m_rcOutsideBounds: CMILSurfaceRect, // Bounds for creation of outside geometry
1107
1108 /*
1109 // Helpful m_rcOutsideBounds casts.
1110 float OutsideLeft() const { return static_cast<float>(m_rcOutsideBounds.left); }
1111 float OutsideRight() const { return static_cast<float>(m_rcOutsideBounds.right); }
1112 float OutsideTop() const { return static_cast<float>(m_rcOutsideBounds.top); }
1113 float OutsideBottom() const { return static_cast<float>(m_rcOutsideBounds.bottom); }
1114 */
1115 // This interval (if we are doing outside) shows the location
1116 // of the current stratum. It is initialized to [FLT_MAX, -FLT_MAX].
1117 //
1118 // If the current stratum is a complex span then
1119 // m_rCurStratumBottom is set to the bottom of the stratum and
1120 // m_rCurStratumTop is set to FLT_MAX.
1121 //
1122 // If the current stratum is a trapezoidal one, then
1123 // m_rCurStratumBottom is its bottom and m_rCurStratumTop is its
1124 // top.
1125 m_rCurStratumTop: f32,
1126 m_rCurStratumBottom: f32,
1127
1128 // If the current stratum is a trapezoidal one, following var stores
1129 // right boundary of the last trapezoid handled by PrepareStratum.
1130 // We need it to cloze the stratus properly.
1131 m_rLastTrapezoidRight: f32,
1132
1133 // These are needed to implement outside geometry using triangle lists
1134 m_rLastTrapezoidTopRight: f32,
1135 m_rLastTrapezoidBottomRight: f32,
1136 }
1137
1138 /*
1139 //+----------------------------------------------------------------------------
1140 //
1141 // Member: CHwVertexBuffer::AddTriangle
1142 //
1143 // Synopsis: Add a triangle using the three indices given to the list
1144 //
1145 impl CHwVertexBuffer {
1146
1147 fn AddTriangle(
1148 i1: WORD, // In: Index of triangle's first vertex
1149 i2: WORD, // In: Index of triangle's second vertex
1150 i3: WORD // In: Index of triangle's third vertex
1151 ) -> HRESULT
1152 {
1153 let hr: HRESULT = S_OK;
1154
1155 // Asserting indices < max vertex requires a debug only pure virtual method
1156 // which is too much of a functionality change between retail and debug.
1157 //
1158 //
1159 // Assert(i1 < GetNumTriListVertices());
1160 // Assert(i2 < GetNumTriListVertices());
1161 // Assert(i3 < GetNumTriListVertices());
1162
1163 WORD *pIndices;
1164
1165 IFC(m_rgIndices.AddMultiple(3, &pIndices));
1166
1167 pIndices[0] = i1;
1168 pIndices[1] = i2;
1169 pIndices[2] = i3;
1170
1171 Cleanup:
1172 RRETURN(hr);
1173 }
1174
1175 //+----------------------------------------------------------------------------
1176 //
1177 // Member: CHwTVertexBuffer<TVertex>::AddTriangle
1178 //
1179 // Synopsis: Add a triangle using given three points to the list
1180 //
1181 //-----------------------------------------------------------------------------
1182 template <class TVertex>
1183 HRESULT
1184 CHwTVertexBuffer<TVertex>::AddTriangle(
1185 __in_ecount(1) const PointXYA &v0,
1186 __in_ecount(1) const PointXYA &v1,
1187 __in_ecount(1) const PointXYA &v2)
1188 {
1189 let hr: HRESULT = S_OK;
1190
1191 TVertex *pVertices;
1192 hr = AddNonIndexedTriListVertices(3,&pVertices);
1193
1194 if (hr == E_OUTOFMEMORY)
1195 {
1196 DebugBreak ();
1197 }
1198 IFC(hr);
1199
1200 pVertices[0].ptPt.X = v0.x;
1201 pVertices[0].ptPt.Y = v0.y;
1202 pVertices[0].Diffuse = reinterpret_cast<const DWORD &>(v0.a);
1203 pVertices[1].ptPt.X = v1.x;
1204 pVertices[1].ptPt.Y = v1.y;
1205 pVertices[1].Diffuse = reinterpret_cast<const DWORD &>(v1.a);
1206 pVertices[2].ptPt.X = v2.x;
1207 pVertices[2].ptPt.Y = v2.y;
1208 pVertices[2].Diffuse = reinterpret_cast<const DWORD &>(v2.a);
1209
1210 Cleanup:
1211 RRETURN(hr);
1212 }
1213 */
1214
1215 impl CHwVertexBuffer<'_> {
1216 //+----------------------------------------------------------------------------
1217 //
1218 // Member: CHwTVertexBuffer<TVertex>::AddLine
1219 //
1220 // Synopsis: Add a nominal width line using given two points to the list
1221 //
1222 //-----------------------------------------------------------------------------
1223 fn AddLine(&mut self,
1224 v0: &PointXYA,
1225 v1: &PointXYA
1226 ) -> HRESULT
1227 {
1228 type TVertex = CD3DVertexXYZDUV2;
1229 let hr = S_OK;
1230
1231 let pVertices: &mut [TVertex];
1232 let mut rgScratchVertices: [TVertex; 2] = Default::default();
1233
1234 assert!(!(v0.y != v1.y));
1235
1236 let fUseTriangles = /*(v0.y < m_pBuilder->GetViewportTop() + 1) ||*/ FORCE_TRIANGLES;
1237
1238 //if (fUseTriangles)
1239 //{
1240 pVertices = &mut rgScratchVertices;
1241 //}
1242 //else
1243 //{
1244 //IFC!(AddLineListVertices(2, &pVertices));
1245 //}
1246
1247 pVertices[0].x = v0.x;
1248 pVertices[0].y = v0.y;
1249 pVertices[0].coverage = v0.a;
1250 pVertices[1].x = v1.x;
1251 pVertices[1].y = v1.y;
1252 pVertices[1].coverage = v1.a;
1253
1254 if (fUseTriangles)
1255 {
1256 IFC!(self.AddLineAsTriangleList(&pVertices[0],&pVertices[1]));
1257 }
1258
1259 RRETURN!(hr);
1260 }
1261 }
1262 /*
1263 //+----------------------------------------------------------------------------
1264 //
1265 // Member: CHwTVertexBuffer<TVertex>::AddTriListVertices
1266 //
1267 // Synopsis: Reserve space for consecutive vertices and return start index
1268 //
1269
1270 template <class TVertex>
1271 MIL_FORCEINLINE
1272 HRESULT
1273 CHwTVertexBuffer<TVertex>::AddTriListVertices(
1274 UINT uDelta,
1275 __deref_ecount(uDelta) TVertex **ppVertices,
1276 __out_ecount(1) WORD *pwIndexStart
1277 )
1278 {
1279 HRESULT hr = S_OK;
1280
1281 Assert(ppVertices);
1282
1283 UINT uCount = static_cast<UINT>(m_rgVerticesTriList.GetCount());
1284 if (uCount > SHRT_MAX)
1285 {
1286 IFC(WGXERR_INVALIDPARAMETER);
1287 }
1288 UINT newCount;
1289 newCount = uDelta + uCount;
1290
1291 if (newCount > SHRT_MAX)
1292 {
1293 IFC(m_pBuilder->FlushReset());
1294 uCount = 0;
1295 newCount = uDelta;
1296 }
1297
1298 if (newCount > m_rgVerticesTriList.GetCapacity())
1299 {
1300 IFC(m_rgVerticesTriList.ReserveSpace(uDelta));
1301 }
1302
1303 m_rgVerticesTriList.SetCount(newCount);
1304 *pwIndexStart = static_cast<WORD>(uCount);
1305 *ppVertices = &m_rgVerticesTriList[uCount];
1306
1307 Cleanup:
1308 RRETURN(hr);
1309 }
1310 */
1311
1312 impl<TVertex: Clone + Default> CHwTVertexBuffer<'_, TVertex> {
1313
1314 fn AddTriVertices(&mut self, v0: TVertex, v1: TVertex, v2: TVertex) {
1315 if let Some(output_buffer) = &mut self.m_rgVerticesBuffer {
1316 let offset = self.m_rgVerticesBufferOffset;
1317 if offset + 3 <= output_buffer.len() {
1318 output_buffer[offset] = v0;
1319 output_buffer[offset + 1] = v1;
1320 output_buffer[offset + 2] = v2;
1321 }
1322 self.m_rgVerticesBufferOffset = offset + 3;
1323 } else {
1324 self.m_rgVerticesTriList.reserve(3);
1325 self.m_rgVerticesTriList.push(v0);
1326 self.m_rgVerticesTriList.push(v1);
1327 self.m_rgVerticesTriList.push(v2);
1328 }
1329 }
1330
1331 fn AddTrapezoidVertices(&mut self, v0: TVertex, v1: TVertex, v2: TVertex, v3: TVertex) {
1332 if let Some(output_buffer) = &mut self.m_rgVerticesBuffer {
1333 let offset = self.m_rgVerticesBufferOffset;
1334 if offset + 6 <= output_buffer.len() {
1335 output_buffer[offset] = v0;
1336 output_buffer[offset + 1] = v1.clone();
1337 output_buffer[offset + 2] = v2.clone();
1338
1339 output_buffer[offset + 3] = v1;
1340 output_buffer[offset + 4] = v2;
1341 output_buffer[offset + 5] = v3;
1342 }
1343 self.m_rgVerticesBufferOffset = offset + 6;
1344 } else {
1345 self.m_rgVerticesTriList.reserve(6);
1346
1347 self.m_rgVerticesTriList.push(v0);
1348 self.m_rgVerticesTriList.push(v1.clone());
1349 self.m_rgVerticesTriList.push(v2.clone());
1350
1351 self.m_rgVerticesTriList.push(v1);
1352 self.m_rgVerticesTriList.push(v2);
1353 self.m_rgVerticesTriList.push(v3);
1354 }
1355 }
1356
1357 fn AddedNonLineSegment(&mut self) {
1358 #[cfg(debug_assertions)]
1359 {
1360 self.m_fDbgNonLineSegmentTriangleStrip = true;
1361 }
1362 }
1363
1364 }
1365
1366 /*
1367 //+----------------------------------------------------------------------------
1368 //
1369 // Member: CHwTVertexBuffer<TVertex>::AddNonIndexedTriListVertices
1370 //
1371 // Synopsis: Reserve space for triangle list vertices.
1372 //
1373
1374 template <class TVertex>
1375 MIL_FORCEINLINE
1376 HRESULT
1377 CHwTVertexBuffer<TVertex>::AddNonIndexedTriListVertices(
1378 UINT uCount,
1379 __deref_ecount(uCount) TVertex **ppVertices
1380 )
1381 {
1382 HRESULT hr = S_OK;
1383
1384 UINT Count = static_cast<UINT>(m_rgVerticesNonIndexedTriList.GetCount());
1385 UINT newCount = Count + uCount;
1386
1387 if (newCount > m_rgVerticesNonIndexedTriList.GetCapacity())
1388 {
1389 IFC(m_rgVerticesNonIndexedTriList.ReserveSpace(uCount));
1390 }
1391
1392 m_rgVerticesNonIndexedTriList.SetCount(newCount);
1393 *ppVertices = &m_rgVerticesNonIndexedTriList[Count];
1394
1395 Cleanup:
1396 RRETURN(hr);
1397 }
1398
1399 //+----------------------------------------------------------------------------
1400 //
1401 // Member: CHwTVertexBuffer<TVertex>::AddLineListVertices
1402 //
1403 // Synopsis: Reserve space for consecutive vertices
1404 //
1405
1406 template <class TVertex>
1407 MIL_FORCEINLINE
1408 HRESULT
1409 CHwTVertexBuffer<TVertex>::AddLineListVertices(
1410 UINT uCount,
1411 __deref_ecount(uCount) TVertex **ppVertices
1412 )
1413 {
1414 HRESULT hr = S_OK;
1415
1416 Assert(ppVertices);
1417
1418 UINT Count = static_cast<UINT>(m_rgVerticesLineList.GetCount());
1419 UINT newCount = Count + uCount;
1420
1421 if (newCount > m_rgVerticesLineList.GetCapacity())
1422 {
1423 IFC(m_rgVerticesLineList.ReserveSpace(uCount));
1424 }
1425
1426 m_rgVerticesLineList.SetCount(newCount);
1427 *ppVertices = &m_rgVerticesLineList[Count];
1428
1429 Cleanup:
1430 RRETURN(hr);
1431 }
1432
1433 //+----------------------------------------------------------------------------
1434 //
1435 // Class: CHwVertexBuffer::Builder
1436 //
1437 //-----------------------------------------------------------------------------
1438
1439 //+----------------------------------------------------------------------------
1440 //
1441 // Member: CHwTVertexBuffer<TVertex>::Builder::GetOutVertexFormat
1442 //
1443 // Synopsis: Return MIL vertex format covered by specific builders
1444 //
1445 //-----------------------------------------------------------------------------
1446
1447 template <>
1448 MilVertexFormat
1449 CHwTVertexBuffer<CD3DVertexXYZDUV2>::Builder::GetOutVertexFormat()
1450 {
1451 return (MILVFAttrXYZ | MILVFAttrDiffuse | MILVFAttrUV2);
1452 }
1453
1454 template <>
1455 MilVertexFormat
1456 CHwTVertexBuffer<CD3DVertexXYZDUV8>::Builder::GetOutVertexFormat()
1457 {
1458 return (MILVFAttrXYZ | MILVFAttrDiffuse | MILVFAttrUV8);
1459 }
1460
1461 template <>
1462 MilVertexFormat
1463 CHwTVertexBuffer<CD3DVertexXYZDUV6>::Builder::GetOutVertexFormat()
1464 {
1465 return (MILVFAttrXYZ | MILVFAttrDiffuse | MILVFAttrUV6);
1466 }
1467
1468 template <>
1469 MilVertexFormat
1470 CHwTVertexBuffer<CD3DVertexXYZNDSUV4>::Builder::GetOutVertexFormat()
1471 {
1472 return (MILVFAttrXYZ |
1473 MILVFAttrNormal |
1474 MILVFAttrDiffuse |
1475 MILVFAttrSpecular |
1476 MILVFAttrUV4);
1477 }
1478
1479
1480 //+----------------------------------------------------------------------------
1481 //
1482 // Member: CHwVertexBuffer::Builder::Create
1483 //
1484 // Synopsis: Choose the appropriate final vertex format and instantiate the
1485 // matching vertex builder
1486 //
1487 */
1488 pub type CHwVertexBufferBuilder<'y, 'z> = CHwTVertexBufferBuilder<'y, 'z, OutputVertex>;
1489 impl<'y, 'z> CHwVertexBufferBuilder<'y, 'z> {
1490 pub fn Create(
1491 vfIn: MilVertexFormat,
1492 vfOut: MilVertexFormat,
1493 mvfaAntiAliasScaleLocation: MilVertexFormatAttribute,
1494 pVertexBuffer: &'y mut CHwVertexBuffer<'z>,
1495 /*pBufferDispenser: &CBufferDispenser*/
1496 ) -> CHwVertexBufferBuilder<'y, 'z>
1497 {
1498 CHwVertexBufferBuilder::CreateTemplate(pVertexBuffer, vfIn, vfOut, mvfaAntiAliasScaleLocation)
1499 //let hr: HRESULT = S_OK;
1500
1501 //assert!(ppVertexBufferBuilder);
1502
1503 //*ppVertexBufferBuilder = None;
1504 /*
1505 if (!(vfOut & ~CHwTVertexBuffer<CD3DVertexXYZDUV2>::Builder::GetOutVertexFormat()))
1506 {
1507 CHwTVertexBuffer<CD3DVertexXYZDUV2> *pVB = pDevice->GetVB_XYZDUV2();
1508 CHwTVertexBuffer<CD3DVertexXYZDUV2>::Builder *pVBB = NULL;
1509
1510 IFC(CHwTVertexBuffer<CD3DVertexXYZDUV2>::Builder::Create(
1511 pVB,
1512 vfIn,
1513 vfOut,
1514 mvfaAntiAliasScaleLocation,
1515 pBufferDispenser,
1516 &pVBB
1517 ));
1518
1519 *ppVertexBufferBuilder = pVBB;
1520 }
1521 else if (!(vfOut & ~CHwTVertexBuffer<CD3DVertexXYZDUV8>::Builder::GetOutVertexFormat()))
1522 {
1523 CHwTVertexBuffer<CD3DVertexXYZDUV8> *pVB = pDevice->GetVB_XYZRHWDUV8();
1524 CHwTVertexBuffer<CD3DVertexXYZDUV8>::Builder *pVBB = NULL;
1525
1526 IFC(CHwTVertexBuffer<CD3DVertexXYZDUV8>::Builder::Create(
1527 pVB,
1528 vfIn,
1529 vfOut,
1530 mvfaAntiAliasScaleLocation,
1531 pBufferDispenser,
1532 &pVBB
1533 ));
1534
1535 *ppVertexBufferBuilder = pVBB;
1536 }
1537 else
1538 {
1539 // NOTE-2004/03/22-chrisra Adding another vertexbuffer type requires updating enum
1540 //
1541 // If we add another buffer builder type kMaxVertexBuilderSize enum in hwvertexbuffer.h file
1542 // needs to be updated to reflect possible changes to the maximum size of buffer builders.
1543 //
1544 IFC(E_NOTIMPL);
1545 }
1546
1547 // Store the pipeline, if any, which this VBB can use to spill the vertex buffer to if it
1548 // overflows.
1549 (**ppVertexBufferBuilder).m_pPipelineNoRef = pPipeline;
1550 (**ppVertexBufferBuilder).m_pDeviceNoRef = pDevice;
1551
1552
1553 Cleanup:
1554 RRETURN(hr);*/
1555 //hr
1556 }
1557 /*fn AreWafffling(&self) -> bool {
1558 false
1559 }*/
1560
1561 // Helpful m_rcOutsideBounds casts.
1562 fn OutsideLeft(&self) -> f32 { return self.m_rcOutsideBounds.left as f32; }
1563 fn OutsideRight(&self) -> f32 { return self.m_rcOutsideBounds.right as f32; }
1564 fn OutsideTop(&self) -> f32 { return self.m_rcOutsideBounds.top as f32; }
1565 fn OutsideBottom(&self) -> f32 { return self.m_rcOutsideBounds.bottom as f32; }
1566 }
1567
1568 //+----------------------------------------------------------------------------
1569 //
1570 // Class: THwTVertexMappings<class TVertex>
1571 //
1572 //-----------------------------------------------------------------------------
1573
1574 //+----------------------------------------------------------------------------
1575 //
1576 // Member: THwTVertexMappings<TVertex>::THwTVertexMappings
1577 //
1578 // Synopsis: ctor
1579 //
1580 //-----------------------------------------------------------------------------
1581 /*
1582 template <class TVertex>
1583 CHwTVertexMappings<TVertex>::CHwTVertexMappings()
1584 :
1585 m_mvfMapped(MILVFAttrNone)
1586 {
1587 for (int i = 0; i < ARRAY_SIZE(m_rgWaffleMode); ++i)
1588 {
1589 m_rgWaffleMode[i] = WaffleModeNone;
1590 }
1591
1592 m_matPos2DTransform.SetIdentity();
1593 }
1594
1595
1596 //+----------------------------------------------------------------------------
1597 //
1598 // Member: THwTVertexMappings<TVertex>::SetPositionTransform
1599 //
1600 // Synopsis: Sets the position transform that needs to be applied.
1601 //
1602 //-----------------------------------------------------------------------------
1603 template <class TVertex>
1604 void
1605 CHwTVertexMappings<TVertex>::SetPositionTransform(
1606 __in_ecount(1) const MILMatrix3x2 &matPositionTransform
1607 )
1608 {
1609 m_matPos2DTransform = matPositionTransform;
1610 }
1611
1612 //+----------------------------------------------------------------------------
1613 //
1614 // Member: CHwTVertexMappings<TVertex>::SetConstantMapping
1615 //
1616 // Synopsis: Remember the static color for the given vertex field
1617 //
1618
1619 template <class TVertex>
1620 HRESULT
1621 CHwTVertexMappings<TVertex>::SetConstantMapping(
1622 MilVertexFormatAttribute mvfaLocation,
1623 __in_ecount(1) const CHwConstantColorSource *pConstCS
1624 )
1625 {
1626 HRESULT hr = S_OK;
1627
1628 Assert(!(m_mvfMapped & mvfaLocation));
1629 pConstCS->GetColor(m_colorStatic);
1630 m_mvfMapped |= mvfaLocation; // Remember this field has been mapped
1631
1632 RRETURN(hr);
1633 }
1634
1635 //+----------------------------------------------------------------------------
1636 //
1637 // Function: GetMILVFAttributeOfTextureCoord
1638 //
1639 // Synopsis: Compute MilVertexFormatAttribute for a texture coordinate index
1640 //
1641
1642 MIL_FORCEINLINE
1643 MilVertexFormat
1644 GetMILVFAttributeOfTextureCoord(
1645 DWORD dwCoordIndex
1646 )
1647 {
1648 return MILVFAttrUV1 << dwCoordIndex;
1649 }
1650
1651 //+----------------------------------------------------------------------------
1652 //
1653 // Member: CHwTVertexMappings<TVertex>::PointToUV
1654 //
1655 // Synopsis: Helper function to populate the texture coordinates at the given
1656 // index using the given point
1657 //
1658
1659 template <class TVertex>
1660 MIL_FORCEINLINE void
1661 CHwTVertexMappings<TVertex>::PointToUV(
1662 __in_ecount(1) const MilPoint2F &ptIn,
1663 __bound UINT uIndex,
1664 __out_ecount(1) TVertex *pvOut
1665 )
1666 {
1667 m_rgmatPointToUV[uIndex].TransformPoint(
1668 &pvOut->ptTx[uIndex],
1669 ptIn.X,
1670 ptIn.Y
1671 );
1672 }
1673
1674
1675
1676
1677
1678 //+----------------------------------------------------------------------------
1679 //
1680 // Class: CHwTVertexBuffer<TVertex>::Builder
1681 //
1682 //-----------------------------------------------------------------------------
1683
1684
1685 */
1686
1687 impl<'y, 'z, TVertex: Default> CHwTVertexBufferBuilder<'y, 'z, TVertex> {
1688
1689 //+----------------------------------------------------------------------------
1690 //
1691 // Member: CHwTVertexBuffer<TVertex>::Builder::Create
1692 //
1693 // Synopsis: Instantiate a specific type of vertex builder
1694 //
1695
1696 fn CreateTemplate(
1697 pVertexBuffer: &'y mut CHwTVertexBuffer<'z, TVertex>,
1698 mvfIn: MilVertexFormat,
1699 mvfOut: MilVertexFormat,
1700 mvfaAntiAliasScaleLocation: MilVertexFormatAttribute,
1701 /*pBufferDispenser: __inout_ecount(1) CBufferDispenser *,*/
1702 ) -> Self
1703 {
1704
1705
1706
1707 let mut pVertexBufferBuilder = CHwTVertexBufferBuilder::<TVertex>::new(pVertexBuffer);
1708
1709 IFC!(pVertexBufferBuilder.SetupConverter(
1710 mvfIn,
1711 mvfOut,
1712 mvfaAntiAliasScaleLocation
1713 ));
1714
1715 return pVertexBufferBuilder;
1716 }
1717
1718 //+----------------------------------------------------------------------------
1719 //
1720 // Member: CHwTVertexBuffer<TVertex>::Builder::Builder
1721 //
1722 // Synopsis: ctor
1723 //
1724 //-----------------------------------------------------------------------------
1725
1726 fn new(pVertexBuffer: &'y mut CHwTVertexBuffer<'z, TVertex>) -> Self
1727 {
1728 Self {
1729 m_pVB: pVertexBuffer,
1730
1731
1732 //m_rgoPrecomputedTriListVertices: NULL(),
1733 //m_cPrecomputedTriListVertices: 0,
1734
1735 //m_rguPrecomputedTriListIndices: NULL(),
1736 //m_cPrecomputedTriListIndices: 0,
1737
1738 // These two track the Y extent of the shape this builder is producing.
1739 m_rCurStratumTop: f32::MAX,
1740 m_rCurStratumBottom: -f32::MAX,
1741 m_fNeedOutsideGeometry: false,
1742 m_fNeedInsideGeometry: true,
1743
1744 m_rLastTrapezoidRight: -f32::MAX,
1745 m_rLastTrapezoidTopRight: -f32::MAX,
1746 m_rLastTrapezoidBottomRight: -f32::MAX,
1747
1748 m_fHasFlushed: false,
1749 //m_map: Default::default(),
1750 m_rcOutsideBounds: Default::default(),
1751 #[cfg(debug_assertions)]
1752 m_mvfDbgOut: MilVertexFormatAttribute::MILVFAttrNone as MilVertexFormat,
1753 m_mvfIn: MilVertexFormatAttribute::MILVFAttrNone as MilVertexFormat,
1754 m_mvfGenerated: MilVertexFormatAttribute::MILVFAttrNone as MilVertexFormat,
1755 m_mvfaAntiAliasScaleLocation: MilVertexFormatAttribute::MILVFAttrNone,
1756 }
1757 }
1758
1759 //+----------------------------------------------------------------------------
1760 //
1761 // Member: CHwTVertexBuffer<TVertex>::Builder::SetupConverter
1762 //
1763 // Synopsis: Choose the appropriate conversion method
1764 //
1765
1766 fn SetupConverter(&mut self,
1767 mvfIn: MilVertexFormat,
1768 mvfOut: MilVertexFormat,
1769 mvfaAntiAliasScaleLocation: MilVertexFormatAttribute,
1770 ) -> HRESULT
1771 {
1772 let hr = S_OK;
1773
1774 self.m_mvfIn = mvfIn;
1775
1776 #[cfg(debug_assertions)]
1777 {
1778 self.m_mvfDbgOut = mvfOut;
1779 }
1780
1781 self.m_mvfGenerated = mvfOut & !self.m_mvfIn;
1782 self.m_mvfaAntiAliasScaleLocation = mvfaAntiAliasScaleLocation;
1783
1784 assert!((self.m_mvfGenerated & MilVertexFormatAttribute::MILVFAttrXY as MilVertexFormat) == 0);
1785
1786 RRETURN!(hr);
1787 }
1788 }
1789 /*
1790
1791 //+----------------------------------------------------------------------------
1792 //
1793 // Member: CHwTVertexBuffer<TVertex>::Builder::SetTransformMapping
1794 //
1795 // Synopsis: Delegate mapping sets to CHwTVertexMappings
1796 //
1797 //-----------------------------------------------------------------------------
1798
1799 template <class TVertex>
1800 void
1801 CHwTVertexBuffer<TVertex>::Builder::SetTransformMapping(
1802 __in_ecount(1) const MILMatrix3x2 &mat2DPositionTransform
1803 )
1804 {
1805 m_map.SetPositionTransform(mat2DPositionTransform);
1806 }
1807
1808 template <class TVertex>
1809 HRESULT
1810 CHwTVertexBuffer<TVertex>::Builder::SetConstantMapping(
1811 MilVertexFormatAttribute mvfaLocation,
1812 __in_ecount(1) const CHwConstantColorSource *pConstCS
1813 )
1814 {
1815 HRESULT hr = S_OK;
1816
1817 IFC(m_map.SetConstantMapping(mvfaLocation, pConstCS));
1818
1819 Cleanup:
1820 RRETURN(hr);
1821 }
1822
1823 //+----------------------------------------------------------------------------
1824 //
1825 // Member: CHwTVertexBuffer<TVertex>::Builder::FinalizeMappings
1826 //
1827 // Synopsis: Complete setup of vertex mappings
1828 //
1829
1830 template <class TVertex>
1831 HRESULT
1832 CHwTVertexBuffer<TVertex>::Builder::FinalizeMappings(
1833 )
1834 {
1835 HRESULT hr = S_OK;
1836
1837 //
1838 // Set default Z if required.
1839 //
1840
1841 if (m_mvfGenerated & MILVFAttrZ)
1842 {
1843 if (!(m_map.m_mvfMapped & MILVFAttrZ))
1844 {
1845 m_map.m_vStatic.Z = 0.5f;
1846 }
1847 }
1848
1849 //
1850 // If AA falloff is not going to scale the diffuse color and it is
1851 // generated then see if the color is constant such that we can do any
1852 // complex conversions just once here instead of in every iteration of the
1853 // expansion loop. If AA falloff is going to scale the diffuse color then
1854 // we can still optimize for the falloff = 1.0 case by precomputing that
1855 // color now and checking for 1.0 during generation. Such a precomputation
1856 // has shown significant to performance.
1857 //
1858
1859 if (m_mvfGenerated & MILVFAttrDiffuse)
1860 {
1861 if (m_map.m_mvfMapped & MILVFAttrDiffuse)
1862 {
1863
1864 // Assumes diffuse color is constant
1865 m_map.m_vStatic.Diffuse =
1866 Convert_MilColorF_scRGB_To_Premultiplied_MilColorB_sRGB(&m_map.m_colorStatic);
1867 }
1868 else
1869 {
1870 // Set default Diffuse value: White
1871 m_map.m_vStatic.Diffuse = MIL_COLOR(0xFF,0xFF,0xFF,0xFF);
1872 }
1873 }
1874
1875 RRETURN(hr);
1876 }*/
1877 impl<TVertex> CHwTVertexBufferBuilder<'_, '_, TVertex> {
1878
1879 //+----------------------------------------------------------------------------
1880 //
1881 // Member: CHwTVertexBuffer<TVertex>::Builder::SetOutsideBounds
1882 //
1883 //
1884 // Synopsis: Enables rendering geometry for areas outside the shape but
1885 // within the bounds. These areas will be created with
1886 // zero alpha.
1887 //
1888
1889 pub fn SetOutsideBounds(&mut self,
1890 prcOutsideBounds: Option<&CMILSurfaceRect>,
1891 fNeedInside: bool,
1892 )
1893 {
1894 // Waffling and outside bounds is not currently implemented. It's
1895 // not difficult to do but currently there is no need.
1896 //assert!(!(self.AreWaffling() && self.prcOutsideBounds));
1897
1898 if let Some(prcOutsideBounds) = prcOutsideBounds
1899 {
1900 self.m_rcOutsideBounds = prcOutsideBounds.clone();
1901 self.m_fNeedOutsideGeometry = true;
1902 self.m_fNeedInsideGeometry = fNeedInside;
1903 }
1904 else
1905 {
1906 self.m_fNeedOutsideGeometry = false;
1907 self.m_fNeedInsideGeometry = true;
1908 }
1909 }
1910
1911 //+----------------------------------------------------------------------------
1912 //
1913 // Member: CHwTVertexBuffer<TVertex>::Builder::BeginBuilding
1914 //
1915 // Synopsis: Prepare for a new primitive by resetting the vertex buffer
1916 //
1917 pub fn BeginBuilding(&mut self,
1918 ) -> HRESULT
1919 {
1920
1921 let hr: HRESULT = S_OK;
1922
1923 self.m_fHasFlushed = false;
1924 self.m_pVB.Reset(/*self*/);
1925
1926 RRETURN!(hr);
1927 }
1928 }
1929 impl IGeometrySink for CHwVertexBufferBuilder<'_, '_> {
1930
1931 fn AddTrapezoid(&mut self,
1932 rPixelYTop: f32, // In: y coordinate of top of trapezoid
1933 rPixelXTopLeft: f32, // In: x coordinate for top left
1934 rPixelXTopRight: f32, // In: x coordinate for top right
1935 rPixelYBottom: f32, // In: y coordinate of bottom of trapezoid
1936 rPixelXBottomLeft: f32, // In: x coordinate for bottom left
1937 rPixelXBottomRight: f32, // In: x coordinate for bottom right
1938 rPixelXLeftDelta: f32, // In: trapezoid expand radius for left edge
1939 rPixelXRightDelta: f32 // In: trapezoid expand radius for right edge
1940 ) -> HRESULT
1941 {
1942 let hr = S_OK;
1943
1944 if (/*self.AreWaffling()*/ false)
1945 {
1946 /*IFC(AddTrapezoidWaffle(
1947 rPixelYTop,
1948 rPixelXTopLeft,
1949 rPixelXTopRight,
1950 rPixelYBottom,
1951 rPixelXBottomLeft,
1952 rPixelXBottomRight,
1953 rPixelXLeftDelta,
1954 rPixelXRightDelta));*/
1955 }
1956 else
1957 {
1958 IFC!(self.AddTrapezoidStandard(
1959 rPixelYTop,
1960 rPixelXTopLeft,
1961 rPixelXTopRight,
1962 rPixelYBottom,
1963 rPixelXBottomLeft,
1964 rPixelXBottomRight,
1965 rPixelXLeftDelta,
1966 rPixelXRightDelta));
1967 }
1968
1969 //Cleanup:
1970 RRETURN!(hr);
1971 }
1972
1973
1974 fn IsEmpty(&self) -> bool {
1975 self.m_pVB.IsEmpty()
1976 }
1977
1978 /*
1979
1980 //+----------------------------------------------------------------------------
1981 //
1982 // Member: CHwTVertexBuffer<TVertex>::Builder::AddVertex
1983 //
1984 // Synopsis: Add a vertex to the vertex buffer
1985 //
1986 // Remember just the given vertex information now and convert later
1987 // in a single, more optimal pass.
1988 //
1989
1990 template <class TVertex>
1991 HRESULT
1992 CHwTVertexBuffer<TVertex>::Builder::AddVertex(
1993 __in_ecount(1) const MilPoint2F &ptPosition,
1994 // Vertex coordinates
1995 __out_ecount(1) WORD *pIndex
1996 // The index of the new vertex
1997 )
1998 {
1999 HRESULT hr = S_OK;
2000
2001 Assert(!NeedOutsideGeometry());
2002 Assert(m_mvfIn == MILVFAttrXY);
2003
2004 TVertex *pVertex;
2005
2006 IFC(m_pVB->AddTriListVertices(1, &pVertex, pIndex));
2007
2008 pVertex->ptPt = ptPosition;
2009
2010 // store coverage as a DWORD instead of float
2011
2012 pVertex->Diffuse = FLOAT_ONE;
2013
2014 Cleanup:
2015 RRETURN(hr);
2016 }
2017
2018 //+----------------------------------------------------------------------------
2019 //
2020 // Member: CHwTVertexBuffer<TVertex>::Builder::AddIndexedVertices, IGeometrySink
2021 //
2022 // Synopsis: Add a fully computed, indexed vertex to the vertex buffer
2023 //
2024
2025 template <class TVertex>
2026 HRESULT
2027 CHwTVertexBuffer<TVertex>::Builder::AddIndexedVertices(
2028 UINT cVertices,
2029 // In: number of vertices
2030 __in_bcount(cVertices*uVertexStride) const void *pVertexBufferNoRef,
2031 // In: vertex buffer containing the vertices
2032 UINT uVertexStride,
2033 // In: size of each vertex
2034 MilVertexFormat mvfFormat,
2035 // In: format of each vertex
2036 UINT cIndices,
2037 // In: Number of indices
2038 __in_ecount(cIndices) const UINT *puIndexBuffer
2039 // In: index buffer
2040 )
2041 {
2042 Assert(m_mvfIn & (MILVFAttrXYZ | MILVFAttrDiffuse | MILVFAttrUV2));
2043 Assert(mvfFormat == (MILVFAttrXYZ | MILVFAttrDiffuse | MILVFAttrUV2));
2044
2045 Assert(uVertexStride == sizeof(TVertex));
2046
2047 m_rgoPrecomputedTriListVertices = reinterpret_cast<const TVertex *>(pVertexBufferNoRef);
2048 m_cPrecomputedTriListVertices = cVertices;
2049
2050 m_rguPrecomputedTriListIndices = puIndexBuffer;
2051 m_cPrecomputedTriListIndices = cIndices;
2052
2053 return S_OK;
2054 }
2055
2056 //+----------------------------------------------------------------------------
2057 //
2058 // Member: CHwTVertexBuffer<TVertex>::Builder::AddTriangle
2059 //
2060 // Synopsis: Add a triangle to the vertex buffer
2061 //
2062
2063 template <class TVertex>
2064 HRESULT
2065 CHwTVertexBuffer<TVertex>::Builder::AddTriangle(
2066 DWORD i1, // In: Index of triangle's first vertex
2067 DWORD i2, // In: Index of triangle's second vertex
2068 DWORD i3 // In: Index of triangle's third vertex
2069 )
2070 {
2071 HRESULT hr = S_OK;
2072
2073 Assert(!NeedOutsideGeometry());
2074
2075 if (AreWaffling())
2076 {
2077 TVertex *pVertex;
2078 UINT uNumVertices;
2079 m_pVB->GetTriListVertices(&pVertex, &uNumVertices);
2080
2081 Assert(i1 < uNumVertices);
2082 Assert(i2 < uNumVertices);
2083 Assert(i3 < uNumVertices);
2084
2085 PointXYA rgPoints[3];
2086 rgPoints[0].x = pVertex[i1].ptPt.X;
2087 rgPoints[0].y = pVertex[i1].ptPt.Y;
2088 rgPoints[0].a = 1;
2089 rgPoints[1].x = pVertex[i2].ptPt.X;
2090 rgPoints[1].y = pVertex[i2].ptPt.Y;
2091 rgPoints[1].a = 1;
2092 rgPoints[2].x = pVertex[i3].ptPt.X;
2093 rgPoints[2].y = pVertex[i3].ptPt.Y;
2094 rgPoints[2].a = 1;
2095
2096 TriangleWaffler<PointXYA> wafflers[NUM_OF_VERTEX_TEXTURE_COORDS(TVertex) * 2];
2097 TriangleWaffler<PointXYA>::ISink *pWaffleSinkNoRef = BuildWafflePipeline(wafflers);
2098 IFC(pWaffleSinkNoRef->AddTriangle(rgPoints[0], rgPoints[1], rgPoints[2]));
2099 }
2100 else
2101 {
2102 IFC(m_pVB->AddTriangle(
2103 static_cast<WORD>(i1),
2104 static_cast<WORD>(i2),
2105 static_cast<WORD>(i3)
2106 ));
2107 }
2108
2109 Cleanup:
2110 RRETURN(hr);
2111 }
2112 */
2113
2114
2115 //+----------------------------------------------------------------------------
2116 //
2117 // Member: CHwTVertexBuffer<TVertex>::Builder::AddComplexScan
2118 //
2119 // Synopsis: Add a coverage span to the vertex buffer
2120 //
2121 //-----------------------------------------------------------------------------
2122 fn AddComplexScan(&mut self,
2123 nPixelY: INT,
2124 // In: y coordinate in pixel space
2125 mut pIntervalSpanStart: Ref<crate::aacoverage::CCoverageInterval>
2126 // In: coverage segments
2127 ) -> HRESULT {
2128
2129 let hr: HRESULT = S_OK;
2130 //let pVertex: *mut CD3DVertexXYZDUV2 = NULL();
2131
2132 IFC!(self.PrepareStratum((nPixelY) as f32,
2133 (nPixelY+1) as f32,
2134 false, /* Not a trapezoid. */
2135 0., 0.,
2136 0., 0., 0., 0.));
2137
2138 let rPixelY: f32;
2139 rPixelY = (nPixelY) as f32 + 0.5;
2140
2141 //LineWaffler<PointXYA> wafflers[NUM_OF_VERTEX_TEXTURE_COORDS(TVertex) * 2];
2142
2143 // Use sink for waffling & the first line fix up (aka the complicated cases.)
2144 //ILineSink<PointXYA> *pLineSink = NULL;
2145 let mut pLineSink = None;
2146
2147 /*if (self.AreWaffling())
2148 {
2149 bool fWafflersUsed;
2150 pLineSink = BuildWafflePipeline(wafflers, OUT fWafflersUsed);
2151 if (!fWafflersUsed)
2152 {
2153 pLineSink = NULL;
2154 }
2155 }*/
2156
2157 // Use triangles instead of lines, for lines too close to the top of the viewport
2158 // because lines are clipped (before rasterization) against a viewport that only
2159 // includes half of the top pixel row. Waffling will take care of this separately.
2160 if (/*pLineSink.is_none() && rPixelY < self.GetViewportTop() + 1 ||*/ FORCE_TRIANGLES)
2161 {
2162 pLineSink = Some(&mut self.m_pVB);
2163 }
2164
2165 //
2166 // Output all segments if creating outside geometry, otherwise only output segments
2167 // with non-zero coverage.
2168 //
2169
2170 if (pLineSink.is_none())
2171 {
2172 /*
2173 UINT nSegmentCount = 0;
2174
2175 for (const CCoverageInterval *pIntervalSpanTemp = pIntervalSpanStart;
2176 pIntervalSpanTemp->m_nPixelX != INT_MAX;
2177 pIntervalSpanTemp = pIntervalSpanTemp->m_pNext
2178 )
2179 {
2180 if (NeedCoverageGeometry(pIntervalSpanTemp->m_nCoverage))
2181 {
2182 ++nSegmentCount;
2183 }
2184 }
2185
2186 //
2187 // Add vertices
2188 //
2189 if (nSegmentCount)
2190 {
2191 IFC(m_pVB->AddLineListVertices(nSegmentCount*2, &pVertex));
2192 }*/
2193 }
2194
2195 //
2196 // Having allocated space (if not using sink), now let's actually output the vertices.
2197 //
2198
2199 while ((*pIntervalSpanStart).m_nPixelX.get() != INT::MAX)
2200 {
2201 assert!(!(*pIntervalSpanStart).m_pNext.get().is_null());
2202
2203 //
2204 // Output line list segments
2205 //
2206 // Note that line segments light pixels by going through the the
2207 // "diamond" interior of a pixel. While we could accomplish this
2208 // by going from left edge to right edge of pixel, D3D10 uses the
2209 // convention that the LASTPIXEL is never lit. We respect that now
2210 // by setting D3DRS_LASTPIXEL to FALSE and use line segments that
2211 // start in center of first pixel and end in center of one pixel
2212 // beyond last.
2213 //
2214 // Since our top left corner is integer, we add 0.5 to get to the
2215 // pixel center.
2216 //
2217 if (self.NeedCoverageGeometry((*pIntervalSpanStart).m_nCoverage.get()))
2218 {
2219 let rCoverage: f32 = ((*pIntervalSpanStart).m_nCoverage.get() as f32)/(c_nShiftSizeSquared as f32);
2220
2221 let mut iBegin: LONG = (*pIntervalSpanStart).m_nPixelX.get();
2222 let mut iEnd: LONG = (*(*pIntervalSpanStart).m_pNext.get()).m_nPixelX.get();
2223 if (self.NeedOutsideGeometry())
2224 {
2225 // Intersect the interval with the outside bounds to create
2226 // start and stop lines. The scan begins (ends) with an
2227 // interval starting (ending) at -inf (+inf).
2228
2229 // The given geometry is not guaranteed to be within m_rcOutsideBounds but
2230 // the additional inner min and max (in that order) produce empty spans
2231 // for intervals not intersecting m_rcOutsideBounds.
2232 //
2233 // We could cull here but that should really be done by the geometry
2234 // generator.
2235
2236 iBegin = iBegin.max(iEnd.min(self.m_rcOutsideBounds.left));
2237 iEnd = iEnd.min(iBegin.max(self.m_rcOutsideBounds.right));
2238 }
2239 let rPixelXBegin: f32= (iBegin as f32) + 0.5;
2240 let rPixelXEnd: f32 = (iEnd as f32) + 0.5;
2241
2242 //
2243 // Output line (linelist or tristrip) for a pixel
2244 //
2245
2246 //if let Some(pLineSink) = pLineSink
2247 {
2248 let mut v0: PointXYA = Default::default(); let mut v1: PointXYA = Default::default();
2249 v0.x = rPixelXBegin;
2250 v0.y = rPixelY;
2251 v0.a = rCoverage;
2252
2253 v1.x = rPixelXEnd;
2254 v1.y = rPixelY;
2255 v1.a = rCoverage;
2256
2257 IFC!(self.m_pVB.AddLine(&v0,&v1));
2258 }
2259 //else
2260 {
2261 /*
2262 let dwDiffuse = ReinterpretFloatAsDWORD(rCoverage);
2263
2264 pVertex[0].ptPt.X = rPixelXBegin;
2265 pVertex[0].ptPt.Y = rPixelY;
2266 pVertex[0].Diffuse = dwDiffuse;
2267
2268 pVertex[1].ptPt.X = rPixelXEnd;
2269 pVertex[1].ptPt.Y = rPixelY;
2270 pVertex[1].Diffuse = dwDiffuse;
2271
2272 // Advance output vertex pointer
2273 pVertex += 2;*/
2274 }
2275 }
2276
2277 //
2278 // Advance coverage buffer
2279 //
2280
2281 pIntervalSpanStart = (*pIntervalSpanStart).m_pNext.get();
2282 }
2283
2284
2285 //Cleanup:
2286 RRETURN!(hr);
2287
2288 }
2289 }
2290
2291 //+----------------------------------------------------------------------------
2292 //
2293 // Member: CHwTVertexBuffer<TVertex>::Builder::AddLineAsTriangleList
2294 //
2295 // Synopsis: Adds a horizontal line as a triangle list to work around
2296 // issue in D3D9 where horizontal lines with y = 0 may not render.
2297 //
2298 // Line clipping in D3D9
2299 // This behavior will change in D3D10 and this work-around will no
2300 // longer be needed. (Pixel center conventions will also change.)
2301 //
2302 //-----------------------------------------------------------------------------
2303 impl CHwVertexBuffer<'_> {
2304 fn AddLineAsTriangleList(&mut self,
2305 pBegin: &CD3DVertexXYZDUV2, // Begin
2306 pEnd: &CD3DVertexXYZDUV2 // End
2307 ) -> HRESULT
2308 {
2309 let hr = S_OK;
2310
2311 // Collect pertinent data from vertices.
2312 debug_assert!(pBegin.y == pEnd.y);
2313 debug_assert!(pBegin.coverage == pEnd.coverage);
2314
2315 // Offset begin and end X left by 0.5 because the line starts on the first
2316 // pixel center and ends on the center of the pixel after the line segment.
2317 let x0 = pBegin.x - 0.5;
2318 let x1 = pEnd.x - 0.5;
2319 let y = pBegin.y;
2320 let dwDiffuse = pBegin.coverage;
2321
2322 //
2323 // Add the vertices
2324 //
2325
2326 // OpenGL doesn't specify how vertex positions are converted to fixed point prior to rasterization. On macOS, with AMD GPUs,
2327 // the GPU appears to truncate to fixed point instead of rounding. This behaviour is controlled by PA_SU_VTX_CNTL
2328 // register. To handle this we'll add a 1./512. subpixel bias to the center vertex to cause the coordinates to round instead
2329 // of truncate.
2330 //
2331 // D3D11 requires the fixed point integer result to be within 0.6ULP which implicitly disallows the truncate behaviour above.
2332 // This means that D2D doesn't need to deal with this problem.
2333 let subpixel_bias = self.subpixel_bias;
2334
2335
2336 // Use a single triangle to cover the entire line
2337 self.AddTriVertices(
2338 OutputVertex{ x: x0, y: y - 0.5, coverage: dwDiffuse },
2339 OutputVertex{ x: x0, y: y + 0.5, coverage: dwDiffuse },
2340 OutputVertex{ x: x1, y: y + subpixel_bias, coverage: dwDiffuse },
2341 );
2342
2343 self.AddedNonLineSegment();
2344
2345 //Cleanup:
2346 RRETURN!(hr);
2347 }
2348 }
2349
2350 /*
2351 //+----------------------------------------------------------------------------
2352 //
2353 // Member: CHwTVertexBuffer<TVertex>::Builder::AddParallelogram
2354 //
2355 // Synopsis: This function adds the coordinates of a parallelogram to the vertex strip buffer.
2356 //
2357 // Parameter: rgPosition contains four coordinates of the parallelogram. Coordinates should have
2358 // a winding order
2359 //
2360 //-----------------------------------------------------------------------------
2361 template <class TVertex>
2362 HRESULT
2363 CHwTVertexBuffer<TVertex>::Builder::AddParallelogram(
2364 __in_ecount(4) const MilPoint2F *rgPosition
2365 )
2366 {
2367 HRESULT hr = S_OK;
2368
2369 if (AreWaffling())
2370 {
2371 PointXYA rgPoints[4];
2372 for (int i = 0; i < 4; ++i)
2373 {
2374 rgPoints[i].x = rgPosition[i].X;
2375 rgPoints[i].y = rgPosition[i].Y;
2376 rgPoints[i].a = 1;
2377 }
2378 TriangleWaffler<PointXYA> wafflers[NUM_OF_VERTEX_TEXTURE_COORDS(TVertex) * 2];
2379 TriangleWaffler<PointXYA>::ISink *pWaffleSinkNoRef = BuildWafflePipeline(wafflers);
2380 IFC(pWaffleSinkNoRef->AddTriangle(rgPoints[0], rgPoints[1], rgPoints[3]));
2381 IFC(pWaffleSinkNoRef->AddTriangle(rgPoints[3], rgPoints[1], rgPoints[2]));
2382 }
2383 else
2384 {
2385 TVertex *pVertex;
2386
2387 //
2388 // Add the vertices
2389 //
2390
2391 IFC(m_pVB->AddTriStripVertices(6, &pVertex));
2392
2393 //
2394 // Duplicate the first vertex. This creates 2 degenerate triangles: one connecting
2395 // the previous rect to this one and another between vertices 0 and 1.
2396 //
2397
2398 pVertex[0].ptPt = rgPosition[0];
2399 pVertex[0].Diffuse = FLOAT_ONE;
2400
2401 pVertex[1].ptPt = rgPosition[0];
2402 pVertex[1].Diffuse = FLOAT_ONE;
2403
2404 pVertex[2].ptPt = rgPosition[1];
2405 pVertex[2].Diffuse = FLOAT_ONE;
2406
2407 pVertex[3].ptPt = rgPosition[3];
2408 pVertex[3].Diffuse = FLOAT_ONE;
2409
2410 pVertex[4].ptPt = rgPosition[2];
2411 pVertex[4].Diffuse = FLOAT_ONE;
2412
2413 //
2414 // Duplicate the last vertex. This creates 2 degenerate triangles: one
2415 // between vertices 4 and 5 and one connecting this Rect to the
2416 // next one.
2417 //
2418
2419 pVertex[5].ptPt = rgPosition[2];
2420 pVertex[5].Diffuse = FLOAT_ONE;
2421 }
2422
2423 Cleanup:
2424 RRETURN(hr);
2425 }
2426
2427 //+----------------------------------------------------------------------------
2428 //
2429 // Member: CHwTVertexBuffer<TVertex>::Builder::BuildWafflePipeline<TWaffler>
2430 //
2431 // Synopsis: Builds a pipeline of wafflers into the provided array of wafflers.
2432 // And returns a pointer (not to be deleted) to the input sink
2433 // of the waffle pipeline.
2434 // the final result is sinked int m_pVB.
2435 //
2436 //-----------------------------------------------------------------------------
2437
2438 template<class TVertex>
2439 template<class TWaffler>
2440 __out_ecount(1) typename TWaffler::ISink *
2441 CHwTVertexBuffer<TVertex>::Builder::BuildWafflePipeline(
2442 __out_xcount(NUM_OF_VERTEX_TEXTURE_COORDS(TVertex) * 2) TWaffler *wafflers,
2443 __out_ecount(1) bool &fWafflersUsed
2444 ) const
2445 {
2446 UINT count = 0;
2447
2448 for (int i = 0; i < NUM_OF_VERTEX_TEXTURE_COORDS(TVertex); ++i)
2449 {
2450 if (m_map.m_rgWaffleMode[i] != 0)
2451 {
2452 const MILMatrix3x2 &pMatWaffle = m_map.m_rgmatPointToUV[i];
2453
2454 // Each column ([a,b,c] transpose) of this matrix specifies a waffler that
2455 // partitions the plane into regions between the lines:
2456 // ax + by + c = k
2457 // for every integer k.
2458 //
2459 // If this partition width is substantially less than a pixel we have
2460 // serious problems with waffling generating too many triangles for
2461 // doubtful visual effect so we don't perform a waffling with width less
2462 // than c_rMinWaffleWidthPixels. So we need to know the width of the partition
2463 // regions:
2464 //
2465 // Changing c just translates the partition so let's assume c = 0.
2466 // The line ax + by = 0 goes through the origin and the line ax + by
2467 // = 1 is adjacent to it in the partition. The distance between
2468 // these lines is also the distance from ax + by = 1 to the origin.
2469 // Using Lagrange multipliers we can determine that this distance
2470 // is
2471 // 1/sqrt(a*a+b*b).
2472 // We want to avoid waffling if this is less than c_rMinWaffleWidthPixels
2473 // or equivalently:
2474 // 1/sqrt(a*a+b*b) < c_rMinWaffleWidthPixels
2475 // sqrt(a*a+b*b) > 1/c_rMinWaffleWidthPixels
2476 // a*a+b*b > 1/(c_rMinWaffleWidthPixels*c_rMinWaffleWidthPixels)
2477 //
2478
2479 const float c_rMaxWaffleMagnitude = 1/(c_rMinWaffleWidthPixels*c_rMinWaffleWidthPixels);
2480
2481 float mag0 = pMatWaffle.m_00*pMatWaffle.m_00+pMatWaffle.m_10*pMatWaffle.m_10;
2482 if (mag0 < c_rMaxWaffleMagnitude)
2483 {
2484 wafflers[count].Set(pMatWaffle.m_00, pMatWaffle.m_10, pMatWaffle.m_20, wafflers+count+1);
2485 ++count;
2486 }
2487
2488 float mag1 = pMatWaffle.m_01*pMatWaffle.m_01+pMatWaffle.m_11*pMatWaffle.m_11;
2489 if (mag1 < c_rMaxWaffleMagnitude)
2490 {
2491 wafflers[count].Set(pMatWaffle.m_01, pMatWaffle.m_11, pMatWaffle.m_21, wafflers+count+1);
2492 ++count;
2493 }
2494 }
2495 }
2496
2497 if (count)
2498 {
2499 fWafflersUsed = true;
2500 // As the last step in the chain we send the triangles to our vertex buffer.
2501 wafflers[count-1].SetSink(m_pVB);
2502 return &wafflers[0];
2503 }
2504 else
2505 {
2506 fWafflersUsed = false;
2507 // If we built no wafflers then sink straight into the vertex buffer.
2508 return m_pVB;
2509 }
2510 }
2511
2512
2513 //+----------------------------------------------------------------------------
2514 //
2515 // Member: CHwTVertexBuffer<TVertex>::Builder::IsEmpty
2516 //
2517 // Synopsis: Does our VB have any triangles/lines?
2518 //
2519 //-----------------------------------------------------------------------------
2520 template <class TVertex>
2521 BOOL
2522 CHwTVertexBuffer<TVertex>::Builder::IsEmpty()
2523 {
2524 return m_pVB->IsEmpty();
2525 }
2526 */
2527 //+----------------------------------------------------------------------------
2528 //
2529 // Member: CHwTVertexBuffer<TVertex>::Builder::AddTrapezoid
2530 //
2531 // Synopsis: Add a trapezoid to the vertex buffer
2532 //
2533 //
2534 // left edge right edge
2535 // ___+_________________+___ <<< top edge
2536 // / + / \ + \
2537 // / + / \ + \
2538 // / + / \ + \
2539 // /__+__/___________________\__+__\ <<< bottom edge
2540 // + ^^ +
2541 // delta
2542 //
2543 impl CHwVertexBufferBuilder<'_, '_> {
2544
2545 //+----------------------------------------------------------------------------
2546 //
2547 // Member: CHwTVertexBuffer<TVertex>::Builder::AddTrapezoidStandard
2548 //
2549 // Synopsis: See AddTrapezoid. This doesn't do waffling & uses tri strips.
2550 //
2551
2552 fn AddTrapezoidStandard(&mut self,
2553 rPixelYTop: f32, // In: y coordinate of top of trapezoid
2554 rPixelXTopLeft: f32, // In: x coordinate for top left
2555 rPixelXTopRight: f32, // In: x coordinate for top right
2556 rPixelYBottom: f32, // In: y coordinate of bottom of trapezoid
2557 rPixelXBottomLeft: f32, // In: x coordinate for bottom left
2558 rPixelXBottomRight: f32, // In: x coordinate for bottom right
2559 rPixelXLeftDelta: f32, // In: trapezoid expand radius for left edge
2560 rPixelXRightDelta: f32 // In: trapezoid expand radius for right edge
2561 ) -> HRESULT
2562 {
2563 type TVertex = CD3DVertexXYZDUV2;
2564 let hr = S_OK;
2565 //TVertex *pVertex;
2566
2567 IFC!(self.PrepareStratum(
2568 rPixelYTop,
2569 rPixelYBottom,
2570 true, /* Trapezoid */
2571 rPixelXTopLeft.min(rPixelXBottomLeft),
2572 rPixelXTopRight.max(rPixelXBottomRight),
2573 rPixelXTopLeft - rPixelXLeftDelta, rPixelXBottomLeft - rPixelXLeftDelta,
2574 rPixelXTopRight + rPixelXRightDelta, rPixelXBottomRight + rPixelXRightDelta
2575 ));
2576
2577 //
2578 // Add the vertices
2579 //
2580
2581 let fNeedOutsideGeometry: bool; let fNeedInsideGeometry: bool;
2582 fNeedOutsideGeometry = self.NeedOutsideGeometry();
2583 fNeedInsideGeometry = self.NeedInsideGeometry();
2584
2585 //
2586 // Fill in the vertices
2587 //
2588
2589 self.m_pVB.AddTrapezoidVertices(
2590 OutputVertex{
2591 x: rPixelXTopLeft - rPixelXLeftDelta,
2592 y: rPixelYTop,
2593 coverage: FLOAT_ZERO,
2594 },
2595 OutputVertex{
2596 x: rPixelXBottomLeft - rPixelXLeftDelta,
2597 y: rPixelYBottom,
2598 coverage: FLOAT_ZERO,
2599 },
2600 OutputVertex{
2601 x: rPixelXTopLeft + rPixelXLeftDelta,
2602 y: rPixelYTop,
2603 coverage: FLOAT_ONE,
2604 },
2605 OutputVertex{
2606 x: rPixelXBottomLeft + rPixelXLeftDelta,
2607 y: rPixelYBottom,
2608 coverage: FLOAT_ONE,
2609 }
2610 );
2611
2612
2613 if (fNeedInsideGeometry)
2614 {
2615 self.m_pVB.AddTrapezoidVertices(
2616 OutputVertex{
2617 x: rPixelXTopLeft + rPixelXLeftDelta,
2618 y: rPixelYTop,
2619 coverage: FLOAT_ONE,
2620 },
2621 OutputVertex{
2622 x: rPixelXBottomLeft + rPixelXLeftDelta,
2623 y: rPixelYBottom,
2624 coverage: FLOAT_ONE,
2625 },
2626 OutputVertex{
2627 x: rPixelXTopRight - rPixelXRightDelta,
2628 y: rPixelYTop,
2629 coverage: FLOAT_ONE,
2630 },
2631 OutputVertex{
2632 x: rPixelXBottomRight - rPixelXRightDelta,
2633 y: rPixelYBottom,
2634 coverage: FLOAT_ONE,
2635 }
2636 );
2637 }
2638
2639 self.m_pVB.AddTrapezoidVertices(
2640 OutputVertex{
2641 x: rPixelXTopRight - rPixelXRightDelta,
2642 y: rPixelYTop,
2643 coverage: FLOAT_ONE,
2644 },
2645 OutputVertex{
2646 x: rPixelXBottomRight - rPixelXRightDelta,
2647 y: rPixelYBottom,
2648 coverage: FLOAT_ONE,
2649 },
2650 OutputVertex{
2651 x: rPixelXTopRight + rPixelXRightDelta,
2652 y: rPixelYTop,
2653 coverage: FLOAT_ZERO,
2654 },
2655 OutputVertex{
2656 x: rPixelXBottomRight + rPixelXRightDelta,
2657 y: rPixelYBottom,
2658 coverage: FLOAT_ZERO,
2659 }
2660 );
2661
2662 if (!fNeedOutsideGeometry)
2663 {
2664 //
2665 // Duplicate the last vertex. This creates 2 degenerate triangles: one
2666 // between vertices 8 and 9 and one connecting this trapezoid to the
2667 // next one.
2668 //
2669
2670 //pVertex.push(OutputVertex{
2671 // x: rPixelXBottomRight + rPixelXRightDelta,
2672 // y: rPixelYBottom,
2673 // coverage: FLOAT_ZERO,
2674 //});
2675 }
2676
2677 self.m_pVB.AddedNonLineSegment();
2678
2679 //Cleanup:
2680 RRETURN!(hr);
2681 }
2682 }
2683 /*
2684 //+----------------------------------------------------------------------------
2685 //
2686 // Member: CHwTVertexBuffer<TVertex>::Builder::AddTrapezoidWaffle
2687 //
2688 // Synopsis: See AddTrapezoid. This adds a waffled trapezoid.
2689 //
2690 //-----------------------------------------------------------------------------
2691 template <class TVertex>
2692 HRESULT
2693 CHwTVertexBuffer<TVertex>::Builder::AddTrapezoidWaffle(
2694 float rPixelYTop, // In: y coordinate of top of trapezoid
2695 float rPixelXTopLeft, // In: x coordinate for top left
2696 float rPixelXTopRight, // In: x coordinate for top right
2697 float rPixelYBottom, // In: y coordinate of bottom of trapezoid
2698 float rPixelXBottomLeft, // In: x coordinate for bottom left
2699 float rPixelXBottomRight, // In: x coordinate for bottom right
2700 float rPixelXLeftDelta, // In: trapezoid expand radius for left edge
2701 float rPixelXRightDelta // In: trapezoid expand radius for right edge
2702 )
2703 {
2704 HRESULT hr = S_OK;
2705
2706 // We have 2 (u & v) wafflers per texture coordinate that need waffling.
2707 TriangleWaffler<PointXYA> wafflers[NUM_OF_VERTEX_TEXTURE_COORDS(TVertex) * 2];
2708 bool fWafflersUsed = false;
2709
2710 TriangleWaffler<PointXYA>::ISink *pWaffleSinkNoRef = BuildWafflePipeline(wafflers, OUT fWafflersUsed);
2711
2712 PointXYA vertices[8];
2713
2714 //
2715 // Fill in the strip vertices
2716 //
2717
2718 // Nonstandard coverage mapping and waffling are not supported at the same time.
2719 Assert(!NeedOutsideGeometry());
2720
2721 vertices[0].x = rPixelXTopLeft - rPixelXLeftDelta;
2722 vertices[0].y = rPixelYTop;
2723 vertices[0].a = 0;
2724
2725 vertices[1].x = rPixelXBottomLeft - rPixelXLeftDelta;
2726 vertices[1].y = rPixelYBottom;
2727 vertices[1].a = 0;
2728
2729 vertices[2].x = rPixelXTopLeft + rPixelXLeftDelta;
2730 vertices[2].y = rPixelYTop;
2731 vertices[2].a = 1;
2732
2733 vertices[3].x = rPixelXBottomLeft + rPixelXLeftDelta;
2734 vertices[3].y = rPixelYBottom;
2735 vertices[3].a = 1;
2736
2737 vertices[4].x = rPixelXTopRight - rPixelXRightDelta;
2738 vertices[4].y = rPixelYTop;
2739 vertices[4].a = 1;
2740
2741 vertices[5].x = rPixelXBottomRight - rPixelXRightDelta;
2742 vertices[5].y = rPixelYBottom;
2743 vertices[5].a = 1;
2744
2745 vertices[6].x = rPixelXTopRight + rPixelXRightDelta;
2746 vertices[6].y = rPixelYTop;
2747 vertices[6].a = 0;
2748
2749 vertices[7].x = rPixelXBottomRight + rPixelXRightDelta;
2750 vertices[7].y = rPixelYBottom;
2751 vertices[7].a = 0;
2752
2753 // Send the triangles in the strip through the waffle pipeline.
2754 for (int i = 0; i < 6; ++i)
2755 {
2756 IFC(pWaffleSinkNoRef->AddTriangle(vertices[i+1], vertices[i], vertices[i+2]));
2757 }
2758
2759 Cleanup:
2760 RRETURN(hr);
2761 }
2762 */
2763 impl CHwVertexBufferBuilder<'_, '_> {
2764
2765 //+----------------------------------------------------------------------------
2766 //
2767 // Member: CHwTVertexBuffer<TVertex>::Builder::NeedCoverageGeometry
2768 //
2769 // Synopsis: Returns true if the coverage value needs to be rendered
2770 // based on NeedInsideGeometry() and NeedOutsideGeometry()
2771 //
2772 // Two cases where we don't need to generate geometry:
2773 // 1. NeedInsideGeometry is false, and coverage is c_nShiftSizeSquared.
2774 // 2. NeedOutsideGeometry is false and coverage is 0
2775 //
2776 //-----------------------------------------------------------------------------
2777 fn NeedCoverageGeometry(&self,
2778 nCoverage: INT
2779 ) -> bool
2780 {
2781 return (self.NeedInsideGeometry() || nCoverage != c_nShiftSizeSquared)
2782 && (self.NeedOutsideGeometry() || nCoverage != 0);
2783 }
2784
2785 //+------------------------------------------------------------------------
2786 //
2787 // Member: NeedOutsideGeometry
2788 //
2789 // Synopsis: True if we should create geometry with zero alpha for
2790 // areas outside the input geometry but within a given
2791 // bounding box.
2792 //
2793 //-------------------------------------------------------------------------
2794 fn NeedOutsideGeometry(&self) -> bool
2795 {
2796 return self.m_fNeedOutsideGeometry;
2797 }
2798
2799 //+------------------------------------------------------------------------
2800 //
2801 // Member: NeedInsideGeometry
2802 //
2803 // Synopsis: True if we should create geometry for areas completely
2804 // withing the input geometry (i.e. alpha 1.) Should only
2805 // be false if NeedOutsideGeometry is true.
2806 //
2807 //-------------------------------------------------------------------------
2808 fn NeedInsideGeometry(&self) -> bool
2809 {
2810 assert!(self.m_fNeedOutsideGeometry || self.m_fNeedInsideGeometry);
2811 return self.m_fNeedInsideGeometry;
2812 }
2813
2814
2815
2816 // Helpers that handle extra shapes in trapezoid mode.
2817 fn PrepareStratum(&mut self,
2818 rStratumTop: f32,
2819 rStratumBottom: f32,
2820 fTrapezoid: bool,
2821 rTrapezoidLeft: f32,
2822 rTrapezoidRight: f32,
2823 rTrapezoidTopLeft: f32, // = 0
2824 rTrapezoidBottomLeft: f32, // = 0
2825 rTrapezoidTopRight: f32, // = 0
2826 rTrapezoidBottomRight: f32, // = 0
2827
2828 ) -> HRESULT
2829 {
2830 return if self.NeedOutsideGeometry() {
2831 self.PrepareStratumSlow(
2832 rStratumTop,
2833 rStratumBottom,
2834 fTrapezoid,
2835 rTrapezoidLeft,
2836 rTrapezoidRight,
2837 rTrapezoidTopLeft,
2838 rTrapezoidBottomLeft,
2839 rTrapezoidTopRight,
2840 rTrapezoidBottomRight
2841 )
2842 } else { S_OK };
2843 }
2844
2845 //+----------------------------------------------------------------------------
2846 //
2847 // Member: CHwTVertexBuffer<TVertex>::Builder::PrepareStratumSlow
2848 //
2849 // Synopsis: Call before producing a new stratum (complex span or trapezoid.)
2850 // Handles several tasks:
2851 // 1. Producing between top of complement geometry & the 1st
2852 // stratum or when a gap between strata occurs (because
2853 // the geometry is not closed and has horizontal gaps.)
2854 // Passing in FLT_MAX for rStratumTop and rStratumBottom
2855 // Fills the gap between the last stratum and the bottom
2856 // of the outside.
2857 // 2. Begins and/or ends the triangle strip corresponding to
2858 // a trapezoid row.
2859 // 3. Updates status vars m_rCurStratumTop & m_rCurStratumBottom
2860 //
2861 // Note: Call PrepareStratum which inlines the check for NeedOutsideGeometry()
2862 // If NeedOutsideGeometry is false PrepareStratum() does nothing.
2863 // This (slow) version asserts NeedOutsideGeometry()
2864 //
2865 //-----------------------------------------------------------------------------
2866 fn PrepareStratumSlow(&mut self,
2867 rStratumTop: f32,
2868 rStratumBottom: f32,
2869 fTrapezoid: bool,
2870 rTrapezoidLeft: f32,
2871 rTrapezoidRight: f32,
2872 rTrapezoidTopLeft: f32,
2873 rTrapezoidBottomLeft: f32,
2874 rTrapezoidTopRight: f32,
2875 rTrapezoidBottomRight: f32,
2876 ) -> HRESULT
2877 {
2878 type TVertex = OutputVertex;
2879 let hr: HRESULT = S_OK;
2880
2881 assert!(!(rStratumTop > rStratumBottom));
2882 assert!(self.NeedOutsideGeometry());
2883
2884 // There's only once case where a stratum can go "backwards"
2885 // and that's when we're done building & calling from
2886 // EndBuildingOutside
2887
2888 let fEndBuildingOutside: f32 = (rStratumBottom == self.OutsideBottom() &&
2889 rStratumTop == self.OutsideBottom()) as i32 as f32;
2890
2891 if (fEndBuildingOutside == 1.)
2892 {
2893 assert!(!fTrapezoid);
2894 }
2895 else
2896 {
2897 assert!(!(rStratumBottom < self.m_rCurStratumBottom));
2898 }
2899
2900 if ( fEndBuildingOutside == 1.
2901 || rStratumBottom != self.m_rCurStratumBottom)
2902 {
2903
2904 // New stratum starting now. Two things to do
2905 // 1. Close out current trapezoid stratum if necessary.
2906 // 2. Begin new trapezoid stratum if necessary.
2907
2908 if (self.m_rCurStratumTop != f32::MAX)
2909 {
2910 // we do not clip trapezoids so RIGHT boundary
2911 // of the stratus can be outside of m_rcOutsideBounds.
2912
2913 let rOutsideRight: f32 = self.OutsideRight().max(self.m_rLastTrapezoidRight);
2914
2915 // End current trapezoid stratum.
2916
2917 self.m_pVB.AddTrapezoidVertices(
2918 OutputVertex{
2919 x: self.m_rLastTrapezoidTopRight,
2920 y: self.m_rCurStratumTop,
2921 coverage: FLOAT_ZERO,
2922 },
2923 OutputVertex{
2924 x: self.m_rLastTrapezoidBottomRight,
2925 y: self.m_rCurStratumBottom,
2926 coverage: FLOAT_ZERO,
2927 },
2928 OutputVertex{
2929 x: rOutsideRight,
2930 y: self.m_rCurStratumTop,
2931 coverage: FLOAT_ZERO,
2932 },
2933 OutputVertex{
2934 x: rOutsideRight,
2935 y: self.m_rCurStratumBottom,
2936 coverage: FLOAT_ZERO,
2937 }
2938 );
2939 }
2940 // Compute the gap between where the last stratum ended and where
2941 // this one begins.
2942 let flGap: f32 = rStratumTop - self.m_rCurStratumBottom;
2943
2944 if (flGap > 0.)
2945 {
2946 // The "special" case of a gap at the beginning is caught here
2947 // using the sentinel initial value of m_rCurStratumBottom.
2948
2949 let flRectTop: f32 = if self.m_rCurStratumBottom == -f32::MAX {
2950 self.OutsideTop() } else {
2951 self.m_rCurStratumBottom };
2952 let flRectBot: f32 = (rStratumTop as f32);
2953
2954 // Produce rectangular for any horizontal intervals in the
2955 // outside bounds that have no generated geometry.
2956 assert!(self.m_rCurStratumBottom != -f32::MAX || self.m_rCurStratumTop == f32::MAX);
2957
2958 let outside_left = self.OutsideLeft();
2959 let outside_right = self.OutsideRight();
2960
2961 // Duplicate first vertex.
2962 self.m_pVB.AddTrapezoidVertices(
2963 OutputVertex{
2964 x: outside_left,
2965 y: flRectTop,
2966 coverage: FLOAT_ZERO,
2967 },
2968 OutputVertex{
2969 x: outside_left,
2970 y: flRectBot,
2971 coverage: FLOAT_ZERO,
2972 },
2973 OutputVertex{
2974 x: outside_right,
2975 y: flRectTop,
2976 coverage: FLOAT_ZERO,
2977 },
2978 OutputVertex{
2979 x: outside_right,
2980 y: flRectBot,
2981 coverage: FLOAT_ZERO,
2982 }
2983 );
2984 }
2985
2986 if (fTrapezoid)
2987 {
2988
2989 // we do not clip trapezoids so left boundary
2990 // of the stratus can be outside of m_rcOutsideBounds.
2991
2992 let rOutsideLeft: f32 = self.OutsideLeft().min(rTrapezoidLeft);
2993
2994 // Begin new trapezoid stratum.
2995
2996 self.m_pVB.AddTrapezoidVertices(
2997 OutputVertex{
2998 x: rOutsideLeft,
2999 y: rStratumTop,
3000 coverage: FLOAT_ZERO,
3001 },
3002 OutputVertex{
3003 x: rOutsideLeft,
3004 y: rStratumBottom,
3005 coverage: FLOAT_ZERO,
3006 },
3007 OutputVertex{
3008 x: rTrapezoidTopLeft,
3009 y: rStratumTop,
3010 coverage: FLOAT_ZERO,
3011 },
3012 OutputVertex{
3013 x: rTrapezoidBottomLeft,
3014 y: rStratumBottom,
3015 coverage: FLOAT_ZERO,
3016 }
3017 );
3018 }
3019 }
3020
3021 if (fTrapezoid)
3022 {
3023 self.m_rLastTrapezoidTopRight = rTrapezoidTopRight;
3024 self.m_rLastTrapezoidBottomRight = rTrapezoidBottomRight;
3025 self.m_rLastTrapezoidRight = rTrapezoidRight;
3026 }
3027
3028 self.m_rCurStratumTop = if fTrapezoid { rStratumTop } else { f32::MAX };
3029 self.m_rCurStratumBottom = rStratumBottom;
3030
3031 RRETURN!(hr);
3032 }
3033
3034 //+----------------------------------------------------------------------------
3035 //
3036 // Member: CHwTVertexBuffer<TVertex>::Builder::EndBuildingOutside
3037 //
3038 // Synopsis: Finish creating outside geometry.
3039 // 1. If no geometry was created then just fill bounds.
3040 // 2. Otherwise:
3041 // A. End last trapezoid row
3042 // B. Produce stop stratum
3043 //
3044 //-----------------------------------------------------------------------------
3045 fn EndBuildingOutside(&mut self) -> HRESULT
3046 {
3047 return self.PrepareStratum(
3048 self.OutsideBottom(),
3049 self.OutsideBottom(),
3050 false, /* Not a trapezoid. */
3051 0., 0.,
3052 0., 0.,
3053 0., 0.,
3054 );
3055 }
3056
3057 //+----------------------------------------------------------------------------
3058 //
3059 // Member: CHwTVertexBuffer<TVertex>::Builder::EndBuilding
3060 //
3061 // Synopsis: Expand all vertices to the full required format and return
3062 // vertex buffer.
3063 //
3064 //-----------------------------------------------------------------------------
3065 pub fn EndBuilding(&mut self) -> HRESULT
3066 {
3067 let hr = S_OK;
3068
3069 IFC!(self.EndBuildingOutside());
3070
3071 //Cleanup:
3072 RRETURN!(hr);
3073 }
3074
3075 }