17ec681f3Smrg/*
27ec681f3Smrg * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
87ec681f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom
97ec681f3Smrg * the Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
197ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
207ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
217ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. */
227ec681f3Smrg
237ec681f3Smrg#include "vertexbuffer9.h"
247ec681f3Smrg#include "device9.h"
257ec681f3Smrg#include "nine_helpers.h"
267ec681f3Smrg#include "nine_pipe.h"
277ec681f3Smrg
287ec681f3Smrg#include "pipe/p_screen.h"
297ec681f3Smrg#include "pipe/p_context.h"
307ec681f3Smrg#include "pipe/p_state.h"
317ec681f3Smrg#include "pipe/p_defines.h"
327ec681f3Smrg#include "pipe/p_format.h"
337ec681f3Smrg#include "util/u_box.h"
347ec681f3Smrg
357ec681f3Smrg#define DBG_CHANNEL DBG_VERTEXBUFFER
367ec681f3Smrg
377ec681f3SmrgHRESULT
387ec681f3SmrgNineVertexBuffer9_ctor( struct NineVertexBuffer9 *This,
397ec681f3Smrg                        struct NineUnknownParams *pParams,
407ec681f3Smrg                        D3DVERTEXBUFFER_DESC *pDesc )
417ec681f3Smrg{
427ec681f3Smrg    HRESULT hr;
437ec681f3Smrg
447ec681f3Smrg    DBG("This=%p Size=0x%x Usage=%x Pool=%u\n", This,
457ec681f3Smrg        pDesc->Size, pDesc->Usage, pDesc->Pool);
467ec681f3Smrg
477ec681f3Smrg    hr = NineBuffer9_ctor(&This->base, pParams, D3DRTYPE_VERTEXBUFFER,
487ec681f3Smrg                          pDesc->Usage, pDesc->Size, pDesc->Pool);
497ec681f3Smrg    if (FAILED(hr))
507ec681f3Smrg        return hr;
517ec681f3Smrg
527ec681f3Smrg    pDesc->Type = D3DRTYPE_VERTEXBUFFER;
537ec681f3Smrg    pDesc->Format = D3DFMT_VERTEXDATA;
547ec681f3Smrg    This->desc = *pDesc;
557ec681f3Smrg
567ec681f3Smrg    return D3D_OK;
577ec681f3Smrg}
587ec681f3Smrg
597ec681f3Smrgvoid
607ec681f3SmrgNineVertexBuffer9_dtor( struct NineVertexBuffer9 *This )
617ec681f3Smrg{
627ec681f3Smrg    NineBuffer9_dtor(&This->base);
637ec681f3Smrg}
647ec681f3Smrg
657ec681f3Smrgstruct pipe_resource *
667ec681f3SmrgNineVertexBuffer9_GetResource( struct NineVertexBuffer9 *This, unsigned *offset )
677ec681f3Smrg{
687ec681f3Smrg    return NineBuffer9_GetResource(&This->base, offset);
697ec681f3Smrg}
707ec681f3Smrg
717ec681f3SmrgHRESULT NINE_WINAPI
727ec681f3SmrgNineVertexBuffer9_Lock( struct NineVertexBuffer9 *This,
737ec681f3Smrg                       UINT OffsetToLock,
747ec681f3Smrg                       UINT SizeToLock,
757ec681f3Smrg                       void **ppbData,
767ec681f3Smrg                       DWORD Flags )
777ec681f3Smrg{
787ec681f3Smrg    return NineBuffer9_Lock(&This->base, OffsetToLock, SizeToLock, ppbData, Flags);
797ec681f3Smrg}
807ec681f3Smrg
817ec681f3SmrgHRESULT NINE_WINAPI
827ec681f3SmrgNineVertexBuffer9_Unlock( struct NineVertexBuffer9 *This )
837ec681f3Smrg{
847ec681f3Smrg    return NineBuffer9_Unlock(&This->base);
857ec681f3Smrg}
867ec681f3Smrg
877ec681f3SmrgHRESULT NINE_WINAPI
887ec681f3SmrgNineVertexBuffer9_GetDesc( struct NineVertexBuffer9 *This,
897ec681f3Smrg                           D3DVERTEXBUFFER_DESC *pDesc )
907ec681f3Smrg{
917ec681f3Smrg    user_assert(pDesc, E_POINTER);
927ec681f3Smrg    *pDesc = This->desc;
937ec681f3Smrg    return D3D_OK;
947ec681f3Smrg}
957ec681f3Smrg
967ec681f3SmrgIDirect3DVertexBuffer9Vtbl NineVertexBuffer9_vtable = {
977ec681f3Smrg    (void *)NineUnknown_QueryInterface,
987ec681f3Smrg    (void *)NineUnknown_AddRef,
997ec681f3Smrg    (void *)NineUnknown_Release,
1007ec681f3Smrg    (void *)NineUnknown_GetDevice, /* actually part of Resource9 iface */
1017ec681f3Smrg    (void *)NineUnknown_SetPrivateData,
1027ec681f3Smrg    (void *)NineUnknown_GetPrivateData,
1037ec681f3Smrg    (void *)NineUnknown_FreePrivateData,
1047ec681f3Smrg    (void *)NineResource9_SetPriority,
1057ec681f3Smrg    (void *)NineResource9_GetPriority,
1067ec681f3Smrg    (void *)NineResource9_PreLoad,
1077ec681f3Smrg    (void *)NineResource9_GetType,
1087ec681f3Smrg    (void *)NineVertexBuffer9_Lock,
1097ec681f3Smrg    (void *)NineVertexBuffer9_Unlock,
1107ec681f3Smrg    (void *)NineVertexBuffer9_GetDesc
1117ec681f3Smrg};
1127ec681f3Smrg
1137ec681f3Smrgstatic const GUID *NineVertexBuffer9_IIDs[] = {
1147ec681f3Smrg    &IID_IDirect3DVertexBuffer9,
1157ec681f3Smrg    &IID_IDirect3DResource9,
1167ec681f3Smrg    &IID_IUnknown,
1177ec681f3Smrg    NULL
1187ec681f3Smrg};
1197ec681f3Smrg
1207ec681f3SmrgHRESULT
1217ec681f3SmrgNineVertexBuffer9_new( struct NineDevice9 *pDevice,
1227ec681f3Smrg                       D3DVERTEXBUFFER_DESC *pDesc,
1237ec681f3Smrg                       struct NineVertexBuffer9 **ppOut )
1247ec681f3Smrg{
1257ec681f3Smrg    NINE_DEVICE_CHILD_NEW(VertexBuffer9, ppOut, /* args */ pDevice, pDesc);
1267ec681f3Smrg}
127