• 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 "Direct3DIndexBuffer8.hpp"
16 
17 #include "Direct3DDevice8.hpp"
18 #include "Resource.hpp"
19 #include "Debug.hpp"
20 
21 #include <assert.h>
22 
23 namespace D3D8
24 {
Direct3DIndexBuffer8(Direct3DDevice8 * device,unsigned int length,unsigned long usage,D3DFORMAT format,D3DPOOL pool)25 	Direct3DIndexBuffer8::Direct3DIndexBuffer8(Direct3DDevice8 *device, unsigned int length, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DResource8(device, D3DRTYPE_INDEXBUFFER, length), length(length), usage(usage), format(format), pool(pool)
26 	{
27 		indexBuffer = new sw::Resource(length + 16);
28 	}
29 
~Direct3DIndexBuffer8()30 	Direct3DIndexBuffer8::~Direct3DIndexBuffer8()
31 	{
32 		indexBuffer->destruct();
33 	}
34 
QueryInterface(const IID & iid,void ** object)35 	long Direct3DIndexBuffer8::QueryInterface(const IID &iid, void **object)
36 	{
37 		TRACE("");
38 
39 		if(iid == IID_IDirect3DIndexBuffer8 ||
40 		   iid == IID_IDirect3DResource8 ||
41 		   iid == IID_IUnknown)
42 		{
43 			AddRef();
44 			*object = this;
45 
46 			return S_OK;
47 		}
48 
49 		*object = 0;
50 
51 		return NOINTERFACE(iid);
52 	}
53 
AddRef()54 	unsigned long Direct3DIndexBuffer8::AddRef()
55 	{
56 		TRACE("");
57 
58 		return Direct3DResource8::AddRef();
59 	}
60 
Release()61 	unsigned long Direct3DIndexBuffer8::Release()
62 	{
63 		TRACE("");
64 
65 		return Direct3DResource8::Release();
66 	}
67 
FreePrivateData(const GUID & guid)68 	long Direct3DIndexBuffer8::FreePrivateData(const GUID &guid)
69 	{
70 		TRACE("");
71 
72 		return Direct3DResource8::FreePrivateData(guid);
73 	}
74 
GetPrivateData(const GUID & guid,void * data,unsigned long * size)75 	long Direct3DIndexBuffer8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
76 	{
77 		TRACE("");
78 
79 		return Direct3DResource8::GetPrivateData(guid, data, size);
80 	}
81 
PreLoad()82 	void Direct3DIndexBuffer8::PreLoad()
83 	{
84 		TRACE("");
85 
86 		Direct3DResource8::PreLoad();
87 	}
88 
SetPrivateData(const GUID & guid,const void * data,unsigned long size,unsigned long flags)89 	long Direct3DIndexBuffer8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
90 	{
91 		TRACE("");
92 
93 		return Direct3DResource8::SetPrivateData(guid, data, size, flags);
94 	}
95 
GetDevice(IDirect3DDevice8 ** device)96 	long Direct3DIndexBuffer8::GetDevice(IDirect3DDevice8 **device)
97 	{
98 		TRACE("");
99 
100 		return Direct3DResource8::GetDevice(device);
101 	}
102 
SetPriority(unsigned long newPriority)103 	unsigned long Direct3DIndexBuffer8::SetPriority(unsigned long newPriority)
104 	{
105 		TRACE("");
106 
107 		return Direct3DResource8::SetPriority(newPriority);
108 	}
109 
GetPriority()110 	unsigned long Direct3DIndexBuffer8::GetPriority()
111 	{
112 		TRACE("");
113 
114 		return Direct3DResource8::GetPriority();
115 	}
116 
GetType()117 	D3DRESOURCETYPE Direct3DIndexBuffer8::GetType()
118 	{
119 		TRACE("");
120 
121 		return Direct3DResource8::GetType();
122 	}
123 
GetDesc(D3DINDEXBUFFER_DESC * description)124 	long Direct3DIndexBuffer8::GetDesc(D3DINDEXBUFFER_DESC *description)
125 	{
126 		TRACE("");
127 
128 		if(!description)
129 		{
130 			return INVALIDCALL();
131 		}
132 
133 		description->Format = format;
134 		description->Pool = pool;
135 		description->Size = length;
136 		description->Type = GetType();
137 		description->Usage = usage;
138 
139 		return 0;
140 	}
141 
Lock(unsigned int offset,unsigned int size,unsigned char ** data,unsigned long flags)142 	long Direct3DIndexBuffer8::Lock(unsigned int offset, unsigned int size, unsigned char **data, unsigned long flags)
143 	{
144 		TRACE("");
145 
146 		if(offset == 0 && size == 0)   // Lock whole buffer
147 		{
148 			size = length;
149 		}
150 
151 		if(!data || offset + size > length)
152 		{
153 			return INVALIDCALL();
154 		}
155 
156 		lockOffset = offset;
157 		lockSize = size;
158 
159 		*data = (unsigned char*)indexBuffer->lock(sw::PUBLIC) + offset;
160 		indexBuffer->unlock();
161 
162 		return D3D_OK;
163 	}
164 
Unlock()165 	long Direct3DIndexBuffer8::Unlock()
166 	{
167 		TRACE("");
168 
169 		return D3D_OK;
170 	}
171 
getResource() const172 	sw::Resource *Direct3DIndexBuffer8::getResource() const
173 	{
174 		return indexBuffer;
175 	}
176 
is32Bit() const177 	bool Direct3DIndexBuffer8::is32Bit() const
178 	{
179 		switch(format)
180 		{
181 		case D3DFMT_INDEX16:
182 			return false;
183 		case D3DFMT_INDEX32:
184 			return true;
185 		default:
186 			ASSERT(false);
187 		}
188 
189 		return false;
190 	}
191 }