-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Removed an assumption that application will always run using OpenGL 3 - Added support for ES 2/3 - MacOS builds should now be compatible with lower OS versions (Starting with 10.13, High Sierra)
- Loading branch information
Showing
21 changed files
with
1,289 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @file backend.h | ||
* @author Dennis Sitelew | ||
* @date Sep. 14, 2021 | ||
*/ | ||
#ifndef INCLUDE_ASP_RENDER_BACKEND_H | ||
#define INCLUDE_ASP_RENDER_BACKEND_H | ||
|
||
#include <memory> | ||
|
||
namespace asp::render { | ||
|
||
enum class version { opengl2 = 2, opengl3 = 3, gles2 = 20, gles3 = 30 }; | ||
|
||
class frontend; | ||
|
||
class backend { | ||
public: | ||
backend(frontend &v) | ||
: frontend_{&v} {} | ||
|
||
virtual ~backend() = default; | ||
|
||
public: | ||
virtual void init() = 0; | ||
virtual void new_frame() = 0; | ||
virtual void render() = 0; | ||
virtual version get_version() = 0; | ||
|
||
static std::unique_ptr<backend> make(version v, frontend &f); | ||
|
||
protected: | ||
frontend *frontend_; | ||
}; | ||
|
||
} // namespace asp::render | ||
|
||
#endif /* INCLUDE_ASP_RENDER_BACKEND_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// ImGui SDL2 binding with OpenGL2 | ||
// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. | ||
|
||
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. | ||
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). | ||
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. | ||
// https://github.com/ocornut/imgui | ||
|
||
#ifndef IMGUI_IMPL_SDL_ES2 | ||
#define IMGUI_IMPL_SDL_ES2 | ||
|
||
#include <imgui.h> | ||
|
||
struct SDL_Window; | ||
typedef union SDL_Event SDL_Event; | ||
|
||
IMGUI_API bool ImGui_ImplSdlGLES2_Init(); | ||
IMGUI_API void ImGui_ImplSdlGLES2_Shutdown(); | ||
IMGUI_API void ImGui_ImplSdlGLES2_NewFrame(SDL_Window* window); | ||
IMGUI_API void ImGui_ImplSdlGLES2_RenderDrawLists(ImDrawData* draw_data); | ||
|
||
// Use if you want to reset your rendering device without losing ImGui state. | ||
IMGUI_API void ImGui_ImplSdlGLES2_InvalidateDeviceObjects(); | ||
IMGUI_API bool ImGui_ImplSdlGLES2_CreateDeviceObjects(); | ||
|
||
#endif // IMGUI_IMPL_SDL_ES2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// ImGui SDL2 binding with OpenGL3 | ||
// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. | ||
|
||
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. | ||
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). | ||
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. | ||
// https://github.com/ocornut/imgui | ||
|
||
#ifndef IMGUI_IMPL_SDL_ES3 | ||
#define IMGUI_IMPL_SDL_ES3 | ||
|
||
#include <imgui.h> | ||
|
||
struct SDL_Window; | ||
typedef union SDL_Event SDL_Event; | ||
|
||
IMGUI_API bool ImGui_ImplSdlGLES3_Init(); | ||
IMGUI_API void ImGui_ImplSdlGLES3_Shutdown(); | ||
IMGUI_API void ImGui_ImplSdlGLES3_NewFrame(SDL_Window* window); | ||
IMGUI_API void ImGui_ImplSdlGLES3_RenderDrawLists(ImDrawData* draw_data); | ||
|
||
// Use if you want to reset your rendering device without losing ImGui state. | ||
IMGUI_API void ImGui_ImplSdlGLES3_InvalidateDeviceObjects(); | ||
IMGUI_API bool ImGui_ImplSdlGLES3_CreateDeviceObjects(); | ||
|
||
#endif // IMGUI_IMPL_SDL_ES3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @file frontend.h | ||
* @author Dennis Sitelew | ||
* @date Sep. 14, 2021 | ||
*/ | ||
#ifndef INCLUDE_ASP_RENDER_FRONTEND_H | ||
#define INCLUDE_ASP_RENDER_FRONTEND_H | ||
|
||
#include <SDL2/SDL.h> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace asp::render { | ||
|
||
class backend; | ||
|
||
class frontend { | ||
public: | ||
frontend(SDL_Window &window, SDL_GLContext context); | ||
~frontend(); | ||
|
||
public: | ||
void new_frame(); | ||
void render(); | ||
void process_event(const SDL_Event &event); | ||
|
||
const std::string &shader_version() const { return shader_version_; } | ||
|
||
SDL_Window &window() { return *window_; } | ||
|
||
private: | ||
SDL_Window *window_; | ||
std::unique_ptr<backend> backend_; | ||
std::string shader_version_; | ||
}; | ||
|
||
} // namespace asp::render | ||
|
||
#endif /* INCLUDE_ASP_RENDER_FRONTEND_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @file gles2.h | ||
* @author Dennis Sitelew | ||
* @date Sep. 14, 2021 | ||
*/ | ||
#ifndef INCLUDE_ASP_RENDER_GLES2_H | ||
#define INCLUDE_ASP_RENDER_GLES2_H | ||
|
||
#include <asp/render/backend.h> | ||
|
||
namespace asp::render { | ||
|
||
class GLES2 : public backend { | ||
public: | ||
using backend::backend; | ||
~GLES2(); | ||
|
||
public: | ||
void init() override; | ||
void new_frame() override; | ||
void render() override; | ||
|
||
version get_version() override { return version::gles2; } | ||
}; | ||
|
||
} // namespace asp::render | ||
|
||
#endif /* INCLUDE_ASP_RENDER_GLES2_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @file gles3.h | ||
* @author Dennis Sitelew | ||
* @date Sep. 14, 2021 | ||
*/ | ||
#ifndef INCLUDE_ASP_RENDER_GLES3_H | ||
#define INCLUDE_ASP_RENDER_GLES3_H | ||
|
||
#include <asp/render/backend.h> | ||
|
||
namespace asp::render { | ||
|
||
class GLES3 : public backend { | ||
public: | ||
using backend::backend; | ||
~GLES3(); | ||
|
||
public: | ||
void init() override; | ||
void new_frame() override; | ||
void render() override; | ||
|
||
version get_version() override { return version::gles3; } | ||
}; | ||
|
||
} // namespace asp::render | ||
|
||
#endif /* INCLUDE_ASP_RENDER_GLES3_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @file opengl2.h | ||
* @author Dennis Sitelew | ||
* @date Sep. 14, 2021 | ||
*/ | ||
#ifndef INCLUDE_ASP_RENDER_OPENGL2_H | ||
#define INCLUDE_ASP_RENDER_OPENGL2_H | ||
|
||
#include <asp/render/backend.h> | ||
|
||
namespace asp::render { | ||
|
||
class OpenGL2 : public backend { | ||
public: | ||
using backend::backend; | ||
~OpenGL2(); | ||
|
||
public: | ||
void init() override; | ||
void new_frame() override; | ||
void render() override; | ||
|
||
version get_version() override { return version::opengl2; } | ||
}; | ||
|
||
} // namespace asp::render | ||
|
||
#endif /* INCLUDE_ASP_RENDER_OPENGL2_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @file opengl3.h | ||
* @author Dennis Sitelew | ||
* @date Sep. 14, 2021 | ||
*/ | ||
#ifndef INCLUDE_ASP_RENDER_OPENGL3_H | ||
#define INCLUDE_ASP_RENDER_OPENGL3_H | ||
|
||
#include <asp/render/backend.h> | ||
|
||
namespace asp::render { | ||
|
||
class OpenGL3 : public backend { | ||
public: | ||
using backend::backend; | ||
~OpenGL3(); | ||
|
||
public: | ||
void init() override; | ||
void new_frame() override; | ||
void render() override; | ||
|
||
version get_version() override { return version::opengl3; } | ||
}; | ||
|
||
} // namespace asp::render | ||
|
||
#endif /* INCLUDE_ASP_RENDER_OPENGL3_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @file backend.cpp | ||
* @author Dennis Sitelew | ||
* @date Sep. 14, 2021 | ||
*/ | ||
|
||
#include <asp/render/backend.h> | ||
#include <asp/render/opengl2.h> | ||
#include <asp/render/opengl3.h> | ||
#include <asp/render/gles2.h> | ||
#include <asp/render/gles3.h> | ||
|
||
#include <string> | ||
#include <stdexcept> | ||
|
||
using namespace asp::render; | ||
|
||
std::unique_ptr<backend> backend::make(version v, frontend &f) { | ||
switch (v) { | ||
case version::opengl2: | ||
return std::make_unique<OpenGL2>(f); | ||
|
||
case version::opengl3: | ||
return std::make_unique<OpenGL3>(f); | ||
|
||
case version::gles2: | ||
return std::make_unique<GLES2>(f); | ||
|
||
case version::gles3: | ||
return std::make_unique<GLES3>(f); | ||
} | ||
|
||
throw std::runtime_error("Unexpected GL Version: " + | ||
std::to_string(static_cast<int>(v))); | ||
} |
Oops, something went wrong.