mirror of https://github.com/axmolengine/axmol.git
Enable cache render data for webgl by default (#2151)
* Remove unused static function
This commit is contained in:
parent
9258d8a47f
commit
cfcdddd89b
|
@ -531,9 +531,9 @@ set(AX_WASM_SHELL_FILE "${_AX_ROOT}/core/platform/wasm/shell_minimal.html" CACHE
|
|||
|
||||
option(AX_WASM_ENABLE_DEVTOOLS "Enable wasm devtools" ON)
|
||||
|
||||
set(_AX_WASM_EXPORTS "_main")
|
||||
set(_AX_WASM_EXPORTS "_main,_axmol_wgl_context_lost,_axmol_wgl_context_restored,_axmol_hdoc_visibilitychange")
|
||||
if(AX_WASM_ENABLE_DEVTOOLS)
|
||||
set(_AX_WASM_EXPORTS "${_AX_WASM_EXPORTS},_axmol_director_pause,_axmol_director_resume,_axmol_director_step")
|
||||
string(APPEND _AX_WASM_EXPORTS ",_axmol_dev_pause,_axmol_dev_resume,_axmol_dev_step")
|
||||
endif()
|
||||
set(AX_WASM_EXPORTS "${_AX_WASM_EXPORTS}" CACHE STRING "" FORCE)
|
||||
|
||||
|
|
|
@ -95,13 +95,6 @@ void RenderTexture::listenToBackground(EventCustom* /*event*/)
|
|||
void RenderTexture::listenToForeground(EventCustom* /*event*/)
|
||||
{
|
||||
#if AX_ENABLE_CACHE_TEXTURE_DATA
|
||||
const Vec2& s = _texture2D->getContentSizeInPixels();
|
||||
// TODO new-renderer: field _depthAndStencilFormat removal
|
||||
// if (_depthAndStencilFormat != 0)
|
||||
// {
|
||||
// setupDepthAndStencil(s.width, s.height);
|
||||
// }
|
||||
|
||||
_texture2D->setAntiAliasTexParameters();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCEVENT_TYPE_H__
|
||||
#define __CCEVENT_TYPE_H__
|
||||
#ifndef __AXEVENT_TYPE_H__
|
||||
#define __AXEVENT_TYPE_H__
|
||||
/// @cond DO_NOT_SHOW
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,11 +27,12 @@ THE SOFTWARE.
|
|||
#include "base/Random.h"
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <limits>
|
||||
#include <emscripten.h>
|
||||
# include <limits>
|
||||
# include <emscripten.h>
|
||||
std::mt19937& ax::RandomHelper::getEngine()
|
||||
{
|
||||
static std::mt19937 engine(emscripten_random() * (std::numeric_limits<int>::max)());
|
||||
static std::mt19937 engine(
|
||||
static_cast<int>(emscripten_random() * static_cast<float>((std::numeric_limits<int>::max)())));
|
||||
return engine;
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -172,7 +172,7 @@ namespace ax { namespace network {
|
|||
dir = storagePath.substr(0, found + 1);
|
||||
if (false == util->isDirectoryExist(dir))
|
||||
{
|
||||
if (false == util->createDirectory(dir))
|
||||
if (false == util->createDirectories(dir))
|
||||
{
|
||||
errCode = DownloadTask::ERROR_CREATE_DIR_FAILED;
|
||||
errCodeInternal = 0;
|
||||
|
|
|
@ -88,7 +88,7 @@ Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
|
|||
*
|
||||
* @since v0.99.5
|
||||
*/
|
||||
#if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID)
|
||||
#if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) || (AX_TARGET_PLATFORM == AX_PLATFORM_WASM)
|
||||
# if !defined(AX_ENABLE_CACHE_TEXTURE_DATA)
|
||||
# define AX_ENABLE_CACHE_TEXTURE_DATA 1
|
||||
# endif
|
||||
|
|
|
@ -88,7 +88,7 @@ JNIEXPORT void JNICALL Java_org_axmol_lib_AxmolRenderer_nativeInit(JNIEnv*, jcla
|
|||
auto glView = director->getGLView();
|
||||
if (!glView)
|
||||
{
|
||||
glView = ax::GLViewImpl::create("Android app");
|
||||
glView = ax::GLViewImpl::create("axmol2");
|
||||
glView->setFrameSize(w, h);
|
||||
director->setGLView(glView);
|
||||
|
||||
|
@ -97,7 +97,7 @@ JNIEXPORT void JNICALL Java_org_axmol_lib_AxmolRenderer_nativeInit(JNIEnv*, jcla
|
|||
else
|
||||
{
|
||||
backend::DriverBase::getInstance()->resetState();
|
||||
ax::Director::getInstance()->resetMatrixStack();
|
||||
director->resetMatrixStack();
|
||||
ax::EventCustom recreatedEvent(EVENT_RENDERER_RECREATED);
|
||||
director->getEventDispatcher()->dispatchEvent(&recreatedEvent, true);
|
||||
director->setGLDefaultValues();
|
||||
|
|
|
@ -28,35 +28,71 @@ THE SOFTWARE.
|
|||
#include "platform/PlatformConfig.h"
|
||||
#if AX_TARGET_PLATFORM == AX_PLATFORM_WASM
|
||||
|
||||
#include "platform/wasm/Application-wasm.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <string>
|
||||
#include "base/Director.h"
|
||||
#include "base/Utils.h"
|
||||
#include "platform/FileUtils.h"
|
||||
#include <emscripten/emscripten.h>
|
||||
# include "platform/wasm/Application-wasm.h"
|
||||
# include "platform/wasm/devtools-wasm.h"
|
||||
# include <unistd.h>
|
||||
# include <sys/time.h>
|
||||
# include <string>
|
||||
# include "base/Director.h"
|
||||
# include "base/Utils.h"
|
||||
# include "platform/FileUtils.h"
|
||||
# include <emscripten/emscripten.h>
|
||||
|
||||
extern "C" {
|
||||
//
|
||||
void axmol_hdoc_visibilitychange(bool hidden)
|
||||
{
|
||||
ax::EventCustom event(hidden ? EVENT_COME_TO_BACKGROUND : EVENT_COME_TO_FOREGROUND);
|
||||
ax::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event, true);
|
||||
}
|
||||
|
||||
// webglcontextlost
|
||||
void axmol_wgl_context_lost()
|
||||
{
|
||||
AXLOGI("receive event: webglcontextlost");
|
||||
}
|
||||
|
||||
// webglcontextrestored
|
||||
void axmol_wgl_context_restored()
|
||||
{
|
||||
AXLOGI("receive event: webglcontextrestored");
|
||||
|
||||
auto director = ax::Director::getInstance();
|
||||
ax::backend::DriverBase::getInstance()->resetState();
|
||||
director->resetMatrixStack();
|
||||
ax::EventCustom recreatedEvent(EVENT_RENDERER_RECREATED);
|
||||
director->getEventDispatcher()->dispatchEvent(&recreatedEvent, true);
|
||||
director->setGLDefaultValues();
|
||||
# if AX_ENABLE_CACHE_TEXTURE_DATA
|
||||
ax::VolatileTextureMgr::reloadAllTextures();
|
||||
# endif
|
||||
}
|
||||
|
||||
void axmol_dev_pause()
|
||||
{
|
||||
ax::DevToolsImpl::getInstance()->pause();
|
||||
}
|
||||
|
||||
void axmol_dev_resume()
|
||||
{
|
||||
ax::DevToolsImpl::getInstance()->resume();
|
||||
}
|
||||
|
||||
void axmol_dev_step()
|
||||
{
|
||||
ax::DevToolsImpl::getInstance()->step();
|
||||
}
|
||||
}
|
||||
|
||||
namespace ax
|
||||
{
|
||||
|
||||
|
||||
// sharedApplication pointer
|
||||
Application * Application::sm_pSharedApplication = nullptr;
|
||||
Application* Application::sm_pSharedApplication = nullptr;
|
||||
|
||||
static long getCurrentMillSecond() {
|
||||
long lLastTime;
|
||||
struct timeval stCurrentTime;
|
||||
|
||||
gettimeofday(&stCurrentTime,NULL);
|
||||
lLastTime = stCurrentTime.tv_sec*1000+stCurrentTime.tv_usec*0.001; // milliseconds
|
||||
return lLastTime;
|
||||
}
|
||||
|
||||
Application::Application()
|
||||
: _animationSpeed(60)
|
||||
Application::Application() : _animationSpeed(60)
|
||||
{
|
||||
AX_ASSERT(! sm_pSharedApplication);
|
||||
AX_ASSERT(!sm_pSharedApplication);
|
||||
sm_pSharedApplication = this;
|
||||
}
|
||||
|
||||
|
@ -79,7 +115,7 @@ int Application::run()
|
|||
{
|
||||
initGLContextAttrs();
|
||||
// Initialize instance and cocos2d.
|
||||
if (! applicationDidFinishLaunching())
|
||||
if (!applicationDidFinishLaunching())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -90,7 +126,7 @@ int Application::run()
|
|||
// Retain glview to avoid glview being released in the while loop
|
||||
glview->retain();
|
||||
|
||||
//emscripten_set_main_loop(&mainLoopIter, 0, 1);
|
||||
// emscripten_set_main_loop(&mainLoopIter, 0, 1);
|
||||
emscripten_set_main_loop(&mainLoopIter, _animationSpeed, 1);
|
||||
// TODO: ? does these cleanup really run?
|
||||
/* Only work on Desktop
|
||||
|
@ -143,9 +179,7 @@ std::string Application::getVersion()
|
|||
|
||||
bool Application::openURL(std::string_view url)
|
||||
{
|
||||
EM_ASM_ARGS({
|
||||
window.open(UTF8ToString($0));
|
||||
}, url.data());
|
||||
EM_ASM_ARGS({ window.open(UTF8ToString($0)); }, url.data());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -165,21 +199,26 @@ Application* Application::sharedApplication()
|
|||
return Application::getInstance();
|
||||
}
|
||||
|
||||
const char * Application::getCurrentLanguageCode()
|
||||
const char* Application::getCurrentLanguageCode()
|
||||
{
|
||||
static char code[3]={0};
|
||||
static char code[3] = {0};
|
||||
char pLanguageName[16];
|
||||
|
||||
EM_ASM_ARGS({
|
||||
EM_ASM_ARGS(
|
||||
{
|
||||
var lang = localStorage.getItem('localization_language');
|
||||
if (lang == null) {
|
||||
stringToUTF8(window.navigator.language.replace(/-.*/, ""), $0, 16);
|
||||
} else {
|
||||
if (lang == null)
|
||||
{
|
||||
stringToUTF8(window.navigator.language.replace(/ - .*/, ""), $0, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
stringToUTF8(lang, $0, 16);
|
||||
}
|
||||
}, pLanguageName);
|
||||
strncpy(code,pLanguageName,2);
|
||||
code[2]='\0';
|
||||
},
|
||||
pLanguageName);
|
||||
strncpy(code, pLanguageName, 2);
|
||||
code[2] = '\0';
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -187,19 +226,23 @@ LanguageType Application::getCurrentLanguage()
|
|||
{
|
||||
char pLanguageName[16];
|
||||
|
||||
EM_ASM_ARGS({
|
||||
EM_ASM_ARGS(
|
||||
{
|
||||
var lang = localStorage.getItem('localization_language');
|
||||
if (lang == null) {
|
||||
stringToUTF8(window.navigator.language.replace(/-.*/, ""), $0, 16);
|
||||
} else {
|
||||
if (lang == null)
|
||||
{
|
||||
stringToUTF8(window.navigator.language.replace(/ - .*/, ""), $0, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
stringToUTF8(lang, $0, 16);
|
||||
}
|
||||
}, pLanguageName);
|
||||
},
|
||||
pLanguageName);
|
||||
|
||||
return utils::getLanguageTypeByISO2(pLanguageName);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace ax
|
||||
|
||||
#endif // AX_TARGET_PLATFORM == AX_PLATFORM_WASM
|
||||
|
||||
|
|
|
@ -78,22 +78,4 @@ DevToolsImpl* DevToolsImpl::getInstance()
|
|||
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void axmol_director_pause()
|
||||
{
|
||||
ax::DevToolsImpl::getInstance()->pause();
|
||||
}
|
||||
|
||||
void axmol_director_resume()
|
||||
{
|
||||
ax::DevToolsImpl::getInstance()->resume();
|
||||
}
|
||||
|
||||
void axmol_director_step()
|
||||
{
|
||||
ax::DevToolsImpl::getInstance()->step();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // AX_TARGET_PLATFORM == AX_PLATFORM_WASM
|
||||
|
|
|
@ -46,9 +46,9 @@
|
|||
<input type="button" value="Fullscreen" onclick="Module.requestFullscreen(document.getElementById('pointerLock').checked,
|
||||
document.getElementById('resize').checked)">
|
||||
|
|
||||
<input type="button" value="Pause" onclick="Module.ccall('axmol_director_pause')">
|
||||
<input type="button" value="Resume" onclick="Module.ccall('axmol_director_resume')">
|
||||
<input type="button" value="Step" onclick="Module.ccall('axmol_director_step')">
|
||||
<input type="button" value="Pause" onclick="Module.ccall('axmol_dev_pause')">
|
||||
<input type="button" value="Resume" onclick="Module.ccall('axmol_dev_resume')">
|
||||
<input type="button" value="Step" onclick="Module.ccall('axmol_dev_step')">
|
||||
</div>
|
||||
|
||||
<div class="emscripten">
|
||||
|
@ -140,7 +140,10 @@
|
|||
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
|
||||
// application robust, you may want to override this behavior before shipping!
|
||||
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
|
||||
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
|
||||
canvas.addEventListener("webglcontextlost", function(e) { Module.ccall('axmol_wgl_context_lost'); alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
|
||||
canvas.addEventListener("webglcontextrestored", function(e) { Module.ccall('axmol_wgl_context_restored'); e.preventDefault(); }, false);
|
||||
|
||||
document.addEventListener("visibilitychange", () => { Module.ccall('axmol_hdoc_visibilitychange', document.hidden); });
|
||||
|
||||
return canvas;
|
||||
})(),
|
||||
|
|
|
@ -97,15 +97,14 @@ void AxmolRenderer::DeviceLost()
|
|||
auto director = ax::Director::getInstance();
|
||||
if (director->getGLView())
|
||||
{
|
||||
// TODO:
|
||||
// ax::GL::invalidateStateCache();
|
||||
// ax::GLProgramCache::getInstance()->reloadDefaultGLPrograms();
|
||||
// ax::DrawPrimitives::init();
|
||||
// ax::VolatileTextureMgr::reloadAllTextures();
|
||||
|
||||
backend::DriverBase::getInstance()->resetState();
|
||||
ax::Director::getInstance()->resetMatrixStack();
|
||||
ax::EventCustom recreatedEvent(EVENT_RENDERER_RECREATED);
|
||||
director->getEventDispatcher()->dispatchEvent(&recreatedEvent, true);
|
||||
director->setGLDefaultValues();
|
||||
#if AX_ENABLE_CACHE_TEXTURE_DATA
|
||||
ax::VolatileTextureMgr::reloadAllTextures();
|
||||
#endif
|
||||
|
||||
Application::getInstance()->applicationWillEnterForeground();
|
||||
ax::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND);
|
||||
|
|
Loading…
Reference in New Issue