• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "Direct3DCubeTexture8.hpp"
16 
17 #include "Direct3DSurface8.hpp"
18 #include "Resource.hpp"
19 #include "Debug.hpp"
20 
21 #include <assert.h>
22 
23 namespace D3D8
24 {
Direct3DCubeTexture8(Direct3DDevice8 * device,unsigned int edgeLength,unsigned int levels,unsigned long usage,D3DFORMAT format,D3DPOOL pool)25 	Direct3DCubeTexture8::Direct3DCubeTexture8(Direct3DDevice8 *device, unsigned int edgeLength, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DBaseTexture8(device, D3DRTYPE_CUBETEXTURE, levels, usage), edgeLength(edgeLength), format(format), pool(pool)
26 	{
27 		if(levels == 0)
28 		{
29 			this->levels = sw::log2(sw::max((int)edgeLength, 1)) + 1;
30 		}
31 
32 		for(unsigned int face = 0; face < 6; face++)
33 		{
34 			int width = edgeLength;
35 			int height = edgeLength;
36 
37 			for(unsigned int level = 0; level < sw::MIPMAP_LEVELS; level++)
38 			{
39 				if(level < this->levels)
40 				{
41 					surfaceLevel[face][level] = new Direct3DSurface8(device, this, width, height, format, pool, D3DMULTISAMPLE_NONE, true, usage);
42 					surfaceLevel[face][level]->bind();
43 				}
44 				else
45 				{
46 					surfaceLevel[face][level] = 0;
47 				}
48 
49 				width = sw::max(1, width / 2);
50 				height = sw::max(1, height / 2);
51 			}
52 		}
53 	}
54 
~Direct3DCubeTexture8()55 	Direct3DCubeTexture8::~Direct3DCubeTexture8()
56 	{
57 		for(unsigned int face = 0; face < 6; face++)
58 		{
59 			for(int level = 0; level < sw::MIPMAP_LEVELS; level++)
60 			{
61 				if(surfaceLevel[face][level])
62 				{
63 					surfaceLevel[face][level]->unbind();
64 					surfaceLevel[face][level] = 0;
65 				}
66 			}
67 		}
68 	}
69 
QueryInterface(const IID & iid,void ** object)70 	long Direct3DCubeTexture8::QueryInterface(const IID &iid, void **object)
71 	{
72 		TRACE("");
73 
74 		if(iid == IID_IDirect3DCubeTexture8 ||
75 		   iid == IID_IDirect3DBaseTexture8 ||
76 		   iid == IID_IDirect3DResource8 ||
77 		   iid == IID_IUnknown)
78 		{
79 			AddRef();
80 			*object = this;
81 
82 			return S_OK;
83 		}
84 
85 		*object = 0;
86 
87 		return NOINTERFACE(iid);
88 	}
89 
AddRef()90 	unsigned long Direct3DCubeTexture8::AddRef()
91 	{
92 		TRACE("");
93 
94 		return Direct3DBaseTexture8::AddRef();
95 	}
96 
Release()97 	unsigned long Direct3DCubeTexture8::Release()
98 	{
99 		TRACE("");
100 
101 		return Direct3DBaseTexture8::Release();
102 	}
103 
FreePrivateData(const GUID & guid)104 	long Direct3DCubeTexture8::FreePrivateData(const GUID &guid)
105 	{
106 		TRACE("");
107 
108 		return Direct3DBaseTexture8::FreePrivateData(guid);
109 	}
110 
GetPrivateData(const GUID & guid,void * data,unsigned long * size)111 	long Direct3DCubeTexture8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
112 	{
113 		TRACE("");
114 
115 		return Direct3DBaseTexture8::GetPrivateData(guid, data, size);
116 	}
117 
PreLoad()118 	void Direct3DCubeTexture8::PreLoad()
119 	{
120 		TRACE("");
121 
122 		Direct3DBaseTexture8::PreLoad();
123 	}
124 
SetPrivateData(const GUID & guid,const void * data,unsigned long size,unsigned long flags)125 	long Direct3DCubeTexture8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
126 	{
127 		TRACE("");
128 
129 		return Direct3DBaseTexture8::SetPrivateData(guid, data, size, flags);
130 	}
131 
GetDevice(IDirect3DDevice8 ** device)132 	long Direct3DCubeTexture8::GetDevice(IDirect3DDevice8 **device)
133 	{
134 		TRACE("");
135 
136 		return Direct3DBaseTexture8::GetDevice(device);
137 	}
138 
SetPriority(unsigned long newPriority)139 	unsigned long Direct3DCubeTexture8::SetPriority(unsigned long newPriority)
140 	{
141 		TRACE("");
142 
143 		return Direct3DBaseTexture8::SetPriority(newPriority);
144 	}
145 
GetPriority()146 	unsigned long Direct3DCubeTexture8::GetPriority()
147 	{
148 		TRACE("");
149 
150 		return Direct3DBaseTexture8::GetPriority();
151 	}
152 
GetType()153 	D3DRESOURCETYPE Direct3DCubeTexture8::GetType()
154 	{
155 		TRACE("");
156 
157 		return Direct3DBaseTexture8::GetType();
158 	}
159 
GetLevelCount()160 	unsigned long Direct3DCubeTexture8::GetLevelCount()
161 	{
162 		TRACE("");
163 
164 		return Direct3DBaseTexture8::GetLevelCount();
165 	}
166 
GetLOD()167 	unsigned long Direct3DCubeTexture8::GetLOD()
168 	{
169 		TRACE("");
170 
171 		return Direct3DBaseTexture8::GetLOD();
172 	}
173 
SetLOD(unsigned long newLOD)174 	unsigned long Direct3DCubeTexture8::SetLOD(unsigned long newLOD)
175 	{
176 		TRACE("");
177 
178 		return Direct3DBaseTexture8::SetLOD(newLOD);
179 	}
180 
AddDirtyRect(D3DCUBEMAP_FACES face,const RECT * dirtyRect)181 	long Direct3DCubeTexture8::AddDirtyRect(D3DCUBEMAP_FACES face, const RECT *dirtyRect)
182 	{
183 		TRACE("");
184 
185 	//	UNIMPLEMENTED();
186 
187 		return D3D_OK;
188 	}
189 
GetCubeMapSurface(D3DCUBEMAP_FACES face,unsigned int level,IDirect3DSurface8 ** cubeMapSurface)190 	long Direct3DCubeTexture8::GetCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level , IDirect3DSurface8 **cubeMapSurface)
191 	{
192 		TRACE("");
193 
194 		*cubeMapSurface = 0;   // FIXME: Verify
195 
196 		if(face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
197 		{
198 			return INVALIDCALL();
199 		}
200 
201 		surfaceLevel[face][level]->AddRef();
202 		*cubeMapSurface = surfaceLevel[face][level];
203 
204 		return D3D_OK;
205 	}
206 
GetLevelDesc(unsigned int level,D3DSURFACE_DESC * description)207 	long Direct3DCubeTexture8::GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description)
208 	{
209 		TRACE("");
210 
211 		if(!description || level >= GetLevelCount() || !surfaceLevel[0][level])
212 		{
213 			return INVALIDCALL();
214 		}
215 
216 		surfaceLevel[0][level]->GetDesc(description);
217 
218 		return D3D_OK;
219 	}
220 
LockRect(D3DCUBEMAP_FACES face,unsigned int level,D3DLOCKED_RECT * lockedRect,const RECT * rect,unsigned long flags)221 	long Direct3DCubeTexture8::LockRect(D3DCUBEMAP_FACES face, unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags)
222 	{
223 		TRACE("");
224 
225 		if(!lockedRect || face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
226 		{
227 			return INVALIDCALL();
228 		}
229 
230 		surfaceLevel[face][level]->LockRect(lockedRect, rect, flags);
231 
232 		return D3D_OK;
233 	}
234 
UnlockRect(D3DCUBEMAP_FACES face,unsigned int level)235 	long Direct3DCubeTexture8::UnlockRect(D3DCUBEMAP_FACES face, unsigned int level)
236 	{
237 		TRACE("");
238 
239 		if(face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
240 		{
241 			return INVALIDCALL();
242 		}
243 
244 		return surfaceLevel[face][level]->UnlockRect();
245 	}
246 
getInternalCubeMapSurface(D3DCUBEMAP_FACES face,unsigned int level)247 	Direct3DSurface8 *Direct3DCubeTexture8::getInternalCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level)
248 	{
249 		return surfaceLevel[face][level];
250 	}
251 }
252