"VRam List" wrapped for VBO (useful later)
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 6m25s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 6m25s
This commit is contained in:
@@ -16,4 +16,21 @@ namespace JGL {
|
||||
inline bool operator&(Direction a, Direction b) {
|
||||
return (u8)a & (u8)b;
|
||||
}
|
||||
}
|
||||
|
||||
static std::string to_string(JGL::Direction direction) {
|
||||
switch (direction) {
|
||||
case JGL::Direction::None:
|
||||
return "None";
|
||||
case JGL::Direction::Vertical:
|
||||
return "Vertical";
|
||||
case JGL::Direction::Horizontal:
|
||||
return "Horizontal";
|
||||
case JGL::Direction::Diagonal_NWSE:
|
||||
return "Diagonal_NWSE";
|
||||
case JGL::Direction::Diagonal_SWNE:
|
||||
return "Diagonal_SWNE";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
30
include/JGL/types/VRamList.h
Normal file
30
include/JGL/types/VRamList.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <J3ML/LinearAlgebra/Vector3.hpp>
|
||||
#include <J3ML/LinearAlgebra/Vector4.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace JGL {
|
||||
class VRamList;
|
||||
}
|
||||
|
||||
/// A wrapper for VBO, Storing texture coordinates or vertices or indices in vram.
|
||||
/// For J2D, We can't really store the vertices into vram. But we can store the texture coordinates.
|
||||
class JGL::VRamList {
|
||||
private:
|
||||
GLuint list_handle = 0;
|
||||
void load(const GLfloat* data, const long& size);
|
||||
void load(const GLuint* data, const long& size);
|
||||
public:
|
||||
VRamList() = default;
|
||||
VRamList(const GLfloat* data, const long& size);
|
||||
VRamList(Vector2* data, const long& size);
|
||||
VRamList(Vector3* data, const long& size);
|
||||
VRamList(Vector4* data, const long& size);
|
||||
VRamList(const GLuint* data, const long& size);
|
||||
public:
|
||||
[[nodiscard]] GLuint GetHandle() const;
|
||||
void Erase();
|
||||
};
|
33
main.cpp
33
main.cpp
@@ -119,14 +119,11 @@ public:
|
||||
float fov = 90;
|
||||
float sprite_radians = 0;
|
||||
bool fov_increasing = true;
|
||||
unsigned long long frames = 0;
|
||||
bool framerate_measurement = false;
|
||||
std::chrono::high_resolution_clock::time_point start;
|
||||
float elapsed = 0.0f;
|
||||
float fps = 0.0f;
|
||||
|
||||
void display() {
|
||||
if (framerate_measurement)
|
||||
start = std::chrono::high_resolution_clock::now();
|
||||
start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
JGL::Update(getSize());
|
||||
if (fov_increasing)
|
||||
@@ -157,8 +154,9 @@ public:
|
||||
J3D::End();
|
||||
|
||||
|
||||
J2D::Begin(j2d_render_target, true);
|
||||
J2D::Begin();
|
||||
J2D::FillRect(Colors::Blue, {0,52}, {100,100});
|
||||
J2D::DrawSprite(*image, {300, 300}, 0, {0,0}, {1, 1}, Colors::White, Direction::Vertical | Direction::Horizontal);
|
||||
J2D::DrawMirrorSprite(*image, {400, 300}, Direction::Horizontal | Direction::Vertical, sprite_radians, {0.5,0.5}, {1, 1}, Colors::White);
|
||||
J2D::DrawPartialSprite(*image, {225, 300}, image->GetDimensions() * 0.25, image->GetDimensions() * 0.75, sprite_radians, {0.5, 0.5});
|
||||
J2D::FillRect(Colors::Pinks::HotPink, {68, 120}, {32, 32});
|
||||
@@ -178,6 +176,7 @@ public:
|
||||
J2D::DrawString(Colors::Green, "Jupteroid Font", 0.f, 0, 1.f, 16, Jupiteroid);
|
||||
J2D::DrawString(Colors::White, "Position: " + std::to_string(camera->position.x) + " " + std::to_string(camera->position.y) + " " + std::to_string(camera->position.z), 0, 16, 1,16, Jupiteroid);
|
||||
J2D::DrawString(Colors::White, "ViewAngle: " + std::to_string(camera->angle.x) + " " + std::to_string(camera->angle.y) + " " + std::to_string(camera->angle.z), 0, 33, 1,16, Jupiteroid);
|
||||
J2D::DrawString(Colors::White, "Framerate: " + std::to_string((int) fps), 0, 48, 1, 16, Jupiteroid);
|
||||
J2D::OutlinePolygon(Colors::White, {{200, 400}, {220, 420}, {220, 430}, {230, 410}, {200, 400}});
|
||||
//J2D::FillPolygon(Colors::White, {{200, 400}, {220, 420}, {220, 430}, {230, 410}, {200, 400}});
|
||||
J2D::DrawCubicBezierCurve(Colors::Blues::CornflowerBlue,
|
||||
@@ -194,25 +193,15 @@ public:
|
||||
J2D::End();
|
||||
|
||||
//Draw the Render Target that we just drew all that stuff onto.
|
||||
/*
|
||||
J2D::Begin();
|
||||
J2D::DrawRenderTargetAsSprite(*j2d_render_target, {0, 0}, sprite_radians * 0.25, {0.5, 0.5}, {1,1}, Colors::White);
|
||||
J2D::DrawRenderTargetAsSprite(*j2d_render_target, {0, 0}, 0, {0.5, 0.5}, {1,1}, Colors::White);
|
||||
J2D::End();
|
||||
*/
|
||||
|
||||
if (framerate_measurement) {
|
||||
frames++;
|
||||
std::chrono::high_resolution_clock::time_point stop = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<float> frame_time = stop - start;
|
||||
elapsed += frame_time.count();
|
||||
if (elapsed >= 1)
|
||||
std::cout << "Framerate: " << frames << std::endl,
|
||||
frames = 0,
|
||||
elapsed = 0,
|
||||
framerate_measurement = false,
|
||||
setVsyncEnabled(true);
|
||||
} else if (isKeyDown(Keys::One))
|
||||
framerate_measurement = true,
|
||||
frames = 0,
|
||||
setVsyncEnabled(false);
|
||||
std::chrono::high_resolution_clock::time_point stop = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<float> frame_time = stop - start;
|
||||
fps = 1.0f / frame_time.count();
|
||||
}
|
||||
|
||||
void OnRefresh(float elapsed) override {
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <glad/glad.h>
|
||||
#include <jlog/Logger.hpp>
|
||||
|
||||
#if __linux__
|
||||
#include <freetype2/ft2build.h>
|
||||
@@ -122,6 +123,7 @@ namespace JGL
|
||||
return extents;
|
||||
}
|
||||
|
||||
jlog::Warning("Measuring a font size that is not cached, This is *super* slow.");
|
||||
FT_Set_Pixel_Sizes(this->face, ptSize, ptSize);
|
||||
|
||||
for (const char& c : text) {
|
||||
|
51
src/types/VRamList.cpp
Normal file
51
src/types/VRamList.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <JGL/types/VRamList.h>
|
||||
#include <jlog/Logger.hpp>
|
||||
|
||||
void JGL::VRamList::load(const GLfloat* data, const long& size) {
|
||||
GLint current_array_buffer = 0;
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, ¤t_array_buffer);
|
||||
glGenBuffers(1, &list_handle);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, list_handle);
|
||||
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, current_array_buffer);
|
||||
}
|
||||
|
||||
void JGL::VRamList::load(const GLuint* data, const long& size) {
|
||||
GLint current_element_array_buffer = 0;
|
||||
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, ¤t_element_array_buffer);
|
||||
glGenBuffers(1, &list_handle);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, list_handle);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, current_element_array_buffer);
|
||||
}
|
||||
|
||||
JGL::VRamList::VRamList(const GLfloat* data, const long& size) {
|
||||
load(data, sizeof(GLfloat) * size);
|
||||
}
|
||||
|
||||
JGL::VRamList::VRamList(const GLuint* data, const long& size) {
|
||||
load(data, sizeof(GLuint) * size);
|
||||
}
|
||||
|
||||
JGL::VRamList::VRamList(Vector2* data, const long& size) {
|
||||
load(reinterpret_cast<GLfloat*>(data), sizeof(Vector2) * size);
|
||||
}
|
||||
|
||||
JGL::VRamList::VRamList(Vector3* data, const long& size) {
|
||||
load(reinterpret_cast<GLfloat*>(data), sizeof(Vector3) * size);
|
||||
}
|
||||
|
||||
JGL::VRamList::VRamList(Vector4* data, const long& size) {
|
||||
load(reinterpret_cast<GLfloat*>(data), sizeof(Vector4) * size);
|
||||
}
|
||||
|
||||
void JGL::VRamList::Erase() {
|
||||
if (list_handle == 0)
|
||||
jlog::Warning("Erasing an uninitialized array buffer?");
|
||||
|
||||
glDeleteBuffers(1, &list_handle);
|
||||
}
|
||||
|
||||
GLuint JGL::VRamList::GetHandle() const {
|
||||
return list_handle;
|
||||
}
|
Reference in New Issue
Block a user