xref: /reactos/dll/directx/d3d9/d3d9_texture.c (revision c2c66aff)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS ReactX
4  * FILE:            dll/directx/d3d9/d3d9_texture.c
5  * PURPOSE:         d3d9.dll internal texture surface functions
6  * PROGRAMERS:      Gregor Gullwi <gbrunmar (dot) ros (at) gmail (dot) com>
7  */
8 #include "d3d9_texture.h"
9 
10 #define LOCK_D3DDEVICE9()   D3D9BaseObject_LockDevice(&This->BaseResource.BaseObject)
11 #define UNLOCK_D3DDEVICE9() D3D9BaseObject_UnlockDevice(&This->BaseResource.BaseObject)
12 
13 /* Convert a IDirect3DBaseTexture9 pointer safely to the internal implementation struct */
14 Direct3DBaseTexture9_INT* IDirect3DBaseTexture9ToImpl(LPDIRECT3DBASETEXTURE9 iface)
15 {
16     if (NULL == iface)
17         return NULL;
18 
19     return (Direct3DBaseTexture9_INT*)((ULONG_PTR)iface - FIELD_OFFSET(Direct3DBaseTexture9_INT, lpVtbl));
20 }
21 
22 void InitDirect3DBaseTexture9(Direct3DBaseTexture9_INT* pBaseTexture,
23                               IDirect3DBaseTexture9Vtbl* pVtbl,
24                               DWORD Usage,
25                               UINT Levels,
26                               D3DFORMAT Format,
27                               D3DPOOL Pool,
28                               struct _Direct3DDevice9_INT* pDevice,
29                               enum REF_TYPE RefType)
30 {
31     InitDirect3DResource9(&pBaseTexture->BaseResource, Pool, pDevice, RefType);
32 
33     pBaseTexture->lpVtbl = pVtbl;
34     pBaseTexture->Format = Format;
35     pBaseTexture->wPaletteIndex = 0xFFFF;
36     pBaseTexture->Usage = Usage;
37     pBaseTexture->MipMapLevels = Levels;
38     pBaseTexture->MipMapLevels2 = Levels;
39 
40     pBaseTexture->FilterType = D3DTEXF_LINEAR;
41     pBaseTexture->bIsAutoGenMipMap = (Usage & D3DUSAGE_AUTOGENMIPMAP) != 0;
42 }
43 
44 /*++
45 * @name IDirect3DBaseTexture9::GetAutoGenFilterType
46 * @implemented
47 *
48 * The function D3D9Texture_GetAutoGenFilterType returns filter type
49 * that is used when automated mipmaping is set.
50 *
51 * @param LPDIRECT3DBASETEXTURE9 iface
52 * Pointer to a IDirect3DBaseTexture9 interface
53 *
54 * @return D3DTEXTUREFILTERTYPE
55 * Filter type used when automated mipmaping is set for the specified texture.
56 *
57 */
58 D3DTEXTUREFILTERTYPE WINAPI D3D9Texture_GetAutoGenFilterType(LPDIRECT3DBASETEXTURE9 iface)
59 {
60     D3DTEXTUREFILTERTYPE FilterType;
61     Direct3DBaseTexture9_INT* This = IDirect3DBaseTexture9ToImpl(iface);
62     LOCK_D3DDEVICE9();
63 
64     FilterType = This->dwFilterType;
65 
66     UNLOCK_D3DDEVICE9();
67     return FilterType;
68 }
69 
70 /*++
71 * @name IDirect3DBaseTexture9::GetLOD
72 * @implemented
73 *
74 * The function D3D9Texture_GetLOD returns the number
75 * max LODs for the specified texture, if it's managed.
76 *
77 * @param LPDIRECT3DBASETEXTURE9 iface
78 * Pointer to a IDirect3DBaseTexture9 interface
79 *
80 * @return DWORD
81 * Returns the number of LODs in the specified texture if it's managed.
82 *
83 */
84 DWORD WINAPI D3D9Texture_GetLOD(LPDIRECT3DBASETEXTURE9 iface)
85 {
86     DWORD MaxLOD = 0;
87     Direct3DBaseTexture9_INT* This = IDirect3DBaseTexture9ToImpl(iface);
88     LOCK_D3DDEVICE9();
89 
90     if (This->BaseResource.bIsManaged)
91         MaxLOD = This->MaxLOD;
92 
93     UNLOCK_D3DDEVICE9();
94     return MaxLOD;
95 }
96 
97 /*++
98 * @name IDirect3DBaseTexture9::GetLevelCount
99 * @implemented
100 *
101 * The function D3D9Texture_GetLevelCount returns the number of mip map levels
102 * in the specified texture.
103 *
104 * @param LPDIRECT3DBASETEXTURE9 iface
105 * Pointer to a IDirect3DBaseTexture9 interface
106 *
107 * @return DWORD
108 * Returns the number of levels in the specified texture.
109 *
110 */
111 DWORD WINAPI D3D9Texture_GetLevelCount(LPDIRECT3DBASETEXTURE9 iface)
112 {
113     DWORD MipMapLevels;
114     Direct3DBaseTexture9_INT* This = IDirect3DBaseTexture9ToImpl(iface);
115     LOCK_D3DDEVICE9();
116 
117     MipMapLevels = This->MipMapLevels;
118 
119     UNLOCK_D3DDEVICE9();
120     return MipMapLevels;
121 }
122