Enable cache render data for webgl by default (#2151)

* Remove unused static function
This commit is contained in:
halx99 2024-09-15 06:00:48 +08:00 committed by GitHub
parent 9258d8a47f
commit cfcdddd89b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 124 additions and 103 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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
/**

View File

@ -31,7 +31,8 @@ THE SOFTWARE.
# 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

View File

@ -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;

View File

@ -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

View File

@ -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();

View File

@ -29,6 +29,7 @@ THE SOFTWARE.
#if AX_TARGET_PLATFORM == AX_PLATFORM_WASM
# include "platform/wasm/Application-wasm.h"
# include "platform/wasm/devtools-wasm.h"
# include <unistd.h>
# include <sys/time.h>
# include <string>
@ -37,24 +38,59 @@ THE SOFTWARE.
# 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;
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);
sm_pSharedApplication = this;
@ -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;
}
@ -170,14 +204,19 @@ const char * Application::getCurrentLanguageCode()
static char code[3] = {0};
char pLanguageName[16];
EM_ASM_ARGS({
EM_ASM_ARGS(
{
var lang = localStorage.getItem('localization_language');
if (lang == null) {
if (lang == null)
{
stringToUTF8(window.navigator.language.replace(/ - .*/, ""), $0, 16);
} else {
}
else
{
stringToUTF8(lang, $0, 16);
}
}, pLanguageName);
},
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) {
if (lang == null)
{
stringToUTF8(window.navigator.language.replace(/ - .*/, ""), $0, 16);
} else {
}
else
{
stringToUTF8(lang, $0, 16);
}
}, pLanguageName);
},
pLanguageName);
return utils::getLanguageTypeByISO2(pLanguageName);
}
}
} // namespace ax
#endif // AX_TARGET_PLATFORM == AX_PLATFORM_WASM

View File

@ -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

View File

@ -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;
})(),

View File

@ -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);