-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
140 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,36 @@ | ||
#include <jni.h> | ||
#include <stdexcept> | ||
#include <android/log.h> | ||
#include <EGL/egl.h> | ||
#include "renderer_gl/renderer_gl.hpp" | ||
#include "emulator.hpp" | ||
|
||
std::unique_ptr<Emulator> emulator; | ||
std::unique_ptr<Emulator> emulator = nullptr; | ||
RendererGL* renderer = nullptr; | ||
|
||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_Initialize(JNIEnv* env, jobject obj) { | ||
__android_log_print(ANDROID_LOG_INFO, "Panda3DS", "Initializing Alber Driver"); | ||
emulator = std::make_unique<Emulator>(); | ||
__android_log_print(ANDROID_LOG_INFO, "Panda3DS", "Done"); | ||
if (emulator->getRendererType() != RendererType::OpenGL) { | ||
throw std::runtime_error("Renderer is not OpenGL"); | ||
} | ||
renderer = static_cast<RendererGL*>(emulator->getRenderer()); | ||
__android_log_print(ANDROID_LOG_INFO, "AlberDriver", "OpenGL ES Before %d.%d", GLVersion.major, GLVersion.minor); | ||
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(eglGetProcAddress))) { | ||
throw std::runtime_error("OpenGL ES init failed"); | ||
} | ||
__android_log_print(ANDROID_LOG_INFO, "AlberDriver", "OpenGL ES %d.%d", GLVersion.major, GLVersion.minor); | ||
emulator->initGraphicsContext(nullptr); | ||
// girlboss it for now :3 | ||
emulator->loadROM("/data/data/com.panda3ds.pandroid/files/rom.3ds"); | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_RunFrame(JNIEnv* env, jobject obj, jint fbo) { | ||
renderer->setFBO(fbo); | ||
renderer->resetStateManager(); | ||
emulator->runFrame(); | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_Finalize(JNIEnv* env, jobject obj) { | ||
emulator = nullptr; | ||
renderer = nullptr; | ||
} |
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
79 changes: 79 additions & 0 deletions
79
src/pandroid/app/src/main/java/com/panda3ds/pandroid/PandaGlRenderer.java
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,79 @@ | ||
package com.panda3ds.pandroid; | ||
|
||
import javax.microedition.khronos.egl.EGLConfig; | ||
import javax.microedition.khronos.opengles.GL10; | ||
|
||
import static android.opengl.GLES32.*; | ||
|
||
import android.content.res.Resources; | ||
import android.opengl.GLSurfaceView; | ||
import android.util.DisplayMetrics; | ||
import android.util.Log; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
import java.nio.FloatBuffer; | ||
|
||
public class PandaGlRenderer implements GLSurfaceView.Renderer { | ||
int screenWidth, screenHeight; | ||
int screenTexture; | ||
public int screenFbo; | ||
|
||
PandaGlRenderer() { | ||
super(); | ||
} | ||
|
||
@Override | ||
protected void finalize() throws Throwable { | ||
if (screenTexture != 0) { | ||
glDeleteTextures(1, new int[]{screenTexture}, 0); | ||
} | ||
if (screenFbo != 0) { | ||
glDeleteFramebuffers(1, new int[]{screenFbo}, 0); | ||
} | ||
super.finalize(); | ||
} | ||
|
||
public void onSurfaceCreated(GL10 unused, EGLConfig config) { | ||
Log.i("pandroid", glGetString(GL_EXTENSIONS)); | ||
Log.w("pandroid", glGetString(GL_VERSION)); | ||
screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels; | ||
screenHeight = Resources.getSystem().getDisplayMetrics().heightPixels; | ||
|
||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | ||
glClear(GL_COLOR_BUFFER_BIT); | ||
|
||
int[] generateBuffer = new int[1]; | ||
glGenTextures(1, generateBuffer, 0); | ||
screenTexture = generateBuffer[0]; | ||
glBindTexture(GL_TEXTURE_2D, screenTexture); | ||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, screenWidth, screenHeight); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||
glBindTexture(GL_TEXTURE_2D, 0); | ||
|
||
glGenFramebuffers(1, generateBuffer, 0); | ||
screenFbo = generateBuffer[0]; | ||
glBindFramebuffer(GL_FRAMEBUFFER, screenFbo); | ||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, screenTexture, 0); | ||
glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
|
||
AlberDriver.Initialize(); | ||
} | ||
|
||
public void onDrawFrame(GL10 unused) { | ||
AlberDriver.RunFrame(screenFbo); | ||
// is this needed? prob not | ||
glBindTexture(GL_TEXTURE_2D, 0); | ||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); | ||
glBindFramebuffer(GL_READ_FRAMEBUFFER, screenFbo); | ||
glBlitFramebuffer(0, 0, 400, 480, 0, 0, screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); | ||
} | ||
|
||
public void onSurfaceChanged(GL10 unused, int width, int height) { | ||
glViewport(0, 0, width, height); | ||
screenWidth = width; | ||
screenHeight = height; | ||
glDisable(GL_SCISSOR_TEST); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/pandroid/app/src/main/java/com/panda3ds/pandroid/PandaGlSurfaceView.java
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,19 @@ | ||
package com.panda3ds.pandroid; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.opengl.GLSurfaceView; | ||
import android.util.DisplayMetrics; | ||
|
||
import com.panda3ds.pandroid.PandaGlRenderer; | ||
|
||
public class PandaGlSurfaceView extends GLSurfaceView { | ||
final PandaGlRenderer renderer; | ||
|
||
public PandaGlSurfaceView(Context context) { | ||
super(context); | ||
setEGLContextClientVersion(3); | ||
renderer = new PandaGlRenderer(); | ||
setRenderer(renderer); | ||
} | ||
} |