[glutils,nostalgia] Ptr to ref changes

This commit is contained in:
2023-12-06 23:56:49 -06:00
parent 7e19f45c69
commit db91ea6a63
4 changed files with 29 additions and 22 deletions

View File

@ -129,8 +129,9 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept {
glGenTextures(1, &fb.color.id);
glBindTexture(GL_TEXTURE_2D, fb.color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb.color, 0);
// depth texture
glGenRenderbuffers(1, &fb.depth.id);
@ -146,21 +147,24 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept {
return fb;
}
void resizeInitFrameBuffer(FrameBuffer *fb, int width, int height) noexcept {
if (!*fb) {
*fb = generateFrameBuffer(width, height);
void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept {
if (!fb) {
fb = generateFrameBuffer(width, height);
return;
}
width = ox::max(1, width);
height = ox::max(1, height);
fb->width = width;
fb->height = height;
glBindFramebuffer(GL_FRAMEBUFFER, *fb);
fb.width = width;
fb.height = height;
glBindFramebuffer(GL_FRAMEBUFFER, fb);
// color texture
glBindTexture(GL_TEXTURE_2D, fb->color);
glBindTexture(GL_TEXTURE_2D, fb.color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// depth texture
glBindRenderbuffer(GL_RENDERBUFFER, fb->depth);
glBindRenderbuffer(GL_RENDERBUFFER, fb.depth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
// restore primary FB
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -168,13 +172,13 @@ void resizeInitFrameBuffer(FrameBuffer *fb, int width, int height) noexcept {
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
void sendVbo(const BufferSet &bs) noexcept {
void sendVbo(BufferSet const&bs) noexcept {
const auto bufferSize = static_cast<GLsizeiptr>(sizeof(decltype(bs.vertices)::value_type) * bs.vertices.size());
glBindBuffer(GL_ARRAY_BUFFER, bs.vbo);
glBufferData(GL_ARRAY_BUFFER, bufferSize, bs.vertices.data(), GL_DYNAMIC_DRAW);
}
void sendEbo(const BufferSet &bs) noexcept {
void sendEbo(BufferSet const&bs) noexcept {
const auto bufferSize = static_cast<GLsizeiptr>(sizeof(decltype(bs.elements)::value_type) * bs.elements.size());
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bs.ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferSize, bs.elements.data(), GL_STATIC_DRAW);

View File

@ -162,7 +162,7 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept;
/**
* Resizes a FrameBuffer, and creates if it does not already exist.
*/
void resizeInitFrameBuffer(FrameBuffer *fb, int width, int height) noexcept;
void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept;
struct BufferSet {
glutils::GLVertexArray vao;
@ -173,9 +173,9 @@ struct BufferSet {
ox::Vector<GLuint> elements;
};
void sendVbo(const BufferSet &bs) noexcept;
void sendEbo(const BufferSet &bs) noexcept;
void sendVbo(BufferSet const&bs) noexcept;
void sendEbo(BufferSet const&bs) noexcept;
void clearScreen() noexcept;