]> git.cworth.org Git - apitrace/blob - helpers/d3dsize.hpp
79095011873501ad6791988fbb25247775102b16
[apitrace] / helpers / d3dsize.hpp
1 /**************************************************************************
2  *
3  * Copyright 2012 Jose Fonseca
4  * All Rights Reserved.
5  * 
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sub license,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  * 
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  * 
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
20  * AUTHORS,
21  * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  *
26  **************************************************************************/
27
28
29 /*
30  * Auxiliary functions to compute the size of array/blob arguments.
31  */
32
33 #ifndef _D3D_SIZE_HPP_
34 #define _D3D_SIZE_HPP_
35
36
37 /* We purposedly don't include any D3D header, so that this header can be used
38  * with all D3D versions. */
39
40 #include "os.hpp"
41
42
43 static inline size_t
44 _vertexCount(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount)
45 {
46     switch (PrimitiveType) {
47     case D3DPT_POINTLIST:
48         return PrimitiveCount;
49     case D3DPT_LINELIST:
50         return PrimitiveCount*2;
51     case D3DPT_LINESTRIP:
52         return PrimitiveCount + 1;
53     case D3DPT_TRIANGLELIST:
54         return PrimitiveCount * 3;
55     case D3DPT_TRIANGLESTRIP:
56         return PrimitiveCount + 2;
57     case D3DPT_TRIANGLEFAN:
58         return PrimitiveCount + 1;
59     default:
60         os::log("apitrace: warning: %s: unknown D3DPRIMITIVETYPE %u\n", __FUNCTION__, PrimitiveType);
61         return 0;
62     }
63 }
64
65
66 static inline size_t
67 _vertexDataSize(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, UINT VertexStride) {
68     return _vertexCount(PrimitiveType, PrimitiveCount) * VertexStride;
69 }
70
71
72 static inline size_t
73 _indexDataSize(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, D3DFORMAT IndexDataFormat) {
74     UINT IndexStride;
75     switch (IndexDataFormat) {
76     case D3DFMT_INDEX16:
77         IndexStride = 2;
78         break;
79     case D3DFMT_INDEX32:
80         IndexStride = 4;
81         break;
82     default:
83         os::log("apitrace: warning: %s: unexpected index D3DFORMAT %u\n", __FUNCTION__, IndexDataFormat);
84         return 0;
85     }
86     return _vertexCount(PrimitiveType, PrimitiveCount) * IndexStride;
87 }
88
89
90 #endif /* _D3D_SIZE_HPP_ */