Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor hydra gl interface fixup #327

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/hydra_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class HC_GLOBAL HydraCore final : public hydra::IBase, public hydra::IOpenGlRend
void setOutputSize(hydra::Size size) override;

// IOpenGlRendered
void resetContext() override;
void destroyContext() override;
void setFbo(unsigned handle) override;
void setContext(void* context) override;
void setGetProcAddress(void* function) override;

// IFrontendDriven
Expand All @@ -34,6 +35,7 @@ class HC_GLOBAL HydraCore final : public hydra::IBase, public hydra::IOpenGlRend
RendererGL* renderer;
void (*pollInputCallback)() = nullptr;
int32_t (*checkButtonCallback)(uint32_t player, hydra::ButtonType button) = nullptr;
void* getProcAddress = nullptr;
};

HydraCore::HydraCore() : emulator(new Emulator) {
Expand Down Expand Up @@ -88,7 +90,6 @@ void HydraCore::runFrame() {
}

hid.updateInputs(emulator->getTicks());

emulator->runFrame();
}

Expand All @@ -100,27 +101,28 @@ hydra::Size HydraCore::getNativeSize() { return {400, 480}; }
// Size doesn't matter as the glBlitFramebuffer call is commented out for the core
void HydraCore::setOutputSize(hydra::Size size) {}

void HydraCore::setGetProcAddress(void* function) {
void HydraCore::resetContext() {
#ifdef __ANDROID__
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(function))) {
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(getProcAddress))) {
Helpers::panic("OpenGL ES init failed");
}
#else
if (!gladLoadGLLoader(reinterpret_cast<GLADloadproc>(function))) {
if (!gladLoadGLLoader(reinterpret_cast<GLADloadproc>(getProcAddress))) {
Helpers::panic("OpenGL init failed");
}
#endif
// SDL_Window is not used, so we pass nullptr
emulator->initGraphicsContext(nullptr);
}

void HydraCore::setContext(void*) {}
void HydraCore::destroyContext() { emulator->deinitGraphicsContext(); }
void HydraCore::setFbo(unsigned handle) { renderer->setFBO(handle); }
void HydraCore::setGetProcAddress(void* function) { getProcAddress = function; }

void HydraCore::setPollInputCallback(void (*callback)()) { pollInputCallback = callback; }
void HydraCore::setCheckButtonCallback(int32_t (*callback)(uint32_t player, hydra::ButtonType button)) { checkButtonCallback = callback; }

HC_API hydra::IBase* createEmulator() { return new HydraCore; }
HC_API hydra::IBase* createEmulator() { return new HydraCore(); }
HC_API void destroyEmulator(hydra::IBase* emulator) { delete emulator; }

HC_API const char* getInfo(hydra::InfoType type) {
Expand All @@ -140,4 +142,4 @@ HC_API const char* getInfo(hydra::InfoType type) {

default: return nullptr;
}
}
}
2 changes: 1 addition & 1 deletion third_party/hydra_core