UI with ImGui
This commit is contained in:
parent
78fd92f95a
commit
1802c022fd
|
@ -10,7 +10,8 @@ RZDCY_MODULES := cfg/ hw/arm7/ hw/aica/ hw/holly/ hw/ hw/gdrom/ hw/maple/ hw/mod
|
|||
hw/mem/ hw/pvr/ hw/sh4/ hw/sh4/interpr/ hw/sh4/modules/ plugins/ profiler/ oslib/ \
|
||||
hw/extdev/ hw/arm/ hw/naomi/ imgread/ ./ deps/coreio/ deps/zlib/ deps/chdr/ deps/crypto/ \
|
||||
deps/libelf/ deps/chdpsr/ arm_emitter/ rend/ reios/ deps/libpng/ deps/xbrz/ \
|
||||
deps/picotcp/modules/ deps/picotcp/stack/ deps/xxhash/ deps/libzip/ archive/
|
||||
deps/picotcp/modules/ deps/picotcp/stack/ deps/xxhash/ deps/libzip/ deps/imgui/ \
|
||||
archive/
|
||||
|
||||
ifdef CHD5_LZMA
|
||||
RZDCY_MODULES += deps/lzma/
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
|
||||
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||
//-----------------------------------------------------------------------------
|
||||
// A) You may edit imconfig.h (and not overwrite it when updating imgui, or maintain a patch/branch with your modifications to imconfig.h)
|
||||
// B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h"
|
||||
// If you do so you need to make sure that configuration settings are defined consistently _everywhere_ dear imgui is used, which include
|
||||
// the imgui*.cpp files but also _any_ of your code that uses imgui. This is because some compile-time options have an affect on data structures.
|
||||
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
//---- Define assertion handler. Defaults to calling assert().
|
||||
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||
|
||||
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows.
|
||||
//#define IMGUI_API __declspec( dllexport )
|
||||
//#define IMGUI_API __declspec( dllimport )
|
||||
|
||||
//---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
|
||||
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
|
||||
//---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty)
|
||||
//---- It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp.
|
||||
//#define IMGUI_DISABLE_DEMO_WINDOWS
|
||||
|
||||
//---- Don't implement some functions to reduce linkage requirements.
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc.
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow.
|
||||
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function.
|
||||
//#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself if you don't want to link with vsnprintf.
|
||||
//#define IMGUI_DISABLE_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 wrapper so you can implement them yourself. Declare your prototypes in imconfig.h.
|
||||
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||
|
||||
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||
|
||||
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
|
||||
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||
|
||||
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||
// By default the embedded implementations are declared static and not available outside of imgui cpp files.
|
||||
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||
|
||||
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||
/*
|
||||
#define IM_VEC2_CLASS_EXTRA \
|
||||
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
|
||||
operator MyVec2() const { return MyVec2(x,y); }
|
||||
|
||||
#define IM_VEC4_CLASS_EXTRA \
|
||||
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
|
||||
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||
*/
|
||||
|
||||
//---- Use 32-bit vertex indices (default is 16-bit) to allow meshes with more than 64K vertices. Render function needs to support it.
|
||||
//#define ImDrawIdx unsigned int
|
||||
|
||||
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
|
||||
/*
|
||||
namespace ImGui
|
||||
{
|
||||
void MyFunction(const char* name, const MyMatrix44& v);
|
||||
}
|
||||
*/
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM <GL3/gl3w.h>
|
||||
|
||||
#ifdef _ANDROID
|
||||
#include <android/log.h>
|
||||
|
||||
#define LOG_TAG "reicast"
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,604 @@
|
|||
// dear imgui: Renderer for OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline)
|
||||
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
|
||||
// (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. 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 are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
|
||||
// https://github.com/ocornut/imgui
|
||||
|
||||
// CHANGELOG
|
||||
// (minor and older changes stripped away, please see git history for details)
|
||||
// 2019-02-01: OpenGL: Using GLSL 410 shaders for any version over 410 (e.g. 430, 450).
|
||||
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
||||
// 2018-11-13: OpenGL: Support for GL 4.5's glClipControl(GL_UPPER_LEFT).
|
||||
// 2018-08-29: OpenGL: Added support for more OpenGL loaders: glew and glad, with comments indicative that any loader can be used.
|
||||
// 2018-08-09: OpenGL: Default to OpenGL ES 3 on iOS and Android. GLSL version default to "#version 300 ES".
|
||||
// 2018-07-30: OpenGL: Support for GLSL 300 ES and 410 core. Fixes for Emscripten compilation.
|
||||
// 2018-07-10: OpenGL: Support for more GLSL versions (based on the GLSL version string). Added error output when shaders fail to compile/link.
|
||||
// 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples.
|
||||
// 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
||||
// 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state.
|
||||
// 2018-05-14: OpenGL: Making the call to glBindSampler() optional so 3.2 context won't fail if the function is a NULL pointer.
|
||||
// 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplOpenGL3_Init() so user can override the GLSL version e.g. "#version 150".
|
||||
// 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context.
|
||||
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplSdlGL3_RenderDrawData() in the .h file so you can call it yourself.
|
||||
// 2018-01-07: OpenGL: Changed GLSL shader version from 330 to 150.
|
||||
// 2017-09-01: OpenGL: Save and restore current bound sampler. Save and restore current polygon mode.
|
||||
// 2017-05-01: OpenGL: Fixed save and restore of current blend func state.
|
||||
// 2017-05-01: OpenGL: Fixed save and restore of current GL_ACTIVE_TEXTURE.
|
||||
// 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle.
|
||||
// 2016-07-29: OpenGL: Explicitly setting GL_UNPACK_ROW_LENGTH to reduce issues because SDL changes it. (#752)
|
||||
|
||||
//----------------------------------------
|
||||
// OpenGL GLSL GLSL
|
||||
// version version string
|
||||
//----------------------------------------
|
||||
// 2.0 110 "#version 110"
|
||||
// 2.1 120
|
||||
// 3.0 130
|
||||
// 3.1 140
|
||||
// 3.2 150 "#version 150"
|
||||
// 3.3 330
|
||||
// 4.0 400
|
||||
// 4.1 410 "#version 410 core"
|
||||
// 4.2 420
|
||||
// 4.3 430
|
||||
// ES 2.0 100 "#version 100"
|
||||
// ES 3.0 300 "#version 300 es"
|
||||
//----------------------------------------
|
||||
|
||||
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <stdio.h>
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
|
||||
#include <stddef.h> // intptr_t
|
||||
#else
|
||||
#include <stdint.h> // intptr_t
|
||||
#endif
|
||||
#if defined(__APPLE__)
|
||||
#include "TargetConditionals.h"
|
||||
#endif
|
||||
|
||||
// iOS, Android and Emscripten can use GL ES 3
|
||||
// Call ImGui_ImplOpenGL3_Init() with "#version 300 es"
|
||||
#ifdef GLES
|
||||
#define USE_GL_ES3
|
||||
#endif
|
||||
|
||||
#ifdef USE_GL_ES3
|
||||
// OpenGL ES 3
|
||||
#include <GLES3/gl3.h> // Use GL ES 3
|
||||
#else
|
||||
// Regular OpenGL
|
||||
// About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually.
|
||||
// Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad.
|
||||
// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
|
||||
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
|
||||
#include <GL/gl3w.h>
|
||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
|
||||
#include <GL/glew.h>
|
||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
|
||||
#include <glad/glad.h>
|
||||
#else
|
||||
#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
|
||||
#endif
|
||||
#endif
|
||||
#ifdef GLES
|
||||
#undef GL_SAMPLER_BINDING
|
||||
#endif
|
||||
|
||||
// OpenGL Data
|
||||
static char g_GlslVersionString[32] = "";
|
||||
static GLuint g_FontTexture = 0;
|
||||
static GLuint g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
||||
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
|
||||
static int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0;
|
||||
static unsigned int g_VboHandle = 0, g_ElementsHandle = 0;
|
||||
static GLuint g_BackgroundTexture = 0;
|
||||
|
||||
// Functions
|
||||
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.BackendRendererName = "imgui_impl_opengl3";
|
||||
|
||||
// Store GLSL version string so we can refer to it later in case we recreate shaders. Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure.
|
||||
#ifdef USE_GL_ES3
|
||||
if (glsl_version == NULL)
|
||||
glsl_version = "#version 300 es";
|
||||
#else
|
||||
if (glsl_version == NULL)
|
||||
glsl_version = "#version 130";
|
||||
#endif
|
||||
IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(g_GlslVersionString));
|
||||
strcpy(g_GlslVersionString, glsl_version);
|
||||
strcat(g_GlslVersionString, "\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_Shutdown()
|
||||
{
|
||||
ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_NewFrame()
|
||||
{
|
||||
if (!g_FontTexture)
|
||||
ImGui_ImplOpenGL3_CreateDeviceObjects();
|
||||
}
|
||||
|
||||
// OpenGL3 Render function.
|
||||
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
||||
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so.
|
||||
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_background)
|
||||
{
|
||||
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
int fb_width = (int)(draw_data->DisplaySize.x * io.DisplayFramebufferScale.x);
|
||||
int fb_height = (int)(draw_data->DisplaySize.y * io.DisplayFramebufferScale.y);
|
||||
if (fb_width <= 0 || fb_height <= 0)
|
||||
return;
|
||||
draw_data->ScaleClipRects(io.DisplayFramebufferScale);
|
||||
|
||||
// Backup GL state
|
||||
GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
|
||||
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||
#ifdef GL_SAMPLER_BINDING
|
||||
GLint last_sampler; glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler);
|
||||
#endif
|
||||
GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
||||
GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
||||
#ifdef GL_POLYGON_MODE
|
||||
GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
|
||||
#endif
|
||||
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
||||
GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
|
||||
GLenum last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*)&last_blend_src_rgb);
|
||||
GLenum last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, (GLint*)&last_blend_dst_rgb);
|
||||
GLenum last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, (GLint*)&last_blend_src_alpha);
|
||||
GLenum last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, (GLint*)&last_blend_dst_alpha);
|
||||
GLenum last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, (GLint*)&last_blend_equation_rgb);
|
||||
GLenum last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, (GLint*)&last_blend_equation_alpha);
|
||||
GLboolean last_enable_blend = glIsEnabled(GL_BLEND);
|
||||
GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE);
|
||||
GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
||||
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||
bool clip_origin_lower_left = true;
|
||||
#ifdef GL_CLIP_ORIGIN
|
||||
GLenum last_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)&last_clip_origin); // Support for GL 4.5's glClipControl(GL_UPPER_LEFT)
|
||||
if (last_clip_origin == GL_UPPER_LEFT)
|
||||
clip_origin_lower_left = false;
|
||||
#endif
|
||||
|
||||
if (save_background)
|
||||
{
|
||||
#ifndef GLES
|
||||
glReadBuffer(GL_FRONT);
|
||||
#endif
|
||||
// (Re-)create the background texture and reserve space for it
|
||||
if (g_BackgroundTexture != 0)
|
||||
glDeleteTextures(1, &g_BackgroundTexture);
|
||||
glGenTextures(1, &g_BackgroundTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, g_BackgroundTexture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fb_width, fb_height, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)NULL);
|
||||
|
||||
// Copy the current framebuffer into it
|
||||
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, fb_width, fb_height, 0);
|
||||
}
|
||||
|
||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
#ifdef GL_POLYGON_MODE
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
#endif
|
||||
|
||||
// Setup viewport, orthographic projection matrix
|
||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is typically (0,0) for single viewport apps.
|
||||
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
|
||||
float L = draw_data->DisplayPos.x;
|
||||
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
|
||||
float T = draw_data->DisplayPos.y;
|
||||
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
|
||||
const float ortho_projection[4][4] =
|
||||
{
|
||||
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
||||
{ (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
|
||||
};
|
||||
glUseProgram(g_ShaderHandle);
|
||||
glUniform1i(g_AttribLocationTex, 0);
|
||||
glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
|
||||
#ifdef GL_SAMPLER_BINDING
|
||||
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
|
||||
#endif
|
||||
#ifndef GLES
|
||||
// Recreate the VAO every time
|
||||
// (This is to easily allow multiple GL contexts. VAO are not shared among GL contexts, and we don't track creation/deletion of windows so we don't have an obvious key to use to cache them.)
|
||||
GLuint vao_handle = 0;
|
||||
glGenVertexArrays(1, &vao_handle);
|
||||
glBindVertexArray(vao_handle);
|
||||
#endif
|
||||
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
||||
glEnableVertexAttribArray(g_AttribLocationPosition);
|
||||
glEnableVertexAttribArray(g_AttribLocationUV);
|
||||
glEnableVertexAttribArray(g_AttribLocationColor);
|
||||
glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos));
|
||||
glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv));
|
||||
glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col));
|
||||
|
||||
// Draw
|
||||
ImVec2 pos = draw_data->DisplayPos;
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
const ImDrawIdx* idx_buffer_offset = 0;
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * sizeof(ImDrawVert), (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx), (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW);
|
||||
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
||||
{
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
// User callback (registered via ImDrawList::AddCallback)
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImVec4 clip_rect = ImVec4(pcmd->ClipRect.x - pos.x, pcmd->ClipRect.y - pos.y, pcmd->ClipRect.z - pos.x, pcmd->ClipRect.w - pos.y);
|
||||
if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
|
||||
{
|
||||
// Apply scissor/clipping rectangle
|
||||
if (clip_origin_lower_left)
|
||||
glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x), (int)(clip_rect.w - clip_rect.y));
|
||||
else
|
||||
glScissor((int)clip_rect.x, (int)clip_rect.y, (int)clip_rect.z, (int)clip_rect.w); // Support for GL 4.5's glClipControl(GL_UPPER_LEFT)
|
||||
|
||||
// Bind texture, Draw
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
|
||||
}
|
||||
}
|
||||
idx_buffer_offset += pcmd->ElemCount;
|
||||
}
|
||||
}
|
||||
#ifndef GLES
|
||||
glDeleteVertexArrays(1, &vao_handle);
|
||||
#endif
|
||||
|
||||
// Restore modified GL state
|
||||
glUseProgram(last_program);
|
||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||
#ifdef GL_SAMPLER_BINDING
|
||||
glBindSampler(0, last_sampler);
|
||||
#endif
|
||||
glActiveTexture(last_active_texture);
|
||||
#ifndef GLES
|
||||
glBindVertexArray(last_vertex_array);
|
||||
#endif
|
||||
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
|
||||
glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
|
||||
if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
|
||||
if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
|
||||
if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
|
||||
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
|
||||
#ifdef GL_POLYGON_MODE
|
||||
glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]);
|
||||
#endif
|
||||
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
|
||||
glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
|
||||
}
|
||||
|
||||
bool ImGui_ImplOpenGL3_CreateFontsTexture()
|
||||
{
|
||||
// Build texture atlas
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
unsigned char* pixels;
|
||||
int width, height;
|
||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
|
||||
|
||||
// Upload texture to graphics system
|
||||
GLint last_texture;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||
glGenTextures(1, &g_FontTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
// Store our identifier
|
||||
io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontTexture;
|
||||
|
||||
// Restore state
|
||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_DestroyFontsTexture()
|
||||
{
|
||||
if (g_FontTexture)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
glDeleteTextures(1, &g_FontTexture);
|
||||
io.Fonts->TexID = 0;
|
||||
g_FontTexture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.
|
||||
static bool CheckShader(GLuint handle, const char* desc)
|
||||
{
|
||||
GLint status = 0, log_length = 0;
|
||||
glGetShaderiv(handle, GL_COMPILE_STATUS, &status);
|
||||
glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length);
|
||||
if ((GLboolean)status == GL_FALSE)
|
||||
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s!\n", desc);
|
||||
if (log_length > 0)
|
||||
{
|
||||
ImVector<char> buf;
|
||||
buf.resize((int)(log_length + 1));
|
||||
glGetShaderInfoLog(handle, log_length, NULL, (GLchar*)buf.begin());
|
||||
fprintf(stderr, "%s\n", buf.begin());
|
||||
}
|
||||
return (GLboolean)status == GL_TRUE;
|
||||
}
|
||||
|
||||
// If you get an error please report on GitHub. You may try different GL context version or GLSL version.
|
||||
static bool CheckProgram(GLuint handle, const char* desc)
|
||||
{
|
||||
GLint status = 0, log_length = 0;
|
||||
glGetProgramiv(handle, GL_LINK_STATUS, &status);
|
||||
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
|
||||
if ((GLboolean)status == GL_FALSE)
|
||||
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! (with GLSL '%s')\n", desc, g_GlslVersionString);
|
||||
if (log_length > 0)
|
||||
{
|
||||
ImVector<char> buf;
|
||||
buf.resize((int)(log_length + 1));
|
||||
glGetProgramInfoLog(handle, log_length, NULL, (GLchar*)buf.begin());
|
||||
fprintf(stderr, "%s\n", buf.begin());
|
||||
}
|
||||
return (GLboolean)status == GL_TRUE;
|
||||
}
|
||||
|
||||
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
||||
{
|
||||
// Backup GL state
|
||||
GLint last_texture, last_array_buffer, last_vertex_array;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
||||
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
||||
|
||||
// Parse GLSL version string
|
||||
int glsl_version = 130;
|
||||
sscanf(g_GlslVersionString, "#version %d", &glsl_version);
|
||||
|
||||
const GLchar* vertex_shader_glsl_120 =
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"attribute vec2 Position;\n"
|
||||
"attribute vec2 UV;\n"
|
||||
"attribute vec4 Color;\n"
|
||||
"varying vec2 Frag_UV;\n"
|
||||
"varying vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* vertex_shader_glsl_130 =
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"in vec2 Position;\n"
|
||||
"in vec2 UV;\n"
|
||||
"in vec4 Color;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* vertex_shader_glsl_300_es =
|
||||
"precision mediump float;\n"
|
||||
"layout (location = 0) in vec2 Position;\n"
|
||||
"layout (location = 1) in vec2 UV;\n"
|
||||
"layout (location = 2) in vec4 Color;\n"
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* vertex_shader_glsl_410_core =
|
||||
"layout (location = 0) in vec2 Position;\n"
|
||||
"layout (location = 1) in vec2 UV;\n"
|
||||
"layout (location = 2) in vec4 Color;\n"
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_120 =
|
||||
"#ifdef GL_ES\n"
|
||||
" precision mediump float;\n"
|
||||
"#endif\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"varying vec2 Frag_UV;\n"
|
||||
"varying vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_130 =
|
||||
"uniform sampler2D Texture;\n"
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"out vec4 Out_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_300_es =
|
||||
"precision mediump float;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"layout (location = 0) out vec4 Out_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_410_core =
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"layout (location = 0) out vec4 Out_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
// Select shaders matching our GLSL versions
|
||||
const GLchar* vertex_shader = NULL;
|
||||
const GLchar* fragment_shader = NULL;
|
||||
if (glsl_version < 130)
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_120;
|
||||
fragment_shader = fragment_shader_glsl_120;
|
||||
}
|
||||
else if (glsl_version >= 410)
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_410_core;
|
||||
fragment_shader = fragment_shader_glsl_410_core;
|
||||
}
|
||||
else if (glsl_version == 300)
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_300_es;
|
||||
fragment_shader = fragment_shader_glsl_300_es;
|
||||
}
|
||||
else
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_130;
|
||||
fragment_shader = fragment_shader_glsl_130;
|
||||
}
|
||||
|
||||
// Create shaders
|
||||
const GLchar* vertex_shader_with_version[2] = { g_GlslVersionString, vertex_shader };
|
||||
g_VertHandle = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(g_VertHandle, 2, vertex_shader_with_version, NULL);
|
||||
glCompileShader(g_VertHandle);
|
||||
CheckShader(g_VertHandle, "vertex shader");
|
||||
|
||||
const GLchar* fragment_shader_with_version[2] = { g_GlslVersionString, fragment_shader };
|
||||
g_FragHandle = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(g_FragHandle, 2, fragment_shader_with_version, NULL);
|
||||
glCompileShader(g_FragHandle);
|
||||
CheckShader(g_FragHandle, "fragment shader");
|
||||
|
||||
g_ShaderHandle = glCreateProgram();
|
||||
glAttachShader(g_ShaderHandle, g_VertHandle);
|
||||
glAttachShader(g_ShaderHandle, g_FragHandle);
|
||||
glLinkProgram(g_ShaderHandle);
|
||||
CheckProgram(g_ShaderHandle, "shader program");
|
||||
|
||||
g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture");
|
||||
g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx");
|
||||
g_AttribLocationPosition = glGetAttribLocation(g_ShaderHandle, "Position");
|
||||
g_AttribLocationUV = glGetAttribLocation(g_ShaderHandle, "UV");
|
||||
g_AttribLocationColor = glGetAttribLocation(g_ShaderHandle, "Color");
|
||||
|
||||
// Create buffers
|
||||
glGenBuffers(1, &g_VboHandle);
|
||||
glGenBuffers(1, &g_ElementsHandle);
|
||||
|
||||
ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||
|
||||
// Restore modified GL state
|
||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||
#ifndef GLES
|
||||
glBindVertexArray(last_vertex_array);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
|
||||
{
|
||||
if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle);
|
||||
if (g_ElementsHandle) glDeleteBuffers(1, &g_ElementsHandle);
|
||||
g_VboHandle = g_ElementsHandle = 0;
|
||||
|
||||
if (g_ShaderHandle && g_VertHandle) glDetachShader(g_ShaderHandle, g_VertHandle);
|
||||
if (g_VertHandle) glDeleteShader(g_VertHandle);
|
||||
g_VertHandle = 0;
|
||||
|
||||
if (g_ShaderHandle && g_FragHandle) glDetachShader(g_ShaderHandle, g_FragHandle);
|
||||
if (g_FragHandle) glDeleteShader(g_FragHandle);
|
||||
g_FragHandle = 0;
|
||||
|
||||
if (g_ShaderHandle) glDeleteProgram(g_ShaderHandle);
|
||||
g_ShaderHandle = 0;
|
||||
|
||||
ImGui_ImplOpenGL3_DestroyFontsTexture();
|
||||
|
||||
if (g_BackgroundTexture != 0)
|
||||
glDeleteTextures(1, &g_BackgroundTexture);
|
||||
g_BackgroundTexture = 0;
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_DrawBackground()
|
||||
{
|
||||
if (g_BackgroundTexture != 0)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||
ImGui::SetNextWindowSize(io.DisplaySize);
|
||||
ImGui::Begin("background", NULL, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoFocusOnAppearing
|
||||
| ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoBackground);
|
||||
ImGui::GetWindowDrawList()->AddImage((ImTextureID)(uintptr_t)g_BackgroundTexture, ImVec2(0, 0), io.DisplaySize, ImVec2(0, 1), ImVec2(1, 0), 0xffffffff);
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
// dear imgui: Renderer for OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline)
|
||||
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
|
||||
// (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. 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 are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
|
||||
// https://github.com/ocornut/imgui
|
||||
|
||||
// About OpenGL function loaders:
|
||||
// About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually.
|
||||
// Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad.
|
||||
// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
|
||||
|
||||
// About GLSL version:
|
||||
// The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string.
|
||||
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
|
||||
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
|
||||
|
||||
#pragma once
|
||||
|
||||
// Set default OpenGL loader to be gl3w
|
||||
#if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \
|
||||
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \
|
||||
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \
|
||||
&& !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
|
||||
#endif
|
||||
|
||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL);
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_background = false);
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DrawBackground();
|
||||
|
||||
// Called by Init/NewFrame/Shutdown
|
||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
|
||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,623 @@
|
|||
// stb_rect_pack.h - v0.11 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
// Does not do rotation.
|
||||
//
|
||||
// Not necessarily the awesomest packing method, but better than
|
||||
// the totally naive one in stb_truetype (which is primarily what
|
||||
// this is meant to replace).
|
||||
//
|
||||
// Has only had a few tests run, may have issues.
|
||||
//
|
||||
// More docs to come.
|
||||
//
|
||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||
//
|
||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||
//
|
||||
// Please note: better rectangle packers are welcome! Please
|
||||
// implement them to the same API, but with a different init
|
||||
// function.
|
||||
//
|
||||
// Credits
|
||||
//
|
||||
// Library
|
||||
// Sean Barrett
|
||||
// Minor features
|
||||
// Martins Mozeiko
|
||||
// github:IntellectualKitty
|
||||
//
|
||||
// Bugfixes / warning fixes
|
||||
// Jeremy Jaussaud
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||
// 0.09 (2016-08-27) fix compiler warnings
|
||||
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||
// 0.01: initial release
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file for license information.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// INCLUDE SECTION
|
||||
//
|
||||
|
||||
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||
|
||||
#define STB_RECT_PACK_VERSION 1
|
||||
|
||||
#ifdef STBRP_STATIC
|
||||
#define STBRP_DEF static
|
||||
#else
|
||||
#define STBRP_DEF extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct stbrp_context stbrp_context;
|
||||
typedef struct stbrp_node stbrp_node;
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
|
||||
#ifdef STBRP_LARGE_RECTS
|
||||
typedef int stbrp_coord;
|
||||
#else
|
||||
typedef unsigned short stbrp_coord;
|
||||
#endif
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||
// Assign packed locations to rectangles. The rectangles are of type
|
||||
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||
// are 'num_rects' many of them.
|
||||
//
|
||||
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||
// have the 'was_packed' flag set to 0.
|
||||
//
|
||||
// You should not try to access the 'rects' array from another thread
|
||||
// while this function is running, as the function temporarily reorders
|
||||
// the array while it executes.
|
||||
//
|
||||
// To pack into another rectangle, you need to call stbrp_init_target
|
||||
// again. To continue packing into the same rectangle, you can call
|
||||
// this function again. Calling this multiple times with multiple rect
|
||||
// arrays will probably produce worse packing results than calling it
|
||||
// a single time with the full rectangle array, but the option is
|
||||
// available.
|
||||
//
|
||||
// The function returns 1 if all of the rectangles were successfully
|
||||
// packed and 0 otherwise.
|
||||
|
||||
struct stbrp_rect
|
||||
{
|
||||
// reserved for your use:
|
||||
int id;
|
||||
|
||||
// input:
|
||||
stbrp_coord w, h;
|
||||
|
||||
// output:
|
||||
stbrp_coord x, y;
|
||||
int was_packed; // non-zero if valid packing
|
||||
|
||||
}; // 16 bytes, nominally
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||
// Initialize a rectangle packer to:
|
||||
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||
//
|
||||
// You must call this function every time you start packing into a new target.
|
||||
//
|
||||
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||
// the call (or calls) finish.
|
||||
//
|
||||
// Note: to guarantee best results, either:
|
||||
// 1. make sure 'num_nodes' >= 'width'
|
||||
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||
//
|
||||
// If you don't do either of the above things, widths will be quantized to multiples
|
||||
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||
//
|
||||
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||
// may run out of temporary storage and be unable to pack some rectangles.
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||
// Optionally call this function after init but before doing any packing to
|
||||
// change the handling of the out-of-temp-memory scenario, described above.
|
||||
// If you call init again, this will be reset to the default (false).
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||
// Optionally select which packing heuristic the library should use. Different
|
||||
// heuristics will produce better/worse results for different data sets.
|
||||
// If you call init again, this will be reset to the default.
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP_HEURISTIC_Skyline_default=0,
|
||||
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// the details of the following structures don't matter to you, but they must
|
||||
// be visible so you can handle the memory allocations for them
|
||||
|
||||
struct stbrp_node
|
||||
{
|
||||
stbrp_coord x,y;
|
||||
stbrp_node *next;
|
||||
};
|
||||
|
||||
struct stbrp_context
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int align;
|
||||
int init_mode;
|
||||
int heuristic;
|
||||
int num_nodes;
|
||||
stbrp_node *active_head;
|
||||
stbrp_node *free_head;
|
||||
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPLEMENTATION SECTION
|
||||
//
|
||||
|
||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||
#ifndef STBRP_SORT
|
||||
#include <stdlib.h>
|
||||
#define STBRP_SORT qsort
|
||||
#endif
|
||||
|
||||
#ifndef STBRP_ASSERT
|
||||
#include <assert.h>
|
||||
#define STBRP_ASSERT assert
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STBRP__NOTUSED(v) (void)(v)
|
||||
#define STBRP__CDECL __cdecl
|
||||
#else
|
||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||
#define STBRP__CDECL
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP__INIT_skyline = 1
|
||||
};
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||
{
|
||||
switch (context->init_mode) {
|
||||
case STBRP__INIT_skyline:
|
||||
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||
context->heuristic = heuristic;
|
||||
break;
|
||||
default:
|
||||
STBRP_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||
{
|
||||
if (allow_out_of_mem)
|
||||
// if it's ok to run out of memory, then don't bother aligning them;
|
||||
// this gives better packing, but may fail due to OOM (even though
|
||||
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||
context->align = 1;
|
||||
else {
|
||||
// if it's not ok to run out of memory, then quantize the widths
|
||||
// so that num_nodes is always enough nodes.
|
||||
//
|
||||
// I.e. num_nodes * align >= width
|
||||
// align >= width / num_nodes
|
||||
// align = ceil(width/num_nodes)
|
||||
|
||||
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||
{
|
||||
int i;
|
||||
#ifndef STBRP_LARGE_RECTS
|
||||
STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
|
||||
#endif
|
||||
|
||||
for (i=0; i < num_nodes-1; ++i)
|
||||
nodes[i].next = &nodes[i+1];
|
||||
nodes[i].next = NULL;
|
||||
context->init_mode = STBRP__INIT_skyline;
|
||||
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||
context->free_head = &nodes[0];
|
||||
context->active_head = &context->extra[0];
|
||||
context->width = width;
|
||||
context->height = height;
|
||||
context->num_nodes = num_nodes;
|
||||
stbrp_setup_allow_out_of_mem(context, 0);
|
||||
|
||||
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||
context->extra[0].x = 0;
|
||||
context->extra[0].y = 0;
|
||||
context->extra[0].next = &context->extra[1];
|
||||
context->extra[1].x = (stbrp_coord) width;
|
||||
#ifdef STBRP_LARGE_RECTS
|
||||
context->extra[1].y = (1<<30);
|
||||
#else
|
||||
context->extra[1].y = 65535;
|
||||
#endif
|
||||
context->extra[1].next = NULL;
|
||||
}
|
||||
|
||||
// find minimum y position if it starts at x1
|
||||
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||
{
|
||||
stbrp_node *node = first;
|
||||
int x1 = x0 + width;
|
||||
int min_y, visited_width, waste_area;
|
||||
|
||||
STBRP__NOTUSED(c);
|
||||
|
||||
STBRP_ASSERT(first->x <= x0);
|
||||
|
||||
#if 0
|
||||
// skip in case we're past the node
|
||||
while (node->next->x <= x0)
|
||||
++node;
|
||||
#else
|
||||
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||
#endif
|
||||
|
||||
STBRP_ASSERT(node->x <= x0);
|
||||
|
||||
min_y = 0;
|
||||
waste_area = 0;
|
||||
visited_width = 0;
|
||||
while (node->x < x1) {
|
||||
if (node->y > min_y) {
|
||||
// raise min_y higher.
|
||||
// we've accounted for all waste up to min_y,
|
||||
// but we'll now add more waste for everything we've visted
|
||||
waste_area += visited_width * (node->y - min_y);
|
||||
min_y = node->y;
|
||||
// the first time through, visited_width might be reduced
|
||||
if (node->x < x0)
|
||||
visited_width += node->next->x - x0;
|
||||
else
|
||||
visited_width += node->next->x - node->x;
|
||||
} else {
|
||||
// add waste area
|
||||
int under_width = node->next->x - node->x;
|
||||
if (under_width + visited_width > width)
|
||||
under_width = width - visited_width;
|
||||
waste_area += under_width * (min_y - node->y);
|
||||
visited_width += under_width;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
*pwaste = waste_area;
|
||||
return min_y;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x,y;
|
||||
stbrp_node **prev_link;
|
||||
} stbrp__findresult;
|
||||
|
||||
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||
{
|
||||
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||
stbrp__findresult fr;
|
||||
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||
|
||||
// align to multiple of c->align
|
||||
width = (width + c->align - 1);
|
||||
width -= width % c->align;
|
||||
STBRP_ASSERT(width % c->align == 0);
|
||||
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
while (node->x + width <= c->width) {
|
||||
int y,waste;
|
||||
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||
// bottom left
|
||||
if (y < best_y) {
|
||||
best_y = y;
|
||||
best = prev;
|
||||
}
|
||||
} else {
|
||||
// best-fit
|
||||
if (y + height <= c->height) {
|
||||
// can only use it if it first vertically
|
||||
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||
|
||||
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||
//
|
||||
// e.g, if fitting
|
||||
//
|
||||
// ____________________
|
||||
// |____________________|
|
||||
//
|
||||
// into
|
||||
//
|
||||
// | |
|
||||
// | ____________|
|
||||
// |____________|
|
||||
//
|
||||
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||
//
|
||||
// This makes BF take about 2x the time
|
||||
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||
tail = c->active_head;
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
// find first node that's admissible
|
||||
while (tail->x < width)
|
||||
tail = tail->next;
|
||||
while (tail) {
|
||||
int xpos = tail->x - width;
|
||||
int y,waste;
|
||||
STBRP_ASSERT(xpos >= 0);
|
||||
// find the left position that matches this
|
||||
while (node->next->x <= xpos) {
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||
if (y + height < c->height) {
|
||||
if (y <= best_y) {
|
||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||
best_x = xpos;
|
||||
STBRP_ASSERT(y <= best_y);
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
|
||||
fr.prev_link = best;
|
||||
fr.x = best_x;
|
||||
fr.y = best_y;
|
||||
return fr;
|
||||
}
|
||||
|
||||
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||
{
|
||||
// find best position according to heuristic
|
||||
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||
stbrp_node *node, *cur;
|
||||
|
||||
// bail if:
|
||||
// 1. it failed
|
||||
// 2. the best node doesn't fit (we don't always check this)
|
||||
// 3. we're out of memory
|
||||
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||
res.prev_link = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
// on success, create new node
|
||||
node = context->free_head;
|
||||
node->x = (stbrp_coord) res.x;
|
||||
node->y = (stbrp_coord) (res.y + height);
|
||||
|
||||
context->free_head = node->next;
|
||||
|
||||
// insert the new node into the right starting point, and
|
||||
// let 'cur' point to the remaining nodes needing to be
|
||||
// stiched back in
|
||||
|
||||
cur = *res.prev_link;
|
||||
if (cur->x < res.x) {
|
||||
// preserve the existing one, so start testing with the next one
|
||||
stbrp_node *next = cur->next;
|
||||
cur->next = node;
|
||||
cur = next;
|
||||
} else {
|
||||
*res.prev_link = node;
|
||||
}
|
||||
|
||||
// from here, traverse cur and free the nodes, until we get to one
|
||||
// that shouldn't be freed
|
||||
while (cur->next && cur->next->x <= res.x + width) {
|
||||
stbrp_node *next = cur->next;
|
||||
// move the current node to the free list
|
||||
cur->next = context->free_head;
|
||||
context->free_head = cur;
|
||||
cur = next;
|
||||
}
|
||||
|
||||
// stitch the list back in
|
||||
node->next = cur;
|
||||
|
||||
if (cur->x < res.x + width)
|
||||
cur->x = (stbrp_coord) (res.x + width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
cur = context->active_head;
|
||||
while (cur->x < context->width) {
|
||||
STBRP_ASSERT(cur->x < cur->next->x);
|
||||
cur = cur->next;
|
||||
}
|
||||
STBRP_ASSERT(cur->next == NULL);
|
||||
|
||||
{
|
||||
int count=0;
|
||||
cur = context->active_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
cur = context->free_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
STBRP_ASSERT(count == context->num_nodes+2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
if (p->h > q->h)
|
||||
return -1;
|
||||
if (p->h < q->h)
|
||||
return 1;
|
||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
#ifdef STBRP_LARGE_RECTS
|
||||
#define STBRP__MAXVAL 0xffffffff
|
||||
#else
|
||||
#define STBRP__MAXVAL 0xffff
|
||||
#endif
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||
{
|
||||
int i, all_rects_packed = 1;
|
||||
|
||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = i;
|
||||
#ifndef STBRP_LARGE_RECTS
|
||||
STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff);
|
||||
#endif
|
||||
}
|
||||
|
||||
// sort according to heuristic
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||
} else {
|
||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||
if (fr.prev_link) {
|
||||
rects[i].x = (stbrp_coord) fr.x;
|
||||
rects[i].y = (stbrp_coord) fr.y;
|
||||
} else {
|
||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unsort
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
|
||||
// set was_packed flags and all_rects_packed status
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||
if (!rects[i].was_packed)
|
||||
all_rects_packed = 0;
|
||||
}
|
||||
|
||||
// return the all_rects_packed status
|
||||
return all_rects_packed;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -2,6 +2,7 @@
|
|||
#include "ta.h"
|
||||
#include "hw/pvr/pvr_mem.h"
|
||||
#include "rend/TexCache.h"
|
||||
#include "rend/gui.h"
|
||||
|
||||
#include "deps/zlib/zlib.h"
|
||||
|
||||
|
@ -269,12 +270,31 @@ bool rend_single_frame()
|
|||
do
|
||||
{
|
||||
#if !defined(TARGET_NO_THREADS)
|
||||
if (gui_is_open())
|
||||
{
|
||||
if (!rs.Wait(1000 / 60))
|
||||
{
|
||||
gui_display_ui();
|
||||
FinishRender(NULL);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(_ANDROID)
|
||||
if (!rs.Wait(100))
|
||||
return false;
|
||||
if (!rs.Wait(100))
|
||||
return false;
|
||||
#else
|
||||
rs.Wait();
|
||||
rs.Wait();
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
if (gui_is_open())
|
||||
{
|
||||
gui_display_ui();
|
||||
FinishRender(NULL);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
if (!renderer_enabled)
|
||||
return false;
|
||||
|
@ -284,8 +304,10 @@ bool rend_single_frame()
|
|||
while (!_pvrrc);
|
||||
bool do_swp = rend_frame(_pvrrc, true);
|
||||
|
||||
#if !defined(TARGET_NO_THREADS)
|
||||
if (_pvrrc->rend.isRTT)
|
||||
re.Set();
|
||||
#endif
|
||||
|
||||
//clear up & free data ..
|
||||
FinishRender(_pvrrc);
|
||||
|
@ -648,6 +670,7 @@ void check_framebuffer_write()
|
|||
|
||||
void rend_cancel_emu_wait()
|
||||
{
|
||||
FinishRender(NULL);
|
||||
#if !defined(TARGET_NO_THREADS)
|
||||
re.Set();
|
||||
#endif
|
||||
|
|
|
@ -198,12 +198,13 @@ bool rend_framePending() {
|
|||
|
||||
void FinishRender(TA_context* ctx)
|
||||
{
|
||||
verify(rqueue == ctx);
|
||||
verify(ctx == NULL || rqueue == ctx);
|
||||
mtx_rqueue.Lock();
|
||||
rqueue = 0;
|
||||
mtx_rqueue.Unlock();
|
||||
|
||||
tactx_Recycle(ctx);
|
||||
if (ctx != NULL)
|
||||
tactx_Recycle(ctx);
|
||||
frame_finished.Set();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "cfg/cfg.h"
|
||||
#include "linux-dist/x11.h"
|
||||
#include "linux-dist/main.h"
|
||||
#include "rend/gui.h"
|
||||
|
||||
#if FEAT_HAS_NIXPROF
|
||||
#include "profiler/profiler.h"
|
||||
|
@ -47,7 +48,6 @@ extern bool naomi_test_button;
|
|||
void dc_stop(void);
|
||||
bool dc_loadstate(void);
|
||||
bool dc_savestate(void);
|
||||
void dc_enable_dynarec(bool enable);
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -395,20 +395,15 @@ void input_x11_handle()
|
|||
}
|
||||
if (x11_keyboard_input)
|
||||
{
|
||||
// Normal keyboard handling
|
||||
if (e.type == KeyRelease && e.xkey.keycode == KEY_ESC
|
||||
&& !(e.xkey.state & (ControlMask | ShiftMask | Mod1Mask)))
|
||||
{
|
||||
dc_stop();
|
||||
}
|
||||
#ifndef RELEASE
|
||||
else if (e.xkey.keycode == KEY_F10)
|
||||
if (e.xkey.keycode == KEY_F10)
|
||||
{
|
||||
// Dump the next frame into a file
|
||||
dump_frame_switch = e.type == KeyPress;
|
||||
}
|
||||
else
|
||||
#elif FEAT_HAS_NIXPROF
|
||||
else if (e.type == KeyRelease && e.xkey.keycode == KEY_F10)
|
||||
if (e.type == KeyRelease && e.xkey.keycode == KEY_F10)
|
||||
{
|
||||
if (sample_Switch(3000)) {
|
||||
printf("Starting profiling\n");
|
||||
|
@ -416,8 +411,9 @@ void input_x11_handle()
|
|||
printf("Stopping profiling\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
else if (e.type == KeyRelease && e.xkey.keycode == KEY_F11)
|
||||
if (e.type == KeyRelease && e.xkey.keycode == KEY_F11)
|
||||
{
|
||||
x11_fullscreen = !x11_fullscreen;
|
||||
x11_window_set_fullscreen(x11_fullscreen);
|
||||
|
@ -430,13 +426,6 @@ void input_x11_handle()
|
|||
{
|
||||
dc_loadstate() ;
|
||||
}
|
||||
else if (e.type == KeyRelease && e.xkey.keycode == KEY_F12)
|
||||
{
|
||||
extern bool renderer_changed;
|
||||
settings.pvr.rend = settings.pvr.rend == 0 ? 3 : 0; // Alternate between per-pixel and per-triangle
|
||||
printf("OpenGL: renderer changed to %d\n", settings.pvr.rend);
|
||||
renderer_changed = true;
|
||||
}
|
||||
#if DC_PLATFORM == DC_PLATFORM_NAOMI || DC_PLATFORM == DC_PLATFORM_ATOMISWAVE
|
||||
else if (e.xkey.keycode == KEY_F8)
|
||||
{
|
||||
|
@ -447,11 +436,12 @@ void input_x11_handle()
|
|||
naomi_test_button = e.type == KeyPress;
|
||||
}
|
||||
#endif
|
||||
else if (e.type == KeyRelease && e.xkey.keycode == KEY_F6)
|
||||
else if (e.type == KeyRelease && e.xkey.keycode == KEY_TAB)
|
||||
{
|
||||
dc_enable_dynarec(settings.dynarec.Enable == 0);
|
||||
gui_open_settings();
|
||||
}
|
||||
else
|
||||
|
||||
if (!gui_is_open())
|
||||
{
|
||||
int dc_key = x11_keymap[e.xkey.keycode];
|
||||
|
||||
|
@ -609,6 +599,9 @@ void x11_window_create()
|
|||
return;
|
||||
}
|
||||
x11Screen = XDefaultScreen(x11Display);
|
||||
float xdpi = (float)DisplayWidth(x11Display, x11Screen) / DisplayWidthMM(x11Display, x11Screen) * 25.4;
|
||||
float ydpi = (float)DisplayHeight(x11Display, x11Screen) / DisplayHeightMM(x11Display, x11Screen) * 25.4;
|
||||
screen_dpi = max(xdpi, ydpi);
|
||||
|
||||
// Gets the window parameters
|
||||
sRootWindow = RootWindow(x11Display, x11Screen);
|
||||
|
@ -682,8 +675,7 @@ void x11_window_create()
|
|||
|
||||
// Add to these for handling other events
|
||||
sWA.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask;
|
||||
if (settings.input.DCMouse)
|
||||
sWA.event_mask |= PointerMotionMask | FocusChangeMask;
|
||||
sWA.event_mask |= PointerMotionMask | FocusChangeMask;
|
||||
ui32Mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;
|
||||
|
||||
x11_width = cfgLoadInt("x11", "width", DEFAULT_WINDOW_WIDTH);
|
||||
|
|
144
core/nullDC.cpp
144
core/nullDC.cpp
|
@ -19,14 +19,15 @@
|
|||
#include "hw/sh4/sh4_sched.h"
|
||||
#include "hw/pvr/Renderer_if.h"
|
||||
#include "hw/pvr/spg.h"
|
||||
#include "hw/aica/dsp.h"
|
||||
|
||||
void FlushCache();
|
||||
static void LoadCustom();
|
||||
|
||||
settings_t settings;
|
||||
static bool continue_running = false;
|
||||
static cMutex mtx_serialization ;
|
||||
static cMutex mtx_mainloop ;
|
||||
static int new_dynarec_setting = -1;
|
||||
|
||||
/*
|
||||
libndc
|
||||
|
@ -426,6 +427,7 @@ void dc_run()
|
|||
{
|
||||
while ( true )
|
||||
{
|
||||
bool dynarec_enabled = settings.dynarec.Enable;
|
||||
continue_running = false ;
|
||||
mtx_mainloop.Lock() ;
|
||||
sh4_cpu.Run();
|
||||
|
@ -434,9 +436,8 @@ void dc_run()
|
|||
mtx_serialization.Lock() ;
|
||||
mtx_serialization.Unlock() ;
|
||||
|
||||
if (new_dynarec_setting != -1 && new_dynarec_setting != settings.dynarec.Enable)
|
||||
if (dynarec_enabled != settings.dynarec.Enable)
|
||||
{
|
||||
settings.dynarec.Enable = new_dynarec_setting;
|
||||
if (settings.dynarec.Enable)
|
||||
{
|
||||
Get_Sh4Recompiler(&sh4_cpu);
|
||||
|
@ -463,9 +464,7 @@ void dc_term()
|
|||
|
||||
mcfg_DestroyDevices();
|
||||
|
||||
#ifndef _ANDROID
|
||||
SaveSettings();
|
||||
#endif
|
||||
SaveRomFiles(get_writable_data_path("/data/"));
|
||||
|
||||
TermAudio();
|
||||
|
@ -588,7 +587,7 @@ void LoadSettings()
|
|||
*/
|
||||
}
|
||||
|
||||
void LoadCustom()
|
||||
static void LoadCustom()
|
||||
{
|
||||
#if DC_PLATFORM == DC_PLATFORM_DREAMCAST
|
||||
char *reios_id = reios_disk_id();
|
||||
|
@ -628,17 +627,43 @@ void LoadCustom()
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifndef _ANDROID
|
||||
void SaveSettings()
|
||||
{
|
||||
cfgSaveInt("config","Dynarec.Enabled", settings.dynarec.Enable);
|
||||
#if DC_PLATFORM == DC_PLATFORM_DREAMCAST
|
||||
cfgSaveInt("config","Dreamcast.Cable", settings.dreamcast.cable);
|
||||
cfgSaveInt("config","Dreamcast.Region", settings.dreamcast.region);
|
||||
cfgSaveInt("config","Dreamcast.Broadcast", settings.dreamcast.broadcast);
|
||||
#endif
|
||||
}
|
||||
cfgSaveInt("config", "Dynarec.Enabled", settings.dynarec.Enable);
|
||||
cfgSaveInt("config", "Dreamcast.Cable", settings.dreamcast.cable);
|
||||
cfgSaveInt("config", "Dreamcast.Region", settings.dreamcast.region);
|
||||
cfgSaveInt("config", "Dreamcast.Broadcast", settings.dreamcast.broadcast);
|
||||
cfgSaveInt("config", "Dynarec.idleskip", settings.dynarec.idleskip);
|
||||
cfgSaveInt("config", "Dynarec.unstable-opt", settings.dynarec.unstable_opt);
|
||||
cfgSaveInt("config", "Dynarec.safe-mode", settings.dynarec.safemode);
|
||||
cfgSaveInt("config", "Dreamcast.Language", settings.dreamcast.language);
|
||||
cfgSaveInt("config", "aica.LimitFPS", settings.aica.LimitFPS);
|
||||
cfgSaveInt("config", "aica.NoBatch", settings.aica.NoBatch);
|
||||
cfgSaveInt("config", "rend.WideScreen", settings.rend.WideScreen);
|
||||
cfgSaveInt("config", "rend.ShowFPS", settings.rend.ShowFPS);
|
||||
cfgSaveInt("config", "rend.RenderToTextureBuffer", settings.rend.RenderToTextureBuffer);
|
||||
cfgSaveInt("config", "rend.RenderToTextureUpscale", settings.rend.RenderToTextureUpscale);
|
||||
cfgSaveInt("config", "rend.ModifierVolumes", settings.rend.ModifierVolumes);
|
||||
cfgSaveInt("config", "rend.Clipping", settings.rend.Clipping);
|
||||
cfgSaveInt("config", "rend.TextureUpscale", settings.rend.TextureUpscale);
|
||||
cfgSaveInt("config", "rend.MaxFilteredTextureSize", settings.rend.MaxFilteredTextureSize);
|
||||
cfgSaveInt("config", "rend.CustomTextures", settings.rend.CustomTextures);
|
||||
cfgSaveInt("config", "rend.DumpTextures", settings.rend.DumpTextures);
|
||||
cfgSaveInt("config", "ta.skip", settings.pvr.ta_skip);
|
||||
cfgSaveInt("config", "pvr.rend", settings.pvr.rend);
|
||||
|
||||
bool wait_until_dc_running()
|
||||
cfgSaveInt("config", "pvr.MaxThreads", settings.pvr.MaxThreads);
|
||||
cfgSaveInt("config", "pvr.SynchronousRendering", settings.pvr.SynchronousRender);
|
||||
|
||||
cfgSaveInt("config", "Debug.SerialConsoleEnabled", settings.debug.SerialConsole);
|
||||
cfgSaveInt("input", "DCKeyboard", settings.input.DCKeyboard);
|
||||
cfgSaveInt("input", "DCMouse", settings.input.DCMouse);
|
||||
cfgSaveInt("input", "MouseSensitivity", settings.input.MouseSensitivity);
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool wait_until_dc_running()
|
||||
{
|
||||
int64_t start_time = get_time_usec() ;
|
||||
const int64_t FIVE_SECONDS = 5*1000000 ;
|
||||
|
@ -653,7 +678,7 @@ bool wait_until_dc_running()
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool acquire_mainloop_lock()
|
||||
static bool acquire_mainloop_lock()
|
||||
{
|
||||
bool result = false ;
|
||||
int64_t start_time = get_time_usec() ;
|
||||
|
@ -667,24 +692,51 @@ bool acquire_mainloop_lock()
|
|||
return result ;
|
||||
}
|
||||
|
||||
void dc_enable_dynarec(bool enable)
|
||||
bool dc_pause_emu()
|
||||
{
|
||||
#if FEAT_SHREC != DYNAREC_NONE
|
||||
continue_running = true;
|
||||
new_dynarec_setting = enable;
|
||||
dc_stop();
|
||||
if (sh4_cpu.IsCpuRunning())
|
||||
{
|
||||
#ifndef TARGET_NO_THREADS
|
||||
mtx_serialization.Lock();
|
||||
if (!wait_until_dc_running()) {
|
||||
printf("Can't open settings - dc loop kept running\n");
|
||||
mtx_serialization.Unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
dc_stop();
|
||||
|
||||
if (!acquire_mainloop_lock())
|
||||
{
|
||||
printf("Can't open settings - could not acquire main loop lock\n");
|
||||
continue_running = true;
|
||||
mtx_serialization.Unlock();
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
dc_stop();
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void cleanup_serialize(void *data)
|
||||
void dc_resume_emu(bool continue_running)
|
||||
{
|
||||
if (!sh4_cpu.IsCpuRunning())
|
||||
{
|
||||
::continue_running = continue_running;
|
||||
rend_cancel_emu_wait();
|
||||
mtx_serialization.Unlock();
|
||||
mtx_mainloop.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup_serialize(void *data)
|
||||
{
|
||||
if ( data != NULL )
|
||||
free(data) ;
|
||||
|
||||
continue_running = true ;
|
||||
mtx_serialization.Unlock() ;
|
||||
mtx_mainloop.Unlock() ;
|
||||
|
||||
dc_resume_emu(true);
|
||||
}
|
||||
|
||||
static string get_savestate_file_path()
|
||||
|
@ -702,7 +754,7 @@ static string get_savestate_file_path()
|
|||
return get_writable_data_path("/data/") + state_file;
|
||||
}
|
||||
|
||||
void* dc_savestate_thread(void* p)
|
||||
static void* dc_savestate_thread(void* p)
|
||||
{
|
||||
string filename;
|
||||
unsigned int total_size = 0 ;
|
||||
|
@ -710,22 +762,8 @@ void* dc_savestate_thread(void* p)
|
|||
void *data_ptr = NULL ;
|
||||
FILE *f ;
|
||||
|
||||
mtx_serialization.Lock() ;
|
||||
if ( !wait_until_dc_running()) {
|
||||
printf("Failed to save state - dc loop kept running\n") ;
|
||||
mtx_serialization.Unlock() ;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dc_stop() ;
|
||||
|
||||
if ( !acquire_mainloop_lock() )
|
||||
{
|
||||
printf("Failed to save state - could not acquire main loop lock\n") ;
|
||||
continue_running = true ;
|
||||
mtx_serialization.Unlock() ;
|
||||
return NULL;
|
||||
}
|
||||
if (!dc_pause_emu())
|
||||
return NULL;
|
||||
|
||||
if ( ! dc_serialize(&data, &total_size) )
|
||||
{
|
||||
|
@ -770,7 +808,7 @@ void* dc_savestate_thread(void* p)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void* dc_loadstate_thread(void* p)
|
||||
static void* dc_loadstate_thread(void* p)
|
||||
{
|
||||
string filename;
|
||||
unsigned int total_size = 0 ;
|
||||
|
@ -778,22 +816,8 @@ void* dc_loadstate_thread(void* p)
|
|||
void *data_ptr = NULL ;
|
||||
FILE *f ;
|
||||
|
||||
mtx_serialization.Lock() ;
|
||||
if ( !wait_until_dc_running()) {
|
||||
printf("Failed to load state - dc loop kept running\n") ;
|
||||
mtx_serialization.Unlock() ;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dc_stop() ;
|
||||
|
||||
if ( !acquire_mainloop_lock() )
|
||||
{
|
||||
printf("Failed to load state - could not acquire main loop lock\n") ;
|
||||
continue_running = true ;
|
||||
mtx_serialization.Unlock() ;
|
||||
return NULL;
|
||||
}
|
||||
if (!dc_pause_emu())
|
||||
return NULL;
|
||||
|
||||
filename = get_savestate_file_path();
|
||||
f = fopen(filename.c_str(), "rb") ;
|
||||
|
@ -833,12 +857,12 @@ void* dc_loadstate_thread(void* p)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
dsp.dyndirty = true;
|
||||
sh4_sched_ffts();
|
||||
CalculateSync();
|
||||
|
||||
cleanup_serialize(data) ;
|
||||
printf("Loaded state from %s size %d\n", filename.c_str(), total_size) ;
|
||||
rend_cancel_emu_wait();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "oslib/oslib.h"
|
||||
#include "rend/rend.h"
|
||||
#include "rend/gui.h"
|
||||
|
||||
//Fragment and vertex shaders code
|
||||
|
||||
|
@ -541,6 +542,8 @@ static bool gl_create_resources()
|
|||
|
||||
gl_load_osd_resources();
|
||||
|
||||
gui_init();
|
||||
|
||||
// Create the buffer for Translucent poly params
|
||||
glGenBuffers(1, &gl4.vbo.tr_poly_params);
|
||||
// Bind it
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "glcache.h"
|
||||
#include "rend/TexCache.h"
|
||||
#include "cfg/cfg.h"
|
||||
#include "rend/gui.h"
|
||||
|
||||
#ifdef TARGET_PANDORA
|
||||
#include <unistd.h>
|
||||
|
@ -736,6 +737,7 @@ void findGLVersion()
|
|||
if (glGetError() == GL_INVALID_ENUM)
|
||||
gl.gl_major = 2;
|
||||
const char *version = (const char *)glGetString(GL_VERSION);
|
||||
printf("OpenGL version: %s\n", version);
|
||||
if (!strncmp(version, "OpenGL ES", 9))
|
||||
{
|
||||
gl.is_gles = true;
|
||||
|
@ -1082,6 +1084,8 @@ bool gl_create_resources()
|
|||
|
||||
gl_load_osd_resources();
|
||||
|
||||
gui_init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,452 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "oslib/oslib.h"
|
||||
#include "cfg/cfg.h"
|
||||
#include "hw/maple/maple_cfg.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui/imgui_impl_opengl3.h"
|
||||
#include "imgui/roboto_medium.h"
|
||||
#include "gles/gles.h"
|
||||
|
||||
extern bool dc_pause_emu();
|
||||
extern void dc_resume_emu(bool continue_running);
|
||||
extern void dc_loadstate();
|
||||
extern void dc_savestate();
|
||||
extern void dc_reset();
|
||||
|
||||
extern int screen_width, screen_height;
|
||||
extern u8 kb_shift; // shift keys pressed (bitmask)
|
||||
extern u8 kb_key[6]; // normal keys pressed
|
||||
extern s32 mo_x_abs;
|
||||
extern s32 mo_y_abs;
|
||||
extern u32 mo_buttons;
|
||||
extern bool renderer_changed;
|
||||
|
||||
int screen_dpi = 96;
|
||||
|
||||
static bool inited = false;
|
||||
static float scaling = 1.f;
|
||||
static enum { Closed, Commands, Settings, ClosedNoResume } gui_state;
|
||||
static bool settings_opening;
|
||||
static bool touch_up;
|
||||
|
||||
void gui_init()
|
||||
{
|
||||
if (inited)
|
||||
return;
|
||||
inited = true;
|
||||
|
||||
// Setup Dear ImGui context
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
|
||||
io.KeyMap[ImGuiKey_Tab] = 0x2B;
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = 0x50;
|
||||
io.KeyMap[ImGuiKey_RightArrow] = 0x4F;
|
||||
io.KeyMap[ImGuiKey_UpArrow] = 0x52;
|
||||
io.KeyMap[ImGuiKey_DownArrow] = 0x51;
|
||||
io.KeyMap[ImGuiKey_PageUp] = 0x4B;
|
||||
io.KeyMap[ImGuiKey_PageDown] = 0x4E;
|
||||
io.KeyMap[ImGuiKey_Home] = 0x4A;
|
||||
io.KeyMap[ImGuiKey_End] = 0x4D;
|
||||
io.KeyMap[ImGuiKey_Insert] = 0x49;
|
||||
io.KeyMap[ImGuiKey_Delete] = 0x4C;
|
||||
io.KeyMap[ImGuiKey_Backspace] = 0x2A;
|
||||
io.KeyMap[ImGuiKey_Space] = 0x2C;
|
||||
io.KeyMap[ImGuiKey_Enter] = 0x28;
|
||||
io.KeyMap[ImGuiKey_Escape] = 0x29;
|
||||
io.KeyMap[ImGuiKey_A] = 0x04;
|
||||
io.KeyMap[ImGuiKey_C] = 0x06;
|
||||
io.KeyMap[ImGuiKey_V] = 0x19;
|
||||
io.KeyMap[ImGuiKey_X] = 0x1B;
|
||||
io.KeyMap[ImGuiKey_Y] = 0x1C;
|
||||
io.KeyMap[ImGuiKey_Z] = 0x1D;
|
||||
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
//ImGui::StyleColorsClassic();
|
||||
|
||||
// Setup Platform/Renderer bindings
|
||||
#ifdef GLES
|
||||
ImGui_ImplOpenGL3_Init("#version 100"); // OpenGL ES 2.0
|
||||
#else
|
||||
ImGui_ImplOpenGL3_Init("#version 130"); // OpenGL 3.0
|
||||
#endif
|
||||
|
||||
// Load Fonts
|
||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
||||
// - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
||||
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
||||
// - Read 'misc/fonts/README.txt' for more instructions and details.
|
||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||
//io.Fonts->AddFontDefault();
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
|
||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||
//IM_ASSERT(font != NULL);
|
||||
|
||||
scaling = max(1.f, screen_dpi / 100.f * 0.75f);
|
||||
if (scaling > 1)
|
||||
ImGui::GetStyle().ScaleAllSizes(scaling);
|
||||
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(roboto_medium_compressed_data, roboto_medium_compressed_size, 17 * scaling);
|
||||
printf("Screen DPI is %d, size %d x %d. Scaling by %.2f\n", screen_dpi, screen_width, screen_height, scaling);
|
||||
}
|
||||
|
||||
static void ImGui_Impl_NewFrame()
|
||||
{
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui::GetIO().DisplaySize.x = screen_width;
|
||||
ImGui::GetIO().DisplaySize.y = screen_height;
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// Read keyboard modifiers inputs
|
||||
io.KeyCtrl = (kb_shift & (0x01 | 0x10)) != 0;
|
||||
io.KeyShift = (kb_shift & (0x02 | 0x20)) != 0;
|
||||
io.KeyAlt = false;
|
||||
io.KeySuper = false;
|
||||
|
||||
memset(&io.KeysDown[0], 0, sizeof(io.KeysDown));
|
||||
for (int i = 0; i < IM_ARRAYSIZE(kb_key); i++)
|
||||
if (kb_key[i] != 0)
|
||||
io.KeysDown[kb_key[i]] = true;
|
||||
else
|
||||
break;
|
||||
float scale = screen_height / 480.0f;
|
||||
float x_offset = (screen_width - 640.0f * scale) / 2;
|
||||
int real_x = mo_x_abs * scale + x_offset;
|
||||
int real_y = mo_y_abs * scale;
|
||||
if (real_x < 0 || real_x >= screen_width || real_y < 0 || real_y >= screen_height)
|
||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||
else
|
||||
io.MousePos = ImVec2(real_x, real_y);
|
||||
#ifdef _ANDROID
|
||||
// Put the "mouse" outside the screen one frame after a touch up
|
||||
// This avoids buttons and the like to stay selected
|
||||
if ((mo_buttons & 0xf) == 0xf)
|
||||
{
|
||||
if (touch_up)
|
||||
{
|
||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||
touch_up = false;
|
||||
}
|
||||
else if (io.MouseDown[0])
|
||||
touch_up = true;
|
||||
}
|
||||
#endif
|
||||
io.MouseDown[0] = (mo_buttons & (1 << 2)) == 0;
|
||||
io.MouseDown[1] = (mo_buttons & (1 << 1)) == 0;
|
||||
io.MouseDown[2] = (mo_buttons & (1 << 3)) == 0;
|
||||
io.MouseDown[3] = (mo_buttons & (1 << 0)) == 0;
|
||||
}
|
||||
|
||||
static double last_render;
|
||||
std::vector<float> render_times;
|
||||
|
||||
void gui_dosmth(int width, int height)
|
||||
{
|
||||
if (last_render == 0)
|
||||
{
|
||||
last_render = os_GetSeconds();
|
||||
return;
|
||||
}
|
||||
double new_time = os_GetSeconds();
|
||||
render_times.push_back((float)(new_time - last_render));
|
||||
if (render_times.size() > 100)
|
||||
render_times.erase(render_times.begin());
|
||||
last_render = new_time;
|
||||
|
||||
ImGui_Impl_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::PlotLines("Render Times", &render_times[0], render_times.size(), 0, "", 0.0, 1.0 / 30.0, ImVec2(300, 50));
|
||||
|
||||
// Render dear imgui into screen
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
|
||||
// Helper to display a little (?) mark which shows a tooltip when hovered.
|
||||
static void ShowHelpMarker(const char* desc)
|
||||
{
|
||||
ImGui::TextDisabled("(?)");
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
|
||||
ImGui::TextUnformatted(desc);
|
||||
ImGui::PopTextWrapPos();
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
void gui_open_settings()
|
||||
{
|
||||
if (gui_state == Closed)
|
||||
{
|
||||
gui_state = Commands;
|
||||
settings_opening = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool gui_is_open()
|
||||
{
|
||||
return gui_state != Closed;
|
||||
}
|
||||
|
||||
static void gui_display_commands()
|
||||
{
|
||||
if (!dc_pause_emu())
|
||||
{
|
||||
gui_state = Closed;
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui_Impl_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
if (!settings_opening)
|
||||
ImGui_ImplOpenGL3_DrawBackground();
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(screen_width / 2.f, screen_height / 2.f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
ImGui::SetNextWindowSize(ImVec2(330 * scaling, 0));
|
||||
|
||||
ImGui::Begin("Reicast", NULL, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize);
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Columns(2, "buttons", false);
|
||||
if (ImGui::Button("Load State", ImVec2(150 * scaling, 50 * scaling)))
|
||||
{
|
||||
gui_state = ClosedNoResume;
|
||||
dc_loadstate();
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::Button("Save State", ImVec2(150 * scaling, 50 * scaling)))
|
||||
{
|
||||
gui_state = ClosedNoResume;
|
||||
dc_savestate();
|
||||
}
|
||||
ImGui::Spacing(); ImGui::Spacing();
|
||||
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::Button("Settings", ImVec2(150 * scaling, 50 * scaling)))
|
||||
{
|
||||
gui_state = Settings;
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::Button("Resume", ImVec2(150 * scaling, 50 * scaling)))
|
||||
{
|
||||
gui_state = Closed;
|
||||
}
|
||||
ImGui::Spacing(); ImGui::Spacing();
|
||||
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::Button("Restart", ImVec2(150 * scaling, 50 * scaling)))
|
||||
{
|
||||
dc_reset();
|
||||
gui_state = Closed;
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::Button("Exit", ImVec2(150 * scaling, 50 * scaling)))
|
||||
{
|
||||
dc_resume_emu(false);
|
||||
}
|
||||
ImGui::Spacing();
|
||||
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData(), settings_opening);
|
||||
settings_opening = false;
|
||||
}
|
||||
|
||||
static void gui_display_settings()
|
||||
{
|
||||
ImGui_Impl_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
int dynarec_enabled = settings.dynarec.Enable;
|
||||
u32 renderer = settings.pvr.rend;
|
||||
int playerCount = cfgLoadInt("players", "nb", 1);
|
||||
|
||||
if (!settings_opening)
|
||||
ImGui_ImplOpenGL3_DrawBackground();
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(screen_width / 2.f, screen_height / 2.f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
if (scaling < 1.5f)
|
||||
ImGui::SetNextWindowSize(ImVec2(screen_height / 480.f * 640.f * 90.f / 100.f, screen_height * 90.f / 100.f));
|
||||
else
|
||||
// Use the entire screen width
|
||||
ImGui::SetNextWindowSize(ImVec2(screen_width * 90.f / 100.f, screen_height * 90.f / 100.f));
|
||||
|
||||
ImGui::Begin("Settings", NULL, /*ImGuiWindowFlags_AlwaysAutoResize |*/ ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse);
|
||||
|
||||
if (ImGui::Button("Done", ImVec2(100 * scaling, 30 * scaling)))
|
||||
{
|
||||
gui_state = Commands;
|
||||
#if DC_PLATFORM == DC_PLATFORM_DREAMCAST
|
||||
if (playerCount != cfgLoadInt("players", "nb", 1))
|
||||
{
|
||||
cfgSaveInt("players", "nb", playerCount);
|
||||
mcfg_DestroyDevices();
|
||||
mcfg_CreateDevicesFromConfig();
|
||||
}
|
||||
#endif
|
||||
SaveSettings();
|
||||
}
|
||||
ImGui::Spacing(); ImGui::Spacing();
|
||||
if (ImGui::BeginTabBar("settings", ImGuiTabBarFlags_NoTooltip))
|
||||
{
|
||||
if (ImGui::BeginTabItem("General"))
|
||||
{
|
||||
const char *languages[] = { "Japanese", "English", "German", "French", "Spanish", "Italian", "Default" };
|
||||
if (ImGui::BeginCombo("Language", languages[settings.dreamcast.language], ImGuiComboFlags_None))
|
||||
{
|
||||
for (int i = 0; i < IM_ARRAYSIZE(languages); i++)
|
||||
{
|
||||
bool is_selected = settings.dreamcast.language == i;
|
||||
if (ImGui::Selectable(languages[i], &is_selected))
|
||||
settings.dreamcast.language = i;
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ShowHelpMarker("The language as configured in the Dreamcast BIOS.");
|
||||
|
||||
const char *broadcast[] = { "NTSC", "PAL", "PAL/M", "PAL/N", "Default" };
|
||||
if (ImGui::BeginCombo("Broadcast", broadcast[settings.dreamcast.broadcast], ImGuiComboFlags_None))
|
||||
{
|
||||
for (int i = 0; i < IM_ARRAYSIZE(broadcast); i++)
|
||||
{
|
||||
bool is_selected = settings.dreamcast.broadcast == i;
|
||||
if (ImGui::Selectable(broadcast[i], &is_selected))
|
||||
settings.dreamcast.broadcast = i;
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
const char *region[] = { "Japan", "USA", "Europe", "Default" };
|
||||
if (ImGui::BeginCombo("Region", region[settings.dreamcast.region], ImGuiComboFlags_None))
|
||||
{
|
||||
for (int i = 0; i < IM_ARRAYSIZE(region); i++)
|
||||
{
|
||||
bool is_selected = settings.dreamcast.region == i;
|
||||
if (ImGui::Selectable(region[i], &is_selected))
|
||||
settings.dreamcast.region = i;
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
const char *cable[] = { "VGA", "VGA", "RGB Component", "TV Composite" };
|
||||
if (ImGui::BeginCombo("Cable", cable[settings.dreamcast.cable], ImGuiComboFlags_None))
|
||||
{
|
||||
for (int i = 0; i < IM_ARRAYSIZE(cable); i++)
|
||||
{
|
||||
bool is_selected = settings.dreamcast.cable == i;
|
||||
if (ImGui::Selectable(cable[i], &is_selected))
|
||||
settings.dreamcast.cable = i;
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("Controls"))
|
||||
{
|
||||
#if DC_PLATFORM == DC_PLATFORM_DREAMCAST
|
||||
ImGui::SliderInt("Players", (int *)&playerCount, 1, 4);
|
||||
ImGui::Checkbox("Emulate keyboard", &settings.input.DCKeyboard);
|
||||
ImGui::Checkbox("Emulate mouse", &settings.input.DCMouse);
|
||||
#endif
|
||||
ImGui::SliderInt("Mouse sensitivity", (int *)&settings.input.MouseSensitivity, 1, 500);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("Video"))
|
||||
{
|
||||
ImGui::Text("Renderer");
|
||||
ImGui::Columns(2, "renderers", false);
|
||||
ImGui::RadioButton("Per-triangle", (int *)&settings.pvr.rend, 0);
|
||||
ImGui::NextColumn();
|
||||
ImGui::RadioButton("Per-pixel", (int *)&settings.pvr.rend, 3);
|
||||
ImGui::Columns(1, NULL, false);
|
||||
ImGui::Separator();
|
||||
ImGui::Checkbox("Synchronous rendering", &settings.pvr.SynchronousRender);
|
||||
ImGui::Checkbox("Clipping", &settings.rend.Clipping);
|
||||
ImGui::Checkbox("Shadows", &settings.rend.ModifierVolumes);
|
||||
ImGui::Checkbox("Widescreen", &settings.rend.WideScreen);
|
||||
ImGui::Checkbox("Show FPS counter", &settings.rend.ShowFPS);
|
||||
ImGui::SliderInt("Frame skipping", (int *)&settings.pvr.ta_skip, 0, 6);
|
||||
ImGui::Separator();
|
||||
ImGui::Checkbox("Render textures to VRAM", &settings.rend.RenderToTextureBuffer);
|
||||
ImGui::SliderInt("Render to texture upscaling", (int *)&settings.rend.RenderToTextureUpscale, 1, 8);
|
||||
ImGui::Separator();
|
||||
ImGui::SliderInt("Texture upscaling", (int *)&settings.rend.TextureUpscale, 1, 8);
|
||||
ImGui::SliderInt("Upscaled texture max size", (int *)&settings.rend.MaxFilteredTextureSize, 8, 1024);
|
||||
ImGui::SliderInt("Max threads", (int *)&settings.pvr.MaxThreads, 1, 8);
|
||||
ImGui::Checkbox("Load custom textures", &settings.rend.CustomTextures);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("Audio"))
|
||||
{
|
||||
ImGui::Checkbox("Disable sound", &settings.aica.NoSound);
|
||||
ImGui::Checkbox("Enable DSP", &settings.aica.NoBatch);
|
||||
ImGui::Checkbox("Limit FPS", &settings.aica.LimitFPS);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("Advanced"))
|
||||
{
|
||||
ImGui::Text("CPU Mode");
|
||||
ImGui::Columns(2, "cpu_modes", false);
|
||||
ImGui::RadioButton("Dynarec", &dynarec_enabled, 1);
|
||||
ImGui::NextColumn();
|
||||
ImGui::RadioButton("Interpreter", &dynarec_enabled, 0);
|
||||
ImGui::Columns(1, NULL, false);
|
||||
ImGui::Separator();
|
||||
ImGui::Checkbox("Dynarec safe mode", &settings.dynarec.safemode);
|
||||
ImGui::Checkbox("Dynarec unstable opt.", &settings.dynarec.unstable_opt);
|
||||
ImGui::Checkbox("Dynarec idle skip", &settings.dynarec.idleskip);
|
||||
ImGui::Checkbox("Serial console", &settings.debug.SerialConsole);
|
||||
ImGui::Checkbox("Dump textures", &settings.rend.DumpTextures);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData(), false);
|
||||
|
||||
if (renderer != settings.pvr.rend)
|
||||
renderer_changed = true;
|
||||
settings.dynarec.Enable = (bool)dynarec_enabled;
|
||||
}
|
||||
|
||||
void gui_display_ui()
|
||||
{
|
||||
switch (gui_state)
|
||||
{
|
||||
case Settings:
|
||||
os_DoEvents();
|
||||
gui_display_settings();
|
||||
break;
|
||||
case Commands:
|
||||
os_DoEvents();
|
||||
gui_display_commands();
|
||||
break;
|
||||
case Closed:
|
||||
break;
|
||||
}
|
||||
|
||||
if (gui_state == Closed)
|
||||
dc_resume_emu(true);
|
||||
else if (gui_state == ClosedNoResume)
|
||||
gui_state = Closed;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
void gui_init();
|
||||
void gui_dosmth(int width, int height);
|
||||
void gui_open_settings();
|
||||
bool gui_is_open();
|
||||
bool gui_display_ui();
|
||||
|
||||
extern int screen_dpi;
|
|
@ -756,14 +756,14 @@ struct settings_t
|
|||
{
|
||||
u32 HW_mixing; //(0) -> SW , 1 -> HW , 2 -> Auto
|
||||
u32 BufferSize; //In samples ,*4 for bytes (1024)
|
||||
u32 LimitFPS; //0 -> no , (1) -> limit
|
||||
bool LimitFPS; // defaults to true
|
||||
u32 GlobalFocus; //0 -> only hwnd , (1) -> Global
|
||||
u32 BufferCount; //BufferCount+2 buffers used , max 60 , default 0
|
||||
u32 CDDAMute;
|
||||
u32 GlobalMute;
|
||||
u32 DSPEnabled; //0 -> no, 1 -> yes
|
||||
u32 NoBatch;
|
||||
u32 NoSound; //0 ->sound, 1 -> no sound
|
||||
bool NoBatch;
|
||||
bool NoSound;
|
||||
} aica;
|
||||
|
||||
#if USE_OMX
|
||||
|
@ -826,7 +826,7 @@ struct settings_t
|
|||
u32 rend;
|
||||
|
||||
u32 MaxThreads;
|
||||
u32 SynchronousRender;
|
||||
bool SynchronousRender;
|
||||
|
||||
string HashLogFile;
|
||||
string HashCheckFile;
|
||||
|
@ -852,7 +852,6 @@ struct settings_t
|
|||
extern settings_t settings;
|
||||
|
||||
void LoadSettings();
|
||||
void LoadCustom();
|
||||
void SaveSettings();
|
||||
u32 GetRTC_now();
|
||||
extern u32 patchRB;
|
||||
|
|
|
@ -3,7 +3,9 @@ package com.reicast.emulator;
|
|||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.util.Log;
|
||||
|
||||
import com.reicast.emulator.emu.JNIdc;
|
||||
|
||||
|
@ -13,6 +15,7 @@ public class Emulator extends Application {
|
|||
public static final String pref_dynarecopt = "dynarec_opt";
|
||||
public static final String pref_unstable = "unstable_opt";
|
||||
public static final String pref_dynsafemode = "dyn_safemode";
|
||||
public static final String pref_idleskip = "idle_skip";
|
||||
public static final String pref_cable = "dc_cable";
|
||||
public static final String pref_dcregion = "dc_region";
|
||||
public static final String pref_broadcast = "dc_broadcast";
|
||||
|
@ -27,9 +30,11 @@ public class Emulator extends Application {
|
|||
public static final String pref_pvrrender = "pvr_render";
|
||||
public static final String pref_syncedrender = "synced_render";
|
||||
public static final String pref_modvols = "modifier_volumes";
|
||||
public static final String pref_clipping = "clipping";
|
||||
public static final String pref_bootdisk = "boot_disk";
|
||||
public static final String pref_usereios = "use_reios";
|
||||
public static final String pref_customtextures = "custom_textures";
|
||||
public static final String pref_showfps = "show_fps";
|
||||
|
||||
public static boolean dynarecopt = true;
|
||||
public static boolean idleskip = true;
|
||||
|
@ -50,10 +55,12 @@ public class Emulator extends Application {
|
|||
public static boolean pvrrender = false;
|
||||
public static boolean syncedrender = false;
|
||||
public static boolean modvols = true;
|
||||
public static boolean clipping = true;
|
||||
public static String bootdisk = null;
|
||||
public static boolean usereios = false;
|
||||
public static boolean nativeact = false;
|
||||
public static boolean customtextures = false;
|
||||
public static boolean showfps = false;
|
||||
|
||||
/**
|
||||
* Load the user configuration from preferences
|
||||
|
@ -63,6 +70,7 @@ public class Emulator extends Application {
|
|||
Emulator.dynarecopt = mPrefs.getBoolean(pref_dynarecopt, dynarecopt);
|
||||
Emulator.unstableopt = mPrefs.getBoolean(pref_unstable, unstableopt);
|
||||
Emulator.dynsafemode = mPrefs.getBoolean(pref_dynsafemode, dynsafemode);
|
||||
Emulator.idleskip = mPrefs.getBoolean(pref_idleskip, idleskip);
|
||||
Emulator.cable = mPrefs.getInt(pref_cable, cable);
|
||||
Emulator.dcregion = mPrefs.getInt(pref_dcregion, dcregion);
|
||||
Emulator.broadcast = mPrefs.getInt(pref_broadcast, broadcast);
|
||||
|
@ -75,10 +83,13 @@ public class Emulator extends Application {
|
|||
Emulator.frameskip = mPrefs.getInt(pref_frameskip, frameskip);
|
||||
Emulator.pvrrender = mPrefs.getBoolean(pref_pvrrender, pvrrender);
|
||||
Emulator.syncedrender = mPrefs.getBoolean(pref_syncedrender, syncedrender);
|
||||
Emulator.modvols = mPrefs.getBoolean(pref_modvols, modvols);
|
||||
Emulator.clipping = mPrefs.getBoolean(pref_clipping, clipping);
|
||||
Emulator.bootdisk = mPrefs.getString(pref_bootdisk, bootdisk);
|
||||
Emulator.usereios = mPrefs.getBoolean(pref_usereios, usereios);
|
||||
Emulator.nativeact = mPrefs.getBoolean(pref_nativeact, nativeact);
|
||||
Emulator.customtextures = mPrefs.getBoolean(pref_customtextures, customtextures);
|
||||
Emulator.showfps = mPrefs.getBoolean(pref_showfps, showfps);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,9 +115,11 @@ public class Emulator extends Application {
|
|||
JNIdc.pvrrender(Emulator.pvrrender ? 1 : 0);
|
||||
JNIdc.syncedrender(Emulator.syncedrender ? 1 : 0);
|
||||
JNIdc.modvols(Emulator.modvols ? 1 : 0);
|
||||
JNIdc.clipping(Emulator.clipping ? 1 : 0);
|
||||
JNIdc.usereios(Emulator.usereios ? 1 : 0);
|
||||
JNIdc.bootdisk(Emulator.bootdisk);
|
||||
JNIdc.customtextures(Emulator.customtextures ? 1 : 0);
|
||||
JNIdc.showfps(Emulator.showfps);
|
||||
}
|
||||
|
||||
public void loadGameConfiguration(String gameId) {
|
||||
|
@ -118,10 +131,68 @@ public class Emulator extends Application {
|
|||
JNIdc.pvrrender(mPrefs.getBoolean(pref_pvrrender, pvrrender) ? 1 : 0);
|
||||
JNIdc.syncedrender(mPrefs.getBoolean(pref_syncedrender, syncedrender) ? 1 : 0);
|
||||
JNIdc.modvols(mPrefs.getBoolean(pref_modvols, modvols) ? 1 : 0);
|
||||
JNIdc.clipping(mPrefs.getBoolean(pref_clipping, clipping) ? 1 : 0);
|
||||
JNIdc.bootdisk(mPrefs.getString(pref_bootdisk, bootdisk));
|
||||
JNIdc.customtextures(mPrefs.getBoolean(pref_customtextures, customtextures) ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch current configuration settings from the emulator and save them
|
||||
*
|
||||
*/
|
||||
public void SaveSettings()
|
||||
{
|
||||
Log.i("Emulator", "SaveSettings: saving preferences");
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
Emulator.dynarecopt = JNIdc.getDynarec();
|
||||
Emulator.idleskip = JNIdc.getIdleskip();
|
||||
Emulator.unstableopt = JNIdc.getUnstable();
|
||||
Emulator.dynsafemode = JNIdc.getSafemode();
|
||||
Emulator.cable = JNIdc.getCable();
|
||||
Emulator.dcregion = JNIdc.getRegion();
|
||||
Emulator.broadcast = JNIdc.getBroadcast();
|
||||
Emulator.language = JNIdc.getLanguage();
|
||||
Emulator.limitfps = JNIdc.getLimitfps();
|
||||
Emulator.nobatch = JNIdc.getNobatch();
|
||||
Emulator.nosound = JNIdc.getNosound();
|
||||
Emulator.mipmaps = JNIdc.getMipmaps();
|
||||
Emulator.widescreen = JNIdc.getWidescreen();
|
||||
//JNIdc.subdivide(Emulator.subdivide);
|
||||
Emulator.frameskip = JNIdc.getFrameskip();
|
||||
//Emulator.pvrrender = JNIdc.getPvrrender();
|
||||
Emulator.syncedrender = JNIdc.getSyncedrender();
|
||||
Emulator.modvols = JNIdc.getModvols();
|
||||
Emulator.clipping = JNIdc.getClipping();
|
||||
Emulator.usereios = JNIdc.getUsereios();
|
||||
//Emulator.bootdisk = JNIdc.getBootdisk();
|
||||
Emulator.customtextures = JNIdc.getCustomtextures();
|
||||
Emulator.showfps = JNIdc.getShowfps();
|
||||
|
||||
prefs.edit()
|
||||
.putBoolean(Emulator.pref_dynarecopt, Emulator.dynarecopt)
|
||||
.putBoolean(Emulator.pref_idleskip, Emulator.idleskip)
|
||||
.putBoolean(Emulator.pref_unstable, Emulator.unstableopt)
|
||||
.putBoolean(Emulator.pref_dynsafemode, Emulator.dynsafemode)
|
||||
.putInt(Emulator.pref_cable, Emulator.cable)
|
||||
.putInt(Emulator.pref_dcregion, Emulator.dcregion)
|
||||
.putInt(Emulator.pref_broadcast, Emulator.broadcast)
|
||||
.putInt(Emulator.pref_language, Emulator.language)
|
||||
.putBoolean(Emulator.pref_limitfps, Emulator.limitfps)
|
||||
.putBoolean(Emulator.pref_nobatch, Emulator.nobatch)
|
||||
.putBoolean(Emulator.pref_nosound, Emulator.nosound)
|
||||
.putBoolean(Emulator.pref_mipmaps, Emulator.mipmaps)
|
||||
.putBoolean(Emulator.pref_widescreen, Emulator.widescreen)
|
||||
.putInt(Emulator.pref_frameskip, Emulator.frameskip)
|
||||
.putBoolean(Emulator.pref_syncedrender, Emulator.syncedrender)
|
||||
.putBoolean(Emulator.pref_modvols, Emulator.modvols)
|
||||
.putBoolean(Emulator.pref_clipping, Emulator.clipping)
|
||||
.putBoolean(Emulator.pref_usereios, Emulator.usereios)
|
||||
.putBoolean(Emulator.pref_customtextures, Emulator.customtextures)
|
||||
.putBoolean(Emulator.pref_showfps, Emulator.showfps)
|
||||
.apply();
|
||||
}
|
||||
|
||||
static {
|
||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@ import com.reicast.emulator.emu.GL2JNIView;
|
|||
import com.reicast.emulator.emu.JNIdc;
|
||||
import com.reicast.emulator.emu.OnScreenMenu;
|
||||
import com.reicast.emulator.emu.OnScreenMenu.FpsPopup;
|
||||
import com.reicast.emulator.emu.OnScreenMenu.MainPopup;
|
||||
import com.reicast.emulator.emu.OnScreenMenu.VmuPopup;
|
||||
import com.reicast.emulator.periph.Gamepad;
|
||||
import com.reicast.emulator.periph.SipEmulator;
|
||||
|
||||
|
@ -37,8 +35,6 @@ import tv.ouya.console.api.OuyaController;
|
|||
public class GL2JNIActivity extends Activity {
|
||||
public GL2JNIView mView;
|
||||
OnScreenMenu menu;
|
||||
public MainPopup popUp;
|
||||
VmuPopup vmuPop;
|
||||
FpsPopup fpsPop;
|
||||
private SharedPreferences prefs;
|
||||
|
||||
|
@ -214,21 +210,7 @@ public class GL2JNIActivity extends Activity {
|
|||
JNIdc.setupMic(sip);
|
||||
}
|
||||
|
||||
popUp = menu.new MainPopup(this);
|
||||
vmuPop = menu.new VmuPopup(this);
|
||||
if(prefs.getBoolean(Config.pref_vmu, false)){
|
||||
//kind of a hack - if the user last had the vmu on screen
|
||||
//inverse it and then "toggle"
|
||||
prefs.edit().putBoolean(Config.pref_vmu, false).apply();
|
||||
//can only display a popup after onCreate
|
||||
mView.post(new Runnable() {
|
||||
public void run() {
|
||||
toggleVmu();
|
||||
}
|
||||
});
|
||||
}
|
||||
JNIdc.setupVmu(menu.getVmu());
|
||||
if (prefs.getBoolean(Config.pref_showfps, false)) {
|
||||
if (Emulator.showfps) {
|
||||
fpsPop = menu.new FpsPopup(this);
|
||||
mView.setFpsDisplay(fpsPop);
|
||||
mView.post(new Runnable() {
|
||||
|
@ -248,29 +230,6 @@ public class GL2JNIActivity extends Activity {
|
|||
fpsPop.update(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
public void toggleVmu() {
|
||||
boolean showFloating = !prefs.getBoolean(Config.pref_vmu, false);
|
||||
if (showFloating) {
|
||||
if (popUp.isShowing()) {
|
||||
popUp.dismiss();
|
||||
}
|
||||
//remove from popup menu
|
||||
popUp.hideVmu();
|
||||
//add to floating window
|
||||
vmuPop.showVmu();
|
||||
vmuPop.showAtLocation(mView, Gravity.TOP | Gravity.RIGHT, 4, 4);
|
||||
vmuPop.update(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
} else {
|
||||
vmuPop.dismiss();
|
||||
//remove from floating window
|
||||
vmuPop.hideVmu();
|
||||
//add back to popup menu
|
||||
popUp.showVmu();
|
||||
}
|
||||
prefs.edit().putBoolean(Config.pref_vmu, showFloating).apply();
|
||||
}
|
||||
|
||||
public void screenGrab() {
|
||||
mView.screenGrab();
|
||||
}
|
||||
|
@ -306,17 +265,7 @@ public class GL2JNIActivity extends Activity {
|
|||
}
|
||||
|
||||
private boolean showMenu() {
|
||||
if (popUp != null) {
|
||||
if (menu.dismissPopUps()) {
|
||||
popUp.dismiss();
|
||||
} else {
|
||||
if (!popUp.isShowing()) {
|
||||
displayPopUp(popUp);
|
||||
} else {
|
||||
popUp.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
JNIdc.guiOpenSettings();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,6 @@ import com.reicast.emulator.emu.GL2JNIView;
|
|||
import com.reicast.emulator.emu.JNIdc;
|
||||
import com.reicast.emulator.emu.OnScreenMenu;
|
||||
import com.reicast.emulator.emu.OnScreenMenu.FpsPopup;
|
||||
import com.reicast.emulator.emu.OnScreenMenu.MainPopup;
|
||||
import com.reicast.emulator.emu.OnScreenMenu.VmuPopup;
|
||||
import com.reicast.emulator.periph.Gamepad;
|
||||
import com.reicast.emulator.periph.SipEmulator;
|
||||
|
||||
|
@ -39,8 +37,6 @@ import tv.ouya.console.api.OuyaController;
|
|||
public class GL2JNINative extends NativeActivity {
|
||||
public GL2JNIView mView;
|
||||
OnScreenMenu menu;
|
||||
public MainPopup popUp;
|
||||
VmuPopup vmuPop;
|
||||
FpsPopup fpsPop;
|
||||
private SharedPreferences prefs;
|
||||
|
||||
|
@ -212,21 +208,7 @@ public class GL2JNINative extends NativeActivity {
|
|||
JNIdc.setupMic(sip);
|
||||
}
|
||||
|
||||
popUp = menu.new MainPopup(this);
|
||||
vmuPop = menu.new VmuPopup(this);
|
||||
if(prefs.getBoolean(Config.pref_vmu, false)){
|
||||
//kind of a hack - if the user last had the vmu on screen
|
||||
//inverse it and then "toggle"
|
||||
prefs.edit().putBoolean(Config.pref_vmu, false).apply();
|
||||
//can only display a popup after onCreate
|
||||
mView.post(new Runnable() {
|
||||
public void run() {
|
||||
toggleVmu();
|
||||
}
|
||||
});
|
||||
}
|
||||
JNIdc.setupVmu(menu.getVmu());
|
||||
if (prefs.getBoolean(Config.pref_showfps, false)) {
|
||||
if (Emulator.showfps) {
|
||||
fpsPop = menu.new FpsPopup(this);
|
||||
mView.setFpsDisplay(fpsPop);
|
||||
mView.post(new Runnable() {
|
||||
|
@ -247,74 +229,8 @@ public class GL2JNINative extends NativeActivity {
|
|||
fpsPop.update(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
|
||||
public void toggleVmu() {
|
||||
boolean showFloating = !prefs.getBoolean(Config.pref_vmu, false);
|
||||
if (showFloating) {
|
||||
if (popUp.isShowing()) {
|
||||
popUp.dismiss();
|
||||
}
|
||||
//remove from popup menu
|
||||
popUp.hideVmu();
|
||||
//add to floating window
|
||||
vmuPop.showVmu();
|
||||
vmuPop.showAtLocation(mView, Gravity.TOP | Gravity.RIGHT, 4, 4);
|
||||
vmuPop.update(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
} else {
|
||||
vmuPop.dismiss();
|
||||
//remove from floating window
|
||||
vmuPop.hideVmu();
|
||||
//add back to popup menu
|
||||
popUp.showVmu();
|
||||
}
|
||||
prefs.edit().putBoolean(Config.pref_vmu, showFloating).apply();
|
||||
}
|
||||
|
||||
public void screenGrab() {
|
||||
mView.screenGrab();
|
||||
}
|
||||
|
||||
public void displayPopUp(PopupWindow popUp) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
popUp.showAtLocation(mView, Gravity.BOTTOM, 0, 60);
|
||||
} else {
|
||||
popUp.showAtLocation(mView, Gravity.BOTTOM, 0, 0);
|
||||
}
|
||||
popUp.update(LayoutParams.WRAP_CONTENT,
|
||||
LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
|
||||
public void displayConfig(PopupWindow popUpConfig) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
popUpConfig.showAtLocation(mView, Gravity.BOTTOM, 0, 60);
|
||||
} else {
|
||||
popUpConfig.showAtLocation(mView, Gravity.BOTTOM, 0, 0);
|
||||
}
|
||||
popUpConfig.update(LayoutParams.WRAP_CONTENT,
|
||||
LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
|
||||
public void displayDebug(PopupWindow popUpDebug) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
popUpDebug.showAtLocation(mView, Gravity.BOTTOM, 0, 60);
|
||||
} else {
|
||||
popUpDebug.showAtLocation(mView, Gravity.BOTTOM, 0, 0);
|
||||
}
|
||||
popUpDebug.update(LayoutParams.WRAP_CONTENT,
|
||||
LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
|
||||
private boolean showMenu() {
|
||||
if (popUp != null) {
|
||||
if (menu.dismissPopUps()) {
|
||||
popUp.dismiss();
|
||||
} else {
|
||||
if (!popUp.isShowing()) {
|
||||
displayPopUp(popUp);
|
||||
} else {
|
||||
popUp.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
JNIdc.guiOpenSettings();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ public class Config {
|
|||
|
||||
public static final String pref_gamedetails = "game_details";
|
||||
|
||||
public static final String pref_showfps = "show_fps";
|
||||
public static final String pref_rendertype = "render_type";
|
||||
public static final String pref_renderdepth = "depth_render";
|
||||
|
||||
|
|
|
@ -525,10 +525,10 @@ public class OptionsFragment extends Fragment {
|
|||
|
||||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
boolean isChecked) {
|
||||
mPrefs.edit().putBoolean(Config.pref_showfps, isChecked).apply();
|
||||
mPrefs.edit().putBoolean(Emulator.pref_showfps, isChecked).apply();
|
||||
}
|
||||
};
|
||||
boolean counter = mPrefs.getBoolean(Config.pref_showfps, false);
|
||||
boolean counter = mPrefs.getBoolean(Emulator.pref_showfps, false);
|
||||
fps_opt.setChecked(counter);
|
||||
fps_opt.setOnCheckedChangeListener(fps_options);
|
||||
|
||||
|
@ -746,10 +746,14 @@ public class OptionsFragment extends Fragment {
|
|||
mPrefs.edit().remove(Emulator.pref_pvrrender).apply();
|
||||
mPrefs.edit().remove(Emulator.pref_syncedrender).apply();
|
||||
mPrefs.edit().remove(Emulator.pref_bootdisk).apply();
|
||||
mPrefs.edit().remove(Config.pref_showfps).apply();
|
||||
mPrefs.edit().remove(Emulator.pref_showfps).apply();
|
||||
mPrefs.edit().remove(Config.pref_rendertype).apply();
|
||||
mPrefs.edit().remove(Emulator.pref_nosound).apply();
|
||||
mPrefs.edit().remove(Emulator.pref_nobatch).apply();
|
||||
mPrefs.edit().remove(Emulator.pref_customtextures).apply();
|
||||
mPrefs.edit().remove(Emulator.pref_modvols).apply();
|
||||
mPrefs.edit().remove(Emulator.pref_clipping).apply();
|
||||
mPrefs.edit().remove(Emulator.pref_dynsafemode).apply();
|
||||
mPrefs.edit().remove(Config.pref_renderdepth).apply();
|
||||
mPrefs.edit().remove(Config.pref_theme).apply();
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import android.os.Handler;
|
|||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ScaleGestureDetector;
|
||||
|
@ -134,6 +135,9 @@ public class GL2JNIView extends GLSurfaceView
|
|||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
JNIdc.screenDpi((int)Math.max(dm.xdpi, dm.ydpi));
|
||||
|
||||
JNIdc.config(prefs.getString(Config.pref_home,
|
||||
Environment.getExternalStorageDirectory().getAbsolutePath()));
|
||||
|
||||
|
@ -159,7 +163,7 @@ public class GL2JNIView extends GLSurfaceView
|
|||
JNIdc.data(1, GL2JNIActivity.syms);
|
||||
}
|
||||
JNIdc.init(fileName);
|
||||
JNIdc.query(ethd);
|
||||
JNIdc.query(ethd, context.getApplicationContext());
|
||||
|
||||
// By default, GLSurfaceView() creates a RGB_565 opaque surface.
|
||||
// If we want a translucent one, we should change the surface's
|
||||
|
@ -291,6 +295,8 @@ public class GL2JNIView extends GLSurfaceView
|
|||
public static int[] rt = new int[4];
|
||||
public static int[] jx = new int[4];
|
||||
public static int[] jy = new int[4];
|
||||
public static int[] mouse_pos = { -32768, -32768 };
|
||||
public static int mouse_btns = 0xFFFF;
|
||||
|
||||
float editLastX = 0, editLastY = 0;
|
||||
|
||||
|
@ -309,130 +315,124 @@ public class GL2JNIView extends GLSurfaceView
|
|||
int aid = event.getActionMasked();
|
||||
int pid = event.getActionIndex();
|
||||
|
||||
if (editVjoyMode && selectedVjoyElement != -1 && aid == MotionEvent.ACTION_MOVE && !scaleGestureDetector.isInProgress()) {
|
||||
float x = (event.getX()-tx)/scl;
|
||||
float y = (event.getY()-ty)/scl;
|
||||
if (!JNIdc.guiIsOpen()) {
|
||||
if (editVjoyMode && selectedVjoyElement != -1 && aid == MotionEvent.ACTION_MOVE && !scaleGestureDetector.isInProgress()) {
|
||||
float x = (event.getX() - tx) / scl;
|
||||
float y = (event.getY() - ty) / scl;
|
||||
|
||||
if (editLastX != 0 && editLastY != 0) {
|
||||
float deltaX = x - editLastX;
|
||||
float deltaY = y - editLastY;
|
||||
if (editLastX != 0 && editLastY != 0) {
|
||||
float deltaX = x - editLastX;
|
||||
float deltaY = y - editLastY;
|
||||
|
||||
vjoy_d_custom[selectedVjoyElement][0] += isTablet() ? deltaX * 2 : deltaX;
|
||||
vjoy_d_custom[selectedVjoyElement][1] += isTablet() ? deltaY * 2 : deltaY;
|
||||
vjoy_d_custom[selectedVjoyElement][0] += isTablet() ? deltaX * 2 : deltaX;
|
||||
vjoy_d_custom[selectedVjoyElement][1] += isTablet() ? deltaY * 2 : deltaY;
|
||||
|
||||
requestLayout();
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
editLastX = x;
|
||||
editLastY = y;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
editLastX = x;
|
||||
editLastY = y;
|
||||
for (int i = 0; i < event.getPointerCount(); i++) {
|
||||
float x = (event.getX(i) - tx) / scl;
|
||||
float y = (event.getY(i) - ty) / scl;
|
||||
if (anal_id != event.getPointerId(i)) {
|
||||
if (aid == MotionEvent.ACTION_POINTER_UP && pid == i)
|
||||
continue;
|
||||
for (int j = 0; j < vjoy.length; j++) {
|
||||
if (x > vjoy[j][0] && x <= (vjoy[j][0] + vjoy[j][2])) {
|
||||
/*
|
||||
//Disable pressure sensitive R/L
|
||||
//Doesn't really work properly
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i=0;i<event.getPointerCount();i++)
|
||||
{
|
||||
float x = (event.getX(i)-tx)/scl;
|
||||
float y = (event.getY(i)-ty)/scl;
|
||||
if (anal_id != event.getPointerId(i))
|
||||
{
|
||||
if (aid == MotionEvent.ACTION_POINTER_UP && pid==i)
|
||||
continue;
|
||||
for (int j=0;j<vjoy.length;j++)
|
||||
{
|
||||
if(x>vjoy[j][0] && x<=(vjoy[j][0]+vjoy[j][2]))
|
||||
{
|
||||
/*
|
||||
//Disable pressure sensitive R/L
|
||||
//Doesn't really work properly
|
||||
|
||||
int pre=(int)(event.getPressure(i)*255);
|
||||
if (pre>20)
|
||||
{
|
||||
pre-=20;
|
||||
pre*=7;
|
||||
}
|
||||
if (pre>255) pre=255;
|
||||
*/
|
||||
|
||||
int pre = 255;
|
||||
|
||||
if (y > vjoy[j][1] && y <= (vjoy[j][1]+vjoy[j][3]))
|
||||
{
|
||||
if (vjoy[j][4] >= -2)
|
||||
{
|
||||
if (vjoy[j][5]==0)
|
||||
if (!editVjoyMode && touchVibrationEnabled)
|
||||
vib.vibrate(vibrationDuration);
|
||||
vjoy[j][5]=2;
|
||||
}
|
||||
|
||||
|
||||
if (vjoy[j][4] == -3)
|
||||
{
|
||||
if (editVjoyMode) {
|
||||
selectedVjoyElement = 5; // Analog
|
||||
resetEditMode();
|
||||
} else {
|
||||
vjoy[j+1][0]=x-vjoy[j+1][2]/2;
|
||||
vjoy[j+1][1]=y-vjoy[j+1][3]/2;
|
||||
|
||||
JNIdc.vjoy(j+1, vjoy[j+1][0], vjoy[j+1][1] , vjoy[j+1][2], vjoy[j+1][3]);
|
||||
anal_id=event.getPointerId(i);
|
||||
int pre=(int)(event.getPressure(i)*255);
|
||||
if (pre>20)
|
||||
{
|
||||
pre-=20;
|
||||
pre*=7;
|
||||
}
|
||||
} else if (vjoy[j][4] != -4) {
|
||||
if (vjoy[j][4] == -1) {
|
||||
if (pre>255) pre=255;
|
||||
*/
|
||||
|
||||
int pre = 255;
|
||||
|
||||
if (y > vjoy[j][1] && y <= (vjoy[j][1] + vjoy[j][3])) {
|
||||
if (vjoy[j][4] >= -2) {
|
||||
if (vjoy[j][5] == 0)
|
||||
if (!editVjoyMode && touchVibrationEnabled)
|
||||
vib.vibrate(vibrationDuration);
|
||||
vjoy[j][5] = 2;
|
||||
}
|
||||
|
||||
|
||||
if (vjoy[j][4] == -3) {
|
||||
if (editVjoyMode) {
|
||||
selectedVjoyElement = 3; // Left Trigger
|
||||
selectedVjoyElement = 5; // Analog
|
||||
resetEditMode();
|
||||
} else {
|
||||
lt[0] = pre;
|
||||
lt_id = event.getPointerId(i);
|
||||
vjoy[j + 1][0] = x - vjoy[j + 1][2] / 2;
|
||||
vjoy[j + 1][1] = y - vjoy[j + 1][3] / 2;
|
||||
|
||||
JNIdc.vjoy(j + 1, vjoy[j + 1][0], vjoy[j + 1][1], vjoy[j + 1][2], vjoy[j + 1][3]);
|
||||
anal_id = event.getPointerId(i);
|
||||
}
|
||||
} else if (vjoy[j][4] == -2) {
|
||||
if (editVjoyMode) {
|
||||
selectedVjoyElement = 4; // Right Trigger
|
||||
resetEditMode();
|
||||
} else if (vjoy[j][4] != -4) {
|
||||
if (vjoy[j][4] == -1) {
|
||||
if (editVjoyMode) {
|
||||
selectedVjoyElement = 3; // Left Trigger
|
||||
resetEditMode();
|
||||
} else {
|
||||
lt[0] = pre;
|
||||
lt_id = event.getPointerId(i);
|
||||
}
|
||||
} else if (vjoy[j][4] == -2) {
|
||||
if (editVjoyMode) {
|
||||
selectedVjoyElement = 4; // Right Trigger
|
||||
resetEditMode();
|
||||
} else {
|
||||
rt[0] = pre;
|
||||
rt_id = event.getPointerId(i);
|
||||
}
|
||||
} else {
|
||||
rt[0] = pre;
|
||||
rt_id = event.getPointerId(i);
|
||||
if (editVjoyMode) {
|
||||
selectedVjoyElement = getElementIdFromButtonId(j);
|
||||
resetEditMode();
|
||||
} else
|
||||
rv &= ~(int) vjoy[j][4];
|
||||
}
|
||||
} else {
|
||||
if (editVjoyMode) {
|
||||
selectedVjoyElement = getElementIdFromButtonId(j);
|
||||
resetEditMode();
|
||||
} else
|
||||
rv &= ~(int) vjoy[j][4];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (x < vjoy[11][0])
|
||||
x = vjoy[11][0];
|
||||
else if (x > (vjoy[11][0] + vjoy[11][2]))
|
||||
x = vjoy[11][0] + vjoy[11][2];
|
||||
|
||||
if (y < vjoy[11][1])
|
||||
y = vjoy[11][1];
|
||||
else if (y > (vjoy[11][1] + vjoy[11][3]))
|
||||
y = vjoy[11][1] + vjoy[11][3];
|
||||
|
||||
int j = 11;
|
||||
vjoy[j + 1][0] = x - vjoy[j + 1][2] / 2;
|
||||
vjoy[j + 1][1] = y - vjoy[j + 1][3] / 2;
|
||||
|
||||
JNIdc.vjoy(j + 1, vjoy[j + 1][0], vjoy[j + 1][1], vjoy[j + 1][2], vjoy[j + 1][3]);
|
||||
|
||||
}
|
||||
} else {
|
||||
if (x<vjoy[11][0])
|
||||
x=vjoy[11][0];
|
||||
else if (x>(vjoy[11][0]+vjoy[11][2]))
|
||||
x=vjoy[11][0]+vjoy[11][2];
|
||||
|
||||
if (y<vjoy[11][1])
|
||||
y=vjoy[11][1];
|
||||
else if (y>(vjoy[11][1]+vjoy[11][3]))
|
||||
y=vjoy[11][1]+vjoy[11][3];
|
||||
|
||||
int j=11;
|
||||
vjoy[j+1][0]=x-vjoy[j+1][2]/2;
|
||||
vjoy[j+1][1]=y-vjoy[j+1][3]/2;
|
||||
|
||||
JNIdc.vjoy(j+1, vjoy[j+1][0], vjoy[j+1][1] , vjoy[j+1][2], vjoy[j+1][3]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (int j=0;j<vjoy.length;j++)
|
||||
{
|
||||
if (vjoy[j][5]==2)
|
||||
vjoy[j][5]=1;
|
||||
else if (vjoy[j][5]==1)
|
||||
vjoy[j][5]=0;
|
||||
for (int j = 0; j < vjoy.length; j++) {
|
||||
if (vjoy[j][5] == 2)
|
||||
vjoy[j][5] = 1;
|
||||
else if (vjoy[j][5] == 1)
|
||||
vjoy[j][5] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
switch(aid)
|
||||
|
@ -449,6 +449,7 @@ public class GL2JNIView extends GLSurfaceView
|
|||
rt_id=-1;
|
||||
for (int j=0;j<vjoy.length;j++)
|
||||
vjoy[j][5]=0;
|
||||
mouse_btns = 0xFFFF;
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
|
@ -471,9 +472,31 @@ public class GL2JNIView extends GLSurfaceView
|
|||
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
if (event.getPointerCount() != 1)
|
||||
{
|
||||
mouse_btns = 0xFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
MotionEvent.PointerCoords pointerCoords = new MotionEvent.PointerCoords();
|
||||
event.getPointerCoords(0, pointerCoords);
|
||||
mouse_pos[0] = Math.round((pointerCoords.x - tx) / scl);
|
||||
mouse_pos[1] = Math.round(pointerCoords.y / scl);
|
||||
mouse_btns = 0xFFFB; // Mouse button A down
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (event.getPointerCount() == 1)
|
||||
{
|
||||
MotionEvent.PointerCoords pointerCoords = new MotionEvent.PointerCoords();
|
||||
event.getPointerCoords(0, pointerCoords);
|
||||
mouse_pos[0] = Math.round((pointerCoords.x - tx) / scl);
|
||||
mouse_pos[1] = Math.round(pointerCoords.y / scl);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (getResources().getString(R.string.flavor).equals("naomi"))
|
||||
if (getResources().getString(R.string.flavor).equals("naomi")) // FIXME
|
||||
{
|
||||
if (lt[0] != 0)
|
||||
rv &= ~VJoy.key_CONT_C; // Service key/coin
|
||||
|
@ -507,7 +530,7 @@ public class GL2JNIView extends GLSurfaceView
|
|||
}
|
||||
|
||||
public void pushInput(){
|
||||
JNIdc.kcode(kcode_raw,lt,rt,jx,jy);
|
||||
JNIdc.kcode(kcode_raw,lt,rt,jx,jy,mouse_pos,mouse_btns);
|
||||
}
|
||||
|
||||
private static class Renderer implements GLSurfaceView.Renderer
|
||||
|
@ -532,6 +555,8 @@ public class GL2JNIView extends GLSurfaceView
|
|||
mView.takeScreenshot = false;
|
||||
FileUtils.saveScreenshot(mView.getContext(), mView.getWidth(), mView.getHeight(), gl);
|
||||
}
|
||||
if (mView.ethd.getState() == Thread.State.TERMINATED)
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void onSurfaceChanged(GL10 gl,int width,int height)
|
||||
|
|
|
@ -7,7 +7,7 @@ public final class JNIdc
|
|||
|
||||
public static native void config(String dirName);
|
||||
public static native void init(String fileName);
|
||||
public static native void query(Object thread);
|
||||
public static native void query(Object thread, Object emulator);
|
||||
public static native void run(Object track);
|
||||
public static native void pause();
|
||||
public static native void destroy();
|
||||
|
@ -18,7 +18,7 @@ public final class JNIdc
|
|||
public static native void rendinit(int w, int y);
|
||||
public static native boolean rendframe();
|
||||
|
||||
public static native void kcode(int[] kcode, int[] lt, int[] rt, int[] jx, int[] jy);
|
||||
public static native void kcode(int[] kcode, int[] lt, int[] rt, int[] jx, int[] jy, int[] mouse_pos, int mouse_btns);
|
||||
|
||||
public static native void vjoy(int id,float x, float y, float w, float h);
|
||||
//public static native int play(short result[],int size);
|
||||
|
@ -29,27 +29,54 @@ public final class JNIdc
|
|||
public static native void diskSwap(String disk);
|
||||
public static native void vmuSwap();
|
||||
public static native void setupVmu(Object sip);
|
||||
public static native boolean getDynarec();
|
||||
public static native void dynarec(int dynarec);
|
||||
public static native boolean getIdleskip();
|
||||
public static native void idleskip(int idleskip);
|
||||
public static native boolean getUnstable();
|
||||
public static native void unstable(int unstable);
|
||||
public static native boolean getSafemode();
|
||||
public static native void safemode(int safemode);
|
||||
public static native int getCable();
|
||||
public static native void cable(int cable);
|
||||
public static native int getRegion();
|
||||
public static native void region(int region);
|
||||
public static native int getBroadcast();
|
||||
public static native void broadcast(int broadcast);
|
||||
public static native int getLanguage();
|
||||
public static native void language(int language);
|
||||
public static native boolean getLimitfps();
|
||||
public static native void limitfps(int limiter);
|
||||
public static native boolean getNobatch();
|
||||
public static native void nobatch(int nobatch);
|
||||
public static native boolean getNosound();
|
||||
public static native void nosound(int noaudio);
|
||||
public static native boolean getMipmaps();
|
||||
public static native void mipmaps(int mipmaps);
|
||||
public static native boolean getWidescreen();
|
||||
public static native void widescreen(int stretch);
|
||||
public static native void subdivide(int subdivide);
|
||||
public static native int getFrameskip();
|
||||
public static native void frameskip(int frames);
|
||||
public static native int getPvrrender();
|
||||
public static native void pvrrender(int render);
|
||||
public static native boolean getSyncedrender();
|
||||
public static native void syncedrender(int sync);
|
||||
public static native boolean getModvols();
|
||||
public static native void modvols(int volumes);
|
||||
public static native boolean getClipping();
|
||||
public static native void clipping(int clipping);
|
||||
public static native void bootdisk(String disk);
|
||||
public static native boolean getUsereios();
|
||||
public static native void usereios(int reios);
|
||||
public static native boolean getCustomtextures();
|
||||
public static native void customtextures(int customtex);
|
||||
public static native boolean getShowfps();
|
||||
public static native void showfps(boolean showfps);
|
||||
|
||||
public static native void screenDpi(int screenDpi);
|
||||
public static native void guiOpenSettings();
|
||||
public static native boolean guiIsOpen();
|
||||
|
||||
public static void show_osd() {
|
||||
JNIdc.vjoy(13, 1,0,0,0);
|
||||
|
|
|
@ -31,18 +31,6 @@ public class OnScreenMenu {
|
|||
|
||||
private Activity mContext;
|
||||
|
||||
private VmuLcd vmuLcd;
|
||||
|
||||
private Vector<PopupWindow> popups;
|
||||
|
||||
private int frames = Emulator.frameskip;
|
||||
private boolean screen = Emulator.widescreen;
|
||||
private boolean limit = Emulator.limitfps;
|
||||
private boolean audio;
|
||||
private boolean masteraudio;
|
||||
private boolean boosted = false;
|
||||
private boolean syncedrender;
|
||||
|
||||
public OnScreenMenu(Activity context, SharedPreferences prefs) {
|
||||
if (context instanceof GL2JNINative) {
|
||||
this.mContext = context;
|
||||
|
@ -50,34 +38,8 @@ public class OnScreenMenu {
|
|||
if (context instanceof GL2JNIActivity) {
|
||||
this.mContext = context;
|
||||
}
|
||||
popups = new Vector<>();
|
||||
if (prefs != null) {
|
||||
masteraudio = !Emulator.nosound;
|
||||
audio = masteraudio;
|
||||
syncedrender = Emulator.syncedrender;
|
||||
}
|
||||
vmuLcd = new VmuLcd(mContext);
|
||||
vmuLcd.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) OnScreenMenu.this.mContext).toggleVmu();
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) OnScreenMenu.this.mContext).toggleVmu();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void displayDebugPopup() {
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) mContext).displayDebug(new DebugPopup(mContext));
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) mContext).displayDebug(new DebugPopup(mContext));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class FpsPopup extends PopupWindow {
|
||||
|
||||
|
@ -100,486 +62,7 @@ public class OnScreenMenu {
|
|||
}
|
||||
}
|
||||
|
||||
private void removePopUp(PopupWindow window) {
|
||||
window.dismiss();
|
||||
popups.remove(window);
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) mContext)
|
||||
.displayPopUp(((GL2JNINative) OnScreenMenu.this.mContext).popUp);
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) mContext)
|
||||
.displayPopUp(((GL2JNIActivity) OnScreenMenu.this.mContext).popUp);
|
||||
}
|
||||
}
|
||||
|
||||
public class DebugPopup extends PopupWindow {
|
||||
|
||||
DebugPopup(Context c) {
|
||||
super(c);
|
||||
//noinspection deprecation
|
||||
setBackgroundDrawable(new BitmapDrawable());
|
||||
|
||||
View shell = mContext.getLayoutInflater().inflate(R.layout.menu_popup_debug, null);
|
||||
ScrollView hlay = (ScrollView) shell.findViewById(R.id.menuDebug);
|
||||
|
||||
OnClickListener clickBack = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
removePopUp(DebugPopup.this);
|
||||
}
|
||||
};
|
||||
Button buttonBack = (Button) hlay.findViewById(R.id.buttonBack);
|
||||
addimg(buttonBack, R.drawable.up, clickBack);
|
||||
|
||||
OnClickListener clickClearCache = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
JNIdc.send(0, 0); // Killing texture cache
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
Button buttonCache = (Button) hlay.findViewById(R.id.buttonClearCache);
|
||||
addimg(buttonCache, R.drawable.clear_cache, clickClearCache);
|
||||
|
||||
OnClickListener clickProfilerOne = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
JNIdc.send(1, 3000); // sample_Start(param);
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
Button buttonProfilerOne = (Button) hlay.findViewById(R.id.buttonProfilerOne);
|
||||
addimg(buttonProfilerOne, R.drawable.profiler, clickProfilerOne);
|
||||
|
||||
OnClickListener clickProfilerTwo = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
JNIdc.send(1, 0); // sample_Start(param);
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
Button buttonProfilerTwo = (Button) hlay.findViewById(R.id.buttonProfilerTwo);
|
||||
addimg(buttonProfilerTwo, R.drawable.profiler, clickProfilerTwo);
|
||||
|
||||
OnClickListener clickPrintStats = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
JNIdc.send(0, 2);
|
||||
dismiss(); // print_stats=true;
|
||||
}
|
||||
};
|
||||
Button buttonPrintStats = (Button) hlay.findViewById(R.id.buttonPrintStats);
|
||||
addimg(buttonPrintStats, R.drawable.print_stats, clickPrintStats);
|
||||
|
||||
setContentView(shell);
|
||||
setFocusable(true);
|
||||
popups.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void displayConfigPopup() {
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) mContext).displayConfig(new ConfigPopup(mContext));
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) mContext)
|
||||
.displayConfig(new ConfigPopup(mContext));
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfigPopup extends PopupWindow {
|
||||
|
||||
private Button framelimit;
|
||||
private Button audiosetting;
|
||||
private Button fastforward;
|
||||
private Button fdown;
|
||||
private Button fup;
|
||||
|
||||
ConfigPopup(Context c) {
|
||||
super(c);
|
||||
//noinspection deprecation
|
||||
setBackgroundDrawable(new BitmapDrawable());
|
||||
|
||||
View shell = mContext.getLayoutInflater().inflate(R.layout.menu_popup_config, null);
|
||||
final ScrollView hlay = (ScrollView) shell.findViewById(R.id.menuConfig);
|
||||
|
||||
OnClickListener clickBack = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
removePopUp(ConfigPopup.this);
|
||||
}
|
||||
};
|
||||
Button buttonBack = (Button) hlay.findViewById(R.id.buttonBack);
|
||||
addimg(buttonBack, R.drawable.up, clickBack);
|
||||
|
||||
final Button buttonScreen = (Button) hlay.findViewById(R.id.buttonWidescreen);
|
||||
OnClickListener clickScreen = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (screen) {
|
||||
JNIdc.widescreen(0);
|
||||
screen = false;
|
||||
addimg(buttonScreen, R.drawable.widescreen, this);
|
||||
} else {
|
||||
JNIdc.widescreen(1);
|
||||
screen = true;
|
||||
addimg(buttonScreen, R.drawable.normal_view, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (screen) {
|
||||
addimg(buttonScreen, R.drawable.normal_view, clickScreen);
|
||||
} else {
|
||||
addimg(buttonScreen, R.drawable.widescreen, clickScreen);
|
||||
}
|
||||
|
||||
fdown = (Button) hlay.findViewById(R.id.buttonFramesDown);
|
||||
OnClickListener clickFdown = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (frames > 0) {
|
||||
frames--;
|
||||
}
|
||||
JNIdc.frameskip(frames);
|
||||
enableState(fdown, fup);
|
||||
}
|
||||
};
|
||||
addimg(fdown, R.drawable.frames_down, clickFdown);
|
||||
|
||||
fup = (Button) hlay.findViewById(R.id.buttonFramesUp);
|
||||
OnClickListener clickFup = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (frames < 5) {
|
||||
frames++;
|
||||
}
|
||||
JNIdc.frameskip(frames);
|
||||
enableState(fdown, fup);
|
||||
}
|
||||
};
|
||||
addimg(fup, R.drawable.frames_up, clickFup);
|
||||
enableState(fdown, fup);
|
||||
|
||||
framelimit = (Button) hlay.findViewById(R.id.buttonFrameLimit);
|
||||
OnClickListener clickFrameLimit = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (limit) {
|
||||
JNIdc.limitfps(0);
|
||||
limit = false;
|
||||
addimg(framelimit, R.drawable.frames_limit_on, this);
|
||||
} else {
|
||||
JNIdc.limitfps(1);
|
||||
limit = true;
|
||||
addimg(framelimit, R.drawable.frames_limit_off, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (limit) {
|
||||
addimg(framelimit, R.drawable.frames_limit_off, clickFrameLimit);
|
||||
} else {
|
||||
addimg(framelimit, R.drawable.frames_limit_on, clickFrameLimit);
|
||||
}
|
||||
|
||||
audiosetting = (Button) hlay.findViewById(R.id.buttonAudio);
|
||||
OnClickListener clickAudio = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (audio) {
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) mContext).mView
|
||||
.audioDisable(true);
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) mContext).mView
|
||||
.audioDisable(true);
|
||||
}
|
||||
audio = false;
|
||||
addimg(audiosetting, R.drawable.enable_sound, this);
|
||||
} else {
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) mContext).mView
|
||||
.audioDisable(false);
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) mContext).mView
|
||||
.audioDisable(false);
|
||||
}
|
||||
audio = true;
|
||||
addimg(audiosetting, R.drawable.mute_sound, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (audio) {
|
||||
addimg(audiosetting, R.drawable.mute_sound, clickAudio);
|
||||
} else {
|
||||
addimg(audiosetting, R.drawable.enable_sound, clickAudio);
|
||||
}
|
||||
if (!masteraudio) {
|
||||
audiosetting.setEnabled(false);
|
||||
}
|
||||
|
||||
fastforward = (Button) hlay.findViewById(R.id.buttonTurbo);
|
||||
OnClickListener clickTurbo = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (boosted) {
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) mContext).mView
|
||||
.audioDisable(!audio);
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) mContext).mView
|
||||
.audioDisable(!audio);
|
||||
}
|
||||
JNIdc.nosound(!audio ? 1 : 0);
|
||||
audiosetting.setEnabled(true);
|
||||
JNIdc.limitfps(limit ? 1 : 0);
|
||||
framelimit.setEnabled(true);
|
||||
JNIdc.frameskip(frames);
|
||||
enableState(fdown, fup);
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) mContext).mView.fastForward(false);
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) mContext).mView
|
||||
.fastForward(false);
|
||||
}
|
||||
boosted = false;
|
||||
addimg(fastforward, R.drawable.star, this);
|
||||
} else {
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) mContext).mView.audioDisable(true);
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) mContext).mView
|
||||
.audioDisable(true);
|
||||
}
|
||||
JNIdc.nosound(1);
|
||||
audiosetting.setEnabled(false);
|
||||
JNIdc.limitfps(0);
|
||||
framelimit.setEnabled(false);
|
||||
JNIdc.frameskip(5);
|
||||
fdown.setEnabled(false);
|
||||
fup.setEnabled(false);
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) mContext).mView.fastForward(true);
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) mContext).mView.fastForward(true);
|
||||
}
|
||||
boosted = true;
|
||||
addimg(fastforward, R.drawable.reset, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
fastforward.setOnClickListener(clickTurbo);
|
||||
if (boosted) {
|
||||
addimg(fastforward, R.drawable.reset, clickTurbo);
|
||||
} else {
|
||||
addimg(fastforward, R.drawable.star, clickTurbo);
|
||||
}
|
||||
if (syncedrender) {
|
||||
fastforward.setEnabled(false);
|
||||
}
|
||||
|
||||
setContentView(shell);
|
||||
setFocusable(true);
|
||||
popups.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the frameskip button visibility by current value
|
||||
*
|
||||
* @param fdown
|
||||
* The frameskip reduction button view
|
||||
* @param fup
|
||||
* The frameskip increase button view
|
||||
*/
|
||||
private void enableState(Button fdown, Button fup) {
|
||||
if (frames == 0) {
|
||||
fdown.setEnabled(false);
|
||||
} else {
|
||||
fdown.setEnabled(true);
|
||||
}
|
||||
if (frames == 5) {
|
||||
fup.setEnabled(false);
|
||||
} else {
|
||||
fup.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean dismissPopUps() {
|
||||
for (PopupWindow popup : popups) {
|
||||
if (popup.isShowing()) {
|
||||
popup.dismiss();
|
||||
popups.remove(popup);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getPixelsFromDp(float dps, Context context) {
|
||||
return (int) (dps * context.getResources().getDisplayMetrics().density + 0.5f);
|
||||
}
|
||||
|
||||
public VmuLcd getVmu() {
|
||||
return vmuLcd;
|
||||
}
|
||||
|
||||
View addbut(int x, String l, OnClickListener ocl) {
|
||||
Button but = new Button(mContext);
|
||||
Drawable image = mContext.getResources().getDrawable(x);
|
||||
image.setBounds(0, 0, 72, 72);
|
||||
but.setCompoundDrawables(image, null, null, null);
|
||||
but.setOnClickListener(ocl);
|
||||
return but;
|
||||
}
|
||||
|
||||
Button addimg(Button but, int x, OnClickListener ocl) {
|
||||
Drawable image = mContext.getResources().getDrawable(x);
|
||||
image.setBounds(0, 0, 72, 72);
|
||||
but.setCompoundDrawables(image, null, null, null);
|
||||
but.setOnClickListener(ocl);
|
||||
return but;
|
||||
}
|
||||
|
||||
void modbut (View button, int x) {
|
||||
Button but = (Button) button;
|
||||
Drawable image = mContext.getResources().getDrawable(x);
|
||||
image.setBounds(0, 0, 72, 72);
|
||||
but.setCompoundDrawables(image, null, null, null);
|
||||
}
|
||||
|
||||
public class VmuPopup extends PopupWindow {
|
||||
LayoutParams vparams;
|
||||
LinearLayout vlay;
|
||||
|
||||
public VmuPopup(Context c) {
|
||||
super(c);
|
||||
setBackgroundDrawable(null);
|
||||
int pX = OnScreenMenu.getPixelsFromDp(96, mContext);
|
||||
int pY = OnScreenMenu.getPixelsFromDp(68, mContext);
|
||||
vparams = new LayoutParams(pX, pY);
|
||||
vlay = new LinearLayout(mContext);
|
||||
vlay.setOrientation(LinearLayout.HORIZONTAL);
|
||||
setContentView(vlay);
|
||||
setFocusable(false);
|
||||
}
|
||||
|
||||
public void showVmu() {
|
||||
vmuLcd.configureScale(96);
|
||||
vlay.addView(vmuLcd, vparams);
|
||||
}
|
||||
|
||||
public void hideVmu() {
|
||||
vlay.removeView(vmuLcd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class MainPopup extends PopupWindow {
|
||||
|
||||
private LinearLayout vmuIcon;
|
||||
LinearLayout.LayoutParams params;
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
private LinearLayout.LayoutParams setVmuParams() {
|
||||
int vpX = getPixelsFromDp(72, mContext);
|
||||
int vpY = getPixelsFromDp(52, mContext);
|
||||
LinearLayout.LayoutParams vmuParams = new LinearLayout.LayoutParams(
|
||||
vpX, vpY);
|
||||
vmuParams.weight = 1.0f;
|
||||
vmuParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
|
||||
vmuParams.leftMargin = 6;
|
||||
return vmuParams;
|
||||
}
|
||||
|
||||
public MainPopup(Context c) {
|
||||
super(c);
|
||||
//noinspection deprecation
|
||||
setBackgroundDrawable(new BitmapDrawable());
|
||||
|
||||
View shell = mContext.getLayoutInflater().inflate(R.layout.menu_popup_main, null);
|
||||
ScrollView hlay = (ScrollView) shell.findViewById(R.id.menuMain);
|
||||
|
||||
vmuIcon = (LinearLayout) hlay.findViewById(R.id.vmuIcon);
|
||||
vmuLcd.configureScale(72);
|
||||
params = setVmuParams();
|
||||
vmuIcon.addView(vmuLcd, params);
|
||||
|
||||
OnClickListener clickDisk = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (Emulator.bootdisk != null)
|
||||
JNIdc.diskSwap(null);
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
Button buttonDisk = (Button) hlay.findViewById(R.id.buttonDisk);
|
||||
addimg(buttonDisk, R.drawable.disk_swap, clickDisk);
|
||||
|
||||
OnClickListener clickVmuSwap = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
JNIdc.vmuSwap();
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
Button buttonVmuSwap = (Button) hlay.findViewById(R.id.buttonVmuSwap);
|
||||
addimg(buttonVmuSwap, R.drawable.vmu_swap, clickVmuSwap);
|
||||
|
||||
OnClickListener clickOptions = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
displayConfigPopup();
|
||||
popups.remove(MainPopup.this);
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
Button buttonOptions = (Button) hlay.findViewById(R.id.buttonOptions);
|
||||
addimg(buttonOptions, R.drawable.config, clickOptions);
|
||||
|
||||
OnClickListener clickDebugging = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
displayDebugPopup();
|
||||
popups.remove(MainPopup.this);
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
Button buttonDebugging = (Button) hlay.findViewById(R.id.buttonDebugging);
|
||||
addimg(buttonDebugging, R.drawable.disk_unknown, clickDebugging);
|
||||
|
||||
OnClickListener clickScreenshot = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// screenshot
|
||||
if (mContext instanceof GL2JNINative) {
|
||||
((GL2JNINative) OnScreenMenu.this.mContext)
|
||||
.screenGrab();
|
||||
}
|
||||
if (mContext instanceof GL2JNIActivity) {
|
||||
((GL2JNIActivity) OnScreenMenu.this.mContext)
|
||||
.screenGrab();
|
||||
}
|
||||
}
|
||||
};
|
||||
Button buttonScreenshot = (Button) hlay.findViewById(R.id.buttonScreenshot);
|
||||
addimg(buttonScreenshot, R.drawable.print_stats, clickScreenshot);
|
||||
|
||||
OnClickListener clickExit = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (Config.externalIntent) {
|
||||
mContext.finish();
|
||||
} else {
|
||||
Intent inte = new Intent(mContext, MainActivity.class);
|
||||
mContext.startActivity(inte);
|
||||
mContext.finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
Button buttonExit = (Button) hlay.findViewById(R.id.buttonExit);
|
||||
addimg(buttonExit, R.drawable.close, clickExit);
|
||||
|
||||
setContentView(shell);
|
||||
setFocusable(true);
|
||||
}
|
||||
|
||||
public void hideVmu() {
|
||||
vmuIcon.removeView(vmuLcd);
|
||||
}
|
||||
|
||||
public void showVmu() {
|
||||
vmuLcd.configureScale(72);
|
||||
params = setVmuParams();
|
||||
vmuIcon.addView(vmuLcd, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,13 @@
|
|||
#include "oslib/audiobackend_android.h"
|
||||
#include "reios/reios.h"
|
||||
#include "imgread/common.h"
|
||||
#include "rend/gui.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_config(JNIEnv *env,jobject obj,jstring dirName) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_init(JNIEnv *env,jobject obj,jstring fileName) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_query(JNIEnv *env,jobject obj,jobject emu_thread) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_query(JNIEnv *env,jobject obj,jobject emu_thread, jobject emulator) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_run(JNIEnv *env,jobject obj,jobject emu_thread) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_pause(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_destroy(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
|
@ -34,7 +35,7 @@ JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_data(JNIEnv *env,jobj
|
|||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_rendinit(JNIEnv *env,jobject obj,jint w,jint h) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_rendframe(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_kcode(JNIEnv * env, jobject obj, jintArray k_code, jintArray l_t, jintArray r_t, jintArray jx, jintArray jy) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_kcode(JNIEnv * env, jobject obj, jintArray k_code, jintArray l_t, jintArray r_t, jintArray jx, jintArray jy, jintArray mouse_pos, jint mouse_btns) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_vjoy(JNIEnv * env, jobject obj,u32 id,float x, float y, float w, float h) __attribute__((visibility("default")));
|
||||
//JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_play(JNIEnv *env,jobject obj,jshortArray result,jint size);
|
||||
|
||||
|
@ -45,6 +46,29 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_diskSwap(JNIEnv *env,
|
|||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_vmuSwap(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setupVmu(JNIEnv *env,jobject obj,jobject sip) __attribute__((visibility("default")));
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getDynarec(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getIdleskip(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getUnstable(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getSafemode(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getCable(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getRegion(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getBroadcast(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getLanguage(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getLimitfps(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getNobatch(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getNosound(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getMipmaps(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getWidescreen(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getFrameskip(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getPvrrender(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getSyncedrender(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getModvols(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getClipping(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getBootdisk(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getUsereios(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getCustomtextures(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getShowfps(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_dynarec(JNIEnv *env,jobject obj, jint dynarec) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_idleskip(JNIEnv *env,jobject obj, jint idleskip) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_unstable(JNIEnv *env,jobject obj, jint unstable) __attribute__((visibility("default")));
|
||||
|
@ -63,11 +87,122 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_frameskip(JNIEnv *env
|
|||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_pvrrender(JNIEnv *env,jobject obj, jint render) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_syncedrender(JNIEnv *env,jobject obj, jint sync) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_modvols(JNIEnv *env,jobject obj, jint volumes) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_clipping(JNIEnv *env,jobject obj, jboolean clipping) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_bootdisk(JNIEnv *env,jobject obj, jstring disk) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_usereios(JNIEnv *env,jobject obj, jint reios) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_customtextures(JNIEnv *env,jobject obj, jint customtex) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_showfps(JNIEnv *env,jobject obj, jboolean showfps) __attribute__((visibility("default")));
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_screenDpi(JNIEnv *env,jobject obj, jint screenDpi) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_guiOpenSettings(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_guiIsOpen(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
};
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getDynarec(JNIEnv *env,jobject objc)
|
||||
{
|
||||
return settings.dynarec.Enable;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getIdleskip(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.dynarec.idleskip;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getUnstable(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.dynarec.unstable_opt;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getSafemode(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.dynarec.safemode;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getCable(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.dreamcast.cable;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getRegion(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.dreamcast.region;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getBroadcast(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.dreamcast.broadcast;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getLanguage(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.dreamcast.language;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getLimitfps(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.aica.LimitFPS;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getNobatch(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.aica.NoBatch;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getNosound(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.aica.NoSound;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getMipmaps(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.rend.UseMipmaps;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getWidescreen(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.rend.WideScreen;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getFrameskip(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.pvr.ta_skip;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_getPvrrender(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.pvr.rend;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getSyncedrender(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.pvr.SynchronousRender;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getModvols(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.rend.ModifierVolumes;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getClipping(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.rend.Clipping;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getUsereios(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.bios.UseReios;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getCustomtextures(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.rend.CustomTextures;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_getShowfps(JNIEnv *env,jobject obj)
|
||||
{
|
||||
return settings.rend.ShowFPS;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_dynarec(JNIEnv *env,jobject obj, jint dynarec)
|
||||
{
|
||||
settings.dynarec.Enable = dynarec;
|
||||
|
@ -153,12 +288,16 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_syncedrender(JNIEnv *
|
|||
settings.pvr.SynchronousRender = sync;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_modvols(JNIEnv *env,jobject obj, jint volumes)
|
||||
{
|
||||
settings.rend.ModifierVolumes = volumes;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_clipping(JNIEnv *env,jobject obj, jboolean clipping)
|
||||
{
|
||||
settings.rend.Clipping = clipping;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_usereios(JNIEnv *env,jobject obj, jint reios)
|
||||
{
|
||||
settings.bios.UseReios = reios;
|
||||
|
@ -169,6 +308,16 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_customtextures(JNIEnv
|
|||
settings.rend.CustomTextures = customtex;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_showfps(JNIEnv *env,jobject obj, jboolean showfps)
|
||||
{
|
||||
settings.rend.ShowFPS = showfps;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_screenDpi(JNIEnv *env,jobject obj, jint screenDpi)
|
||||
{
|
||||
screen_dpi = screenDpi;
|
||||
}
|
||||
|
||||
void egl_stealcntx();
|
||||
void SetApplicationPath(wchar *path);
|
||||
void reios_init(int argc,wchar* argv[]);
|
||||
|
@ -199,6 +348,10 @@ s8 joyx[4],joyy[4];
|
|||
u8 rt[4],lt[4];
|
||||
float vjoy_pos[14][8];
|
||||
|
||||
extern s32 mo_x_abs;
|
||||
extern s32 mo_y_abs;
|
||||
extern u32 mo_buttons;
|
||||
|
||||
extern bool print_stats;
|
||||
|
||||
|
||||
|
@ -392,8 +545,12 @@ jmethodID getmicdata;
|
|||
jobject vmulcd = NULL;
|
||||
jbyteArray jpix = NULL;
|
||||
jmethodID updatevmuscreen;
|
||||
//stuff for saving prefs
|
||||
JavaVM* g_jvm;
|
||||
jobject g_emulator;
|
||||
jmethodID saveSettingsMid;
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_query(JNIEnv *env,jobject obj,jobject emu_thread)
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_query(JNIEnv *env,jobject obj,jobject emu_thread, jobject emulator)
|
||||
{
|
||||
jmethodID reiosInfoMid=env->GetMethodID(env->GetObjectClass(emu_thread),"reiosInfo","(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
|
||||
|
@ -407,6 +564,10 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_query(JNIEnv *env,job
|
|||
|
||||
env->CallVoidMethod(emu_thread, reiosInfoMid, reios_id, reios_name);
|
||||
|
||||
env->GetJavaVM(&g_jvm);
|
||||
g_emulator = env->NewGlobalRef(emulator);
|
||||
saveSettingsMid = env->GetMethodID(env->GetObjectClass(emulator), "SaveSettings", "()V");
|
||||
|
||||
dc_init();
|
||||
}
|
||||
|
||||
|
@ -530,7 +691,7 @@ JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_rendframe(JNIEnv
|
|||
return (jboolean)rend_single_frame();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_kcode(JNIEnv * env, jobject obj, jintArray k_code, jintArray l_t, jintArray r_t, jintArray jx, jintArray jy)
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_kcode(JNIEnv * env, jobject obj, jintArray k_code, jintArray l_t, jintArray r_t, jintArray jx, jintArray jy, jintArray mouse_pos, jint mouse_btns)
|
||||
{
|
||||
jint *k_code_body = env->GetIntArrayElements(k_code, 0);
|
||||
jint *l_t_body = env->GetIntArrayElements(l_t, 0);
|
||||
|
@ -552,6 +713,12 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_kcode(JNIEnv * env, j
|
|||
env->ReleaseIntArrayElements(r_t, r_t_body, 0);
|
||||
env->ReleaseIntArrayElements(jx, jx_body, 0);
|
||||
env->ReleaseIntArrayElements(jy, jy_body, 0);
|
||||
|
||||
jint *mouse_pos_body = env->GetIntArrayElements(mouse_pos, 0);
|
||||
mo_x_abs = mouse_pos_body[0];
|
||||
mo_y_abs = mouse_pos_body[1];
|
||||
env->ReleaseIntArrayElements(mouse_pos, mouse_pos_body, 0);
|
||||
mo_buttons = mouse_btns;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_rendinit(JNIEnv * env, jobject obj, jint w,jint h)
|
||||
|
@ -606,6 +773,16 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_initControllers(JNIEn
|
|||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_guiOpenSettings(JNIEnv *env, jobject obj)
|
||||
{
|
||||
gui_open_settings();
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_guiIsOpen(JNIEnv *env, jobject obj)
|
||||
{
|
||||
return gui_is_open();
|
||||
}
|
||||
|
||||
// Audio Stuff
|
||||
u32 androidaudio_push(void* frame, u32 amt, bool wait)
|
||||
{
|
||||
|
@ -669,6 +846,32 @@ void os_DebugBreak()
|
|||
{
|
||||
// TODO: notify the parent thread about it ...
|
||||
|
||||
raise(SIGSTOP);
|
||||
|
||||
// Attach debugger here to figure out what went wrong
|
||||
for(;;) ;
|
||||
}
|
||||
|
||||
void SaveSettings()
|
||||
{
|
||||
if (g_jvm == NULL)
|
||||
return;
|
||||
|
||||
JNIEnv *env;
|
||||
bool detach_thread = false;
|
||||
int rc = g_jvm->GetEnv((void **)&env, JNI_VERSION_1_6);
|
||||
if (rc == JNI_EDETACHED) {
|
||||
if (g_jvm->AttachCurrentThread(&env, NULL) != 0)
|
||||
// abort
|
||||
return;
|
||||
detach_thread = true;
|
||||
}
|
||||
else if (rc == JNI_EVERSION)
|
||||
// abort
|
||||
return;
|
||||
|
||||
env->CallVoidMethod(g_emulator, saveSettingsMid);
|
||||
|
||||
if (detach_thread)
|
||||
g_jvm->DetachCurrentThread();
|
||||
}
|
Loading…
Reference in New Issue