mirror of https://github.com/axmolengine/axmol.git
Merge pull request #19513 from Mee-gu/feature/AddDeviceInfo
Feature/add device info
This commit is contained in:
commit
8452b55b82
|
@ -32,6 +32,7 @@
|
|||
#include "base/CCMap.h"
|
||||
#include "base/ccUTF8.h"
|
||||
#include "renderer/CCTextureCache.h"
|
||||
#include "renderer/backend/Device.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <set>
|
||||
|
@ -524,15 +525,14 @@ void BMFontConfiguration::parseCommonArguments(const char* line)
|
|||
tmp = strstr(tmp, "scaleW=") + 7;
|
||||
sscanf(tmp, "%d", &value);
|
||||
|
||||
//TODO coulsonwang
|
||||
// int maxTextureSize = Configuration::getInstance()->getMaxTextureSize();
|
||||
// CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
|
||||
auto deviceInfo = backend::Device::getInstance()->getDeviceInfo();
|
||||
int maxTextureSize = deviceInfo->getMaxTextureSize();
|
||||
CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
|
||||
|
||||
// scaleH. sanity check
|
||||
tmp = strstr(tmp, "scaleH=") + 7;
|
||||
sscanf(tmp, "%d", &value);
|
||||
//TODO coulsonwang
|
||||
// CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
|
||||
CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
|
||||
|
||||
// pages. sanity check
|
||||
tmp = strstr(tmp, "pages=") + 6;
|
||||
|
|
|
@ -39,6 +39,7 @@ set(COCOS_RENDERER_HEADER
|
|||
renderer/backend/VertexLayout.h
|
||||
renderer/backend/ProgramState.h
|
||||
renderer/backend/ShaderCache.h
|
||||
renderer/backend/DeviceInfo.h
|
||||
)
|
||||
|
||||
set(COCOS_RENDERER_SRC
|
||||
|
@ -88,6 +89,7 @@ list(APPEND COCOS_RENDERER_HEADER
|
|||
renderer/backend/opengl/ShaderModuleGL.h
|
||||
renderer/backend/opengl/TextureGL.h
|
||||
renderer/backend/opengl/UtilsGL.h
|
||||
renderer/backend/opengl/DeviceInfoGL.h
|
||||
)
|
||||
|
||||
list(APPEND COCOS_RENDERER_SRC
|
||||
|
@ -101,6 +103,7 @@ list(APPEND COCOS_RENDERER_SRC
|
|||
renderer/backend/opengl/ShaderModuleGL.cpp
|
||||
renderer/backend/opengl/TextureGL.cpp
|
||||
renderer/backend/opengl/UtilsGL.cpp
|
||||
renderer/backend/opengl/DeviceInfoGL.cpp
|
||||
)
|
||||
|
||||
else()
|
||||
|
@ -117,6 +120,7 @@ list(APPEND COCOS_RENDERER_HEADER
|
|||
renderer/backend/metal/TextureMTL.h
|
||||
renderer/backend/metal/Utils.h
|
||||
renderer/backend/metal/ProgramMTL.h
|
||||
renderer/backend/metal/DeviceInfoMTL.h
|
||||
)
|
||||
|
||||
list(APPEND COCOS_RENDERER_SRC
|
||||
|
@ -131,6 +135,7 @@ list(APPEND COCOS_RENDERER_SRC
|
|||
renderer/backend/metal/TextureMTL.mm
|
||||
renderer/backend/metal/Utils.mm
|
||||
renderer/backend/metal/ProgramMTL.mm
|
||||
renderer/backend/metal/DeviceInfoMTL.mm
|
||||
)
|
||||
|
||||
endif()
|
|
@ -9,6 +9,7 @@
|
|||
#include "BlendState.h"
|
||||
#include "ProgramCache.h"
|
||||
#include "ShaderCache.h"
|
||||
#include "DeviceInfo.h"
|
||||
|
||||
#include "base/CCRef.h"
|
||||
|
||||
|
@ -45,12 +46,15 @@ public:
|
|||
// Create a render pipeline, not auto released.
|
||||
virtual RenderPipeline* newRenderPipeline(const RenderPipelineDescriptor& descriptor) = 0;
|
||||
|
||||
inline DeviceInfo* getDeviceInfo() const { return _deviceInfo; }
|
||||
protected:
|
||||
// Create a auto released shader module.
|
||||
virtual ShaderModule* newShaderModule(ShaderStage stage, const std::string& source) = 0;
|
||||
// Create a auto released program.
|
||||
virtual Program* newProgram(const std::string& vertexShader, const std::string& fragmentShader) = 0;
|
||||
|
||||
DeviceInfo* _deviceInfo = nullptr;
|
||||
|
||||
private:
|
||||
static Device* _instance;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Macros.h"
|
||||
|
||||
CC_BACKEND_BEGIN
|
||||
|
||||
class DeviceInfo
|
||||
{
|
||||
public:
|
||||
virtual ~DeviceInfo() = default;
|
||||
virtual bool init() = 0;
|
||||
|
||||
inline int getMaxTextureSize() const { return _maxTextureSize; }
|
||||
inline int getMaxAttributes() const { return _maxAttributes; }
|
||||
|
||||
protected:
|
||||
DeviceInfo() = default;
|
||||
|
||||
int _maxAttributes = 0;
|
||||
int _maxTextureSize = 0;
|
||||
};
|
||||
|
||||
CC_BACKEND_END
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "../DeviceInfo.h"
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
CC_BACKEND_BEGIN
|
||||
|
||||
class DeviceInfoMTL : public DeviceInfo
|
||||
{
|
||||
public:
|
||||
DeviceInfoMTL(id<MTLDevice> device);
|
||||
virtual ~DeviceInfoMTL() = default;
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
private:
|
||||
void getTextureSizeInfo();
|
||||
|
||||
//MTLFeatureSet _currentFeatureSet;
|
||||
};
|
||||
|
||||
CC_BACKEND_END
|
|
@ -0,0 +1,29 @@
|
|||
#include "DeviceInfoMTL.h"
|
||||
#include "base/ccMacros.h"
|
||||
|
||||
CC_BACKEND_BEGIN
|
||||
|
||||
DeviceInfoMTL::DeviceInfoMTL(id<MTLDevice> device)
|
||||
{
|
||||
}
|
||||
|
||||
bool DeviceInfoMTL::init()
|
||||
{
|
||||
_maxAttributes = 31;
|
||||
|
||||
getTextureSizeInfo();
|
||||
return true;
|
||||
}
|
||||
|
||||
//todo coulsonwang
|
||||
void DeviceInfoMTL::getTextureSizeInfo()
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
_maxTextureSize = 4096;
|
||||
|
||||
#else
|
||||
_maxTextureSize = 16384;
|
||||
#endif
|
||||
}
|
||||
|
||||
CC_BACKEND_END
|
|
@ -8,8 +8,9 @@
|
|||
#include "BlendStateMTL.h"
|
||||
#include "Utils.h"
|
||||
#include "ProgramMTL.h"
|
||||
#include "base/ccMacros.h"
|
||||
#include "DeviceInfoMTL.h"
|
||||
|
||||
#include "base/ccMacros.h"
|
||||
|
||||
CC_BACKEND_BEGIN
|
||||
|
||||
|
@ -46,12 +47,19 @@ DeviceMTL::DeviceMTL()
|
|||
{
|
||||
_mtlDevice = DeviceMTL::_metalLayer.device;
|
||||
_mtlCommandQueue = [_mtlDevice newCommandQueue];
|
||||
ProgramCache::getInstance();
|
||||
_deviceInfo = new (std::nothrow) DeviceInfoMTL(_mtlDevice);
|
||||
if(!_deviceInfo || _deviceInfo->init() == false)
|
||||
{
|
||||
delete _deviceInfo;
|
||||
_deviceInfo = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
DeviceMTL::~DeviceMTL()
|
||||
{
|
||||
ProgramCache::destroyInstance();
|
||||
delete _deviceInfo;
|
||||
_deviceInfo = nullptr;
|
||||
}
|
||||
|
||||
CommandBuffer* DeviceMTL::newCommandBuffer()
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "DepthStencilStateGL.h"
|
||||
#include "BlendStateGL.h"
|
||||
#include "ProgramGL.h"
|
||||
#include "DeviceInfoGL.h"
|
||||
|
||||
CC_BACKEND_BEGIN
|
||||
|
||||
|
@ -20,12 +21,19 @@ Device* Device::getInstance()
|
|||
|
||||
DeviceGL::DeviceGL()
|
||||
{
|
||||
ProgramCache::getInstance();
|
||||
_deviceInfo = new (std::nothrow) DeviceInfoGL();
|
||||
if(!_deviceInfo || _deviceInfo->init() == false)
|
||||
{
|
||||
delete _deviceInfo;
|
||||
_deviceInfo = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
DeviceGL::~DeviceGL()
|
||||
{
|
||||
ProgramCache::destroyInstance();
|
||||
delete _deviceInfo;
|
||||
_deviceInfo = nullptr;
|
||||
}
|
||||
|
||||
CommandBuffer* DeviceGL::newCommandBuffer()
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#include "DeviceInfoGL.h"
|
||||
#include "platform/CCGL.h"
|
||||
|
||||
CC_BACKEND_BEGIN
|
||||
|
||||
bool DeviceInfoGL::init()
|
||||
{
|
||||
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &_maxAttributes);
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_maxTextureSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
CC_BACKEND_END
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "../DeviceInfo.h"
|
||||
|
||||
CC_BACKEND_BEGIN
|
||||
|
||||
class DeviceInfoGL: public DeviceInfo
|
||||
{
|
||||
public:
|
||||
DeviceInfoGL() = default;
|
||||
virtual ~DeviceInfoGL() = default;
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
CC_BACKEND_END
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include "../testResource.h"
|
||||
#include "renderer/backend/Device.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
|
@ -2565,8 +2566,8 @@ Sprite3DNormalMappingTest::Sprite3DNormalMappingTest()
|
|||
addChild(sprite);
|
||||
}
|
||||
|
||||
int maxAttributes;
|
||||
maxAttributes = Configuration::getInstance()->getValue("max_vertex_attributes").asInt();
|
||||
auto deviceInfo = backend::Device::getInstance()->getDeviceInfo();
|
||||
int maxAttributes = deviceInfo->getMaxAttributes();
|
||||
CCASSERT(maxAttributes > 8, "attributes supported must be greater than 8");
|
||||
if (maxAttributes > 8)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue