This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/gpu/opengl/gl_vertex_buffer.hh
Jeroen Bakker 87055dc71b GPU: Compute Pipeline.
With the compute pipeline calculation can be offloaded to the GPU.
This patch only adds the framework for compute. So no changes for users at
this moment.

NOTE: As this is an OpenGL4.3 feature it must always have a fallback.

Use `GPU_compute_shader_support` to check if compute pipeline can be used.
Check `gpu_shader_compute*` test cases for usage.

This patch also adds support for shader storage buffer objects and device only
vertex/index buffers.

An alternative that had been discussed was adding this to the `GPUBatch`, this
was eventually not chosen as it would lead to more code when used as part of a
shading group. The idea is that we add an `eDRWCommandType` in the near
future.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D10913
2021-05-26 16:49:30 +02:00

110 lines
2.7 KiB
C++

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2020 Blender Foundation.
* All rights reserved.
*/
/** \file
* \ingroup gpu
*/
#pragma once
#include "MEM_guardedalloc.h"
#include "glew-mx.h"
#include "gpu_vertex_buffer_private.hh"
namespace blender {
namespace gpu {
class GLVertBuf : public VertBuf {
friend class GLTexture; /* For buffer texture. */
friend class GLShader; /* For transform feedback. */
private:
/** OpenGL buffer handle. Init on first upload. Immutable after that. */
GLuint vbo_id_ = 0;
/** Size on the GPU. */
size_t vbo_size_ = 0;
public:
void bind(void);
void update_sub(uint start, uint len, void *data) override;
const void *read() const override;
void *unmap(const void *mapped_data) const override;
protected:
void acquire_data(void) override;
void resize_data(void) override;
void release_data(void) override;
void upload_data(void) override;
void duplicate_data(VertBuf *dst) override;
void bind_as_ssbo(uint binding) override;
private:
bool is_active() const;
MEM_CXX_CLASS_ALLOC_FUNCS("GLVertBuf");
};
static inline GLenum to_gl(GPUUsageType type)
{
switch (type) {
case GPU_USAGE_STREAM:
return GL_STREAM_DRAW;
case GPU_USAGE_DYNAMIC:
return GL_DYNAMIC_DRAW;
case GPU_USAGE_STATIC:
case GPU_USAGE_DEVICE_ONLY:
return GL_STATIC_DRAW;
default:
BLI_assert(0);
return GL_STATIC_DRAW;
}
}
static inline GLenum to_gl(GPUVertCompType type)
{
switch (type) {
case GPU_COMP_I8:
return GL_BYTE;
case GPU_COMP_U8:
return GL_UNSIGNED_BYTE;
case GPU_COMP_I16:
return GL_SHORT;
case GPU_COMP_U16:
return GL_UNSIGNED_SHORT;
case GPU_COMP_I32:
return GL_INT;
case GPU_COMP_U32:
return GL_UNSIGNED_INT;
case GPU_COMP_F32:
return GL_FLOAT;
case GPU_COMP_I10:
return GL_INT_2_10_10_10_REV;
default:
BLI_assert(0);
return GL_FLOAT;
}
}
} // namespace gpu
} // namespace blender