axmol/core/platform/desktop/CCGLViewImpl-desktop.cpp

1318 lines
47 KiB
C++
Raw Normal View History

2012-07-21 12:23:40 +08:00
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2020 C4games Ltd.
Copyright (c) 2021-2022 Bytedance Inc.
2022-10-01 16:24:52 +08:00
https://axmolengine.github.io/
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.
****************************************************************************/
#include "platform/desktop/CCGLViewImpl-desktop.h"
2014-09-10 07:50:02 +08:00
#include <cmath>
2014-09-10 07:50:02 +08:00
#include <unordered_map>
#include "platform/CCApplication.h"
2014-04-30 08:37:36 +08:00
#include "base/CCDirector.h"
#include "base/CCTouch.h"
#include "base/CCEventDispatcher.h"
#include "base/CCEventKeyboard.h"
#include "base/CCEventMouse.h"
Squashed commit of the following: commit a794d107ad85667e3d754f0b6251fc864dfbf288 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 14:33:49 2014 -0700 Yeah... everything compiles on win32 and wp8 commit 4740be6e4a0d16f742c27996e7ab2c100adc76af Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:58:38 2014 -0700 CCIME moved to base and compiles on Android commit ff3e1bf1eb27a01019f4e1b56d1aebbe2d385f72 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:02:57 2014 -0700 compiles Ok for Windows Phone 8 commit 8160a4eb2ecdc61b5bd1cf56b90d2da6f11e3ebd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 12:25:31 2014 -0700 fixes for Windows Phone 8 commit 418197649efc93032aee0adc205e502101cdb53d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 11:15:13 2014 -0700 Compiles on Win32 commit 08813ed7cf8ac1079ffadeb1ce78ea9e833e1a33 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 10:08:31 2014 -0700 Compiles on linux! commit 118896521e5b335a5257090b6863f1fb2a2002fe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 09:30:42 2014 -0700 moves cocos/2d/platform -> cocos/platform commit 4fe9319d7717b0c1bccb2db0156eeb86255a89e0 Merge: bd68ec2 511295e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 08:24:41 2014 -0700 Merge remote-tracking branch 'cocos2d/v3' into files commit bd68ec2f0e3a826d8b2f4b60564ba65ce766bc56 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu May 15 19:36:23 2014 -0700 files in the correct directory
2014-05-17 05:36:00 +08:00
#include "base/CCIMEDispatcher.h"
2014-07-14 20:45:24 +08:00
#include "base/ccUtils.h"
2014-08-10 00:42:21 +08:00
#include "base/ccUTF8.h"
2015-06-01 14:26:08 +08:00
#include "2d/CCCamera.h"
2023-01-21 17:57:56 +08:00
#if AX_ICON_SET_SUPPORT
# include "platform/CCImage.h"
#endif /* AX_ICON_SET_SUPPORT */
2020-10-17 16:32:16 +08:00
2023-01-21 17:57:56 +08:00
#include "renderer/CCRenderer.h"
2023-01-24 13:58:29 +08:00
#if defined(AX_USE_METAL)
2023-01-21 18:49:02 +08:00
# include <Metal/Metal.h>
# include "renderer/backend/metal/DeviceMTL.h"
# include "renderer/backend/metal/UtilsMTL.h"
2023-01-21 17:57:56 +08:00
#else
2023-01-21 18:49:02 +08:00
# include "renderer/backend/opengl/MacrosGL.h"
2023-01-21 17:57:56 +08:00
#endif // #if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC)
2021-07-07 14:09:11 +08:00
2023-01-21 18:49:02 +08:00
/** glfw3native.h */
#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32)
# ifndef GLFW_EXPOSE_NATIVE_WIN32
# define GLFW_EXPOSE_NATIVE_WIN32
# endif
# ifndef GLFW_EXPOSE_NATIVE_WGL
# define GLFW_EXPOSE_NATIVE_WGL
# endif
#endif /* (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32) */
#if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC)
# ifndef GLFW_EXPOSE_NATIVE_NSGL
# define GLFW_EXPOSE_NATIVE_NSGL
# endif
# ifndef GLFW_EXPOSE_NATIVE_COCOA
# define GLFW_EXPOSE_NATIVE_COCOA
# endif
#endif // #if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC)
#include "glfw3native.h"
2020-10-17 16:32:16 +08:00
#if defined(_WIN32)
2021-12-25 10:04:45 +08:00
# include "glfw3ext.h"
2020-10-17 16:32:16 +08:00
#endif
NS_AX_BEGIN
2012-09-04 02:06:04 +08:00
2020-09-04 17:58:34 +08:00
class GLFWEventHandler
{
public:
static void onGLFWError(int errorID, const char* errorDesc)
{
if (_view)
_view->onGLFWError(errorID, errorDesc);
}
static void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
{
if (_view)
_view->onGLFWMouseCallBack(window, button, action, modify);
}
static void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
{
if (_view)
_view->onGLFWMouseMoveCallBack(window, x, y);
}
static void onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
{
if (_view)
_view->onGLFWMouseScrollCallback(window, x, y);
}
static void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (_view)
_view->onGLFWKeyCallback(window, key, scancode, action, mods);
}
static void onGLFWCharCallback(GLFWwindow* window, unsigned int character)
{
if (_view)
_view->onGLFWCharCallback(window, character);
}
static void onGLFWWindowPosCallback(GLFWwindow* windows, int x, int y)
{
if (_view)
_view->onGLFWWindowPosCallback(windows, x, y);
}
// Notes: Unused on windows or macos Metal renderer backend
// static void onGLFWframebufferSize(GLFWwindow* window, int w, int h)
// {
// if (_view)
// _view->onGLFWframebufferSize(window, w, h);
// }
2021-12-25 10:04:45 +08:00
static void onGLFWWindowSizeCallback(GLFWwindow* window, int width, int height)
2020-09-04 17:58:34 +08:00
{
if (_view)
_view->onGLFWWindowSizeCallback(window, width, height);
}
2021-12-25 10:04:45 +08:00
static void setGLViewImpl(GLViewImpl* view) { _view = view; }
2020-09-04 17:58:34 +08:00
static void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified)
{
if (_view)
{
_view->onGLFWWindowIconifyCallback(window, iconified);
}
}
static void onGLFWWindowFocusCallback(GLFWwindow* window, int focused)
{
if (_view)
{
_view->onGLFWWindowFocusCallback(window, focused);
}
}
private:
static GLViewImpl* _view;
};
GLViewImpl* GLFWEventHandler::_view = nullptr;
2021-12-25 10:04:45 +08:00
const std::string GLViewImpl::EVENT_WINDOW_RESIZED = "glview_window_resized";
const std::string GLViewImpl::EVENT_WINDOW_FOCUSED = "glview_window_focused";
const std::string GLViewImpl::EVENT_WINDOW_UNFOCUSED = "glview_window_unfocused";
////////////////////////////////////////////////////
struct keyCodeItem
{
int glfwKeyCode;
EventKeyboard::KeyCode keyCode;
};
static std::unordered_map<int, EventKeyboard::KeyCode> g_keyCodeMap;
static keyCodeItem g_keyCodeStructArray[] = {
/* The unknown key */
2021-12-25 10:04:45 +08:00
{GLFW_KEY_UNKNOWN, EventKeyboard::KeyCode::KEY_NONE},
2014-03-07 13:59:56 +08:00
/* Printable keys */
2021-12-25 10:04:45 +08:00
{GLFW_KEY_SPACE, EventKeyboard::KeyCode::KEY_SPACE},
{GLFW_KEY_APOSTROPHE, EventKeyboard::KeyCode::KEY_APOSTROPHE},
{GLFW_KEY_COMMA, EventKeyboard::KeyCode::KEY_COMMA},
{GLFW_KEY_MINUS, EventKeyboard::KeyCode::KEY_MINUS},
{GLFW_KEY_PERIOD, EventKeyboard::KeyCode::KEY_PERIOD},
{GLFW_KEY_SLASH, EventKeyboard::KeyCode::KEY_SLASH},
{GLFW_KEY_0, EventKeyboard::KeyCode::KEY_0},
{GLFW_KEY_1, EventKeyboard::KeyCode::KEY_1},
{GLFW_KEY_2, EventKeyboard::KeyCode::KEY_2},
{GLFW_KEY_3, EventKeyboard::KeyCode::KEY_3},
{GLFW_KEY_4, EventKeyboard::KeyCode::KEY_4},
{GLFW_KEY_5, EventKeyboard::KeyCode::KEY_5},
{GLFW_KEY_6, EventKeyboard::KeyCode::KEY_6},
{GLFW_KEY_7, EventKeyboard::KeyCode::KEY_7},
{GLFW_KEY_8, EventKeyboard::KeyCode::KEY_8},
{GLFW_KEY_9, EventKeyboard::KeyCode::KEY_9},
{GLFW_KEY_SEMICOLON, EventKeyboard::KeyCode::KEY_SEMICOLON},
{GLFW_KEY_EQUAL, EventKeyboard::KeyCode::KEY_EQUAL},
{GLFW_KEY_A, EventKeyboard::KeyCode::KEY_A},
{GLFW_KEY_B, EventKeyboard::KeyCode::KEY_B},
{GLFW_KEY_C, EventKeyboard::KeyCode::KEY_C},
{GLFW_KEY_D, EventKeyboard::KeyCode::KEY_D},
{GLFW_KEY_E, EventKeyboard::KeyCode::KEY_E},
{GLFW_KEY_F, EventKeyboard::KeyCode::KEY_F},
{GLFW_KEY_G, EventKeyboard::KeyCode::KEY_G},
{GLFW_KEY_H, EventKeyboard::KeyCode::KEY_H},
{GLFW_KEY_I, EventKeyboard::KeyCode::KEY_I},
{GLFW_KEY_J, EventKeyboard::KeyCode::KEY_J},
{GLFW_KEY_K, EventKeyboard::KeyCode::KEY_K},
{GLFW_KEY_L, EventKeyboard::KeyCode::KEY_L},
{GLFW_KEY_M, EventKeyboard::KeyCode::KEY_M},
{GLFW_KEY_N, EventKeyboard::KeyCode::KEY_N},
{GLFW_KEY_O, EventKeyboard::KeyCode::KEY_O},
{GLFW_KEY_P, EventKeyboard::KeyCode::KEY_P},
{GLFW_KEY_Q, EventKeyboard::KeyCode::KEY_Q},
{GLFW_KEY_R, EventKeyboard::KeyCode::KEY_R},
{GLFW_KEY_S, EventKeyboard::KeyCode::KEY_S},
{GLFW_KEY_T, EventKeyboard::KeyCode::KEY_T},
{GLFW_KEY_U, EventKeyboard::KeyCode::KEY_U},
{GLFW_KEY_V, EventKeyboard::KeyCode::KEY_V},
{GLFW_KEY_W, EventKeyboard::KeyCode::KEY_W},
{GLFW_KEY_X, EventKeyboard::KeyCode::KEY_X},
{GLFW_KEY_Y, EventKeyboard::KeyCode::KEY_Y},
{GLFW_KEY_Z, EventKeyboard::KeyCode::KEY_Z},
{GLFW_KEY_LEFT_BRACKET, EventKeyboard::KeyCode::KEY_LEFT_BRACKET},
{GLFW_KEY_BACKSLASH, EventKeyboard::KeyCode::KEY_BACK_SLASH},
{GLFW_KEY_RIGHT_BRACKET, EventKeyboard::KeyCode::KEY_RIGHT_BRACKET},
{GLFW_KEY_GRAVE_ACCENT, EventKeyboard::KeyCode::KEY_GRAVE},
{GLFW_KEY_WORLD_1, EventKeyboard::KeyCode::KEY_GRAVE},
{GLFW_KEY_WORLD_2, EventKeyboard::KeyCode::KEY_NONE},
2014-03-07 13:59:56 +08:00
/* Function keys */
2021-12-25 10:04:45 +08:00
{GLFW_KEY_ESCAPE, EventKeyboard::KeyCode::KEY_ESCAPE},
{GLFW_KEY_ENTER, EventKeyboard::KeyCode::KEY_ENTER},
{GLFW_KEY_TAB, EventKeyboard::KeyCode::KEY_TAB},
{GLFW_KEY_BACKSPACE, EventKeyboard::KeyCode::KEY_BACKSPACE},
{GLFW_KEY_INSERT, EventKeyboard::KeyCode::KEY_INSERT},
{GLFW_KEY_DELETE, EventKeyboard::KeyCode::KEY_DELETE},
{GLFW_KEY_RIGHT, EventKeyboard::KeyCode::KEY_RIGHT_ARROW},
{GLFW_KEY_LEFT, EventKeyboard::KeyCode::KEY_LEFT_ARROW},
{GLFW_KEY_DOWN, EventKeyboard::KeyCode::KEY_DOWN_ARROW},
{GLFW_KEY_UP, EventKeyboard::KeyCode::KEY_UP_ARROW},
{GLFW_KEY_PAGE_UP, EventKeyboard::KeyCode::KEY_PG_UP},
{GLFW_KEY_PAGE_DOWN, EventKeyboard::KeyCode::KEY_PG_DOWN},
{GLFW_KEY_HOME, EventKeyboard::KeyCode::KEY_HOME},
{GLFW_KEY_END, EventKeyboard::KeyCode::KEY_END},
{GLFW_KEY_CAPS_LOCK, EventKeyboard::KeyCode::KEY_CAPS_LOCK},
{GLFW_KEY_SCROLL_LOCK, EventKeyboard::KeyCode::KEY_SCROLL_LOCK},
{GLFW_KEY_NUM_LOCK, EventKeyboard::KeyCode::KEY_NUM_LOCK},
{GLFW_KEY_PRINT_SCREEN, EventKeyboard::KeyCode::KEY_PRINT},
{GLFW_KEY_PAUSE, EventKeyboard::KeyCode::KEY_PAUSE},
{GLFW_KEY_F1, EventKeyboard::KeyCode::KEY_F1},
{GLFW_KEY_F2, EventKeyboard::KeyCode::KEY_F2},
{GLFW_KEY_F3, EventKeyboard::KeyCode::KEY_F3},
{GLFW_KEY_F4, EventKeyboard::KeyCode::KEY_F4},
{GLFW_KEY_F5, EventKeyboard::KeyCode::KEY_F5},
{GLFW_KEY_F6, EventKeyboard::KeyCode::KEY_F6},
{GLFW_KEY_F7, EventKeyboard::KeyCode::KEY_F7},
{GLFW_KEY_F8, EventKeyboard::KeyCode::KEY_F8},
{GLFW_KEY_F9, EventKeyboard::KeyCode::KEY_F9},
{GLFW_KEY_F10, EventKeyboard::KeyCode::KEY_F10},
{GLFW_KEY_F11, EventKeyboard::KeyCode::KEY_F11},
{GLFW_KEY_F12, EventKeyboard::KeyCode::KEY_F12},
{GLFW_KEY_F13, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F14, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F15, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F16, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F17, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F18, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F19, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F20, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F21, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F22, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F23, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F24, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_F25, EventKeyboard::KeyCode::KEY_NONE},
{GLFW_KEY_KP_0, EventKeyboard::KeyCode::KEY_0},
{GLFW_KEY_KP_1, EventKeyboard::KeyCode::KEY_1},
{GLFW_KEY_KP_2, EventKeyboard::KeyCode::KEY_2},
{GLFW_KEY_KP_3, EventKeyboard::KeyCode::KEY_3},
{GLFW_KEY_KP_4, EventKeyboard::KeyCode::KEY_4},
{GLFW_KEY_KP_5, EventKeyboard::KeyCode::KEY_5},
{GLFW_KEY_KP_6, EventKeyboard::KeyCode::KEY_6},
{GLFW_KEY_KP_7, EventKeyboard::KeyCode::KEY_7},
{GLFW_KEY_KP_8, EventKeyboard::KeyCode::KEY_8},
{GLFW_KEY_KP_9, EventKeyboard::KeyCode::KEY_9},
{GLFW_KEY_KP_DECIMAL, EventKeyboard::KeyCode::KEY_PERIOD},
{GLFW_KEY_KP_DIVIDE, EventKeyboard::KeyCode::KEY_KP_DIVIDE},
{GLFW_KEY_KP_MULTIPLY, EventKeyboard::KeyCode::KEY_KP_MULTIPLY},
{GLFW_KEY_KP_SUBTRACT, EventKeyboard::KeyCode::KEY_KP_MINUS},
{GLFW_KEY_KP_ADD, EventKeyboard::KeyCode::KEY_KP_PLUS},
{GLFW_KEY_KP_ENTER, EventKeyboard::KeyCode::KEY_KP_ENTER},
{GLFW_KEY_KP_EQUAL, EventKeyboard::KeyCode::KEY_EQUAL},
{GLFW_KEY_LEFT_SHIFT, EventKeyboard::KeyCode::KEY_LEFT_SHIFT},
{GLFW_KEY_LEFT_CONTROL, EventKeyboard::KeyCode::KEY_LEFT_CTRL},
{GLFW_KEY_LEFT_ALT, EventKeyboard::KeyCode::KEY_LEFT_ALT},
{GLFW_KEY_LEFT_SUPER, EventKeyboard::KeyCode::KEY_HYPER},
{GLFW_KEY_RIGHT_SHIFT, EventKeyboard::KeyCode::KEY_RIGHT_SHIFT},
{GLFW_KEY_RIGHT_CONTROL, EventKeyboard::KeyCode::KEY_RIGHT_CTRL},
{GLFW_KEY_RIGHT_ALT, EventKeyboard::KeyCode::KEY_RIGHT_ALT},
{GLFW_KEY_RIGHT_SUPER, EventKeyboard::KeyCode::KEY_HYPER},
{GLFW_KEY_MENU, EventKeyboard::KeyCode::KEY_MENU},
{GLFW_KEY_LAST, EventKeyboard::KeyCode::KEY_NONE}};
//////////////////////////////////////////////////////////////////////////
2014-07-31 00:53:04 +08:00
// implement GLViewImpl
//////////////////////////////////////////////////////////////////////////
GLViewImpl::GLViewImpl(bool initglfw)
2021-12-25 10:04:45 +08:00
: _captured(false)
, _isInRetinaMonitor(false)
, _isRetinaEnabled(false)
, _retinaFactor(1)
, _frameZoomFactor(1.0f)
, _mainWindow(nullptr)
, _monitor(nullptr)
, _mouseX(0.0f)
, _mouseY(0.0f)
{
2023-01-21 17:57:56 +08:00
_viewName = "AXMOL10";
g_keyCodeMap.clear();
for (auto&& item : g_keyCodeStructArray)
2013-08-21 12:01:56 +08:00
{
g_keyCodeMap[item.glfwKeyCode] = item.keyCode;
2013-08-21 12:01:56 +08:00
}
2014-03-07 13:59:56 +08:00
2014-07-31 00:53:04 +08:00
GLFWEventHandler::setGLViewImpl(this);
if (initglfw)
{
glfwSetErrorCallback(GLFWEventHandler::onGLFWError);
2022-07-15 19:17:01 +08:00
#if defined(AX_USE_GLES) && GLFW_VERSION_MAJOR >= 3 && GLFW_VERSION_MINOR >= 4
2021-12-25 10:04:45 +08:00
glfwInitHint(GLFW_ANGLE_PLATFORM_TYPE, GLFW_ANGLE_PLATFORM_TYPE_D3D11); // since glfw-3.4
2020-07-03 11:08:39 +08:00
#endif
2020-10-17 16:32:16 +08:00
#if defined(_WIN32)
glfwxInit();
#else
glfwInit();
2020-10-17 16:32:16 +08:00
#endif
}
}
2014-07-31 00:53:04 +08:00
GLViewImpl::~GLViewImpl()
{
2022-07-16 10:43:05 +08:00
AXLOGINFO("deallocing GLViewImpl: %p", this);
2014-07-31 00:53:04 +08:00
GLFWEventHandler::setGLViewImpl(nullptr);
2020-10-17 16:32:16 +08:00
#if defined(_WIN32)
glfwxTerminate();
#else
glfwTerminate();
2020-10-17 16:32:16 +08:00
#endif
2014-02-10 18:15:30 +08:00
}
2023-01-21 18:49:02 +08:00
#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32)
HWND GLViewImpl::getWin32Window()
{
return glfwGetWin32Window(_mainWindow);
}
#endif /* (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32) */
#if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC)
void* GLViewImpl::getCocoaWindow()
{
return (void*)glfwGetCocoaWindow(_mainWindow);
}
void* GLViewImpl::getNSGLContext()
{
return (void*)glfwGetNSGLContext(_mainWindow);
} // stevetranby: added
#endif // #if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC)
2021-12-26 23:26:34 +08:00
GLViewImpl* GLViewImpl::create(std::string_view viewName)
{
return GLViewImpl::create(viewName, false);
}
2021-12-26 23:26:34 +08:00
GLViewImpl* GLViewImpl::create(std::string_view viewName, bool resizable)
{
2021-12-08 00:11:53 +08:00
auto ret = new GLViewImpl;
2023-01-21 18:49:02 +08:00
if (ret->initWithRect(viewName, ax::Rect(0, 0, 960, 640), 1.0f, resizable))
2021-12-25 10:04:45 +08:00
{
ret->autorelease();
return ret;
}
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(ret);
return nullptr;
}
2023-03-11 22:53:55 +08:00
GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName, const ax::Rect& rect, float frameZoomFactor, bool resizable)
{
2021-12-08 00:11:53 +08:00
auto ret = new GLViewImpl;
2021-12-25 10:04:45 +08:00
if (ret->initWithRect(viewName, rect, frameZoomFactor, resizable))
{
ret->autorelease();
return ret;
}
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(ret);
return nullptr;
}
2021-12-26 23:26:34 +08:00
GLViewImpl* GLViewImpl::createWithFullScreen(std::string_view viewName)
{
2021-12-08 00:11:53 +08:00
auto ret = new GLViewImpl();
2021-12-25 10:04:45 +08:00
if (ret->initWithFullScreen(viewName))
{
ret->autorelease();
return ret;
}
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(ret);
return nullptr;
}
2013-08-21 12:01:56 +08:00
2021-12-26 23:26:34 +08:00
GLViewImpl* GLViewImpl::createWithFullScreen(std::string_view viewName,
2021-12-25 10:04:45 +08:00
const GLFWvidmode& videoMode,
GLFWmonitor* monitor)
{
2021-12-08 00:11:53 +08:00
auto ret = new GLViewImpl();
2021-12-25 10:04:45 +08:00
if (ret->initWithFullscreen(viewName, videoMode, monitor))
{
ret->autorelease();
return ret;
}
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(ret);
return nullptr;
}
2023-03-11 22:53:55 +08:00
bool GLViewImpl::initWithRect(std::string_view viewName, const ax::Rect& rect, float frameZoomFactor, bool resizable)
2012-07-21 12:23:40 +08:00
{
setViewName(viewName);
2014-03-07 13:59:56 +08:00
_frameZoomFactor = frameZoomFactor;
2014-03-07 13:59:56 +08:00
2022-07-15 19:17:01 +08:00
#if defined(AX_USE_GLES)
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
#endif
2021-12-25 10:04:45 +08:00
glfwWindowHint(GLFW_RESIZABLE, resizable ? GL_TRUE : GL_FALSE);
glfwWindowHint(GLFW_RED_BITS, _glContextAttrs.redBits);
glfwWindowHint(GLFW_GREEN_BITS, _glContextAttrs.greenBits);
glfwWindowHint(GLFW_BLUE_BITS, _glContextAttrs.blueBits);
glfwWindowHint(GLFW_ALPHA_BITS, _glContextAttrs.alphaBits);
glfwWindowHint(GLFW_DEPTH_BITS, _glContextAttrs.depthBits);
glfwWindowHint(GLFW_STENCIL_BITS, _glContextAttrs.stencilBits);
glfwWindowHint(GLFW_SAMPLES, _glContextAttrs.multisamplingCount);
2020-10-17 16:32:16 +08:00
glfwWindowHint(GLFW_VISIBLE, _glContextAttrs.visible);
glfwWindowHint(GLFW_DECORATED, _glContextAttrs.decorated);
2021-12-25 10:04:45 +08:00
2023-01-22 07:39:46 +08:00
#if defined(AX_USE_METAL)
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
// Don't create gl context.
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
#endif
2014-03-07 13:59:56 +08:00
2021-12-25 10:04:45 +08:00
int neededWidth = (int)(rect.size.width * _frameZoomFactor);
2019-10-09 17:50:32 +08:00
int neededHeight = (int)(rect.size.height * _frameZoomFactor);
2022-07-15 19:17:01 +08:00
#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32)
2020-10-17 16:32:16 +08:00
glfwxSetParent((HWND)_glContextAttrs.viewParent);
#endif
_mainWindow = glfwCreateWindow(neededWidth, neededHeight, _viewName.c_str(), _monitor, nullptr);
if (_mainWindow == nullptr)
{
std::string message = "Can't create window";
if (!_glfwError.empty())
{
message.append("\nMore info: \n");
message.append(_glfwError);
}
ccMessageBox(message.c_str(), "Error launch application");
2021-12-25 10:04:45 +08:00
utils::killCurrentProcess(); // kill current process, don't cause crash when driver issue.
return false;
}
2023-01-21 17:57:56 +08:00
#if defined(AX_USE_METAL)
int fbWidth, fbHeight;
glfwGetFramebufferSize(_mainWindow, &fbWidth, &fbHeight);
CGSize size;
size.width = static_cast<CGFloat>(fbWidth);
size.height = static_cast<CGFloat>(fbHeight);
// Initialize device.
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
if (!device)
{
AXLOG("Doesn't support metal.");
return false;
}
2023-01-21 21:57:28 +08:00
NSView* contentView = [(id)getCocoaWindow() contentView];
2023-01-21 17:57:56 +08:00
[contentView setWantsLayer:YES];
CAMetalLayer* layer = [CAMetalLayer layer];
[layer setDevice:device];
[layer setPixelFormat:MTLPixelFormatBGRA8Unorm];
[layer setFramebufferOnly:YES];
[layer setDrawableSize:size];
layer.displaySyncEnabled = _glContextAttrs.vsync;
[contentView setLayer:layer];
backend::DeviceMTL::setCAMetalLayer(layer);
#endif
2023-01-24 15:49:40 +08:00
2023-01-24 13:58:29 +08:00
#if defined(AX_USE_GL)
glfwMakeContextCurrent(_mainWindow);
#endif
2023-01-21 17:57:56 +08:00
/*
2021-12-25 10:04:45 +08:00
* Note that the created window and context may differ from what you requested,
* as not all parameters and hints are
* [hard constraints](@ref window_hints_hard). This includes the size of the
* window, especially for full screen windows. To retrieve the actual
* attributes of the created window and context, use queries like @ref
* glfwGetWindowAttrib and @ref glfwGetWindowSize.
*
* see declaration glfwCreateWindow
*/
int realW = 0, realH = 0;
glfwGetWindowSize(_mainWindow, &realW, &realH);
if (realW != neededWidth)
{
rect.size.width = realW / _frameZoomFactor;
}
if (realH != neededHeight)
{
rect.size.height = realH / _frameZoomFactor;
}
glfwSetMouseButtonCallback(_mainWindow, GLFWEventHandler::onGLFWMouseCallBack);
glfwSetCursorPosCallback(_mainWindow, GLFWEventHandler::onGLFWMouseMoveCallBack);
glfwSetScrollCallback(_mainWindow, GLFWEventHandler::onGLFWMouseScrollCallback);
glfwSetCharCallback(_mainWindow, GLFWEventHandler::onGLFWCharCallback);
glfwSetKeyCallback(_mainWindow, GLFWEventHandler::onGLFWKeyCallback);
glfwSetWindowPosCallback(_mainWindow, GLFWEventHandler::onGLFWWindowPosCallback);
glfwSetWindowSizeCallback(_mainWindow, GLFWEventHandler::onGLFWWindowSizeCallback);
2014-08-14 15:48:09 +08:00
glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback);
glfwSetWindowFocusCallback(_mainWindow, GLFWEventHandler::onGLFWWindowFocusCallback);
2014-03-07 13:59:56 +08:00
setFrameSize(rect.size.width, rect.size.height);
2014-03-07 13:59:56 +08:00
2023-01-24 13:58:29 +08:00
#if (AX_TARGET_PLATFORM != AX_PLATFORM_MAC)
loadGL();
2023-01-24 13:58:29 +08:00
#endif
#if defined(AX_USE_GL)
glfwSwapInterval(_glContextAttrs.vsync ? 1 : 0);
2013-08-21 12:01:56 +08:00
// check OpenGL version at first
const GLubyte* glVersion = glGetString(GL_VERSION);
2014-03-07 13:59:56 +08:00
2021-12-25 10:04:45 +08:00
if (utils::atof((const char*)glVersion) < 1.5 && nullptr == strstr((const char*)glVersion, "ANGLE"))
2013-08-21 12:01:56 +08:00
{
char strComplain[256] = {0};
sprintf(strComplain,
"OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.",
glVersion);
ccMessageBox(strComplain, "OpenGL version too old");
2021-12-25 10:04:45 +08:00
utils::killCurrentProcess(); // kill current process, don't cause crash when driver issue.
return false;
2013-08-21 12:01:56 +08:00
}
2023-01-24 15:49:40 +08:00
2023-01-24 13:58:29 +08:00
if (GL_ARB_vertex_shader && GL_ARB_fragment_shader)
ax::print("[GL:%s] Ready for GLSL", glVersion);
else
ax::print("Not totally ready :(");
2021-12-25 10:04:45 +08:00
2023-01-24 15:49:40 +08:00
// Will cause OpenGL error 0x0500 when use ANGLE-GLES on desktop
2023-01-21 20:04:58 +08:00
# if !defined(AX_USE_GLES)
2023-01-24 15:49:40 +08:00
// Enable point size by default.
2023-01-21 20:04:58 +08:00
# if defined(GL_VERSION_2_0)
2013-08-21 12:01:56 +08:00
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
2023-01-21 20:04:58 +08:00
# else
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
2023-01-21 20:04:58 +08:00
# endif
if (_glContextAttrs.multisamplingCount > 0)
glEnable(GL_MULTISAMPLE);
2023-01-21 20:04:58 +08:00
# endif
CHECK_GL_ERROR_DEBUG();
2023-01-21 20:04:58 +08:00
#endif
2021-12-25 10:04:45 +08:00
// // GLFW v3.2 no longer emits "onGLFWWindowSizeFunCallback" at creation time. Force default viewport:
// setViewPortInPoints(0, 0, neededWidth, neededHeight);
//
2013-08-21 12:01:56 +08:00
return true;
2012-07-21 12:23:40 +08:00
}
2021-12-26 23:26:34 +08:00
bool GLViewImpl::initWithFullScreen(std::string_view viewName)
{
2021-12-25 10:04:45 +08:00
// Create fullscreen window on primary monitor at its current video mode.
_monitor = glfwGetPrimaryMonitor();
if (nullptr == _monitor)
return false;
2014-03-07 13:59:56 +08:00
const GLFWvidmode* videoMode = glfwGetVideoMode(_monitor);
2023-01-21 18:49:02 +08:00
return initWithRect(viewName, ax::Rect(0, 0, (float)videoMode->width, (float)videoMode->height), 1.0f, false);
}
2021-12-26 23:26:34 +08:00
bool GLViewImpl::initWithFullscreen(std::string_view viewname, const GLFWvidmode& videoMode, GLFWmonitor* monitor)
{
2021-12-25 10:04:45 +08:00
// Create fullscreen on specified monitor at the specified video mode.
_monitor = monitor;
if (nullptr == _monitor)
return false;
2021-12-25 10:04:45 +08:00
// These are soft constraints. If the video mode is retrieved at runtime, the resulting window and context should
// match these exactly. If invalid attribs are passed (eg. from an outdated cache), window creation will NOT fail
// but the actual window/context may differ.
glfwWindowHint(GLFW_REFRESH_RATE, videoMode.refreshRate);
glfwWindowHint(GLFW_RED_BITS, videoMode.redBits);
glfwWindowHint(GLFW_BLUE_BITS, videoMode.blueBits);
glfwWindowHint(GLFW_GREEN_BITS, videoMode.greenBits);
2021-12-25 10:04:45 +08:00
2023-01-21 18:49:02 +08:00
return initWithRect(viewname, ax::Rect(0, 0, (float)videoMode.width, (float)videoMode.height), 1.0f, false);
}
2014-07-31 00:53:04 +08:00
bool GLViewImpl::isOpenGLReady()
2012-07-21 12:23:40 +08:00
{
2013-08-21 12:01:56 +08:00
return nullptr != _mainWindow;
2012-07-21 12:23:40 +08:00
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::end()
2012-07-21 12:23:40 +08:00
{
2021-12-25 10:04:45 +08:00
if (_mainWindow)
{
2021-12-25 10:04:45 +08:00
glfwSetWindowShouldClose(_mainWindow, 1);
_mainWindow = nullptr;
}
2014-07-31 00:53:04 +08:00
// Release self. Otherwise, GLViewImpl could not be freed.
2014-03-12 21:45:57 +08:00
release();
2012-07-21 12:23:40 +08:00
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::swapBuffers()
2012-07-21 12:23:40 +08:00
{
2023-01-21 17:57:56 +08:00
#if defined(AX_USE_GL)
2021-12-25 10:04:45 +08:00
if (_mainWindow)
2013-08-21 12:01:56 +08:00
glfwSwapBuffers(_mainWindow);
2023-01-21 17:57:56 +08:00
#endif
2012-07-21 12:23:40 +08:00
}
2014-07-31 00:53:04 +08:00
bool GLViewImpl::windowShouldClose()
2012-07-21 12:23:40 +08:00
{
2021-12-25 10:04:45 +08:00
if (_mainWindow)
2014-03-14 15:38:43 +08:00
return glfwWindowShouldClose(_mainWindow) ? true : false;
2012-07-21 12:23:40 +08:00
else
2013-08-21 12:01:56 +08:00
return true;
2012-07-21 12:23:40 +08:00
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::pollEvents()
2013-08-21 12:01:56 +08:00
{
glfwPollEvents();
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::enableRetina(bool enabled)
2023-01-21 17:57:56 +08:00
{
#if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC)
_isRetinaEnabled = enabled;
if (_isRetinaEnabled)
{
_retinaFactor = 1;
}
else
{
_retinaFactor = 2;
}
updateFrameSize();
#endif
}
2021-12-25 10:04:45 +08:00
void GLViewImpl::setIMEKeyboardState(bool /*bOpen*/) {}
2013-08-21 12:01:56 +08:00
2022-07-15 19:17:01 +08:00
#if AX_ICON_SET_SUPPORT
2021-12-26 23:26:34 +08:00
void GLViewImpl::setIcon(std::string_view filename) const
2021-12-25 10:04:45 +08:00
{
2021-12-26 23:26:34 +08:00
this->setIcon(std::vector<std::string_view>{filename});
}
2021-12-26 23:26:34 +08:00
void GLViewImpl::setIcon(const std::vector<std::string_view>& filelist) const
2021-12-25 10:04:45 +08:00
{
if (filelist.empty())
return;
std::vector<Image*> icons;
2021-12-25 10:04:45 +08:00
for (auto const& filename : filelist)
{
2021-12-08 00:11:53 +08:00
Image* icon = new Image();
2021-12-25 10:04:45 +08:00
if (icon->initWithImageFile(filename))
{
icons.emplace_back(icon);
2021-12-25 10:04:45 +08:00
}
else
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(icon);
}
}
2021-12-25 10:04:45 +08:00
if (icons.empty())
return; // No valid images
size_t iconsCount = icons.size();
2021-12-25 10:04:45 +08:00
auto images = new GLFWimage[iconsCount];
for (size_t i = 0; i < iconsCount; i++)
{
auto& image = images[i];
auto& icon = icons[i];
image.width = icon->getWidth();
image.height = icon->getHeight();
image.pixels = icon->getData();
};
GLFWwindow* window = this->getWindow();
glfwSetWindowIcon(window, iconsCount, images);
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE_ARRAY(images);
for (auto&& icon : icons)
2021-12-25 10:04:45 +08:00
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(icon);
}
}
2021-12-25 10:04:45 +08:00
void GLViewImpl::setDefaultIcon() const
{
GLFWwindow* window = this->getWindow();
glfwSetWindowIcon(window, 0, nullptr);
}
2022-07-15 19:17:01 +08:00
#endif /* AX_ICON_SET_SUPPORT */
2021-12-25 10:04:45 +08:00
void GLViewImpl::setCursorVisible(bool isVisible)
{
2021-12-25 10:04:45 +08:00
if (_mainWindow == NULL)
return;
2021-12-25 10:04:45 +08:00
if (isVisible)
glfwSetInputMode(_mainWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
else
glfwSetInputMode(_mainWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::setFrameZoomFactor(float zoomFactor)
2013-08-21 12:01:56 +08:00
{
2022-07-16 10:43:05 +08:00
AXASSERT(zoomFactor > 0.0f, "zoomFactor must be larger than 0");
2014-03-07 13:59:56 +08:00
if (std::abs(_frameZoomFactor - zoomFactor) < FLT_EPSILON)
{
return;
}
2014-03-07 13:59:56 +08:00
_frameZoomFactor = zoomFactor;
updateFrameSize();
2013-08-21 12:01:56 +08:00
}
2014-07-31 00:53:04 +08:00
float GLViewImpl::getFrameZoomFactor() const
2013-08-21 12:01:56 +08:00
{
return _frameZoomFactor;
}
2021-12-25 10:04:45 +08:00
bool GLViewImpl::isFullscreen() const
{
return (_monitor != nullptr);
}
void GLViewImpl::setFullscreen()
{
2020-08-02 16:36:58 +08:00
setFullscreen(-1, -1, -1);
}
2021-12-25 10:04:45 +08:00
void GLViewImpl::setFullscreen(int w, int h, int refreshRate)
{
2020-08-03 10:33:04 +08:00
auto monitor = glfwGetPrimaryMonitor();
2021-12-25 10:04:45 +08:00
if (nullptr == monitor || monitor == _monitor)
{
return;
}
2020-08-03 10:33:04 +08:00
this->setFullscreen(monitor, w, h, refreshRate);
}
void GLViewImpl::setFullscreen(int monitorIndex)
{
2020-08-02 16:36:58 +08:00
setFullscreen(monitorIndex, -1, -1, -1);
}
2021-12-25 10:04:45 +08:00
void GLViewImpl::setFullscreen(int monitorIndex, int w, int h, int refreshRate)
{
int count = 0;
GLFWmonitor** monitors = glfwGetMonitors(&count);
2021-12-25 10:04:45 +08:00
if (monitorIndex < 0 || monitorIndex >= count)
{
return;
}
GLFWmonitor* monitor = monitors[monitorIndex];
2021-12-25 10:04:45 +08:00
if (nullptr == monitor || _monitor == monitor)
{
return;
}
this->setFullscreen(monitor, w, h, refreshRate);
}
2021-12-25 10:04:45 +08:00
void GLViewImpl::setFullscreen(GLFWmonitor* monitor, int w, int h, int refreshRate)
{
_monitor = monitor;
2020-08-02 16:36:58 +08:00
2020-08-02 16:48:19 +08:00
const GLFWvidmode* videoMode = glfwGetVideoMode(_monitor);
if (w == -1)
2020-08-02 16:36:58 +08:00
w = videoMode->width;
2020-08-02 16:48:19 +08:00
if (h == -1)
2020-08-02 16:36:58 +08:00
h = videoMode->height;
2020-08-02 16:48:19 +08:00
if (refreshRate == -1)
2020-08-02 16:36:58 +08:00
refreshRate = videoMode->refreshRate;
glfwSetWindowMonitor(_mainWindow, _monitor, 0, 0, w, h, refreshRate);
updateWindowSize();
}
2021-12-25 10:04:45 +08:00
void GLViewImpl::setWindowed(int width, int height)
{
if (!this->isFullscreen())
{
2019-10-09 17:50:32 +08:00
this->setFrameSize((float)width, (float)height);
2021-12-25 10:04:45 +08:00
}
else
{
const GLFWvidmode* videoMode = glfwGetVideoMode(_monitor);
int xpos = 0, ypos = 0;
glfwGetMonitorPos(_monitor, &xpos, &ypos);
2019-10-09 17:50:32 +08:00
xpos += (int)((videoMode->width - width) * 0.5f);
ypos += (int)((videoMode->height - height) * 0.5f);
_monitor = nullptr;
glfwSetWindowMonitor(_mainWindow, nullptr, xpos, ypos, width, height, GLFW_DONT_CARE);
2022-07-15 19:17:01 +08:00
#if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC)
// on mac window will sometimes lose title when windowed
glfwSetWindowTitle(_mainWindow, _viewName.c_str());
#endif
updateWindowSize();
}
}
void GLViewImpl::updateWindowSize()
{
int w = 0, h = 0;
glfwGetFramebufferSize(_mainWindow, &w, &h);
2021-12-25 10:04:45 +08:00
int frameWidth = w / _frameZoomFactor;
int frameHeight = h / _frameZoomFactor;
setFrameSize(frameWidth, frameHeight);
updateDesignResolutionSize();
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_RESIZED, nullptr);
}
2021-12-25 10:04:45 +08:00
int GLViewImpl::getMonitorCount() const
{
int count = 0;
glfwGetMonitors(&count);
return count;
}
2021-12-25 10:04:45 +08:00
Vec2 GLViewImpl::getMonitorSize() const
{
GLFWmonitor* monitor = _monitor;
2021-12-25 10:04:45 +08:00
if (nullptr == monitor)
{
GLFWwindow* window = this->getWindow();
2021-12-25 10:04:45 +08:00
monitor = glfwGetWindowMonitor(window);
}
2021-12-25 10:04:45 +08:00
if (nullptr == monitor)
{
monitor = glfwGetPrimaryMonitor();
}
2021-12-25 10:04:45 +08:00
if (nullptr != monitor)
{
const GLFWvidmode* videoMode = glfwGetVideoMode(monitor);
2021-12-25 10:04:45 +08:00
Vec2 size = Vec2((float)videoMode->width, (float)videoMode->height);
return size;
}
2021-10-23 23:27:14 +08:00
return Vec2::ZERO;
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::updateFrameSize()
{
if (_screenSize.width > 0 && _screenSize.height > 0)
{
int w = 0, h = 0;
glfwGetWindowSize(_mainWindow, &w, &h);
2014-03-07 13:59:56 +08:00
int frameBufferW = 0, frameBufferH = 0;
glfwGetFramebufferSize(_mainWindow, &frameBufferW, &frameBufferH);
2014-03-07 13:59:56 +08:00
if (frameBufferW == 2 * w && frameBufferH == 2 * h)
{
if (_isRetinaEnabled)
{
_retinaFactor = 1;
}
else
{
_retinaFactor = 2;
}
2021-12-25 10:04:45 +08:00
glfwSetWindowSize(_mainWindow, _screenSize.width / 2 * _retinaFactor * _frameZoomFactor,
_screenSize.height / 2 * _retinaFactor * _frameZoomFactor);
_isInRetinaMonitor = true;
}
else
{
if (_isInRetinaMonitor)
{
_retinaFactor = 1;
}
2021-12-25 10:04:45 +08:00
glfwSetWindowSize(_mainWindow, (int)(_screenSize.width * _retinaFactor * _frameZoomFactor),
(int)(_screenSize.height * _retinaFactor * _frameZoomFactor));
2014-03-07 13:59:56 +08:00
_isInRetinaMonitor = false;
}
}
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::setFrameSize(float width, float height)
2013-08-21 12:01:56 +08:00
{
2014-07-31 00:53:04 +08:00
GLView::setFrameSize(width, height);
updateFrameSize();
2013-08-21 12:01:56 +08:00
}
2021-12-25 10:04:45 +08:00
void GLViewImpl::setViewPortInPoints(float x, float y, float w, float h)
2013-08-21 12:01:56 +08:00
{
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
Viewport vp;
2021-12-25 10:04:45 +08:00
vp.x = (int)(x * _scaleX * _retinaFactor * _frameZoomFactor +
_viewPortRect.origin.x * _retinaFactor * _frameZoomFactor);
vp.y = (int)(y * _scaleY * _retinaFactor * _frameZoomFactor +
_viewPortRect.origin.y * _retinaFactor * _frameZoomFactor);
2019-10-09 17:50:32 +08:00
vp.w = (unsigned int)(w * _scaleX * _retinaFactor * _frameZoomFactor);
vp.h = (unsigned int)(h * _scaleY * _retinaFactor * _frameZoomFactor);
2015-06-01 14:26:08 +08:00
Camera::setDefaultViewport(vp);
}
2021-12-25 10:04:45 +08:00
void GLViewImpl::setScissorInPoints(float x, float y, float w, float h)
{
2021-12-25 10:04:45 +08:00
auto x1 = (int)(x * _scaleX * _retinaFactor * _frameZoomFactor +
_viewPortRect.origin.x * _retinaFactor * _frameZoomFactor);
auto y1 = (int)(y * _scaleY * _retinaFactor * _frameZoomFactor +
_viewPortRect.origin.y * _retinaFactor * _frameZoomFactor);
auto width1 = (unsigned int)(w * _scaleX * _retinaFactor * _frameZoomFactor);
auto height1 = (unsigned int)(h * _scaleY * _retinaFactor * _frameZoomFactor);
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
auto renderer = Director::getInstance()->getRenderer();
renderer->setScissorRect(x1, y1, width1, height1);
}
2023-01-21 18:49:02 +08:00
ax::Rect GLViewImpl::getScissorRect() const
{
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
auto renderer = Director::getInstance()->getRenderer();
2021-12-25 10:04:45 +08:00
auto& rect = renderer->getScissorRect();
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
2021-12-25 10:04:45 +08:00
float x = (rect.x - _viewPortRect.origin.x * _retinaFactor * _frameZoomFactor) /
(_scaleX * _retinaFactor * _frameZoomFactor);
float y = (rect.y - _viewPortRect.origin.y * _retinaFactor * _frameZoomFactor) /
(_scaleY * _retinaFactor * _frameZoomFactor);
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
float w = rect.width / (_scaleX * _retinaFactor * _frameZoomFactor);
2021-12-25 10:04:45 +08:00
float h = rect.height / (_scaleY * _retinaFactor * _frameZoomFactor);
2023-01-21 18:49:02 +08:00
return ax::Rect(x, y, w, h);
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::onGLFWError(int errorID, const char* errorDesc)
{
if (_mainWindow)
{
_glfwError = StringUtils::format("GLFWError #%d Happen, %s", errorID, errorDesc);
}
else
{
_glfwError.append(StringUtils::format("GLFWError #%d Happen, %s\n", errorID, errorDesc));
}
2022-07-16 10:43:05 +08:00
AXLOGERROR("%s", _glfwError.c_str());
}
void GLViewImpl::onGLFWMouseCallBack(GLFWwindow* /*window*/, int button, int action, int /*modify*/)
{
2021-12-25 10:04:45 +08:00
if (GLFW_MOUSE_BUTTON_LEFT == button)
{
2021-12-25 10:04:45 +08:00
if (GLFW_PRESS == action)
{
_captured = true;
2023-01-21 18:49:02 +08:00
if (this->getViewPortRect().equals(ax::Rect::ZERO) ||
2021-12-25 10:04:45 +08:00
this->getViewPortRect().containsPoint(Vec2(_mouseX, _mouseY)))
{
intptr_t id = 0;
this->handleTouchesBegin(1, &id, &_mouseX, &_mouseY);
}
}
2021-12-25 10:04:45 +08:00
else if (GLFW_RELEASE == action)
{
if (_captured)
{
2021-12-25 10:04:45 +08:00
_captured = false;
intptr_t id = 0;
this->handleTouchesEnd(1, &id, &_mouseX, &_mouseY);
}
}
}
2021-12-25 10:04:45 +08:00
// Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
float cursorX = (_mouseX - _viewPortRect.origin.x) / _scaleX;
float cursorY = (_viewPortRect.origin.y + _viewPortRect.size.height - _mouseY) / _scaleY;
2014-03-07 13:59:56 +08:00
2021-12-25 10:04:45 +08:00
if (GLFW_PRESS == action)
{
EventMouse event(EventMouse::MouseEventType::MOUSE_DOWN);
event.setCursorPosition(cursorX, cursorY);
2022-08-08 18:02:17 +08:00
event.setMouseButton(static_cast<ax::EventMouse::MouseButton>(button));
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
}
2021-12-25 10:04:45 +08:00
else if (GLFW_RELEASE == action)
{
EventMouse event(EventMouse::MouseEventType::MOUSE_UP);
event.setCursorPosition(cursorX, cursorY);
2022-08-08 18:02:17 +08:00
event.setMouseButton(static_cast<ax::EventMouse::MouseButton>(button));
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
}
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
{
_mouseX = (float)x;
_mouseY = (float)y;
2014-03-07 13:59:56 +08:00
_mouseX /= this->getFrameZoomFactor();
_mouseY /= this->getFrameZoomFactor();
2014-03-07 13:59:56 +08:00
if (_isInRetinaMonitor)
{
if (_retinaFactor == 1)
{
_mouseX *= 2;
_mouseY *= 2;
}
}
2014-03-07 13:59:56 +08:00
if (_captured)
{
intptr_t id = 0;
this->handleTouchesMove(1, &id, &_mouseX, &_mouseY);
}
2021-12-25 10:04:45 +08:00
// Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
float cursorX = (_mouseX - _viewPortRect.origin.x) / _scaleX;
float cursorY = (_viewPortRect.origin.y + _viewPortRect.size.height - _mouseY) / _scaleY;
2014-03-07 13:59:56 +08:00
EventMouse event(EventMouse::MouseEventType::MOUSE_MOVE);
// Set current button
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
{
2022-08-08 18:02:17 +08:00
event.setMouseButton(static_cast<ax::EventMouse::MouseButton>(GLFW_MOUSE_BUTTON_LEFT));
}
else if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS)
{
2022-08-08 18:02:17 +08:00
event.setMouseButton(static_cast<ax::EventMouse::MouseButton>(GLFW_MOUSE_BUTTON_RIGHT));
}
else if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS)
{
2022-08-08 18:02:17 +08:00
event.setMouseButton(static_cast<ax::EventMouse::MouseButton>(GLFW_MOUSE_BUTTON_MIDDLE));
}
event.setCursorPosition(cursorX, cursorY);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
}
void GLViewImpl::onGLFWMouseScrollCallback(GLFWwindow* /*window*/, double x, double y)
{
EventMouse event(EventMouse::MouseEventType::MOUSE_SCROLL);
2021-12-25 10:04:45 +08:00
// Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
float cursorX = (_mouseX - _viewPortRect.origin.x) / _scaleX;
float cursorY = (_viewPortRect.origin.y + _viewPortRect.size.height - _mouseY) / _scaleY;
event.setScrollData((float)x, -(float)y);
event.setCursorPosition(cursorX, cursorY);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
}
void GLViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*scancode*/, int action, int /*mods*/)
{
// x-studio spec, for repeat press key support.
EventKeyboard event(g_keyCodeMap[key], action);
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->dispatchEvent(&event);
if (GLFW_RELEASE != action)
2014-08-10 00:42:21 +08:00
{
switch (g_keyCodeMap[key])
{
case EventKeyboard::KeyCode::KEY_BACKSPACE:
IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
break;
case EventKeyboard::KeyCode::KEY_HOME:
case EventKeyboard::KeyCode::KEY_KP_HOME:
case EventKeyboard::KeyCode::KEY_DELETE:
case EventKeyboard::KeyCode::KEY_KP_DELETE:
case EventKeyboard::KeyCode::KEY_END:
case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
case EventKeyboard::KeyCode::KEY_ESCAPE:
IMEDispatcher::sharedDispatcher()->dispatchControlKey(g_keyCodeMap[key]);
break;
default:
break;
}
2014-08-10 00:42:21 +08:00
}
}
void GLViewImpl::onGLFWCharCallback(GLFWwindow* /*window*/, unsigned int charCode)
{
2014-08-10 00:42:21 +08:00
std::string utf8String;
StringUtils::UTF32ToUTF8(std::u32string_view{(char32_t*)&charCode, (size_t)1}, utf8String);
static std::unordered_set<std::string_view> controlUnicode = {
2021-12-25 10:04:45 +08:00
"\xEF\x9C\x80", // up
"\xEF\x9C\x81", // down
"\xEF\x9C\x82", // left
"\xEF\x9C\x83", // right
"\xEF\x9C\xA8", // delete
"\xEF\x9C\xA9", // home
"\xEF\x9C\xAB", // end
"\xEF\x9C\xAC", // pageup
"\xEF\x9C\xAD", // pagedown
"\xEF\x9C\xB9" // clear
};
// Check for send control key
if (controlUnicode.find(utf8String) == controlUnicode.end())
{
2021-12-25 10:04:45 +08:00
IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), utf8String.size());
}
}
void GLViewImpl::onGLFWWindowPosCallback(GLFWwindow* /*window*/, int /*x*/, int /*y*/)
{
Director::getInstance()->setViewport();
}
void GLViewImpl::onGLFWWindowSizeCallback(GLFWwindow* /*window*/, int w, int h)
{
if (w && h && _resolutionPolicy != ResolutionPolicy::UNKNOWN)
{
2023-01-21 18:49:02 +08:00
/* Invoke `GLView::setFrameSize` to sync screen size immediately,
this->setFrameSize will invoke `glfwSetWindowSize` which is unnecessary.
*/
GLView::setFrameSize(w, h);
2021-12-25 10:04:45 +08:00
/*
x-studio spec, fix view size incorrect when window size changed.
The original code behavior:
1. first time enter full screen: w,h=1920,1080
2. second or later enter full screen: will trigger 2 times WindowSizeCallback
1). w,h=976,679
2). w,h=1024,768
2021-12-25 10:04:45 +08:00
@remark:
1. we should use glfwSetWindowMonitor to control the window size in full screen mode
@see also: updateWindowSize (call after enter/exit full screen mode)
*/
updateDesignResolutionSize();
2023-01-24 15:49:40 +08:00
#if defined(AX_USE_METAL)
2023-01-21 17:57:56 +08:00
// update metal attachment texture size.
int fbWidth, fbHeight;
glfwGetFramebufferSize(_mainWindow, &fbWidth, &fbHeight);
backend::UtilsMTL::resizeDefaultAttachmentTexture(fbWidth, fbHeight);
2023-01-24 15:49:40 +08:00
#endif
2023-01-24 13:58:29 +08:00
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_RESIZED, nullptr);
2023-01-21 17:57:56 +08:00
}
}
void GLViewImpl::onGLFWWindowIconifyCallback(GLFWwindow* /*window*/, int iconified)
2014-08-13 03:22:47 +08:00
{
2014-08-14 15:48:09 +08:00
if (iconified == GL_TRUE)
{
Application::getInstance()->applicationDidEnterBackground();
}
else
{
Application::getInstance()->applicationWillEnterForeground();
}
2014-08-13 03:22:47 +08:00
}
void GLViewImpl::onGLFWWindowFocusCallback(GLFWwindow* /*window*/, int focused)
{
if (focused == GL_TRUE)
{
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_FOCUSED, nullptr);
}
else
{
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_UNFOCUSED, nullptr);
}
}
2023-01-24 13:58:29 +08:00
#if (AX_TARGET_PLATFORM != AX_PLATFORM_MAC)
2021-12-25 10:04:45 +08:00
static bool loadFboExtensions()
{
const char* gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
2014-03-07 13:59:56 +08:00
// If the current opengl driver doesn't have framebuffers methods, check if an extension exists
if (glGenFramebuffers == nullptr)
2014-03-07 13:59:56 +08:00
{
log("OpenGL: glGenFramebuffers is nullptr, try to detect an extension");
2014-03-07 13:59:56 +08:00
if (strstr(gl_extensions, "ARB_framebuffer_object"))
{
log("OpenGL: ARB_framebuffer_object is supported");
2021-12-25 10:04:45 +08:00
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)glfwGetProcAddress("glIsRenderbuffer");
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)glfwGetProcAddress("glBindRenderbuffer");
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)glfwGetProcAddress("glDeleteRenderbuffers");
2021-12-25 10:04:45 +08:00
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)glfwGetProcAddress("glGenRenderbuffers");
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)glfwGetProcAddress("glRenderbufferStorage");
2021-12-25 10:04:45 +08:00
glGetRenderbufferParameteriv =
(PFNGLGETRENDERBUFFERPARAMETERIVPROC)glfwGetProcAddress("glGetRenderbufferParameteriv");
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)glfwGetProcAddress("glIsFramebuffer");
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)glfwGetProcAddress("glBindFramebuffer");
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)glfwGetProcAddress("glDeleteFramebuffers");
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)glfwGetProcAddress("glGenFramebuffers");
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)glfwGetProcAddress("glCheckFramebufferStatus");
2021-12-25 10:04:45 +08:00
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)glfwGetProcAddress("glFramebufferTexture1D");
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)glfwGetProcAddress("glFramebufferTexture2D");
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)glfwGetProcAddress("glFramebufferTexture3D");
glFramebufferRenderbuffer =
(PFNGLFRAMEBUFFERRENDERBUFFERPROC)glfwGetProcAddress("glFramebufferRenderbuffer");
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)glfwGetProcAddress(
"glGetFramebufferAttachmentParameteriv");
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)glfwGetProcAddress("glGenerateMipmap");
2014-03-07 13:59:56 +08:00
}
else if (strstr(gl_extensions, "EXT_framebuffer_object"))
2014-03-07 13:59:56 +08:00
{
log("OpenGL: EXT_framebuffer_object is supported");
2021-12-25 10:04:45 +08:00
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)glfwGetProcAddress("glIsRenderbufferEXT");
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)glfwGetProcAddress("glBindRenderbufferEXT");
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)glfwGetProcAddress("glDeleteRenderbuffersEXT");
2021-12-25 10:04:45 +08:00
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)glfwGetProcAddress("glGenRenderbuffersEXT");
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)glfwGetProcAddress("glRenderbufferStorageEXT");
2021-12-25 10:04:45 +08:00
glGetRenderbufferParameteriv =
(PFNGLGETRENDERBUFFERPARAMETERIVPROC)glfwGetProcAddress("glGetRenderbufferParameterivEXT");
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)glfwGetProcAddress("glIsFramebufferEXT");
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)glfwGetProcAddress("glBindFramebufferEXT");
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)glfwGetProcAddress("glDeleteFramebuffersEXT");
2021-12-25 10:04:45 +08:00
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)glfwGetProcAddress("glGenFramebuffersEXT");
glCheckFramebufferStatus =
(PFNGLCHECKFRAMEBUFFERSTATUSPROC)glfwGetProcAddress("glCheckFramebufferStatusEXT");
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)glfwGetProcAddress("glFramebufferTexture1DEXT");
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)glfwGetProcAddress("glFramebufferTexture2DEXT");
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)glfwGetProcAddress("glFramebufferTexture3DEXT");
2021-12-25 10:04:45 +08:00
glFramebufferRenderbuffer =
(PFNGLFRAMEBUFFERRENDERBUFFERPROC)glfwGetProcAddress("glFramebufferRenderbufferEXT");
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)glfwGetProcAddress(
"glGetFramebufferAttachmentParameterivEXT");
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)glfwGetProcAddress("glGenerateMipmapEXT");
}
2021-12-25 10:04:45 +08:00
else if (strstr(gl_extensions, "GL_ANGLE_framebuffer_blit"))
{
log("OpenGL: GL_ANGLE_framebuffer_object is supported");
2020-02-16 16:44:14 +08:00
2021-12-25 10:04:45 +08:00
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)glfwGetProcAddress("glIsRenderbufferOES");
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)glfwGetProcAddress("glBindRenderbufferOES");
2020-02-16 16:44:14 +08:00
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)glfwGetProcAddress("glDeleteRenderbuffersOES");
2021-12-25 10:04:45 +08:00
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)glfwGetProcAddress("glGenRenderbuffersOES");
2020-02-16 16:44:14 +08:00
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)glfwGetProcAddress("glRenderbufferStorageOES");
2021-12-25 10:04:45 +08:00
// glGetRenderbufferParameteriv =
// (PFNGLGETRENDERBUFFERPARAMETERIVPROC)glfwGetProcAddress("glGetRenderbufferParameterivOES");
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)glfwGetProcAddress("glIsFramebufferOES");
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)glfwGetProcAddress("glBindFramebufferOES");
2020-02-16 16:44:14 +08:00
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)glfwGetProcAddress("glDeleteFramebuffersOES");
2021-12-25 10:04:45 +08:00
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)glfwGetProcAddress("glGenFramebuffersOES");
glCheckFramebufferStatus =
(PFNGLCHECKFRAMEBUFFERSTATUSPROC)glfwGetProcAddress("glCheckFramebufferStatusOES");
glFramebufferRenderbuffer =
(PFNGLFRAMEBUFFERRENDERBUFFERPROC)glfwGetProcAddress("glFramebufferRenderbufferOES");
2020-02-16 16:44:14 +08:00
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)glfwGetProcAddress("glFramebufferTexture2DOES");
2021-12-25 10:04:45 +08:00
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)glfwGetProcAddress(
"glGetFramebufferAttachmentParameterivOES");
2020-02-16 16:44:14 +08:00
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)glfwGetProcAddress("glGenerateMipmapOES");
2014-03-07 13:59:56 +08:00
}
else
{
log("OpenGL: No framebuffers extension is supported");
log("OpenGL: Any call to Fbo will crash!");
return false;
}
}
return true;
}
2014-01-23 05:51:01 +08:00
// helper
bool GLViewImpl::loadGL()
2014-01-23 05:51:01 +08:00
{
2023-01-21 18:49:02 +08:00
# if (AX_TARGET_PLATFORM != AX_PLATFORM_MAC)
// glad: load all OpenGL function pointers
// ---------------------------------------
2023-01-24 15:49:40 +08:00
# if !defined(AX_USE_GLES)
2022-10-25 09:01:57 +08:00
if (!gladLoadGL(glfwGetProcAddress))
2014-01-23 05:51:01 +08:00
{
log("glad: Failed to Load GL");
2014-01-23 05:51:01 +08:00
return false;
}
2023-01-21 18:49:02 +08:00
# else
2022-10-25 09:01:57 +08:00
if (!gladLoadGLES2(glfwGetProcAddress))
{
log("glad: Failed to Load GLES2");
return false;
}
2023-01-21 18:49:02 +08:00
# endif
2019-05-05 10:57:53 +08:00
loadFboExtensions();
2023-01-21 18:49:02 +08:00
# endif // (AX_TARGET_PLATFORM != AX_PLATFORM_MAC)
2014-01-23 05:51:01 +08:00
2014-01-23 06:17:32 +08:00
return true;
2014-01-23 05:51:01 +08:00
}
2023-01-21 17:57:56 +08:00
#endif
NS_AX_END // end of namespace ax;