2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 #include "volumetexture9.h"
25 #include "nine_helpers.h"
26 #include "nine_pipe.h"
28 #define DBG_CHANNEL DBG_VOLUMETEXTURE
31 NineVolumeTexture9_ctor( struct NineVolumeTexture9
*This
,
32 struct NineUnknownParams
*pParams
,
33 UINT Width
, UINT Height
, UINT Depth
, UINT Levels
,
37 HANDLE
*pSharedHandle
)
39 struct pipe_resource
*info
= &This
->base
.base
.info
;
41 D3DVOLUME_DESC voldesc
;
44 /* An IDirect3DVolume9 cannot be bound as a render target can it ? */
45 user_assert(!(Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
)),
47 user_assert(!(Usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
48 (Pool
!= D3DPOOL_SYSTEMMEM
&& Levels
<= 1), D3DERR_INVALIDCALL
);
50 user_assert(!pSharedHandle
, D3DERR_INVALIDCALL
); /* TODO */
52 if (Usage
& D3DUSAGE_AUTOGENMIPMAP
)
55 This
->base
.format
= Format
;
56 This
->base
.base
.usage
= Usage
;
58 info
->screen
= pParams
->device
->screen
;
59 info
->target
= PIPE_TEXTURE_3D
;
60 info
->format
= d3d9_to_pipe_format(Format
);
62 info
->height0
= Height
;
65 info
->last_level
= Levels
- 1;
67 info
->last_level
= util_logbase2(MAX2(MAX2(Width
, Height
), Depth
));
70 info
->bind
= PIPE_BIND_SAMPLER_VIEW
;
71 info
->usage
= PIPE_USAGE_DEFAULT
;
74 if (Usage
& D3DUSAGE_DYNAMIC
) {
75 info
->usage
= PIPE_USAGE_DYNAMIC
;
77 PIPE_BIND_TRANSFER_READ
|
78 PIPE_BIND_TRANSFER_WRITE
;
81 This
->volumes
= CALLOC(info
->last_level
+ 1, sizeof(*This
->volumes
));
84 This
->base
.pstype
= 3;
86 hr
= NineBaseTexture9_ctor(&This
->base
, pParams
,
87 D3DRTYPE_VOLUMETEXTURE
, Pool
);
91 voldesc
.Format
= Format
;
92 voldesc
.Type
= D3DRTYPE_VOLUME
;
93 voldesc
.Usage
= Usage
;
95 for (l
= 0; l
<= info
->last_level
; ++l
) {
96 voldesc
.Width
= u_minify(Width
, l
);
97 voldesc
.Height
= u_minify(Height
, l
);
98 voldesc
.Depth
= u_minify(Depth
, l
);
100 hr
= NineVolume9_new(This
->base
.base
.base
.device
, NineUnknown(This
),
101 This
->base
.base
.resource
, l
,
102 &voldesc
, &This
->volumes
[l
]);
111 NineVolumeTexture9_dtor( struct NineVolumeTexture9
*This
)
115 DBG("This=%p\n", This
);
118 for (l
= 0; l
< This
->base
.base
.info
.last_level
; ++l
)
119 NineUnknown_Destroy(&This
->volumes
[l
]->base
);
123 NineBaseTexture9_dtor(&This
->base
);
127 NineVolumeTexture9_GetLevelDesc( struct NineVolumeTexture9
*This
,
129 D3DVOLUME_DESC
*pDesc
)
131 user_assert(Level
<= This
->base
.base
.info
.last_level
, D3DERR_INVALIDCALL
);
132 user_assert(Level
== 0 || !(This
->base
.base
.usage
& D3DUSAGE_AUTOGENMIPMAP
),
135 *pDesc
= This
->volumes
[Level
]->desc
;
141 NineVolumeTexture9_GetVolumeLevel( struct NineVolumeTexture9
*This
,
143 IDirect3DVolume9
**ppVolumeLevel
)
145 user_assert(Level
<= This
->base
.base
.info
.last_level
, D3DERR_INVALIDCALL
);
146 user_assert(Level
== 0 || !(This
->base
.base
.usage
& D3DUSAGE_AUTOGENMIPMAP
),
149 NineUnknown_AddRef(NineUnknown(This
->volumes
[Level
]));
150 *ppVolumeLevel
= (IDirect3DVolume9
*)This
->volumes
[Level
];
156 NineVolumeTexture9_LockBox( struct NineVolumeTexture9
*This
,
158 D3DLOCKED_BOX
*pLockedVolume
,
162 user_assert(Level
<= This
->base
.base
.info
.last_level
, D3DERR_INVALIDCALL
);
163 user_assert(Level
== 0 || !(This
->base
.base
.usage
& D3DUSAGE_AUTOGENMIPMAP
),
166 return NineVolume9_LockBox(This
->volumes
[Level
], pLockedVolume
, pBox
,
171 NineVolumeTexture9_UnlockBox( struct NineVolumeTexture9
*This
,
174 user_assert(Level
<= This
->base
.base
.info
.last_level
, D3DERR_INVALIDCALL
);
176 return NineVolume9_UnlockBox(This
->volumes
[Level
]);
180 NineVolumeTexture9_AddDirtyBox( struct NineVolumeTexture9
*This
,
181 const D3DBOX
*pDirtyBox
)
183 if (This
->base
.base
.pool
!= D3DPOOL_MANAGED
) {
184 if (This
->base
.base
.usage
& D3DUSAGE_AUTOGENMIPMAP
)
185 This
->base
.dirty_mip
= TRUE
;
188 This
->base
.dirty
= TRUE
;
190 BASETEX_REGISTER_UPDATE(&This
->base
);
193 This
->dirty_box
.x
= 0;
194 This
->dirty_box
.y
= 0;
195 This
->dirty_box
.z
= 0;
196 This
->dirty_box
.width
= This
->base
.base
.info
.width0
;
197 This
->dirty_box
.height
= This
->base
.base
.info
.height0
;
198 This
->dirty_box
.depth
= This
->base
.base
.info
.depth0
;
201 d3dbox_to_pipe_box(&box
, pDirtyBox
);
202 u_box_union_3d(&This
->dirty_box
, &This
->dirty_box
, &box
);
207 IDirect3DVolumeTexture9Vtbl NineVolumeTexture9_vtable
= {
208 (void *)NineUnknown_QueryInterface
,
209 (void *)NineUnknown_AddRef
,
210 (void *)NineUnknown_Release
,
211 (void *)NineUnknown_GetDevice
, /* actually part of Resource9 iface */
212 (void *)NineResource9_SetPrivateData
,
213 (void *)NineResource9_GetPrivateData
,
214 (void *)NineResource9_FreePrivateData
,
215 (void *)NineResource9_SetPriority
,
216 (void *)NineResource9_GetPriority
,
217 (void *)NineBaseTexture9_PreLoad
,
218 (void *)NineResource9_GetType
,
219 (void *)NineBaseTexture9_SetLOD
,
220 (void *)NineBaseTexture9_GetLOD
,
221 (void *)NineBaseTexture9_GetLevelCount
,
222 (void *)NineBaseTexture9_SetAutoGenFilterType
,
223 (void *)NineBaseTexture9_GetAutoGenFilterType
,
224 (void *)NineBaseTexture9_GenerateMipSubLevels
,
225 (void *)NineVolumeTexture9_GetLevelDesc
,
226 (void *)NineVolumeTexture9_GetVolumeLevel
,
227 (void *)NineVolumeTexture9_LockBox
,
228 (void *)NineVolumeTexture9_UnlockBox
,
229 (void *)NineVolumeTexture9_AddDirtyBox
232 static const GUID
*NineVolumeTexture9_IIDs
[] = {
233 &IID_IDirect3DVolumeTexture9
,
234 &IID_IDirect3DBaseTexture9
,
235 &IID_IDirect3DResource9
,
241 NineVolumeTexture9_new( struct NineDevice9
*pDevice
,
242 UINT Width
, UINT Height
, UINT Depth
, UINT Levels
,
246 struct NineVolumeTexture9
**ppOut
,
247 HANDLE
*pSharedHandle
)
249 NINE_DEVICE_CHILD_NEW(VolumeTexture9
, ppOut
, pDevice
,
250 Width
, Height
, Depth
, Levels
,
251 Usage
, Format
, Pool
, pSharedHandle
);