[nostalgia] Move glutils into separate library
This commit is contained in:
parent
282bdc0fd7
commit
63e46d7bb4
@ -20,6 +20,7 @@ if(NOSTALGIA_BUILD_PLAYER)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
|
if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
|
||||||
|
add_subdirectory(glutils)
|
||||||
add_subdirectory(tools)
|
add_subdirectory(tools)
|
||||||
if(NOSTALGIA_BUILD_STUDIO)
|
if(NOSTALGIA_BUILD_STUDIO)
|
||||||
add_subdirectory(studio)
|
add_subdirectory(studio)
|
||||||
|
@ -9,6 +9,7 @@ find_package(glfw3 REQUIRED)
|
|||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
NostalgiaCore-GLFW PUBLIC
|
NostalgiaCore-GLFW PUBLIC
|
||||||
glfw::glfw
|
glfw::glfw
|
||||||
|
NostalgiaGlUtils
|
||||||
NostalgiaCore-Userspace
|
NostalgiaCore-Userspace
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ add_library(
|
|||||||
NostalgiaCore-Userspace OBJECT
|
NostalgiaCore-Userspace OBJECT
|
||||||
gfx.cpp
|
gfx.cpp
|
||||||
gfx_opengl.cpp
|
gfx_opengl.cpp
|
||||||
glutils.cpp
|
|
||||||
media.cpp
|
media.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -10,19 +9,13 @@ if(NOT MSVC)
|
|||||||
target_compile_options(NostalgiaCore-Userspace PRIVATE -Wsign-conversion)
|
target_compile_options(NostalgiaCore-Userspace PRIVATE -Wsign-conversion)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(APPLE)
|
|
||||||
find_package(OpenGL REQUIRED)
|
|
||||||
else()
|
|
||||||
set(OPENGL_gl_LIBRARY GL)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
NostalgiaCore-Userspace PUBLIC
|
NostalgiaCore-Userspace PUBLIC
|
||||||
OxClaw
|
OxClaw
|
||||||
OxFS
|
OxFS
|
||||||
OxStd
|
OxStd
|
||||||
NostalgiaCore
|
NostalgiaCore
|
||||||
${OPENGL_gl_LIBRARY}
|
NostalgiaGlUtils
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
#include <ox/std/bit.hpp>
|
#include <ox/std/bit.hpp>
|
||||||
#include <ox/std/fmt.hpp>
|
#include <ox/std/fmt.hpp>
|
||||||
|
|
||||||
|
#include <nostalgia/glutils/glutils.hpp>
|
||||||
|
|
||||||
#include <nostalgia/core/config.hpp>
|
#include <nostalgia/core/config.hpp>
|
||||||
#include <nostalgia/core/gfx.hpp>
|
#include <nostalgia/core/gfx.hpp>
|
||||||
|
|
||||||
#include "glutils.hpp"
|
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
|
||||||
@ -30,10 +30,10 @@ constexpr auto BgVertexVboLength = BgVertexVboRows * BgVertexVboRowLength;
|
|||||||
constexpr auto BgVertexEboLength = 6;
|
constexpr auto BgVertexEboLength = 6;
|
||||||
|
|
||||||
struct Background {
|
struct Background {
|
||||||
GLVertexArray vao;
|
glutils::GLVertexArray vao;
|
||||||
GLBuffer vbo;
|
glutils::GLBuffer vbo;
|
||||||
GLBuffer ebo;
|
glutils::GLBuffer ebo;
|
||||||
GLTexture tex;
|
glutils::GLTexture tex;
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
std::array<float, TileCount * BgVertexVboLength> bgVertices = {};
|
std::array<float, TileCount * BgVertexVboLength> bgVertices = {};
|
||||||
@ -41,7 +41,7 @@ struct Background {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct GlImplData {
|
struct GlImplData {
|
||||||
GLProgram bgShader;
|
glutils::GLProgram bgShader;
|
||||||
int64_t prevFpsCheckTime = 0;
|
int64_t prevFpsCheckTime = 0;
|
||||||
uint64_t draws = 0;
|
uint64_t draws = 0;
|
||||||
std::array<Background, 4> backgrounds;
|
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;
|
GLuint vao = 0;
|
||||||
glGenVertexArrays(1, &vao);
|
glGenVertexArrays(1, &vao);
|
||||||
return GLVertexArray(vao);
|
return glutils::GLVertexArray(vao);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLBuffer genBuffer() noexcept {
|
static glutils::GLBuffer genBuffer() noexcept {
|
||||||
GLuint buff = 0;
|
GLuint buff = 0;
|
||||||
glGenBuffers(1, &buff);
|
glGenBuffers(1, &buff);
|
||||||
return GLBuffer(buff);
|
return glutils::GLBuffer(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *bg) noexcept {
|
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)));
|
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;
|
GLuint texId = 0;
|
||||||
glGenTextures(1, &texId);
|
glGenTextures(1, &texId);
|
||||||
GLTexture tex(texId);
|
glutils::GLTexture tex(texId);
|
||||||
tex.width = w;
|
tex.width = w;
|
||||||
tex.height = h;
|
tex.height = h;
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
@ -208,7 +208,7 @@ static void drawBackgrounds(GlImplData *id) noexcept {
|
|||||||
ox::Error init(Context *ctx) noexcept {
|
ox::Error init(Context *ctx) noexcept {
|
||||||
const auto id = new GlImplData;
|
const auto id = new GlImplData;
|
||||||
ctx->setRendererData(id);
|
ctx->setRendererData(id);
|
||||||
oxReturnError(buildShaderProgram(bgvshad, bgfshad).moveTo(&id->bgShader));
|
oxReturnError(glutils::buildShaderProgram(bgvshad, bgfshad).moveTo(&id->bgShader));
|
||||||
for (auto &bg : id->backgrounds) {
|
for (auto &bg : id->backgrounds) {
|
||||||
initBackgroundBufferset(ctx, id->bgShader, &bg);
|
initBackgroundBufferset(ctx, id->bgShader, &bg);
|
||||||
}
|
}
|
||||||
|
27
src/nostalgia/glutils/CMakeLists.txt
Normal file
27
src/nostalgia/glutils/CMakeLists.txt
Normal 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
|
||||||
|
)
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include "glutils.hpp"
|
#include "glutils.hpp"
|
||||||
|
|
||||||
namespace nostalgia::core::renderer {
|
namespace nostalgia::glutils {
|
||||||
|
|
||||||
void deleteBuffer(GLuint b) noexcept {
|
void deleteBuffer(GLuint b) noexcept {
|
||||||
glDeleteBuffers(1, &b);
|
glDeleteBuffers(1, &b);
|
@ -6,6 +6,8 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ox/std/defines.hpp>
|
||||||
|
|
||||||
#define GL_GLEXT_PROTOTYPES 1
|
#define GL_GLEXT_PROTOTYPES 1
|
||||||
#ifdef OX_OS_Darwin
|
#ifdef OX_OS_Darwin
|
||||||
#define GL_SILENCE_DEPRECATION
|
#define GL_SILENCE_DEPRECATION
|
||||||
@ -14,7 +16,7 @@
|
|||||||
#include <GLES3/gl3.h>
|
#include <GLES3/gl3.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace nostalgia::core::renderer {
|
namespace nostalgia::glutils {
|
||||||
|
|
||||||
struct Empty {};
|
struct Empty {};
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user