Share retained sampler and pixel-buffer dispatch bridges
This commit is contained in:
@@ -429,7 +429,11 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p
|
|||||||
tokens used by `Texture2D`, plus cube-map binding and allocation face targets
|
tokens used by `Texture2D`, plus cube-map binding and allocation face targets
|
||||||
used by `TextureCube`. Retained `Texture2D`, `TextureCube`, and RTT texture
|
used by `TextureCube`. Retained `Texture2D`, `TextureCube`, and RTT texture
|
||||||
allocation, bind, parameter, update, mipmap, and delete dispatch now share
|
allocation, bind, parameter, update, mipmap, and delete dispatch now share
|
||||||
the retained `legacy_gl_texture_dispatch` raw callback bridge. It also owns and
|
the retained `legacy_gl_texture_dispatch` raw callback bridge. Retained
|
||||||
|
`Sampler` create, parameter, border-color, bind, and unbind dispatch now
|
||||||
|
share `legacy_gl_sampler_dispatch`, and retained `PBO` allocation,
|
||||||
|
framebuffer readback, map, unmap, and delete dispatch now share
|
||||||
|
`legacy_gl_pixel_buffer_dispatch`. It also owns and
|
||||||
validates framebuffer blit color mask and linear/nearest filters used by
|
validates framebuffer blit color mask and linear/nearest filters used by
|
||||||
`RTT::resize` and `RTT::copy`, renderer API blit-filter to OpenGL token
|
`RTT::resize` and `RTT::copy`, renderer API blit-filter to OpenGL token
|
||||||
mapping, plus the default linear clamp-to-edge render-target texture
|
mapping, plus the default linear clamp-to-edge render-target texture
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1145,7 +1145,11 @@ face targets, RGBA allocation format, and unsigned-byte component type also
|
|||||||
delegate to `pp_renderer_gl`. RGBA8/RGBA32F readback formats, checked byte-count math, PBO
|
delegate to `pp_renderer_gl`. RGBA8/RGBA32F readback formats, checked byte-count math, PBO
|
||||||
pixel-buffer target/usage/access tokens, and PBO allocation/readback/map/unmap/delete
|
pixel-buffer target/usage/access tokens, and PBO allocation/readback/map/unmap/delete
|
||||||
dispatch sequences used by retained recording readbacks now live in
|
dispatch sequences used by retained recording readbacks now live in
|
||||||
`pp_renderer_gl`. The framebuffer blit color mask and linear/nearest
|
`pp_renderer_gl`; retained `PBO` allocation, framebuffer readback, map, unmap,
|
||||||
|
and delete dispatch now share the retained `legacy_gl_pixel_buffer_dispatch`
|
||||||
|
raw callback bridge. Retained `Sampler` create, parameter, border-color, bind,
|
||||||
|
and unbind dispatch now share the retained `legacy_gl_sampler_dispatch` raw
|
||||||
|
callback bridge. The framebuffer blit color mask and linear/nearest
|
||||||
filter tokens used by `RTT::resize` and `RTT::copy`, renderer API blit-filter
|
filter tokens used by `RTT::resize` and `RTT::copy`, renderer API blit-filter
|
||||||
to OpenGL token mapping, plus the default
|
to OpenGL token mapping, plus the default
|
||||||
render-target texture parameters and parameter dispatch, texture/renderbuffer
|
render-target texture parameters and parameter dispatch, texture/renderbuffer
|
||||||
@@ -2563,6 +2567,12 @@ Results:
|
|||||||
`legacy_gl_framebuffer_dispatch`, removing duplicated raw framebuffer and
|
`legacy_gl_framebuffer_dispatch`, removing duplicated raw framebuffer and
|
||||||
readback callbacks from `src/texture.cpp` and `src/rtt.cpp` while
|
readback callbacks from `src/texture.cpp` and `src/rtt.cpp` while
|
||||||
framebuffer/readback ownership remains retained under DEBT-0036.
|
framebuffer/readback ownership remains retained under DEBT-0036.
|
||||||
|
- Retained `Sampler` create, parameter, border-color, bind, and unbind dispatch
|
||||||
|
now share `legacy_gl_sampler_dispatch`, and retained `PBO` allocation,
|
||||||
|
framebuffer readback, map, unmap, and delete dispatch now share
|
||||||
|
`legacy_gl_pixel_buffer_dispatch`; this removes another pair of raw resource
|
||||||
|
callback clusters from `src/texture.cpp` and `src/rtt.cpp` while sampler and
|
||||||
|
pixel-buffer ownership remain retained under DEBT-0036.
|
||||||
- Canvas draw-merge shader-blend selection now consumes the extracted
|
- Canvas draw-merge shader-blend selection now consumes the extracted
|
||||||
`pp_paint_renderer` stroke composite planner for current layer and primary
|
`pp_paint_renderer` stroke composite planner for current layer and primary
|
||||||
brush blend modes, while preserving legacy OpenGL compositing execution under
|
brush blend modes, while preserving legacy OpenGL compositing execution under
|
||||||
|
|||||||
96
src/legacy_gl_pixel_buffer_dispatch.h
Normal file
96
src/legacy_gl_pixel_buffer_dispatch.h
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "legacy_gl_framebuffer_dispatch.h"
|
||||||
|
#include "renderer_gl/opengl_capabilities.h"
|
||||||
|
|
||||||
|
namespace pp::legacy::gl_pixel_buffer {
|
||||||
|
|
||||||
|
inline void gen_opengl_buffers(std::uint32_t count, std::uint32_t* ids) noexcept
|
||||||
|
{
|
||||||
|
glGenBuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void delete_opengl_buffers(std::uint32_t count, const std::uint32_t* ids) noexcept
|
||||||
|
{
|
||||||
|
glDeleteBuffers(static_cast<GLsizei>(count), reinterpret_cast<const GLuint*>(ids));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void bind_opengl_buffer(std::uint32_t target, std::uint32_t buffer) noexcept
|
||||||
|
{
|
||||||
|
glBindBuffer(static_cast<GLenum>(target), static_cast<GLuint>(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_opengl_buffer_data(
|
||||||
|
std::uint32_t target,
|
||||||
|
std::intptr_t byte_count,
|
||||||
|
const void* data,
|
||||||
|
std::uint32_t usage) noexcept
|
||||||
|
{
|
||||||
|
glBufferData(
|
||||||
|
static_cast<GLenum>(target),
|
||||||
|
static_cast<GLsizeiptr>(byte_count),
|
||||||
|
data,
|
||||||
|
static_cast<GLenum>(usage));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void* map_opengl_buffer_range(
|
||||||
|
std::uint32_t target,
|
||||||
|
std::intptr_t offset,
|
||||||
|
std::intptr_t byte_count,
|
||||||
|
std::uint32_t access) noexcept
|
||||||
|
{
|
||||||
|
return glMapBufferRange(
|
||||||
|
static_cast<GLenum>(target),
|
||||||
|
static_cast<GLintptr>(offset),
|
||||||
|
static_cast<GLsizeiptr>(byte_count),
|
||||||
|
static_cast<GLbitfield>(access));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void unmap_opengl_buffer(std::uint32_t target) noexcept
|
||||||
|
{
|
||||||
|
glUnmapBuffer(static_cast<GLenum>(target));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pp::renderer::gl::OpenGlPixelBufferAllocationDispatch pixel_buffer_allocation_dispatch() noexcept
|
||||||
|
{
|
||||||
|
return pp::renderer::gl::OpenGlPixelBufferAllocationDispatch {
|
||||||
|
.gen_buffers = gen_opengl_buffers,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pp::renderer::gl::OpenGlPixelBufferReadbackDispatch pixel_buffer_readback_dispatch() noexcept
|
||||||
|
{
|
||||||
|
return pp::renderer::gl::OpenGlPixelBufferReadbackDispatch {
|
||||||
|
.gen_buffers = gen_opengl_buffers,
|
||||||
|
.bind_buffer = bind_opengl_buffer,
|
||||||
|
.buffer_data = set_opengl_buffer_data,
|
||||||
|
.read_pixels = pp::legacy::gl_framebuffer::read_opengl_pixels,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pp::renderer::gl::OpenGlPixelBufferMapDispatch pixel_buffer_map_dispatch() noexcept
|
||||||
|
{
|
||||||
|
return pp::renderer::gl::OpenGlPixelBufferMapDispatch {
|
||||||
|
.bind_buffer = bind_opengl_buffer,
|
||||||
|
.map_buffer_range = map_opengl_buffer_range,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pp::renderer::gl::OpenGlPixelBufferUnmapDispatch pixel_buffer_unmap_dispatch() noexcept
|
||||||
|
{
|
||||||
|
return pp::renderer::gl::OpenGlPixelBufferUnmapDispatch {
|
||||||
|
.bind_buffer = bind_opengl_buffer,
|
||||||
|
.unmap_buffer = unmap_opengl_buffer,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pp::renderer::gl::OpenGlPixelBufferDeleteDispatch pixel_buffer_delete_dispatch() noexcept
|
||||||
|
{
|
||||||
|
return pp::renderer::gl::OpenGlPixelBufferDeleteDispatch {
|
||||||
|
.delete_buffers = delete_opengl_buffers,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace pp::legacy::gl_pixel_buffer
|
||||||
154
src/legacy_gl_sampler_dispatch.h
Normal file
154
src/legacy_gl_sampler_dispatch.h
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "renderer_gl/opengl_capabilities.h"
|
||||||
|
|
||||||
|
namespace pp::legacy::gl_sampler {
|
||||||
|
|
||||||
|
inline void gen_opengl_samplers(std::uint32_t count, std::uint32_t* ids) noexcept
|
||||||
|
{
|
||||||
|
#if USE_SAMPLER
|
||||||
|
glGenSamplers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
|
||||||
|
#else
|
||||||
|
for (std::uint32_t i = 0U; i < count; ++i) {
|
||||||
|
ids[i] = 0U;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_opengl_sampler_parameter_i(
|
||||||
|
std::uint32_t sampler,
|
||||||
|
std::uint32_t parameter,
|
||||||
|
std::int32_t value) noexcept
|
||||||
|
{
|
||||||
|
#if USE_SAMPLER
|
||||||
|
glSamplerParameteri(
|
||||||
|
static_cast<GLuint>(sampler),
|
||||||
|
static_cast<GLenum>(parameter),
|
||||||
|
static_cast<GLint>(value));
|
||||||
|
#else
|
||||||
|
(void)sampler;
|
||||||
|
(void)parameter;
|
||||||
|
(void)value;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_opengl_sampler_parameter_fv(
|
||||||
|
std::uint32_t sampler,
|
||||||
|
std::uint32_t parameter,
|
||||||
|
const float* values) noexcept
|
||||||
|
{
|
||||||
|
#if USE_SAMPLER && !defined(__GLES__)
|
||||||
|
glSamplerParameterfv(
|
||||||
|
static_cast<GLuint>(sampler),
|
||||||
|
static_cast<GLenum>(parameter),
|
||||||
|
values);
|
||||||
|
#else
|
||||||
|
(void)sampler;
|
||||||
|
(void)parameter;
|
||||||
|
(void)values;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void bind_opengl_sampler(std::uint32_t unit, std::uint32_t sampler) noexcept
|
||||||
|
{
|
||||||
|
#if USE_SAMPLER
|
||||||
|
glBindSampler(static_cast<GLuint>(unit), static_cast<GLuint>(sampler));
|
||||||
|
#else
|
||||||
|
(void)unit;
|
||||||
|
(void)sampler;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pp::renderer::gl::OpenGlSamplerCreateDispatch sampler_create_dispatch() noexcept
|
||||||
|
{
|
||||||
|
return pp::renderer::gl::OpenGlSamplerCreateDispatch {
|
||||||
|
.gen_samplers = gen_opengl_samplers,
|
||||||
|
.sampler_parameter_i = set_opengl_sampler_parameter_i,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pp::renderer::gl::OpenGlSamplerParameterDispatch sampler_parameter_dispatch() noexcept
|
||||||
|
{
|
||||||
|
return pp::renderer::gl::OpenGlSamplerParameterDispatch {
|
||||||
|
.sampler_parameter_i = set_opengl_sampler_parameter_i,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pp::renderer::gl::OpenGlSamplerBorderDispatch sampler_border_dispatch() noexcept
|
||||||
|
{
|
||||||
|
return pp::renderer::gl::OpenGlSamplerBorderDispatch {
|
||||||
|
.sampler_parameter_fv = set_opengl_sampler_parameter_fv,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pp::renderer::gl::OpenGlSamplerBindDispatch sampler_bind_dispatch() noexcept
|
||||||
|
{
|
||||||
|
return pp::renderer::gl::OpenGlSamplerBindDispatch {
|
||||||
|
.bind_sampler = bind_opengl_sampler,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::uint32_t create_sampler(
|
||||||
|
std::span<const pp::renderer::gl::OpenGlTextureParameter> parameters,
|
||||||
|
const char* context)
|
||||||
|
{
|
||||||
|
const auto result = pp::renderer::gl::create_opengl_sampler(parameters, sampler_create_dispatch());
|
||||||
|
if (!result.ok()) {
|
||||||
|
LOG("%s failed because: %s", context, result.status().message);
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
return result.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool set_sampler_parameters(
|
||||||
|
std::uint32_t sampler_id,
|
||||||
|
std::span<const pp::renderer::gl::OpenGlTextureParameter> parameters,
|
||||||
|
const char* context)
|
||||||
|
{
|
||||||
|
const auto status = pp::renderer::gl::set_opengl_sampler_parameters(
|
||||||
|
sampler_id,
|
||||||
|
parameters,
|
||||||
|
sampler_parameter_dispatch());
|
||||||
|
if (!status.ok()) {
|
||||||
|
LOG("%s failed because: %s", context, status.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool set_sampler_border_color(
|
||||||
|
std::uint32_t sampler_id,
|
||||||
|
std::uint32_t parameter,
|
||||||
|
const float* rgba,
|
||||||
|
const char* context)
|
||||||
|
{
|
||||||
|
const auto status = pp::renderer::gl::set_opengl_sampler_border_color(
|
||||||
|
sampler_id,
|
||||||
|
parameter,
|
||||||
|
rgba,
|
||||||
|
sampler_border_dispatch());
|
||||||
|
if (!status.ok()) {
|
||||||
|
LOG("%s failed because: %s", context, status.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool bind_sampler(std::uint32_t unit, std::uint32_t sampler_id, const char* context)
|
||||||
|
{
|
||||||
|
const auto status = pp::renderer::gl::bind_opengl_sampler_object(
|
||||||
|
unit,
|
||||||
|
sampler_id,
|
||||||
|
sampler_bind_dispatch());
|
||||||
|
if (!status.ok()) {
|
||||||
|
LOG("%s failed because: %s", context, status.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace pp::legacy::gl_sampler
|
||||||
90
src/rtt.cpp
90
src/rtt.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "legacy_gl_framebuffer_dispatch.h"
|
#include "legacy_gl_framebuffer_dispatch.h"
|
||||||
|
#include "legacy_gl_pixel_buffer_dispatch.h"
|
||||||
#include "legacy_gl_renderbuffer_dispatch.h"
|
#include "legacy_gl_renderbuffer_dispatch.h"
|
||||||
#include "legacy_gl_texture_dispatch.h"
|
#include "legacy_gl_texture_dispatch.h"
|
||||||
#include "renderer_gl/opengl_capabilities.h"
|
#include "renderer_gl/opengl_capabilities.h"
|
||||||
@@ -32,52 +33,6 @@ void set_opengl_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::
|
|||||||
glColorMask(r, g, b, a);
|
glColorMask(r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gen_opengl_buffers(std::uint32_t count, std::uint32_t* ids) noexcept
|
|
||||||
{
|
|
||||||
glGenBuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
|
|
||||||
}
|
|
||||||
|
|
||||||
void delete_opengl_buffers(std::uint32_t count, const std::uint32_t* ids) noexcept
|
|
||||||
{
|
|
||||||
glDeleteBuffers(static_cast<GLsizei>(count), reinterpret_cast<const GLuint*>(ids));
|
|
||||||
}
|
|
||||||
|
|
||||||
void bind_opengl_buffer(std::uint32_t target, std::uint32_t buffer) noexcept
|
|
||||||
{
|
|
||||||
glBindBuffer(static_cast<GLenum>(target), static_cast<GLuint>(buffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_opengl_buffer_data(
|
|
||||||
std::uint32_t target,
|
|
||||||
std::intptr_t byte_count,
|
|
||||||
const void* data,
|
|
||||||
std::uint32_t usage) noexcept
|
|
||||||
{
|
|
||||||
glBufferData(
|
|
||||||
static_cast<GLenum>(target),
|
|
||||||
static_cast<GLsizeiptr>(byte_count),
|
|
||||||
data,
|
|
||||||
static_cast<GLenum>(usage));
|
|
||||||
}
|
|
||||||
|
|
||||||
void* map_opengl_buffer_range(
|
|
||||||
std::uint32_t target,
|
|
||||||
std::intptr_t offset,
|
|
||||||
std::intptr_t byte_count,
|
|
||||||
std::uint32_t access) noexcept
|
|
||||||
{
|
|
||||||
return glMapBufferRange(
|
|
||||||
static_cast<GLenum>(target),
|
|
||||||
static_cast<GLintptr>(offset),
|
|
||||||
static_cast<GLsizeiptr>(byte_count),
|
|
||||||
static_cast<GLbitfield>(access));
|
|
||||||
}
|
|
||||||
|
|
||||||
void unmap_opengl_buffer(std::uint32_t target) noexcept
|
|
||||||
{
|
|
||||||
glUnmapBuffer(static_cast<GLenum>(target));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RTT& RTT::operator=(RTT&& other)
|
RTT& RTT::operator=(RTT&& other)
|
||||||
@@ -686,9 +641,7 @@ bool PBO::create() noexcept
|
|||||||
{
|
{
|
||||||
App::I->render_task([this] {
|
App::I->render_task([this] {
|
||||||
const auto result = pp::renderer::gl::allocate_opengl_pixel_buffer(
|
const auto result = pp::renderer::gl::allocate_opengl_pixel_buffer(
|
||||||
pp::renderer::gl::OpenGlPixelBufferAllocationDispatch {
|
pp::legacy::gl_pixel_buffer::pixel_buffer_allocation_dispatch());
|
||||||
.gen_buffers = gen_opengl_buffers,
|
|
||||||
});
|
|
||||||
if (!result.ok()) {
|
if (!result.ok()) {
|
||||||
LOG("%s", result.status().message);
|
LOG("%s", result.status().message);
|
||||||
buffer_id = 0U;
|
buffer_id = 0U;
|
||||||
@@ -709,12 +662,7 @@ bool PBO::create(RTT& rtt) noexcept
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
pp::renderer::gl::rgba8_readback_format(),
|
pp::renderer::gl::rgba8_readback_format(),
|
||||||
pp::renderer::gl::OpenGlPixelBufferReadbackDispatch {
|
pp::legacy::gl_pixel_buffer::pixel_buffer_readback_dispatch());
|
||||||
.gen_buffers = gen_opengl_buffers,
|
|
||||||
.bind_buffer = bind_opengl_buffer,
|
|
||||||
.buffer_data = set_opengl_buffer_data,
|
|
||||||
.read_pixels = pp::legacy::gl_framebuffer::read_opengl_pixels,
|
|
||||||
});
|
|
||||||
rtt.unbindFramebuffer();
|
rtt.unbindFramebuffer();
|
||||||
if (!result.ok()) {
|
if (!result.ok()) {
|
||||||
LOG("%s", result.status().message);
|
LOG("%s", result.status().message);
|
||||||
@@ -733,9 +681,7 @@ void PBO::destroy() noexcept
|
|||||||
App::I->render_task_async([id=buffer_id] {
|
App::I->render_task_async([id=buffer_id] {
|
||||||
const auto status = pp::renderer::gl::delete_opengl_pixel_buffer(
|
const auto status = pp::renderer::gl::delete_opengl_pixel_buffer(
|
||||||
id,
|
id,
|
||||||
pp::renderer::gl::OpenGlPixelBufferDeleteDispatch {
|
pp::legacy::gl_pixel_buffer::pixel_buffer_delete_dispatch());
|
||||||
.delete_buffers = delete_opengl_buffers,
|
|
||||||
});
|
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
LOG("%s", status.message);
|
LOG("%s", status.message);
|
||||||
}
|
}
|
||||||
@@ -748,24 +694,6 @@ void PBO::destroy() noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void PBO::bind_read() noexcept
|
|
||||||
{
|
|
||||||
App::I->render_task([this] {
|
|
||||||
const auto buffer_target = static_cast<GLenum>(pp::renderer::gl::pixel_unpack_buffer_target());
|
|
||||||
glBindBuffer(buffer_target, buffer_id);
|
|
||||||
bound_slot = buffer_target;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void PBO::unbind() noexcept
|
|
||||||
{
|
|
||||||
App::I->render_task([this] {
|
|
||||||
glBindBuffer(bound_slot, buffer_id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
glm::uint8_t* PBO::map() noexcept
|
glm::uint8_t* PBO::map() noexcept
|
||||||
{
|
{
|
||||||
App::I->render_task([this] {
|
App::I->render_task([this] {
|
||||||
@@ -774,10 +702,7 @@ glm::uint8_t* PBO::map() noexcept
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
pp::renderer::gl::rgba8_readback_format(),
|
pp::renderer::gl::rgba8_readback_format(),
|
||||||
pp::renderer::gl::OpenGlPixelBufferMapDispatch {
|
pp::legacy::gl_pixel_buffer::pixel_buffer_map_dispatch());
|
||||||
.bind_buffer = bind_opengl_buffer,
|
|
||||||
.map_buffer_range = map_opengl_buffer_range,
|
|
||||||
});
|
|
||||||
if (!result.ok()) {
|
if (!result.ok()) {
|
||||||
LOG("%s", result.status().message);
|
LOG("%s", result.status().message);
|
||||||
mapped_ptr = nullptr;
|
mapped_ptr = nullptr;
|
||||||
@@ -793,10 +718,7 @@ void PBO::unmap() noexcept
|
|||||||
App::I->render_task([this] {
|
App::I->render_task([this] {
|
||||||
const auto status = pp::renderer::gl::unmap_opengl_pixel_buffer(
|
const auto status = pp::renderer::gl::unmap_opengl_pixel_buffer(
|
||||||
buffer_id,
|
buffer_id,
|
||||||
pp::renderer::gl::OpenGlPixelBufferUnmapDispatch {
|
pp::legacy::gl_pixel_buffer::pixel_buffer_unmap_dispatch());
|
||||||
.bind_buffer = bind_opengl_buffer,
|
|
||||||
.unmap_buffer = unmap_opengl_buffer,
|
|
||||||
});
|
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
LOG("%s", status.message);
|
LOG("%s", status.message);
|
||||||
}
|
}
|
||||||
|
|||||||
112
src/texture.cpp
112
src/texture.cpp
@@ -4,70 +4,12 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "legacy_gl_framebuffer_dispatch.h"
|
#include "legacy_gl_framebuffer_dispatch.h"
|
||||||
|
#include "legacy_gl_sampler_dispatch.h"
|
||||||
#include "legacy_gl_texture_dispatch.h"
|
#include "legacy_gl_texture_dispatch.h"
|
||||||
#include "renderer_gl/opengl_capabilities.h"
|
#include "renderer_gl/opengl_capabilities.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
void gen_opengl_samplers(std::uint32_t count, std::uint32_t* ids) noexcept
|
|
||||||
{
|
|
||||||
#if USE_SAMPLER
|
|
||||||
glGenSamplers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
|
|
||||||
#else
|
|
||||||
for (std::uint32_t i = 0U; i < count; ++i) {
|
|
||||||
ids[i] = 0U;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_opengl_sampler_parameter_i(
|
|
||||||
std::uint32_t sampler,
|
|
||||||
std::uint32_t parameter,
|
|
||||||
std::int32_t value) noexcept
|
|
||||||
{
|
|
||||||
#if USE_SAMPLER
|
|
||||||
glSamplerParameteri(
|
|
||||||
static_cast<GLuint>(sampler),
|
|
||||||
static_cast<GLenum>(parameter),
|
|
||||||
static_cast<GLint>(value));
|
|
||||||
#else
|
|
||||||
(void)sampler;
|
|
||||||
(void)parameter;
|
|
||||||
(void)value;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_opengl_sampler_parameter_fv(
|
|
||||||
std::uint32_t sampler,
|
|
||||||
std::uint32_t parameter,
|
|
||||||
const float* values) noexcept
|
|
||||||
{
|
|
||||||
#if USE_SAMPLER && !defined(__GLES__)
|
|
||||||
glSamplerParameterfv(
|
|
||||||
static_cast<GLuint>(sampler),
|
|
||||||
static_cast<GLenum>(parameter),
|
|
||||||
values);
|
|
||||||
#else
|
|
||||||
(void)sampler;
|
|
||||||
(void)parameter;
|
|
||||||
(void)values;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void bind_opengl_sampler(std::uint32_t unit, std::uint32_t sampler) noexcept
|
|
||||||
{
|
|
||||||
#if USE_SAMPLER
|
|
||||||
glBindSampler(static_cast<GLuint>(unit), static_cast<GLuint>(sampler));
|
|
||||||
#else
|
|
||||||
(void)unit;
|
|
||||||
(void)sampler;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<uint16_t, Texture2D> TextureManager::m_textures;
|
std::map<uint16_t, Texture2D> TextureManager::m_textures;
|
||||||
std::array<int, 6> TextureCube::m_faces_map {
|
std::array<int, 6> TextureCube::m_faces_map {
|
||||||
static_cast<int>(pp::renderer::gl::cube_face_texture_target(0U)),
|
static_cast<int>(pp::renderer::gl::cube_face_texture_target(0U)),
|
||||||
@@ -419,19 +361,15 @@ bool Sampler::create(GLint filter, GLint wrap)
|
|||||||
const auto parameters = pp::renderer::gl::sampler_parameters_for_filter_wrap(
|
const auto parameters = pp::renderer::gl::sampler_parameters_for_filter_wrap(
|
||||||
static_cast<std::uint32_t>(filter),
|
static_cast<std::uint32_t>(filter),
|
||||||
static_cast<std::uint32_t>(wrap));
|
static_cast<std::uint32_t>(wrap));
|
||||||
const auto sampler = pp::renderer::gl::create_opengl_sampler(
|
const auto sampler = pp::legacy::gl_sampler::create_sampler(
|
||||||
parameters,
|
parameters,
|
||||||
pp::renderer::gl::OpenGlSamplerCreateDispatch {
|
"Sampler::create()");
|
||||||
.gen_samplers = gen_opengl_samplers,
|
if (sampler == 0U)
|
||||||
.sampler_parameter_i = set_opengl_sampler_parameter_i,
|
|
||||||
});
|
|
||||||
if (!sampler.ok())
|
|
||||||
{
|
{
|
||||||
ret = false;
|
ret = false;
|
||||||
LOG("Sampler::create() failed because: %s", sampler.status().message);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
id = static_cast<GLuint>(sampler.value());
|
id = static_cast<GLuint>(sampler);
|
||||||
ret = true;
|
ret = true;
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
@@ -456,14 +394,10 @@ void Sampler::set(GLint filter, GLint wrap)
|
|||||||
const auto parameters = pp::renderer::gl::sampler_parameters_for_filter_wrap(
|
const auto parameters = pp::renderer::gl::sampler_parameters_for_filter_wrap(
|
||||||
static_cast<std::uint32_t>(filter),
|
static_cast<std::uint32_t>(filter),
|
||||||
static_cast<std::uint32_t>(wrap));
|
static_cast<std::uint32_t>(wrap));
|
||||||
const auto status = pp::renderer::gl::set_opengl_sampler_parameters(
|
pp::legacy::gl_sampler::set_sampler_parameters(
|
||||||
static_cast<std::uint32_t>(id),
|
static_cast<std::uint32_t>(id),
|
||||||
parameters,
|
parameters,
|
||||||
pp::renderer::gl::OpenGlSamplerParameterDispatch {
|
"Sampler::set()");
|
||||||
.sampler_parameter_i = set_opengl_sampler_parameter_i,
|
|
||||||
});
|
|
||||||
if (!status.ok())
|
|
||||||
LOG("Sampler::set() failed because: %s", status.message);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,54 +420,38 @@ void Sampler::set_filter(GLint filter_min, GLint filter_mag)
|
|||||||
const auto parameters = pp::renderer::gl::sampler_filter_parameters(
|
const auto parameters = pp::renderer::gl::sampler_filter_parameters(
|
||||||
static_cast<std::uint32_t>(filter_min),
|
static_cast<std::uint32_t>(filter_min),
|
||||||
static_cast<std::uint32_t>(filter_mag));
|
static_cast<std::uint32_t>(filter_mag));
|
||||||
const auto status = pp::renderer::gl::set_opengl_sampler_parameters(
|
pp::legacy::gl_sampler::set_sampler_parameters(
|
||||||
static_cast<std::uint32_t>(id),
|
static_cast<std::uint32_t>(id),
|
||||||
parameters,
|
parameters,
|
||||||
pp::renderer::gl::OpenGlSamplerParameterDispatch {
|
"Sampler::set_filter()");
|
||||||
.sampler_parameter_i = set_opengl_sampler_parameter_i,
|
|
||||||
});
|
|
||||||
if (!status.ok())
|
|
||||||
LOG("Sampler::set_filter() failed because: %s", status.message);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
void Sampler::set_border(glm::vec4 rgba)
|
void Sampler::set_border(glm::vec4 rgba)
|
||||||
{
|
{
|
||||||
App::I->render_task([this, rgba]
|
App::I->render_task([this, rgba]
|
||||||
{
|
{
|
||||||
const auto status = pp::renderer::gl::set_opengl_sampler_border_color(
|
pp::legacy::gl_sampler::set_sampler_border_color(
|
||||||
static_cast<std::uint32_t>(id),
|
static_cast<std::uint32_t>(id),
|
||||||
pp::renderer::gl::sampler_border_color_parameter_name(),
|
pp::renderer::gl::sampler_border_color_parameter_name(),
|
||||||
glm::value_ptr(rgba),
|
glm::value_ptr(rgba),
|
||||||
pp::renderer::gl::OpenGlSamplerBorderDispatch {
|
"Sampler::set_border()");
|
||||||
.sampler_parameter_fv = set_opengl_sampler_parameter_fv,
|
|
||||||
});
|
|
||||||
if (!status.ok())
|
|
||||||
LOG("Sampler::set_border() failed because: %s", status.message);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
void Sampler::bind(int unit) const
|
void Sampler::bind(int unit) const
|
||||||
{
|
{
|
||||||
assert(App::I->is_render_thread());
|
assert(App::I->is_render_thread());
|
||||||
current_unit = unit;
|
current_unit = unit;
|
||||||
const auto status = pp::renderer::gl::bind_opengl_sampler_object(
|
pp::legacy::gl_sampler::bind_sampler(
|
||||||
static_cast<std::uint32_t>(unit),
|
static_cast<std::uint32_t>(unit),
|
||||||
static_cast<std::uint32_t>(id),
|
static_cast<std::uint32_t>(id),
|
||||||
pp::renderer::gl::OpenGlSamplerBindDispatch {
|
"Sampler::bind()");
|
||||||
.bind_sampler = bind_opengl_sampler,
|
|
||||||
});
|
|
||||||
if (!status.ok())
|
|
||||||
LOG("Sampler::bind() failed because: %s", status.message);
|
|
||||||
}
|
}
|
||||||
void Sampler::unbind()
|
void Sampler::unbind()
|
||||||
{
|
{
|
||||||
assert(App::I->is_render_thread());
|
assert(App::I->is_render_thread());
|
||||||
const auto status = pp::renderer::gl::bind_opengl_sampler_object(
|
pp::legacy::gl_sampler::bind_sampler(
|
||||||
static_cast<std::uint32_t>(current_unit),
|
static_cast<std::uint32_t>(current_unit),
|
||||||
0U,
|
0U,
|
||||||
pp::renderer::gl::OpenGlSamplerBindDispatch {
|
"Sampler::unbind()");
|
||||||
.bind_sampler = bind_opengl_sampler,
|
|
||||||
});
|
|
||||||
if (!status.ok())
|
|
||||||
LOG("Sampler::unbind() failed because: %s", status.message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user