Removes the Java ButtonManager for one in the C++ source so the OSD class can call in to it each frame for drawing the buttons. Copy our assets to the dolphin-emu directory for now. Remove NativeRenderer, ButtonManager, and Button Java classes since they aren't used anymore. Buttons A, B, and Start all work and are drawn on screen now. Button input on Android is still a bit hacky, needs a proper controller interface still. Android specific button drawing code is still hanging out in SWRenderer.cpp

This commit is contained in:
Ryan Houdek 2013-04-14 20:39:56 -05:00
parent 24347e5176
commit bde7ea00ef
16 changed files with 486 additions and 304 deletions

View File

@ -4,7 +4,7 @@
android:versionCode="1"
android:versionName="0.1" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14"/>
<uses-feature android:glEsVersion="0x00020000"></uses-feature>
<uses-feature android:name="android.hardware.screen.landscape" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -1,33 +0,0 @@
package org.dolphinemu.dolphinemu;
public class Button {
private String ButtonID;
private float _x;
private float _y;
private float _ex;
private float _ey;
public Button(String Button, float[] Coords)
{
ButtonID = Button;
_x = Coords[0];
_y = Coords[1];
_ex = Coords[4];
_ey = Coords[5];
}
public float X()
{
return _x;
}
public float Y()
{
return _y;
}
public float EX()
{
return _ex;
}
public float EY()
{
return _ey;
}
}

View File

@ -1,43 +0,0 @@
package org.dolphinemu.dolphinemu;
public class ButtonManager {
private final int NUMBUTTONS = 15;
Button[] Buttons;
float[][] ButtonCoords =
{ // X, Y, X, EY, EX, EY, EX, Y
{0.75f, -1.0f, 0.75f, -0.75f, 1.0f, -0.75f, 1.0f, -1.0f},
{0.50f, -1.0f, 0.50f, -0.75f, 0.75f, -0.75f, 0.75f, -1.0f},
};
public ButtonManager()
{
Buttons = new Button[NUMBUTTONS];
Buttons[0] = new Button("A", ButtonCoords[0]);
Buttons[1] = new Button("B", ButtonCoords[1]);
}
Button GetButton(int ID)
{
return Buttons[ID];
}
float[][] GetButtonCoords()
{
return ButtonCoords;
}
public int ButtonPressed(int action, float x, float y)
{
for (int a = 0; a < 2; ++a)
{
if (x >= Buttons[a].X() &&
x <= Buttons[a].EX() &&
-y >= Buttons[a].Y() &&
-y <= Buttons[a].EY())
{
return a;
}
}
return -1;
}
}

View File

@ -1,29 +1,29 @@
package org.dolphinemu.dolphinemu;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.WindowManager;
public class DolphinEmulator<MainActivity> extends Activity {
public class DolphinEmulator<MainActivity> extends Activity
{
static private NativeGLSurfaceView GLview = null;
static private boolean Running = false;
private float screenWidth;
private float screenHeight;
public static native void SetKey(int Value, int Key);
public static native void onTouchEvent(int Action, float X, float Y);
static
{
@ -36,6 +36,29 @@ public class DolphinEmulator<MainActivity> extends Activity {
Log.w("me", ex.toString());
}
}
private void CopyAsset(String asset, String output) {
InputStream in = null;
OutputStream out = null;
try {
in = getAssets().open(asset);
out = new FileOutputStream(output);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(IOException e) {
Log.e("tag", "Failed to copy asset file: " + asset, e);
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
@Override
public void onStop()
{
@ -67,6 +90,30 @@ public class DolphinEmulator<MainActivity> extends Activity {
{
Intent ListIntent = new Intent(this, NativeListView.class);
startActivityForResult(ListIntent, 1);
// Make the assets directory
try
{
File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"dolphin-emu");
directory.mkdirs();
}
catch (Exception ex)
{
Log.w("me", ex.toString());
}
// Copy assets if needed
java.io.File file = new java.io.File(
Environment.getExternalStorageDirectory()+File.separator+"dolphin-emu" + File.separator + "ButtonStart.png");
if(!file.exists())
{
CopyAsset("ButtonA.png",
Environment.getExternalStorageDirectory()+File.separator+"dolphin-emu" + File.separator + "ButtonA.png");
CopyAsset("ButtonB.png",
Environment.getExternalStorageDirectory()+File.separator+"dolphin-emu" + File.separator + "ButtonB.png");
CopyAsset("ButtonStart.png",
Environment.getExternalStorageDirectory()+File.separator+"dolphin-emu" + File.separator + "ButtonStart.png");
}
}
}
@ -85,7 +132,7 @@ public class DolphinEmulator<MainActivity> extends Activity {
String FileName = data.getStringExtra("Select");
GLview = new NativeGLSurfaceView(this);
//this.getWindow().setUiOptions(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN, View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN);
GLview.SetDimensions(screenWidth, screenHeight);
GLview.SetFileName(FileName);
setContentView(GLview);
@ -102,10 +149,11 @@ public class DolphinEmulator<MainActivity> extends Activity {
Y = event.getY();
Action = event.getActionMasked();
//int Button = Renderer.ButtonPressed(Action, ((X / screenWidth) * 2.0f) - 1.0f, ((Y / screenHeight) * 2.0f) - 1.0f);
//if (Button != -1)
//SetKey(Action, Button);
// Converts button locations 0 - 1 to OGL screen coords -1.0 - 1.0
float ScreenX = ((X / screenWidth) * 2.0f) - 1.0f;
float ScreenY = ((Y / screenHeight) * -2.0f) + 1.0f;
onTouchEvent(Action, ScreenX, ScreenY);
return false;
}

View File

@ -16,7 +16,6 @@ public class NativeGLSurfaceView extends SurfaceView {
static private float height;
public static native void main(String File, Surface surf, int width, int height);
public static native void UnPauseEmulation();
public static native void PauseEmulation();
public static native void StopEmulation();
@ -32,7 +31,6 @@ public class NativeGLSurfaceView extends SurfaceView {
Log.w("me", ex.toString());
}
}
public NativeGLSurfaceView(Context context) {
super(context);
@ -46,11 +44,13 @@ public class NativeGLSurfaceView extends SurfaceView {
}
};
getHolder().addCallback(new SurfaceHolder.Callback() {
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
myRun.start();
if (!Running)
{
myRun.start();
Running = true;
}
}
public void surfaceChanged(SurfaceHolder arg0, int arg1,
@ -72,11 +72,10 @@ public class NativeGLSurfaceView extends SurfaceView {
{
FileName = file;
}
public void SetDimensions(float screenWidth, float screenHeight)
{
width = screenWidth;
height = screenHeight;
}
}

View File

@ -1,165 +0,0 @@
package org.dolphinemu.dolphinemu;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.GLUtils;
import android.util.Log;
public class NativeRenderer implements GLSurfaceView.Renderer {
// Button Manager
private static ButtonManager Buttons;
private static boolean Running = false;
// Context
private static Context _gContext;
// Native
public static native void DrawME();
public static native void DrawButton(int GLTex, int ID);
public static native void SetButtonCoords(float[] Coords);
public static native void PrepareME();
// Texture loading
private static int buttonA = -1;
private static int buttonB = -1;
// Get a new texture id:
private static int newTextureID(GL10 gl)
{
int[] temp = new int[1];
gl.glGenTextures(1, temp, 0);
return temp[0];
}
// Will load a texture out of a drawable resource file, and return an OpenGL texture ID:
private int loadTexture(GL10 gl, String resource)
{
// In which ID will we be storing this texture?
int id = newTextureID(gl);
// Load up, and flip the texture:
InputStream File = null;
try {
File = _gContext.getAssets().open(resource);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
Bitmap bmp = BitmapFactory.decodeStream(File);
gl.glBindTexture(GL10.GL_TEXTURE_2D, id);
// Set all of our texture parameters:
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR_MIPMAP_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
// Generate, and load up all of the mipmaps:
for(int level=0, height = bmp.getHeight(), width = bmp.getWidth(); true; level++)
{
// Push the bitmap onto the GPU:
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bmp, 0);
// We need to stop when the texture is 1x1:
if(height==1 && width==1) break;
// Resize, and let's go again:
width >>= 1; height >>= 1;
if(width<1) width = 1;
if(height<1) height = 1;
Bitmap bmp2 = Bitmap.createScaledBitmap(bmp, width, height, true);
bmp.recycle();
bmp = bmp2;
}
bmp.recycle();
return id;
}
static
{
try
{
System.loadLibrary("dolphin-emu-nogui");
}
catch (Exception ex)
{
Log.w("me", ex.toString());
}
if (!Running)
Buttons = new ButtonManager();
}
public void onSurfaceChanged(GL10 gl, int width, int height)
{
gl.glViewport(0, 0, width, height);
}
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
if (!Running)
{
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
buttonA = loadTexture(gl, "ButtonA.png");
buttonB = loadTexture(gl, "ButtonB.png");
SetButtonCoords(Flatten(Buttons.GetButtonCoords()));
PrepareME();
Running = true;
}
}
public static float[] Flatten(float[][] data) {
float[] list = new float[data.length * data[0].length];
for(int y = 0; y < data.length; ++y)
for (int x = 0; x < data[y].length; ++x)
list[y * data[0].length + x] = data[y][x];
return list;
}
public void onDrawFrame(GL10 gl)
{
if (Running)
{
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
DrawME();
// -1 is left
// -1 is bottom
DrawButton(buttonA, 0);
DrawButton(buttonB, 1);
}
}
public void setContext(Context ctx)
{
_gContext = ctx;
}
public int ButtonPressed(int action, float x, float y)
{
return Buttons.ButtonPressed(action, x, y);
}
}

View File

@ -57,6 +57,7 @@
DIR_SEP USERDATA_DIR DIR_SEP
#elif defined ANDROID
#define SYSDATA_DIR "/sdcard/dolphin-emu"
#define SHARED_USER_DIR SYSDATA_DIR
#else
#ifdef DATA_DIR
#define SYSDATA_DIR DATA_DIR "sys"

View File

@ -87,16 +87,24 @@ void GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// get input
((GCPad*)g_plugin.controllers[_numPAD])->GetInput(_pPADStatus);
#ifdef ANDROID
// XXX: This /really/ needs to be moved to a controller interface
if (Host_GetKeyState(0))
{
_pPADStatus->button |= PAD_BUTTON_A;
_pPADStatus->analogA = 255;
}
if (Host_GetKeyState(1))
{
_pPADStatus->button |= PAD_BUTTON_B;
_pPADStatus->analogB = 255;
}
if (Host_GetKeyState(2))
{
_pPADStatus->button |= PAD_BUTTON_START;
}
#endif
}
// __________________________________________________________________________________________________

View File

@ -32,6 +32,8 @@ if(NOT ANDROID)
set(LIBS ${LIBS} SDL)
endif()
endif()
else()
set(LIBS ${LIBS} png)
endif()
if(LIBAV_FOUND)
@ -89,7 +91,9 @@ if(wxWidgets_FOUND)
set(WXLIBS ${wxWidgets_LIBRARIES})
else()
if(ANDROID)
set(SRCS Src/MainAndroid.cpp)
set(SRCS Src/Android/TextureLoader.cpp
Src/Android/ButtonManager.cpp
Src/MainAndroid.cpp)
else()
set(SRCS Src/MainNoGUI.cpp)
endif()

View File

@ -0,0 +1,90 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include <vector>
#include "GLInterface.h"
#include "Android/TextureLoader.h"
#include "Android/ButtonManager.h"
extern void DrawButton(GLuint tex, float *coords);
namespace ButtonManager
{
std::vector<Button*> m_buttons;
// XXX: This needs to not be here so we can load the locations from file
// This will allow customizable button locations in the future
// These are the OpenGL on screen coordinates
float m_coords[][8] = { // X, Y, X, EY, EX, EY, EX, Y
{0.75f, -1.0f, 0.75f, -0.75f, 1.0f, -0.75f, 1.0f, -1.0f}, // A
{0.50f, -1.0f, 0.50f, -0.75f, 0.75f, -0.75f, 0.75f, -1.0f}, // B
{-0.10f, -1.0f, -0.10f, -0.80f, 0.10f, -0.80f, 0.10f, -1.0f}, // Start
};
void Init()
{
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
// Initialize our buttons
m_buttons.push_back(new Button("ButtonA.png", BUTTON_A, m_coords[0]));
m_buttons.push_back(new Button("ButtonB.png", BUTTON_B, m_coords[1]));
m_buttons.push_back(new Button("ButtonStart.png", BUTTON_START, m_coords[2]));
}
bool GetButtonPressed(ButtonType button)
{
for (auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
if ((*it)->GetButtonType() == button)
return (*it)->Pressed();
return false;
}
void TouchEvent(int action, float x, float y)
{
// Actions
// 0 is press
// 1 is let go
// 2 is move
for (auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
{
float *coords = (*it)->GetCoords();
if ( x >= coords[0] &&
x <= coords[4] &&
y >= coords[1] &&
y <= coords[3])
{
if (action == 0)
(*it)->SetState(BUTTON_PRESSED);
if (action == 1)
(*it)->SetState(BUTTON_RELEASED);
if (action == 2)
; // XXX: Be used later for analog stick
}
}
}
void Shutdown()
{
for(auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
delete *it;
}
void DrawButtons()
{
for(auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
DrawButton((*it)->GetTexture(), (*it)->GetCoords());
}
}

View File

@ -0,0 +1,63 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include <string>
#include "CommonPaths.h"
#include "Android/TextureLoader.h"
namespace ButtonManager
{
enum ButtonType
{
BUTTON_A = 0,
BUTTON_B,
BUTTON_START,
};
enum ButtonState
{
BUTTON_RELEASED = 0,
BUTTON_PRESSED = 1
};
class Button
{
private:
GLuint m_tex;
ButtonType m_button;
ButtonState m_state;
float m_coords[8];
public:
Button(std::string filename, ButtonType button, float *coords)
{
m_tex = LoadPNG((std::string(DOLPHIN_DATA_DIR "/") + filename).c_str());
m_button = button;
memcpy(m_coords, coords, sizeof(float) * 8);
m_state = BUTTON_RELEASED;
}
void SetState(ButtonState state) { m_state = state; }
bool Pressed() { return m_state == BUTTON_PRESSED; }
ButtonType GetButtonType() { return m_button; }
GLuint GetTexture() { return m_tex; }
float *GetCoords() { return m_coords; }
~Button() { glDeleteTextures(1, &m_tex); }
};
void Init();
void DrawButtons();
bool GetButtonPressed(ButtonType button);
void TouchEvent(int action, float x, float y);
void Shutdown();
}

View File

@ -0,0 +1,192 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "GLInterface.h"
#include <png.h>
GLuint OpenGL_ReportGLError()
{
GLint err = glGetError();
if (err != GL_NO_ERROR)
{
ERROR_LOG(VIDEO, "OpenGL error 0x%x\n", err);
}
return err;
}
GLuint LoadPNG(const char *filename)
{
FILE *infile; /* PNG file pointer */
png_structp png_ptr; /* internally used by libpng */
png_infop info_ptr; /* user requested transforms */
char *image_data; /* raw png image data */
char sig[8]; /* PNG signature array */
/*char **row_pointers; */
int bit_depth;
int color_type;
png_uint_32 width; /* PNG image width in pixels */
png_uint_32 height; /* PNG image height in pixels */
unsigned int rowbytes; /* raw bytes at row n in image */
image_data = NULL;
unsigned int i;
png_bytepp row_pointers = NULL;
/* Open the file. */
infile = fopen(filename, "rb");
if (!infile)
return 0;
/*
* 13.3 readpng_init()
*/
/* Check for the 8-byte signature */
fread(sig, 1, 8, infile);
if (!png_check_sig((unsigned char *) sig, 8)) {
fclose(infile);
return 0;
}
/*
* Set up the PNG structs
*/
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
fclose(infile);
return 4; /* out of memory */
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
fclose(infile);
return 4; /* out of memory */
}
/*
* block to handle libpng errors,
* then check whether the PNG file had a bKGD chunk
*/
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(infile);
return 0;
}
/*
* takes our file stream pointer (infile) and
* stores it in the png_ptr struct for later use.
*/
/* png_ptr->io_ptr = (png_voidp)infile;*/
png_init_io(png_ptr, infile);
/*
* lets libpng know that we already checked the 8
* signature bytes, so it should not expect to find
* them at the current file pointer location
*/
png_set_sig_bytes(png_ptr, 8);
/* Read the image */
/*
* reads and processes not only the PNG file's IHDR chunk
* but also any other chunks up to the first IDAT
* (i.e., everything before the image data).
*/
/* read all the info up to the image data */
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, NULL, NULL, NULL);
/* Set up some transforms. */
if (bit_depth > 8)
png_set_strip_16(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
/* Update the png info struct.*/
png_read_update_info(png_ptr, info_ptr);
/* Rowsize in bytes. */
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
/* Allocate the image_data buffer. */
if ((image_data = (char *) malloc(rowbytes * height))==NULL) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return 4;
}
if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
free(image_data);
image_data = NULL;
return 4;
}
/* set the individual row_pointers to point at the correct offsets */
for (i = 0; i < height; ++i)
row_pointers[i] = (png_byte*)(image_data + i*rowbytes);
/* now we can go ahead and just read the whole image */
png_read_image(png_ptr, row_pointers);
/* and we're done! (png_read_end() can be omitted if no processing of
* post-IDAT text/time/etc. is desired) */
/* Clean up. */
free(row_pointers);
/* Clean up. */
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(infile);
GLuint Texture = 0;
glGenTextures(1, &Texture);
/* create a new texture object
* and bind it to texname (unsigned integer > 0)
*/
glBindTexture(GL_TEXTURE_2D, Texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, image_data);
WARN_LOG(COMMON, "Errors below if any");
OpenGL_ReportGLError();
return Texture;
}

View File

@ -0,0 +1,21 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "GLInterface.h"
GLuint LoadPNG(const char *filename);

View File

@ -33,19 +33,17 @@
#include "ConfigManager.h"
#include "LogManager.h"
#include "BootManager.h"
#include "OnScreenDisplay.h"
#include "Android/ButtonManager.h"
#include <jni.h>
#include <android/log.h>
#include <android/native_window_jni.h>
JNIEnv *g_env = NULL;
ANativeWindow* surf;
int g_width, g_height;
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "Dolphinemu", __VA_ARGS__))
bool rendererHasFocus = true;
bool running = true;
bool KeyStates[15];
void Host_NotifyMapLoaded() {}
void Host_RefreshDSPDebuggerWindow() {}
@ -77,7 +75,7 @@ void Host_UpdateBreakPointView(){}
bool Host_GetKeyState(int keycode)
{
return KeyStates[keycode];
return ButtonManager::GetButtonPressed((ButtonManager::ButtonType)keycode);
}
void Host_GetRenderWindowSize(int& x, int& y, int& width, int& height)
@ -123,26 +121,29 @@ void Host_SysMessage(const char *fmt, ...)
void Host_SetWiiMoteConnectionState(int _State) {}
extern void DrawButton(int tex, int ID);
extern void SetButtonCoords(float *Coords);
void OSDCallbacks(u32 UserData)
{
switch(UserData)
{
case 0: // Init
ButtonManager::Init();
break;
case 1: // Draw
ButtonManager::DrawButtons();
break;
case 2: // Shutdown
ButtonManager::Shutdown();
break;
default:
WARN_LOG(COMMON, "Error, wrong OSD type");
break;
}
}
#ifdef __cplusplus
extern "C"
{
#endif
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_SetButtonCoords(JNIEnv *env, jobject obj, jfloatArray Coords)
{
jfloat* flt1 = env->GetFloatArrayElements(Coords, 0);
SetButtonCoords((float*)flt1);
env->ReleaseFloatArrayElements(Coords, flt1, 0);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_DrawButton(JNIEnv *env, jobject obj,
jint GLTex, jint ID
)
{
DrawButton((int)GLTex, (int)ID);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_UnPauseEmulation(JNIEnv *env, jobject obj)
{
PowerPC::Start();
@ -156,10 +157,9 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_StopEm
{
PowerPC::Stop();
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_DolphinEmulator_SetKey(JNIEnv *env, jobject obj, jint Value, jint Key)
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_DolphinEmulator_onTouchEvent(JNIEnv *env, jobject obj, jint Action, jfloat X, jfloat Y)
{
WARN_LOG(COMMON, "Key %d with action %d\n", (int)Key, (int)Value);
KeyStates[(int)Key] = (int)Value == 0 ? true : false;
ButtonManager::TouchEvent(Action, X, Y);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_main(JNIEnv *env, jobject obj, jstring jFile, jobject _surf, jint _width, jint _height)
@ -167,16 +167,19 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_main(J
surf = ANativeWindow_fromSurface(env, _surf);
g_width = (int)_width;
g_height = (int)_height;
g_env = env;
// Install our callbacks
OSD::AddCallback(OSD::OSD_INIT, OSDCallbacks, 0);
OSD::AddCallback(OSD::OSD_ONFRAME, OSDCallbacks, 1);
OSD::AddCallback(OSD::OSD_SHUTDOWN, OSDCallbacks, 2);
LogManager::Init();
SConfig::Init();
VideoBackend::PopulateList();
VideoBackend::ActivateBackend(SConfig::GetInstance().
m_LocalCoreStartupParameter.m_strVideoBackend);
VideoBackend::ActivateBackend(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend);
WiimoteReal::LoadSettings();
const char *File = env->GetStringUTFChars(jFile, NULL);
const char *File = env->GetStringUTFChars(jFile, NULL);
// No use running the loop when booting fails
if ( BootManager::BootCore( File ) )
while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)

View File

@ -77,8 +77,6 @@ void CreateShaders()
uni_tex = glGetUniformLocation(program, "Texture");
attr_pos = glGetAttribLocation(program, "pos");
attr_tex = glGetAttribLocation(program, "TexCoordIn");
}
void SWRenderer::Prepare()
@ -138,12 +136,8 @@ void SWRenderer::DrawDebugText()
SWRenderer::RenderText(debugtext_buffer, 20, 20, 0xFFFFFF00);
}
#ifdef ANDROID
float ButtonCoords[8 * 2];
void SetButtonCoords(float *Coords)
{
memcpy(ButtonCoords, Coords, sizeof(float) * 8 * 2);
}
void DrawButton(int tex, int ID)
void DrawButton(GLuint tex, float *coords)
{
//Texture rectangle uses pixel coordinates
#ifndef USE_GLES
@ -166,7 +160,7 @@ void DrawButton(int tex, int ID)
#endif
glBindTexture(TEX2D, tex);
glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, &ButtonCoords[ID * 8]);
glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, coords);
glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, texverts);
glEnableVertexAttribArray(attr_pos);
glEnableVertexAttribArray(attr_tex);