blob: 40e3fc5bdffe584c63aa8d174ae8620fba6559f4 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
Nicolas Capensee16f0d2015-07-16 17:40:10 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// 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
Nicolas Capensee16f0d2015-07-16 17:40:10 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
Nicolas Capensee16f0d2015-07-16 17:40:10 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// 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.
Nicolas Capensee16f0d2015-07-16 17:40:10 -040014
15#include "Direct3DVertexShader9.hpp"
16
17#include "Direct3DDevice9.hpp"
18#include "Debug.hpp"
19
20namespace D3D9
21{
22 Direct3DVertexShader9::Direct3DVertexShader9(Direct3DDevice9 *device, const unsigned long *shaderToken) : device(device), vertexShader(shaderToken)
23 {
Nicolas Capens8d314222015-07-17 13:17:33 -040024 tokenCount = 0;
25
26 while(shaderToken[tokenCount] != 0x0000FFFF)
27 {
28 tokenCount += sw::Shader::size(shaderToken[tokenCount], (unsigned short)(shaderToken[0] & 0xFFFF)) + 1;
29 }
30
31 tokenCount += 1;
32
33 this->shaderToken = new unsigned long[tokenCount];
34 memcpy(this->shaderToken, shaderToken, tokenCount * sizeof(unsigned long));
Nicolas Capensee16f0d2015-07-16 17:40:10 -040035 }
36
37 Direct3DVertexShader9::~Direct3DVertexShader9()
38 {
Nicolas Capens8d314222015-07-17 13:17:33 -040039 delete[] shaderToken;
40 shaderToken = 0;
Nicolas Capensee16f0d2015-07-16 17:40:10 -040041 }
42
43 long Direct3DVertexShader9::QueryInterface(const IID &iid, void **object)
44 {
45 CriticalSection cs(device);
46
47 TRACE("");
48
49 if(iid == IID_IDirect3DVertexShader9 ||
50 iid == IID_IUnknown)
51 {
52 AddRef();
53 *object = this;
54
55 return S_OK;
56 }
57
58 *object = 0;
59
60 return NOINTERFACE(iid);
61 }
62
63 unsigned long Direct3DVertexShader9::AddRef()
64 {
65 TRACE("");
66
67 return Unknown::AddRef();
68 }
Nicolas Capens0bac2852016-05-07 06:09:58 -040069
Nicolas Capensee16f0d2015-07-16 17:40:10 -040070 unsigned long Direct3DVertexShader9::Release()
71 {
72 TRACE("");
73
74 return Unknown::Release();
75 }
76
77 long Direct3DVertexShader9::GetDevice(IDirect3DDevice9 **device)
78 {
79 CriticalSection cs(this->device);
80
81 TRACE("");
82
83 if(!device)
84 {
85 return INVALIDCALL();
86 }
87
88 this->device->AddRef();
89 *device = this->device;
90
91 return D3D_OK;
92 }
93
94 long Direct3DVertexShader9::GetFunction(void *data, unsigned int *size)
95 {
96 CriticalSection cs(device);
97
98 TRACE("");
99
100 if(!size)
101 {
102 return INVALIDCALL();
103 }
104
Nicolas Capens8d314222015-07-17 13:17:33 -0400105 if(data)
106 {
107 memcpy(data, shaderToken, tokenCount * 4);
108 }
109
110 *size = tokenCount * 4;
Nicolas Capensee16f0d2015-07-16 17:40:10 -0400111
112 return D3D_OK;
113 }
114
115 const sw::VertexShader *Direct3DVertexShader9::getVertexShader() const
116 {
117 return &vertexShader;
118 }
119}