This commit is contained in:
gabriel 2023-11-26 11:59:25 -04:00
commit ce6fa0043a
5 changed files with 18 additions and 37 deletions

View file

@ -2,38 +2,31 @@ package com.panda3ds.pandroid.app;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.C;
import com.panda3ds.pandroid.app.BaseActivity;
import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.view.PandaGlSurfaceView;
public class GameActivity extends BaseActivity {
private PandaGlSurfaceView pandaSurface;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pandaSurface = new PandaGlSurfaceView(this);;
setContentView(pandaSurface);
Intent intent = getIntent();
if(!intent.hasExtra(C.EXTRA_PATH)){
if(!intent.hasExtra(Constants.EXTRA_PATH)){
setContentView(new FrameLayout(this));
Toast.makeText(this, "INVALID ROM PATH", Toast.LENGTH_LONG).show();
finish();
return;
}
pandaSurface.getRenderer().postDrawEvent(()->{
String path = intent.getStringExtra(C.EXTRA_PATH);
Log.i(C.LOG_TAG,"Try load ROM: "+path);
AlberDriver.LoadRom(path);
});
pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.EXTRA_PATH));;
setContentView(pandaSurface);
}
}

View file

@ -10,7 +10,7 @@ import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.panda3ds.pandroid.C;
import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.utils.PathUtils;
@ -48,7 +48,7 @@ public class MainActivity extends AppCompatActivity {
String path = PathUtils.getPath(getApplicationContext(), data.getData());
Toast.makeText(getApplicationContext(), "pandroid opening " + path, Toast.LENGTH_LONG).show();
startActivity(new Intent(this, GameActivity.class)
.putExtra(C.EXTRA_PATH, path));
.putExtra(Constants.EXTRA_PATH, path));
}
super.onActivityResult(requestCode, resultCode, data);
}

View file

@ -1,6 +1,6 @@
package com.panda3ds.pandroid;
package com.panda3ds.pandroid.utils;
public class C {
public class Constants {
public static final String EXTRA_PATH = "path";
public static final String LOG_TAG = "Alber";
}

View file

@ -7,25 +7,22 @@ import static android.opengl.GLES32.*;
import android.content.res.Resources;
import android.opengl.GLSurfaceView;
import android.util.DisplayMetrics;
import android.util.Log;
import com.panda3ds.pandroid.AlberDriver;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.ArrayList;
public class PandaGlRenderer implements GLSurfaceView.Renderer {
private final ArrayList<Runnable> events = new ArrayList<>();
private final String romPath;
int screenWidth, screenHeight;
int screenTexture;
public int screenFbo;
PandaGlRenderer() {
PandaGlRenderer(String romPath) {
super();
this.romPath = romPath;
}
@ -65,10 +62,7 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
AlberDriver.Initialize();
}
public void postDrawEvent(Runnable callback){
events.add(callback);
AlberDriver.LoadRom(romPath);
}
public void onDrawFrame(GL10 unused) {
@ -78,13 +72,6 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer {
glBindFramebuffer(GL_READ_FRAMEBUFFER, screenFbo);
glBlitFramebuffer(0, 0, 400, 480, 0, 0, screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
}
int count = events.size();
while (count > 0){
events.get(0).run();
events.remove(0);
count--;
}
}
public void onSurfaceChanged(GL10 unused, int width, int height) {

View file

@ -6,10 +6,11 @@ import android.opengl.GLSurfaceView;
public class PandaGlSurfaceView extends GLSurfaceView {
final PandaGlRenderer renderer;
public PandaGlSurfaceView(Context context) {
public PandaGlSurfaceView(Context context, String romPath) {
super(context);
setEGLContextClientVersion(3);
renderer = new PandaGlRenderer();
setDebugFlags(DEBUG_LOG_GL_CALLS);
renderer = new PandaGlRenderer(romPath);
setRenderer(renderer);
}