Unify CC_COMPAT_GL to control renderer backend

win32: google angle
mac: NSGL
ios: GLES
This commit is contained in:
halx99 2020-12-02 03:03:05 -08:00
parent 8b4b39bc7a
commit 108399ede3
13 changed files with 825 additions and 258 deletions

View File

@ -103,9 +103,13 @@ function(use_cocos2dx_compile_define target)
if(APPLE)
target_compile_definitions(${target} PUBLIC __APPLE__)
target_compile_definitions(${target} PUBLIC USE_FILE32API)
if(IOS AND CC_FORCE_USE_GLES)
target_compile_definitions(${target} PUBLIC CC_FORCE_USE_GLES=1)
if(CC_COMPAT_GL)
target_compile_definitions(${target}
PUBLIC CC_COMPAT_GL=1
PUBLIC GL_SILENCE_DEPRECATION=1
)
endif()
elseif(LINUX)
target_compile_definitions(${target} PUBLIC LINUX)
target_compile_definitions(${target} PUBLIC _GNU_SOURCE)
@ -113,8 +117,8 @@ function(use_cocos2dx_compile_define target)
target_compile_definitions(${target} PUBLIC ANDROID)
target_compile_definitions(${target} PUBLIC USE_FILE32API)
elseif(WINDOWS)
if(CC_FORCE_USE_GLES)
target_compile_definitions(${target} PUBLIC CC_FORCE_USE_GLES=1)
if(CC_COMPAT_GL)
target_compile_definitions(${target} PUBLIC CC_COMPAT_GL=1)
endif()
target_compile_definitions(${target}
PUBLIC WIN32

View File

@ -65,8 +65,8 @@ if(NOT DEFINED ENGINEX_CORE_LIB)
set(ENGINEX_CORE_LIB cocos2d CACHE INTERNAL "The engine-x core lib name" )
endif()
if (NOT DEFINED CC_FORCE_USE_GLES)
set(CC_FORCE_USE_GLES FALSE CACHE INTERNAL "Force use GLES" )
if (NOT DEFINED CC_COMPAT_GL)
set(CC_COMPAT_GL FALSE CACHE INTERNAL "Enabling CC_COMPAT_GL" )
endif()
project(cocos2d_libs)

View File

@ -36,9 +36,15 @@ THE SOFTWARE.
#include "platform/win32/CCGL-win32.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
#include "platform/linux/CCGL-linux.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS && !defined(CC_USE_METAL)
#elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS
#if CC_COMPAT_GL
#include "platform/ios/CCGL-ios.h"
#endif
#elif CC_TARGET_PLATFORM == CC_PLATFORM_MAC
#if CC_COMPAT_GL
#include "platform/mac/CCGL-mac.h"
#endif
#endif
/// @endcond
#endif /* __PLATFORM_CCPLATFORMDEFINE_H__*/

View File

@ -103,12 +103,13 @@ THE SOFTWARE.
#endif
#endif // CC_PLATFORM_WIN32
/*
* Windows: https://github.com/google/angle
* iOS: Use Apple GLES
/*
windows: https://github.com/google/angle
mac: GL
iOS: GLES
*/
#ifndef CC_FORCE_USE_GLES
#define CC_FORCE_USE_GLES 0
#ifndef CC_COMPAT_GL
#define CC_COMPAT_GL 0
#endif
#if ((CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS))
@ -118,21 +119,27 @@ THE SOFTWARE.
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
#define CC_USE_METAL
#if !CC_COMPAT_GL
#define CC_USE_METAL
#else
#define CC_USE_GL
#endif
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#if !CC_FORCE_USE_GLES
#if !CC_COMPAT_GL
#define CC_USE_METAL
#else
#define CC_USE_GLES
#endif
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#define CC_USE_GLES
#else
#if !CC_FORCE_USE_GLES
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if !CC_COMPAT_GL
#define CC_USE_GL
#else
#define CC_USE_GLES
#endif
#else
#error "Unsupported platform!"
#endif
/// @endcond

View File

@ -101,7 +101,7 @@ elseif(APPLE)
platform/ios/CCInputView-ios.mm
)
if(CC_FORCE_USE_GLES)
if(NOT CC_COMPAT_GL)
set(COCOS_PLATFORM_SPECIFIC_HEADER
${COCOS_PLATFORM_SPECIFIC_HEADER}
platform/ios/CCES2Renderer-ios.h

View File

@ -0,0 +1,113 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
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.
****************************************************************************/
#ifndef __PLATFORM_MAC_CCGL_H__
#define __PLATFORM_MAC_CCGL_H__
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC
#import <OpenGL/gl.h>
#import <OpenGL/glu.h>
#import <OpenGL/glext.h>
#define CC_GL_DEPTH24_STENCIL8 -1
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
#define glGenVertexArrays glGenVertexArraysAPPLE
#define glBindVertexArray glBindVertexArrayAPPLE
#define glClearDepthf glClearDepth
#define glDepthRangef glDepthRange
#define glReleaseShaderCompiler(xxx)
// GLES macros, only for compiling compatible
#if !defined(GL_ETC1_RGB8_OES)
#define GL_ETC1_RGB8_OES 0x8D64
#endif
#if !defined(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG)
#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
#define GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG 0x9137
#define GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG 0x9138
#define GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54
#define GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55
#define GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56
#define GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57
#define GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV2_IMG 0x93F0
#define GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV2_IMG 0x93F1
#endif
#if !defined(GL_COMPRESSED_RGB8_ETC2)
#define GL_COMPRESSED_RGB8_ETC2 0x9274
#define GL_COMPRESSED_SRGB8_ETC2 0x9275
#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279
#endif
#if !defined(GL_ATC_RGB_AMD)
#define GL_ATC_RGB_AMD 0x8C92
#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
#endif
#if !defined(GL_COMPRESSED_RGBA_ASTC_4x4_KHR)
#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD
#endif
#endif // __PLATFORM_MAC_CCGL_H__
#endif //s CC_TARGET_PLATFORM == CC_PLATFORM_MAC

View File

@ -379,8 +379,10 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
glfwWindowHint(GLFW_SAMPLES, _glContextAttrs.multisamplingCount);
#if defined(CC_USE_METAL)
// Don't create gl context.
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
#endif
int neededWidth = rect.size.width * _frameZoomFactor;
int neededHeight = rect.size.height * _frameZoomFactor;
@ -407,7 +409,8 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
CGSize size;
size.width = static_cast<CGFloat>(fbWidth);
size.height = static_cast<CGFloat>(fbHeight);
#if defined(CC_USE_METAL)
// Initialize device.
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
if (!device)
@ -425,6 +428,7 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
[layer setDrawableSize:size];
[contentView setLayer:layer];
backend::DeviceMTL::setCAMetalLayer(layer);
#endif
/*
* Note that the created window and context may differ from what you requested,
@ -447,6 +451,10 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
rect.size.height = realH / _frameZoomFactor;
}
#if defined(CC_USE_GL)
glfwMakeContextCurrent(_mainWindow);
#endif
glfwSetMouseButtonCallback(_mainWindow, GLFWEventHandler::onGLFWMouseCallBack);
glfwSetCursorPosCallback(_mainWindow, GLFWEventHandler::onGLFWMouseMoveCallBack);
glfwSetScrollCallback(_mainWindow, GLFWEventHandler::onGLFWMouseScrollCallback);
@ -507,8 +515,10 @@ void GLViewImpl::end()
void GLViewImpl::swapBuffers()
{
// if(_mainWindow)
// glfwSwapBuffers(_mainWindow);
#if defined(CC_USE_GL)
if(_mainWindow)
glfwSwapBuffers(_mainWindow);
#endif
}
bool GLViewImpl::windowShouldClose()
@ -984,10 +994,12 @@ void GLViewImpl::onGLFWWindowSizeCallback(GLFWwindow* /*window*/, int width, int
Director::getInstance()->setViewport();
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_RESIZED, nullptr);
#if defined(CC_USE_METAL)
//update metal attachment texture size.
int fbWidth, fbHeight;
glfwGetFramebufferSize(_mainWindow, &fbWidth, &fbHeight);
backend::UtilsMTL::resizeDefaultAttachmentTexture(fbWidth, fbHeight);
#endif
}
}

View File

@ -76,7 +76,7 @@ set(COCOS_RENDERER_SRC
renderer/backend/RenderPassParams.cpp
)
if(ANDROID OR WINDOWS OR LINUX OR (IOS AND CC_FORCE_USE_GLES))
if(ANDROID OR WINDOWS OR LINUX OR CC_COMPAT_GL)
list(APPEND COCOS_RENDERER_HEADER
renderer/backend/opengl/BufferGL.h

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*************************************************************************
* GLFW 3.3 - www.glfw.org
* GLFW 3.4 - www.glfw.org
* A library for OpenGL, window and input
*------------------------------------------------------------------------
* Copyright (c) 2002-2006 Marcus Geelnard
@ -94,7 +94,7 @@ extern "C" {
#if defined(__OBJC__)
#import <Cocoa/Cocoa.h>
#else
//#include <ApplicationServices/ApplicationServices.h>
#include <ApplicationServices/ApplicationServices.h>
typedef void* id;
#endif
#elif defined(GLFW_EXPOSE_NATIVE_X11) || defined(GLFW_EXPOSE_NATIVE_GLX)
@ -200,7 +200,7 @@ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window);
*
* @ingroup native
*/
//GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
/*! @brief Returns the `NSWindow` of the specified window.
*

Binary file not shown.

View File

@ -80,7 +80,7 @@ bool AppDelegate::applicationDidFinishLaunching()
// Set the design resolution
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
Size frameSize = glview->getFrameSize();
auto frameSize = glview->getFrameSize();
vector<string> searchPath;

View File

@ -85,7 +85,7 @@ bool HelloWorld::init()
drawNode->setPosition(Vec2(0, 0));
addChild(drawNode);
Rect safeArea = Director::getInstance()->getSafeAreaRect();
auto safeArea = Director::getInstance()->getSafeAreaRect();
drawNode->drawRect(safeArea.origin, safeArea.origin + safeArea.size, Color4F::BLUE);
return true;