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 _D3D8SIZE_HPP_
34 #define _D3D8SIZE_HPP_
37 #include "d3dcommonsize.hpp"
41 _declCount(const DWORD *pDeclaration) {
43 while (pDeclaration[count++] != D3DVSD_END())
50 _getMapInfo(IDirect3DVertexBuffer8 *pBuffer, UINT OffsetToLock, UINT SizeToLock, BYTE ** ppbData,
51 void * & pLockedData, size_t & MappedSize) {
52 pLockedData = *ppbData;
55 if (SizeToLock == 0) {
56 D3DVERTEXBUFFER_DESC Desc;
57 HRESULT hr = pBuffer->GetDesc(&Desc);
61 MappedSize = Desc.Size;
63 MappedSize = SizeToLock;
69 _getMapInfo(IDirect3DIndexBuffer8 *pBuffer, UINT OffsetToLock, UINT SizeToLock, BYTE ** ppbData,
70 void * & pLockedData, size_t & MappedSize) {
71 pLockedData = *ppbData;
74 if (SizeToLock == 0) {
75 D3DINDEXBUFFER_DESC Desc;
76 HRESULT hr = pBuffer->GetDesc(&Desc);
80 MappedSize = Desc.Size;
82 MappedSize = SizeToLock;
88 _getMapInfo(IDirect3DSurface8 *pSurface, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
89 void * & pLockedData, size_t & MappedSize) {
90 pLockedData = pLockedRect->pBits;
96 hr = pSurface->GetDesc(&Desc);
104 Width = pRect->right - pRect->left;
105 Height = pRect->bottom - pRect->top;
108 Height = Desc.Height;
111 MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
116 _getMapInfo(IDirect3DTexture8 *pTexture, UINT Level, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
117 void * & pLockedData, size_t & MappedSize) {
118 pLockedData = pLockedRect->pBits;
123 D3DSURFACE_DESC Desc;
124 hr = pTexture->GetLevelDesc(Level, &Desc);
132 Width = pRect->right - pRect->left;
133 Height = pRect->bottom - pRect->top;
136 Height = Desc.Height;
139 MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
144 _getMapInfo(IDirect3DCubeTexture8 *pTexture, D3DCUBEMAP_FACES FaceType, UINT Level, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
145 void * & pLockedData, size_t & MappedSize) {
146 pLockedData = pLockedRect->pBits;
153 D3DSURFACE_DESC Desc;
154 hr = pTexture->GetLevelDesc(Level, &Desc);
162 Width = pRect->right - pRect->left;
163 Height = pRect->bottom - pRect->top;
166 Height = Desc.Height;
169 MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
174 _getMapInfo(IDirect3DVolume8 *pVolume, const D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox,
175 void * & pLockedData, size_t & MappedSize) {
176 pLockedData = pLockedVolume->pBits;
182 hr = pVolume->GetDesc(&Desc);
191 Width = pBox->Right - pBox->Left;
192 Height = pBox->Bottom - pBox->Top;
193 Depth = pBox->Back - pBox->Front;
196 Height = Desc.Height;
200 MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedVolume->RowPitch, Depth, pLockedVolume->SlicePitch);
205 _getMapInfo(IDirect3DVolumeTexture8 *pTexture, UINT Level, const D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox,
206 void * & pLockedData, size_t & MappedSize) {
207 pLockedData = pLockedVolume->pBits;
213 hr = pTexture->GetLevelDesc(Level, &Desc);
222 Width = pBox->Right - pBox->Left;
223 Height = pBox->Bottom - pBox->Top;
224 Depth = pBox->Back - pBox->Front;
227 Height = Desc.Height;
231 MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedVolume->RowPitch, Depth, pLockedVolume->SlicePitch);
235 #endif /* _D3D8SIZE_HPP_ */