core.c 4.38 KB
Newer Older
Raphael Junqueira's avatar
Raphael Junqueira committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 *
 * Copyright 2002 Raphael Junqueira
 *
 * 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
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Raphael Junqueira's avatar
Raphael Junqueira committed
18 19
 */

20 21
#include <stdarg.h>

22
#define COBJMACROS
Raphael Junqueira's avatar
Raphael Junqueira committed
23 24 25 26
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "wine/debug.h"
27
#include "wine/unicode.h"
Raphael Junqueira's avatar
Raphael Junqueira committed
28

29
#include "d3dx8_private.h"
Raphael Junqueira's avatar
Raphael Junqueira committed
30

31
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
Raphael Junqueira's avatar
Raphael Junqueira committed
32 33

/* ID3DXBuffer IUnknown parts follow: */
34
static HRESULT WINAPI ID3DXBufferImpl_QueryInterface(LPD3DXBUFFER iface, REFIID riid, LPVOID* ppobj) {
35
  ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
36

Raphael Junqueira's avatar
Raphael Junqueira committed
37 38
  if (IsEqualGUID(riid, &IID_IUnknown)
      || IsEqualGUID(riid, &IID_ID3DXBuffer)) {
39
    IUnknown_AddRef(iface);
Raphael Junqueira's avatar
Raphael Junqueira committed
40 41 42 43 44 45 46 47
    *ppobj = This;
    return D3D_OK;
  }

  WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
  return E_NOINTERFACE;
}

48
static ULONG WINAPI ID3DXBufferImpl_AddRef(LPD3DXBUFFER iface) {
49
  ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
50 51
  ULONG ref = InterlockedIncrement(&This->ref);

52
  TRACE("(%p) : AddRef from %d\n", This, ref - 1);
53 54

  return ref;
Raphael Junqueira's avatar
Raphael Junqueira committed
55 56
}

57
static ULONG WINAPI ID3DXBufferImpl_Release(LPD3DXBUFFER iface) {
58
  ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
59 60
  ULONG ref = InterlockedDecrement(&This->ref);

61
  TRACE("(%p) : ReleaseRef to %d\n", This, ref);
62

Raphael Junqueira's avatar
Raphael Junqueira committed
63
  if (ref == 0) {
64
    HeapFree(GetProcessHeap(), 0, This->buffer);
Raphael Junqueira's avatar
Raphael Junqueira committed
65 66 67 68 69 70
    HeapFree(GetProcessHeap(), 0, This);
  }
  return ref;
}

/* ID3DXBuffer Interface follow: */
71
static LPVOID WINAPI ID3DXBufferImpl_GetBufferPointer(LPD3DXBUFFER iface) {
72
  ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
Raphael Junqueira's avatar
Raphael Junqueira committed
73 74 75
  return This->buffer;
}

76
static DWORD WINAPI ID3DXBufferImpl_GetBufferSize(LPD3DXBUFFER iface) {
77
  ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
Raphael Junqueira's avatar
Raphael Junqueira committed
78 79 80
  return This->bufferSize;
}

81
const ID3DXBufferVtbl D3DXBuffer_Vtbl =
Raphael Junqueira's avatar
Raphael Junqueira committed
82 83 84 85 86 87 88
{
    ID3DXBufferImpl_QueryInterface,
    ID3DXBufferImpl_AddRef,
    ID3DXBufferImpl_Release,
    ID3DXBufferImpl_GetBufferPointer,
    ID3DXBufferImpl_GetBufferSize
};
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

HRESULT WINAPI D3DXCreateBuffer(DWORD NumBytes, LPD3DXBUFFER* ppBuffer) {
  ID3DXBufferImpl *object;

  object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXBufferImpl));
  if (NULL == object) {
    *ppBuffer = NULL;
    return E_OUTOFMEMORY;
  }
  object->lpVtbl = &D3DXBuffer_Vtbl;
  object->ref = 1;
  object->bufferSize = NumBytes;
  object->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, NumBytes);
  if (NULL == object->buffer) {
    HeapFree(GetProcessHeap(), 0, object);
    *ppBuffer = NULL;
    return E_OUTOFMEMORY;
  }
  *ppBuffer = (LPD3DXBUFFER)object;
  return D3D_OK;
}

HRESULT WINAPI D3DXAssembleShader(LPCVOID pSrcData, UINT SrcDataLen, DWORD Flags,
			   LPD3DXBUFFER* ppConstants,
			   LPD3DXBUFFER* ppCompiledShader,
			   LPD3DXBUFFER* ppCompilationErrors) {
  FIXME("(void): stub\n");
  return D3D_OK;
}

HRESULT WINAPI D3DXAssembleShaderFromFileA(LPCSTR pSrcFile, DWORD Flags,
				    LPD3DXBUFFER* ppConstants,
				    LPD3DXBUFFER* ppCompiledShader,
				    LPD3DXBUFFER* ppCompilationErrors) {
  LPWSTR pSrcFileW = NULL;
  DWORD len;
  HRESULT ret;

  if (!pSrcFile) return D3DXERR_INVALIDDATA;

  len = MultiByteToWideChar( CP_ACP, 0, pSrcFile, -1, NULL, 0 );
  pSrcFileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
  MultiByteToWideChar( CP_ACP, 0, pSrcFile, -1, pSrcFileW, len );
  ret=D3DXAssembleShaderFromFileW(pSrcFileW, Flags, ppConstants, ppCompiledShader, ppCompilationErrors);
  HeapFree( GetProcessHeap(), 0, pSrcFileW );
  return ret;
}

HRESULT WINAPI D3DXAssembleShaderFromFileW(LPCWSTR pSrcFile, DWORD Flags,
				    LPD3DXBUFFER* ppConstants,
				    LPD3DXBUFFER* ppCompiledShader,
				    LPD3DXBUFFER* ppCompilationErrors) {
  FIXME("(void): stub\n");
  return D3D_OK;
}

HRESULT WINAPI D3DXCreateFont(LPDIRECT3DDEVICE8 pDevice, HFONT hFont, LPD3DXFONT* ppFont) {
  FIXME("(void): stub\n");
  return D3D_OK;
}