[nostalgia] Move glutils into separate library

This commit is contained in:
Gary Talent 2021-05-15 02:27:13 -05:00
parent 282bdc0fd7
commit 63e46d7bb4
7 changed files with 48 additions and 24 deletions

View File

@ -20,6 +20,7 @@ if(NOSTALGIA_BUILD_PLAYER)
endif()
if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
add_subdirectory(glutils)
add_subdirectory(tools)
if(NOSTALGIA_BUILD_STUDIO)
add_subdirectory(studio)

View File

@ -9,6 +9,7 @@ find_package(glfw3 REQUIRED)
target_link_libraries(
NostalgiaCore-GLFW PUBLIC
glfw::glfw
NostalgiaGlUtils
NostalgiaCore-Userspace
)

View File

@ -2,7 +2,6 @@ add_library(
NostalgiaCore-Userspace OBJECT
gfx.cpp
gfx_opengl.cpp
glutils.cpp
media.cpp
)
@ -10,19 +9,13 @@ if(NOT MSVC)
target_compile_options(NostalgiaCore-Userspace PRIVATE -Wsign-conversion)
endif()
if(APPLE)
find_package(OpenGL REQUIRED)
else()
set(OPENGL_gl_LIBRARY GL)
endif()
target_link_libraries(
NostalgiaCore-Userspace PUBLIC
OxClaw
OxFS
OxStd
NostalgiaCore
${OPENGL_gl_LIBRARY}
NostalgiaGlUtils
)
install(

View File

@ -11,11 +11,11 @@
#include <ox/std/bit.hpp>
#include <ox/std/fmt.hpp>
#include <nostalgia/glutils/glutils.hpp>
#include <nostalgia/core/config.hpp>
#include <nostalgia/core/gfx.hpp>
#include "glutils.hpp"
namespace nostalgia::core {
@ -30,10 +30,10 @@ constexpr auto BgVertexVboLength = BgVertexVboRows * BgVertexVboRowLength;
constexpr auto BgVertexEboLength = 6;
struct Background {
GLVertexArray vao;
GLBuffer vbo;
GLBuffer ebo;
GLTexture tex;
glutils::GLVertexArray vao;
glutils::GLBuffer vbo;
glutils::GLBuffer ebo;
glutils::GLTexture tex;
bool enabled = false;
bool updated = false;
std::array<float, TileCount * BgVertexVboLength> bgVertices = {};
@ -41,7 +41,7 @@ struct Background {
};
struct GlImplData {
GLProgram bgShader;
glutils::GLProgram bgShader;
int64_t prevFpsCheckTime = 0;
uint64_t draws = 0;
std::array<Background, 4> backgrounds;
@ -119,16 +119,16 @@ static void initBackgroundBufferObjects(Context *ctx, Background *bg) noexcept {
}
}
static GLVertexArray genVertexArrayObject() noexcept {
static glutils::GLVertexArray genVertexArrayObject() noexcept {
GLuint vao = 0;
glGenVertexArrays(1, &vao);
return GLVertexArray(vao);
return glutils::GLVertexArray(vao);
}
static GLBuffer genBuffer() noexcept {
static glutils::GLBuffer genBuffer() noexcept {
GLuint buff = 0;
glGenBuffers(1, &buff);
return GLBuffer(buff);
return glutils::GLBuffer(buff);
}
static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *bg) noexcept {
@ -151,10 +151,10 @@ static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *bg)
ox::bit_cast<void*>(2 * sizeof(float)));
}
static GLTexture loadTexture(GLsizei w, GLsizei h, void *pixels) noexcept {
static glutils::GLTexture loadTexture(GLsizei w, GLsizei h, void *pixels) noexcept {
GLuint texId = 0;
glGenTextures(1, &texId);
GLTexture tex(texId);
glutils::GLTexture tex(texId);
tex.width = w;
tex.height = h;
glActiveTexture(GL_TEXTURE0);
@ -208,7 +208,7 @@ static void drawBackgrounds(GlImplData *id) noexcept {
ox::Error init(Context *ctx) noexcept {
const auto id = new GlImplData;
ctx->setRendererData(id);
oxReturnError(buildShaderProgram(bgvshad, bgfshad).moveTo(&id->bgShader));
oxReturnError(glutils::buildShaderProgram(bgvshad, bgfshad).moveTo(&id->bgShader));
for (auto &bg : id->backgrounds) {
initBackgroundBufferset(ctx, id->bgShader, &bg);
}

View File

@ -0,0 +1,27 @@
add_library(
NostalgiaGlUtils OBJECT
glutils.cpp
)
if(NOT MSVC)
target_compile_options(NostalgiaGlUtils PRIVATE -Wsign-conversion)
endif()
if(APPLE)
find_package(OpenGL REQUIRED)
else()
set(OPENGL_gl_LIBRARY GL)
endif()
target_link_libraries(
NostalgiaGlUtils PUBLIC
OxStd
${OPENGL_gl_LIBRARY}
)
install(
TARGETS
NostalgiaGlUtils
DESTINATION
include/nostalgia/glutils
)

View File

@ -11,7 +11,7 @@
#include "glutils.hpp"
namespace nostalgia::core::renderer {
namespace nostalgia::glutils {
void deleteBuffer(GLuint b) noexcept {
glDeleteBuffers(1, &b);

View File

@ -6,6 +6,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <ox/std/defines.hpp>
#define GL_GLEXT_PROTOTYPES 1
#ifdef OX_OS_Darwin
#define GL_SILENCE_DEPRECATION
@ -14,7 +16,7 @@
#include <GLES3/gl3.h>
#endif
namespace nostalgia::core::renderer {
namespace nostalgia::glutils {
struct Empty {};