Progress
This commit is contained in:
@ -26,5 +26,5 @@ target_include_directories(${DAWN_TARGET_NAME}
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(assert)
|
||||
# add_subdirectory(display)
|
||||
add_subdirectory(display)
|
||||
# add_subdirectory(scene)
|
69
src/dawnopengl/display/BackBufferRenderTarget.cpp
Normal file
69
src/dawnopengl/display/BackBufferRenderTarget.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "dawnopengl.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
#include "assert/assertgl.hpp"
|
||||
#include "util/Flag.hpp"
|
||||
#include "BackBufferRenderTarget.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
BackBufferRenderTarget::BackBufferRenderTarget() {
|
||||
|
||||
}
|
||||
|
||||
float_t BackBufferRenderTarget::getScale() {
|
||||
return this->scale;
|
||||
}
|
||||
|
||||
float_t BackBufferRenderTarget::getWidth() {
|
||||
return this->width;
|
||||
}
|
||||
|
||||
float_t BackBufferRenderTarget::getHeight() {
|
||||
return this->height;
|
||||
}
|
||||
|
||||
void BackBufferRenderTarget::setSize(
|
||||
const float_t width,
|
||||
const float_t height
|
||||
) {
|
||||
if(this->width == width && this->height == height) return;
|
||||
|
||||
// Fixes a new bug that it seems GLFW has introduced.
|
||||
this->width = width == 0 ? 1 : width;
|
||||
this->height = height == 0 ? 1 : height;
|
||||
// this->eventRenderTargetResized.invoke(*this, width, height);
|
||||
}
|
||||
|
||||
void BackBufferRenderTarget::setClearColor(const struct Color color) {
|
||||
this->clearColor = color;
|
||||
}
|
||||
|
||||
void BackBufferRenderTarget::clear(
|
||||
const enum RenderTargetClearFlag clearFlags
|
||||
) {
|
||||
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
||||
assertNoGLError();
|
||||
|
||||
GLbitfield mask = 0;
|
||||
if(Flag::isOn(clearFlags, RenderTargetClearFlag::COLOR)) {
|
||||
mask |= GL_COLOR_BUFFER_BIT;
|
||||
}
|
||||
if(Flag::isOn(clearFlags, RenderTargetClearFlag::DEPTH)) {
|
||||
mask |= GL_DEPTH_BUFFER_BIT;
|
||||
}
|
||||
|
||||
glClear(mask);
|
||||
assertNoGLError();
|
||||
}
|
||||
|
||||
void BackBufferRenderTarget::bind() {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
assertNoGLError();
|
||||
glViewport(0, 0, (GLsizei)this->width, (GLsizei)this->height);
|
||||
assertNoGLError();
|
||||
}
|
44
src/dawnopengl/display/BackBufferRenderTarget.hpp
Normal file
44
src/dawnopengl/display/BackBufferRenderTarget.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/Color.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class BackBufferRenderTarget final : public RenderTarget {
|
||||
private:
|
||||
float_t width = 1;
|
||||
float_t height = 1;
|
||||
struct Color clearColor = COLOR_CORNFLOWER_BLUE;
|
||||
|
||||
public:
|
||||
float_t scale = 1.0f;
|
||||
|
||||
/**
|
||||
* Construct the back buffer render target.
|
||||
*/
|
||||
BackBufferRenderTarget();
|
||||
|
||||
float_t getScale() override;
|
||||
float_t getWidth() override;
|
||||
float_t getHeight() override;
|
||||
void setClearColor(const struct Color color) override;
|
||||
void clear(const enum RenderTargetClearFlag) override;
|
||||
void bind() override;
|
||||
|
||||
/**
|
||||
* Requests to modify the viewport directly. This is mostly to be called
|
||||
* by whatever is setting the window/display resolution, so that the
|
||||
* backbuffer can keep track of what the viewport size is. This should
|
||||
* also be DPI aware, e.g. "4k @ 2xDPI, resulting in a 1080p equiv" should
|
||||
* still call this method with 3840, 2160.
|
||||
*
|
||||
* @param width New width of the back buffer.
|
||||
* @param height New height of the back buffer.
|
||||
*/
|
||||
void setSize(const float_t width, const float_t height);
|
||||
};
|
||||
}
|
@ -4,13 +4,10 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
# target_sources(${DAWN_TARGET_NAME}
|
||||
# PRIVATE
|
||||
# RenderManager.cpp
|
||||
# BackBufferRenderTarget.cpp
|
||||
# Texture.cpp
|
||||
# TextureRenderTarget.cpp
|
||||
# )
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
BackBufferRenderTarget.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(mesh)
|
@ -22,7 +22,7 @@ void Mesh::createBuffers(
|
||||
this->indiceCount = indiceCount;
|
||||
|
||||
auto sizePos = sizeof(glm::vec3) * verticeCount;
|
||||
auto sizeInds = sizeof(meshindice_t) * indiceCount;
|
||||
auto sizeInds = sizeof(int32_t) * indiceCount;
|
||||
auto sizeCoords = sizeof(glm::vec2) * verticeCount;
|
||||
|
||||
// Generate vertex array, I don't think I need to do this tbh.
|
||||
@ -160,8 +160,8 @@ void Mesh::bufferIndices(
|
||||
assertNoGLError();
|
||||
glBufferSubData(
|
||||
GL_ELEMENT_ARRAY_BUFFER,
|
||||
sizeof(meshindice_t) * pos,
|
||||
sizeof(meshindice_t) * len,
|
||||
sizeof(int32_t) * pos,
|
||||
sizeof(int32_t) * len,
|
||||
(void*)indices
|
||||
);
|
||||
assertNoGLError();
|
||||
|
Reference in New Issue
Block a user