2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "test-graphics-buffer.h"
23 TestGraphicsBuffer::TestGraphicsBuffer(TraceCallStack& callStack, TestGlAbstraction& glAbstraction, uint32_t size, Graphics::BufferUsageFlags usage)
24 : mCallStack(callStack),
29 mGl.GetBufferTrace().EnableLogging(true);
32 void TestGraphicsBuffer::Bind()
34 mCallStack.PushCall("Buffer::Bind", "");
37 mGl.GenBuffers(1, &mId);
39 mGl.BindBuffer(GetTarget(), mId);
42 void TestGraphicsBuffer::Unbind()
44 mCallStack.PushCall("Buffer::Unbind", "");
47 mGl.BindBuffer(GetTarget(), 0);
51 void TestGraphicsBuffer::Upload(uint32_t offset, uint32_t size)
54 o << offset << ", " << size;
55 TraceCallStack::NamedParams namedParams;
56 namedParams["offset"] = offset;
57 namedParams["size"] = size;
58 mCallStack.PushCall("Buffer::Upload", o.str(), namedParams);
59 if(size <= memory.size() && mCreated)
61 // Use subData to avoid re-allocation
62 mGl.BufferSubData(GetTarget(), offset, size, &memory[offset]);
66 mGl.BufferData(GetTarget(), size, &memory[0], GL_STATIC_DRAW); //@todo Query - do we need other usages?
71 GLenum TestGraphicsBuffer::GetTarget()
73 GLenum target = GL_ARRAY_BUFFER;
74 if((mUsage & static_cast<Graphics::BufferUsageFlags>(Graphics::BufferUsage::INDEX_BUFFER)) != 0)
76 target = GL_ELEMENT_ARRAY_BUFFER;