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 | // TransformFeedback.cpp: Implements the es2::TransformFeedback class |
16 | |
17 | #include "TransformFeedback.h" |
18 | |
19 | namespace es2 |
20 | { |
21 | |
22 | TransformFeedback::TransformFeedback(GLuint name) : NamedObject(name), mActive(false), mPaused(false), mVertexOffset(0) |
23 | { |
24 | } |
25 | |
26 | TransformFeedback::~TransformFeedback() |
27 | { |
28 | for(int i = 0; i < MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS; ++i) |
29 | { |
30 | mBuffer[i].set(nullptr); |
31 | } |
32 | } |
33 | |
34 | Buffer* TransformFeedback::getBuffer(GLuint index) const |
35 | { |
36 | return mBuffer[index].get(); |
37 | } |
38 | |
39 | GLuint TransformFeedback::getBufferName(GLuint index) const |
40 | { |
41 | return mBuffer[index].get().name(); |
42 | } |
43 | |
44 | int TransformFeedback::getOffset(GLuint index) const |
45 | { |
46 | return mBuffer[index].getOffset(); |
47 | } |
48 | |
49 | int TransformFeedback::getSize(GLuint index) const |
50 | { |
51 | return mBuffer[index].getSize(); |
52 | } |
53 | |
54 | void TransformFeedback::addVertexOffset(int count) |
55 | { |
56 | if(isActive() && !isPaused()) |
57 | { |
58 | mVertexOffset += count; |
59 | } |
60 | } |
61 | |
62 | int TransformFeedback::vertexOffset() const |
63 | { |
64 | return mVertexOffset; |
65 | } |
66 | |
67 | bool TransformFeedback::isActive() const |
68 | { |
69 | return mActive; |
70 | } |
71 | |
72 | bool TransformFeedback::isPaused() const |
73 | { |
74 | return mPaused; |
75 | } |
76 | |
77 | GLenum TransformFeedback::primitiveMode() const |
78 | { |
79 | return mPrimitiveMode; |
80 | } |
81 | |
82 | void TransformFeedback::begin(GLenum primitiveMode) |
83 | { |
84 | mActive = true; mPrimitiveMode = primitiveMode; |
85 | } |
86 | |
87 | void TransformFeedback::end() |
88 | { |
89 | mActive = false; |
90 | mPaused = false; |
91 | mVertexOffset = 0; |
92 | } |
93 | |
94 | void TransformFeedback::setPaused(bool paused) |
95 | { |
96 | mPaused = paused; |
97 | } |
98 | |
99 | void TransformFeedback::setBuffer(GLuint index, Buffer* buffer) |
100 | { |
101 | mBuffer[index].set(buffer); |
102 | } |
103 | |
104 | void TransformFeedback::setBuffer(GLuint index, Buffer* buffer, GLintptr offset, GLsizeiptr size) |
105 | { |
106 | mBuffer[index].set(buffer, static_cast<int>(offset), static_cast<int>(size)); |
107 | } |
108 | |
109 | void TransformFeedback::detachBuffer(GLuint buffer) |
110 | { |
111 | for(int i = 0; i < MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS; ++i) |
112 | { |
113 | if(mBuffer[i].get().name() == buffer) |
114 | { |
115 | mBuffer[i].set(nullptr); |
116 | } |
117 | } |
118 | } |
119 | |
120 | } |
121 | |