2004-11-24 18:13:41 +00:00
|
|
|
|
/*
|
|
|
|
|
* IWineD3DIndexBuffer Implementation
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2002-2004 Jason Edmeades
|
|
|
|
|
* Copyright 2003-2004 Raphael Junqueira
|
|
|
|
|
* Copyright 2004 Christian Costa
|
2005-07-13 14:15:54 +00:00
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2008-03-29 01:36:13 +00:00
|
|
|
|
* Copyright 2007 Stefan D<EFBFBD>singer for CodeWeavers
|
2004-11-24 18:13:41 +00:00
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-11-24 18:13:41 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
2007-06-09 12:27:41 +00:00
|
|
|
|
#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
|
2004-11-24 18:13:41 +00:00
|
|
|
|
|
|
|
|
|
/* *******************************************
|
|
|
|
|
IWineD3DIndexBuffer IUnknown parts follow
|
|
|
|
|
******************************************* */
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DIndexBufferImpl_QueryInterface(IWineD3DIndexBuffer *iface, REFIID riid, LPVOID *ppobj)
|
2004-11-24 18:13:41 +00:00
|
|
|
|
{
|
|
|
|
|
IWineD3DIndexBufferImpl *This = (IWineD3DIndexBufferImpl *)iface;
|
2005-03-02 13:44:58 +00:00
|
|
|
|
TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
2006-02-06 10:32:41 +00:00
|
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DBase)
|
2005-03-02 13:44:58 +00:00
|
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DResource)
|
|
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DIndexBuffer)){
|
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
|
*ppobj = This;
|
2006-04-25 21:59:12 +00:00
|
|
|
|
return S_OK;
|
2005-03-02 13:44:58 +00:00
|
|
|
|
}
|
2006-04-25 21:59:12 +00:00
|
|
|
|
*ppobj = NULL;
|
2004-11-24 18:13:41 +00:00
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static ULONG WINAPI IWineD3DIndexBufferImpl_AddRef(IWineD3DIndexBuffer *iface) {
|
2004-11-24 18:13:41 +00:00
|
|
|
|
IWineD3DIndexBufferImpl *This = (IWineD3DIndexBufferImpl *)iface;
|
2005-01-19 16:59:01 +00:00
|
|
|
|
ULONG ref = InterlockedIncrement(&This->resource.ref);
|
2006-10-01 03:20:10 +00:00
|
|
|
|
TRACE("(%p) : AddRef increasing from %d\n", This, ref - 1);
|
2005-07-13 14:15:54 +00:00
|
|
|
|
return ref;
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static ULONG WINAPI IWineD3DIndexBufferImpl_Release(IWineD3DIndexBuffer *iface) {
|
2004-11-24 18:13:41 +00:00
|
|
|
|
IWineD3DIndexBufferImpl *This = (IWineD3DIndexBufferImpl *)iface;
|
2005-01-19 16:59:01 +00:00
|
|
|
|
ULONG ref = InterlockedDecrement(&This->resource.ref);
|
2006-10-01 03:20:10 +00:00
|
|
|
|
TRACE("(%p) : Releasing from %d\n", This, ref + 1);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
if (ref == 0) {
|
2007-02-19 14:25:32 +00:00
|
|
|
|
if(This->vbo) {
|
2007-03-17 22:00:39 +00:00
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
|
|
|
|
|
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
2007-08-06 14:27:08 +00:00
|
|
|
|
ENTER_GL();
|
2007-02-20 21:46:31 +00:00
|
|
|
|
/* No need to manually unset the buffer. glDeleteBuffers unsets it for the current context,
|
|
|
|
|
* but not for other contexts. However, because the d3d buffer is destroyed the app has to
|
|
|
|
|
* unset it before doing the next draw, thus dirtifying the index buffer state and forcing
|
|
|
|
|
* binding a new buffer
|
|
|
|
|
*/
|
2007-02-19 14:25:32 +00:00
|
|
|
|
GL_EXTCALL(glDeleteBuffersARB(1, &This->vbo));
|
|
|
|
|
checkGLcall("glDeleteBuffersARB");
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-29 19:01:00 +00:00
|
|
|
|
IWineD3DResourceImpl_CleanUp((IWineD3DResource *)iface);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
}
|
|
|
|
|
return ref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ****************************************************
|
|
|
|
|
IWineD3DIndexBuffer IWineD3DResource parts follow
|
|
|
|
|
**************************************************** */
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DIndexBufferImpl_GetDevice(IWineD3DIndexBuffer *iface, IWineD3DDevice** ppDevice) {
|
2005-01-17 13:44:57 +00:00
|
|
|
|
return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DIndexBufferImpl_SetPrivateData(IWineD3DIndexBuffer *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
|
2005-01-17 13:44:57 +00:00
|
|
|
|
return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DIndexBufferImpl_GetPrivateData(IWineD3DIndexBuffer *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
|
2005-01-17 13:44:57 +00:00
|
|
|
|
return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DIndexBufferImpl_FreePrivateData(IWineD3DIndexBuffer *iface, REFGUID refguid) {
|
2005-01-17 13:44:57 +00:00
|
|
|
|
return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static DWORD WINAPI IWineD3DIndexBufferImpl_SetPriority(IWineD3DIndexBuffer *iface, DWORD PriorityNew) {
|
2005-01-17 13:44:57 +00:00
|
|
|
|
return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static DWORD WINAPI IWineD3DIndexBufferImpl_GetPriority(IWineD3DIndexBuffer *iface) {
|
2005-01-17 13:44:57 +00:00
|
|
|
|
return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static void WINAPI IWineD3DIndexBufferImpl_PreLoad(IWineD3DIndexBuffer *iface) {
|
2007-06-06 21:40:30 +00:00
|
|
|
|
IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-12 21:56:30 +00:00
|
|
|
|
static void WINAPI IWineD3DIndexBufferImpl_UnLoad(IWineD3DIndexBuffer *iface) {
|
2008-01-12 21:57:49 +00:00
|
|
|
|
IWineD3DIndexBufferImpl *This = (IWineD3DIndexBufferImpl *) iface;
|
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
|
|
/* This is easy: The whole content is shadowed in This->resource.allocatedMemory,
|
|
|
|
|
* so we only have to destroy the vbo. Only do it if we have a vbo, which implies
|
|
|
|
|
* that vbos are supported.
|
|
|
|
|
* (TODO: Make a IWineD3DBuffer base class for index and vertex buffers and share
|
|
|
|
|
* this code. Also needed for D3D10)
|
|
|
|
|
*/
|
|
|
|
|
if(This->vbo) {
|
|
|
|
|
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
GL_EXTCALL(glDeleteBuffersARB(1, &This->vbo));
|
|
|
|
|
checkGLcall("glDeleteBuffersARB");
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
This->vbo = 0;
|
|
|
|
|
}
|
2008-01-12 21:56:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static WINED3DRESOURCETYPE WINAPI IWineD3DIndexBufferImpl_GetType(IWineD3DIndexBuffer *iface) {
|
2005-01-17 13:44:57 +00:00
|
|
|
|
return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DIndexBufferImpl_GetParent(IWineD3DIndexBuffer *iface, IUnknown **pParent) {
|
2005-01-17 13:44:57 +00:00
|
|
|
|
return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******************************************************
|
|
|
|
|
IWineD3DIndexBuffer IWineD3DIndexBuffer parts follow
|
|
|
|
|
****************************************************** */
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DIndexBufferImpl_Lock(IWineD3DIndexBuffer *iface, UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags) {
|
2004-11-24 18:13:41 +00:00
|
|
|
|
IWineD3DIndexBufferImpl *This = (IWineD3DIndexBufferImpl *)iface;
|
2007-02-19 14:25:32 +00:00
|
|
|
|
TRACE("(%p) : offset %d, size %d, Flags=%x\n", This, OffsetToLock, SizeToLock, Flags);
|
|
|
|
|
|
|
|
|
|
InterlockedIncrement(&This->lockcount);
|
2008-01-23 21:39:59 +00:00
|
|
|
|
*ppbData = This->resource.allocatedMemory + OffsetToLock;
|
2007-02-19 14:25:32 +00:00
|
|
|
|
|
|
|
|
|
if(Flags & (WINED3DLOCK_READONLY | WINED3DLOCK_NO_DIRTY_UPDATE) || This->vbo == 0) {
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(This->dirtystart != This->dirtyend) {
|
|
|
|
|
if(This->dirtystart > OffsetToLock) This->dirtystart = OffsetToLock;
|
|
|
|
|
if(SizeToLock) {
|
|
|
|
|
if(This->dirtyend < OffsetToLock + SizeToLock) This->dirtyend = OffsetToLock + SizeToLock;
|
|
|
|
|
} else {
|
|
|
|
|
This->dirtyend = This->resource.size;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
This->dirtystart = OffsetToLock;
|
|
|
|
|
if(SizeToLock)
|
|
|
|
|
This->dirtyend = OffsetToLock + SizeToLock;
|
|
|
|
|
else
|
|
|
|
|
This->dirtyend = This->resource.size;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3D_OK;
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DIndexBufferImpl_Unlock(IWineD3DIndexBuffer *iface) {
|
2004-11-24 18:13:41 +00:00
|
|
|
|
IWineD3DIndexBufferImpl *This = (IWineD3DIndexBufferImpl *)iface;
|
2007-02-19 14:25:32 +00:00
|
|
|
|
unsigned long locks = InterlockedDecrement(&This->lockcount);
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
|
|
/* For now load in unlock */
|
2007-04-19 16:11:36 +00:00
|
|
|
|
if(locks == 0 && This->vbo && (This->dirtyend - This->dirtystart) > 0) {
|
2007-03-17 22:00:39 +00:00
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
|
2008-01-02 18:51:51 +00:00
|
|
|
|
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
2007-03-17 22:00:39 +00:00
|
|
|
|
|
2007-08-06 14:27:08 +00:00
|
|
|
|
ENTER_GL();
|
2007-02-19 14:25:32 +00:00
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, This->vbo));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
GL_EXTCALL(glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
|
|
|
|
|
This->dirtystart, This->dirtyend - This->dirtystart, This->resource.allocatedMemory + This->dirtystart));
|
|
|
|
|
checkGLcall("glBufferSubDataARB");
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
This->dirtystart = 0;
|
|
|
|
|
This->dirtyend = 0;
|
2007-02-20 21:46:31 +00:00
|
|
|
|
/* TODO: Move loading into preload when the buffer is used, that avoids dirtifying the state */
|
2007-03-17 22:00:39 +00:00
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_INDEXBUFFER);
|
2007-02-19 14:25:32 +00:00
|
|
|
|
}
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3D_OK;
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DIndexBufferImpl_GetDesc(IWineD3DIndexBuffer *iface, WINED3DINDEXBUFFER_DESC *pDesc) {
|
2004-11-24 18:13:41 +00:00
|
|
|
|
IWineD3DIndexBufferImpl *This = (IWineD3DIndexBufferImpl *)iface;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
2005-03-29 19:01:00 +00:00
|
|
|
|
pDesc->Format = This->resource.format;
|
2004-11-24 18:13:41 +00:00
|
|
|
|
pDesc->Type = This->resource.resourceType;
|
2005-03-29 19:01:00 +00:00
|
|
|
|
pDesc->Usage = This->resource.usage;
|
|
|
|
|
pDesc->Pool = This->resource.pool;
|
|
|
|
|
pDesc->Size = This->resource.size;
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3D_OK;
|
2004-11-24 18:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-06 19:50:35 +00:00
|
|
|
|
const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl =
|
2004-11-24 18:13:41 +00:00
|
|
|
|
{
|
2005-07-13 14:15:54 +00:00
|
|
|
|
/* IUnknown */
|
2004-11-24 18:13:41 +00:00
|
|
|
|
IWineD3DIndexBufferImpl_QueryInterface,
|
|
|
|
|
IWineD3DIndexBufferImpl_AddRef,
|
|
|
|
|
IWineD3DIndexBufferImpl_Release,
|
2005-07-13 14:15:54 +00:00
|
|
|
|
/* IWineD3DResource */
|
2004-11-24 18:13:41 +00:00
|
|
|
|
IWineD3DIndexBufferImpl_GetParent,
|
|
|
|
|
IWineD3DIndexBufferImpl_GetDevice,
|
|
|
|
|
IWineD3DIndexBufferImpl_SetPrivateData,
|
|
|
|
|
IWineD3DIndexBufferImpl_GetPrivateData,
|
|
|
|
|
IWineD3DIndexBufferImpl_FreePrivateData,
|
|
|
|
|
IWineD3DIndexBufferImpl_SetPriority,
|
|
|
|
|
IWineD3DIndexBufferImpl_GetPriority,
|
|
|
|
|
IWineD3DIndexBufferImpl_PreLoad,
|
2008-01-12 21:56:30 +00:00
|
|
|
|
IWineD3DIndexBufferImpl_UnLoad,
|
2004-11-24 18:13:41 +00:00
|
|
|
|
IWineD3DIndexBufferImpl_GetType,
|
2005-07-13 14:15:54 +00:00
|
|
|
|
/* IWineD3DIndexBuffer */
|
2004-11-24 18:13:41 +00:00
|
|
|
|
IWineD3DIndexBufferImpl_Lock,
|
|
|
|
|
IWineD3DIndexBufferImpl_Unlock,
|
|
|
|
|
IWineD3DIndexBufferImpl_GetDesc
|
|
|
|
|
};
|