1 /**************************************************************************
3 * Copyright 2012 Jose Fonseca
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:
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
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
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
26 **************************************************************************/
30 * Auxiliary functions to compute the size of array/blob arguments.
33 #ifndef _D3D9SIZE_HPP_
34 #define _D3D9SIZE_HPP_
37 #include "d3dcommonsize.hpp"
41 _declCount(const D3DVERTEXELEMENT9 *pVertexElements) {
43 if (pVertexElements) {
44 while (pVertexElements[count++].Stream != 0xff)
51 _getMapInfo(IDirect3DVertexBuffer9 *pBuffer, UINT OffsetToLock, UINT SizeToLock, void ** ppbData,
52 void * & pLockedData, size_t & MappedSize) {
53 pLockedData = *ppbData;
56 if (SizeToLock == 0) {
57 D3DVERTEXBUFFER_DESC Desc;
58 HRESULT hr = pBuffer->GetDesc(&Desc);
62 MappedSize = Desc.Size;
64 MappedSize = SizeToLock;
70 _getMapInfo(IDirect3DIndexBuffer9 *pBuffer, UINT OffsetToLock, UINT SizeToLock, void ** ppbData,
71 void * & pLockedData, size_t & MappedSize) {
72 pLockedData = *ppbData;
75 if (SizeToLock == 0) {
76 D3DINDEXBUFFER_DESC Desc;
77 HRESULT hr = pBuffer->GetDesc(&Desc);
81 MappedSize = Desc.Size;
83 MappedSize = SizeToLock;
89 _getMapInfo(IDirect3DSurface9 *pSurface, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
90 void * & pLockedData, size_t & MappedSize) {
91 pLockedData = pLockedRect->pBits;
97 hr = pSurface->GetDesc(&Desc);
105 Width = pRect->right - pRect->left;
106 Height = pRect->bottom - pRect->top;
109 Height = Desc.Height;
112 MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
117 _getMapInfo(IDirect3DTexture9 *pTexture, UINT Level, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
118 void * & pLockedData, size_t & MappedSize) {
119 pLockedData = pLockedRect->pBits;
124 D3DSURFACE_DESC Desc;
125 hr = pTexture->GetLevelDesc(Level, &Desc);
133 Width = pRect->right - pRect->left;
134 Height = pRect->bottom - pRect->top;
137 Height = Desc.Height;
140 MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
145 _getMapInfo(IDirect3DCubeTexture9 *pTexture, D3DCUBEMAP_FACES FaceType, UINT Level, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
146 void * & pLockedData, size_t & MappedSize) {
147 pLockedData = pLockedRect->pBits;
154 D3DSURFACE_DESC Desc;
155 hr = pTexture->GetLevelDesc(Level, &Desc);
163 Width = pRect->right - pRect->left;
164 Height = pRect->bottom - pRect->top;
167 Height = Desc.Height;
170 MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
175 _getMapInfo(IDirect3DVolume9 *pVolume, const D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox,
176 void * & pLockedData, size_t & MappedSize) {
177 pLockedData = pLockedVolume->pBits;
183 hr = pVolume->GetDesc(&Desc);
192 Width = pBox->Right - pBox->Left;
193 Height = pBox->Bottom - pBox->Top;
194 Depth = pBox->Back - pBox->Front;
197 Height = Desc.Height;
201 MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedVolume->RowPitch, Depth, pLockedVolume->SlicePitch);
206 _getMapInfo(IDirect3DVolumeTexture9 *pTexture, UINT Level, const D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox,
207 void * & pLockedData, size_t & MappedSize) {
208 pLockedData = pLockedVolume->pBits;
214 hr = pTexture->GetLevelDesc(Level, &Desc);
223 Width = pBox->Right - pBox->Left;
224 Height = pBox->Bottom - pBox->Top;
225 Depth = pBox->Back - pBox->Front;
228 Height = Desc.Height;
232 MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedVolume->RowPitch, Depth, pLockedVolume->SlicePitch);
236 #endif /* _D3D9SIZE_HPP_ */