• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TransformFeedback(GLuint name)22 TransformFeedback::TransformFeedback(GLuint name) : NamedObject(name), mActive(false), mPaused(false), mVertexOffset(0)
23 {
24 	mGenericBuffer = nullptr;
25 }
26 
~TransformFeedback()27 TransformFeedback::~TransformFeedback()
28 {
29 	mGenericBuffer = nullptr;
30 	for(int i = 0; i < MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS; ++i)
31 	{
32 		mBuffer[i].set(nullptr);
33 	}
34 }
35 
getGenericBuffer() const36 Buffer* TransformFeedback::getGenericBuffer() const
37 {
38 	return mGenericBuffer;
39 }
40 
getBuffer(GLuint index) const41 Buffer* TransformFeedback::getBuffer(GLuint index) const
42 {
43 	return mBuffer[index].get();
44 }
45 
getGenericBufferName() const46 GLuint TransformFeedback::getGenericBufferName() const
47 {
48 	return mGenericBuffer.name();
49 }
50 
getBufferName(GLuint index) const51 GLuint TransformFeedback::getBufferName(GLuint index) const
52 {
53 	return mBuffer[index].get().name();
54 }
55 
getOffset(GLuint index) const56 int TransformFeedback::getOffset(GLuint index) const
57 {
58 	return mBuffer[index].getOffset();
59 }
60 
getSize(GLuint index) const61 int TransformFeedback::getSize(GLuint index) const
62 {
63 	return mBuffer[index].getSize();
64 }
65 
addVertexOffset(int count)66 void TransformFeedback::addVertexOffset(int count)
67 {
68 	if(isActive() && !isPaused())
69 	{
70 		mVertexOffset += count;
71 	}
72 }
73 
vertexOffset() const74 int TransformFeedback::vertexOffset() const
75 {
76 	return mVertexOffset;
77 }
78 
isActive() const79 bool TransformFeedback::isActive() const
80 {
81 	return mActive;
82 }
83 
isPaused() const84 bool TransformFeedback::isPaused() const
85 {
86 	return mPaused;
87 }
88 
primitiveMode() const89 GLenum TransformFeedback::primitiveMode() const
90 {
91 	return mPrimitiveMode;
92 }
93 
begin(GLenum primitiveMode)94 void TransformFeedback::begin(GLenum primitiveMode)
95 {
96 	mActive = true; mPrimitiveMode = primitiveMode;
97 }
98 
end()99 void TransformFeedback::end()
100 {
101 	mActive = false;
102 	mPaused = false;
103 	mVertexOffset = 0;
104 }
105 
setPaused(bool paused)106 void TransformFeedback::setPaused(bool paused)
107 {
108 	mPaused = paused;
109 }
110 
setGenericBuffer(Buffer * buffer)111 void TransformFeedback::setGenericBuffer(Buffer* buffer)
112 {
113 	mGenericBuffer = buffer;
114 }
115 
setBuffer(GLuint index,Buffer * buffer)116 void TransformFeedback::setBuffer(GLuint index, Buffer* buffer)
117 {
118 	mBuffer[index].set(buffer);
119 }
120 
setBuffer(GLuint index,Buffer * buffer,GLintptr offset,GLsizeiptr size)121 void TransformFeedback::setBuffer(GLuint index, Buffer* buffer, GLintptr offset, GLsizeiptr size)
122 {
123 	mBuffer[index].set(buffer, static_cast<int>(offset), static_cast<int>(size));
124 }
125 
detachBuffer(GLuint buffer)126 void TransformFeedback::detachBuffer(GLuint buffer)
127 {
128 	if(mGenericBuffer.name() == buffer)
129 	{
130 		mGenericBuffer = nullptr;
131 	}
132 
133 	for(int i = 0; i < MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS; ++i)
134 	{
135 		if(mBuffer[i].get().name() == buffer)
136 		{
137 			mBuffer[i].set(nullptr);
138 		}
139 	}
140 }
141 
142 }
143