mirror of https://github.com/axmolengine/axmol.git
fix #41
This commit is contained in:
parent
82808a321d
commit
734b5bd44f
|
@ -1,64 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace cocos2d{
|
||||
|
||||
template<typename Enum>
|
||||
struct EnableBitMaskOperators
|
||||
{
|
||||
static const bool enable = false;
|
||||
};
|
||||
|
||||
template<typename Enum>
|
||||
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
|
||||
operator |(Enum lhs, Enum rhs)
|
||||
{
|
||||
using underlying = typename std::underlying_type<Enum>::type;
|
||||
return static_cast<Enum> (
|
||||
static_cast<underlying>(lhs) |
|
||||
static_cast<underlying>(rhs)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename Enum>
|
||||
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, bool>::type
|
||||
operator ==(Enum lhs, Enum rhs)
|
||||
{
|
||||
using underlying = typename std::underlying_type<Enum>::type;
|
||||
static_cast<underlying>(lhs) == static_cast<underlying>(rhs);
|
||||
}
|
||||
|
||||
template<typename Enum>
|
||||
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type&
|
||||
operator |=(Enum& lhs, Enum rhs)
|
||||
{
|
||||
using underlying = typename std::underlying_type<Enum>::type;
|
||||
lhs = static_cast<Enum> (
|
||||
static_cast<underlying>(lhs) |
|
||||
static_cast<underlying>(rhs)
|
||||
);
|
||||
|
||||
return lhs;
|
||||
}
|
||||
|
||||
template<typename Enum>
|
||||
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, unsigned int>::type
|
||||
operator &(Enum lhs, Enum rhs)
|
||||
{
|
||||
using underlying = typename std::underlying_type<Enum>::type;
|
||||
using impl_type = typename std::make_unsigned<underlying>::type;
|
||||
return impl_type (
|
||||
static_cast<impl_type>(lhs) &
|
||||
static_cast<impl_type>(rhs)
|
||||
);
|
||||
}
|
||||
|
||||
#define ENABLE_BITMASK_OPERATORS(x) \
|
||||
template<> \
|
||||
struct EnableBitMaskOperators<x> \
|
||||
{ \
|
||||
static const bool enable = true; \
|
||||
};
|
||||
|
||||
} // end of namespace cocos2d{
|
|
@ -4,6 +4,7 @@ Copyright (c) 2010-2012 cocos2d-x.org
|
|||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2020 c4games.com.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -32,7 +33,6 @@ THE SOFTWARE.
|
|||
#include "math/CCGeometry.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "base/CCRef.h"
|
||||
#include "base/CCEnumClass.h"
|
||||
#include "renderer/backend/Types.h"
|
||||
|
||||
/**
|
||||
|
@ -660,7 +660,7 @@ enum class ClearFlag : uint8_t
|
|||
STENCIL = 1 << 2,
|
||||
ALL = COLOR | DEPTH | STENCIL
|
||||
};
|
||||
ENABLE_BITMASK_OPERATORS(ClearFlag)
|
||||
CC_ENABLE_BITMASK_OPS(ClearFlag)
|
||||
|
||||
enum class RenderTargetFlag : uint8_t
|
||||
{
|
||||
|
@ -669,7 +669,7 @@ enum class RenderTargetFlag : uint8_t
|
|||
STENCIL = 1 << 2,
|
||||
ALL = COLOR | DEPTH | STENCIL
|
||||
};
|
||||
ENABLE_BITMASK_OPERATORS(RenderTargetFlag)
|
||||
CC_ENABLE_BITMASK_OPS(RenderTargetFlag)
|
||||
using TextureUsage = backend::TextureUsage;
|
||||
using PixelFormat = backend::PixelFormat;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2020 c4games.com.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -590,13 +591,12 @@ void Renderer::drawBatchedTriangles()
|
|||
}
|
||||
else
|
||||
{
|
||||
// is this the first one?
|
||||
if (!firstCommand)
|
||||
{
|
||||
batchesTotal++;
|
||||
_triBatchesToDraw[batchesTotal].offset =
|
||||
_triBatchesToDraw[batchesTotal-1].offset + _triBatchesToDraw[batchesTotal-1].indicesToDraw;
|
||||
}
|
||||
// is this the first one?
|
||||
if (!firstCommand)
|
||||
{
|
||||
batchesTotal++;
|
||||
_triBatchesToDraw[batchesTotal].offset = _triBatchesToDraw[batchesTotal - 1].offset + _triBatchesToDraw[batchesTotal - 1].indicesToDraw;
|
||||
}
|
||||
|
||||
_triBatchesToDraw[batchesTotal].cmd = cmd;
|
||||
_triBatchesToDraw[batchesTotal].indicesToDraw = (int) cmd->getIndexCount();
|
||||
|
@ -778,7 +778,7 @@ void Renderer::beginRenderPass(RenderCommand* cmd)
|
|||
void Renderer::setRenderTarget(RenderTargetFlag flags, Texture2D* colorAttachment, Texture2D* depthAttachment, Texture2D* stencilAttachment)
|
||||
{
|
||||
_renderTargetFlag = flags;
|
||||
if (flags & RenderTargetFlag::COLOR)
|
||||
if (_Bitmask_includes(RenderTargetFlag::COLOR, flags))
|
||||
{
|
||||
_renderPassDescriptor.needColorAttachment = true;
|
||||
if (colorAttachment)
|
||||
|
@ -795,7 +795,7 @@ void Renderer::setRenderTarget(RenderTargetFlag flags, Texture2D* colorAttachmen
|
|||
_renderPassDescriptor.colorAttachmentsTexture[0] = nullptr;
|
||||
}
|
||||
|
||||
if (flags & RenderTargetFlag::DEPTH)
|
||||
if (_Bitmask_includes(RenderTargetFlag::DEPTH, flags))
|
||||
{
|
||||
_renderPassDescriptor.depthTestEnabled = true;
|
||||
if (depthAttachment)
|
||||
|
@ -812,7 +812,7 @@ void Renderer::setRenderTarget(RenderTargetFlag flags, Texture2D* colorAttachmen
|
|||
_depthAttachment = nullptr;
|
||||
}
|
||||
|
||||
if (flags & RenderTargetFlag::STENCIL)
|
||||
if (_Bitmask_includes(RenderTargetFlag::STENCIL, flags))
|
||||
{
|
||||
_stencilAttachment = stencilAttachment;
|
||||
_renderPassDescriptor.stencilTestEnabled = true;
|
||||
|
@ -838,7 +838,7 @@ void Renderer::clear(ClearFlag flags, const Color4F& color, float depth, unsigne
|
|||
command->func = [=]() -> void {
|
||||
backend::RenderPassDescriptor descriptor;
|
||||
|
||||
if (flags & ClearFlag::COLOR)
|
||||
if (_Bitmask_includes(ClearFlag::COLOR, flags))
|
||||
{
|
||||
_clearColor = color;
|
||||
descriptor.clearColorValue = {color.r, color.g, color.b, color.a};
|
||||
|
@ -846,14 +846,14 @@ void Renderer::clear(ClearFlag flags, const Color4F& color, float depth, unsigne
|
|||
descriptor.needColorAttachment = true;
|
||||
descriptor.colorAttachmentsTexture[0] = _renderPassDescriptor.colorAttachmentsTexture[0];
|
||||
}
|
||||
if (flags & ClearFlag::DEPTH)
|
||||
if (_Bitmask_includes(ClearFlag::DEPTH, flags))
|
||||
{
|
||||
descriptor.clearDepthValue = depth;
|
||||
descriptor.needClearDepth = true;
|
||||
descriptor.depthTestEnabled = true;
|
||||
descriptor.depthAttachmentTexture = _renderPassDescriptor.depthAttachmentTexture;
|
||||
}
|
||||
if (flags & ClearFlag::STENCIL)
|
||||
if (_Bitmask_includes(ClearFlag::STENCIL, flags))
|
||||
{
|
||||
descriptor.clearStencilValue = stencil;
|
||||
descriptor.needClearStencil = true;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2020 c4games.com.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -28,6 +29,7 @@
|
|||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "base/bitmask.h"
|
||||
|
||||
CC_BACKEND_BEGIN
|
||||
|
||||
|
@ -235,15 +237,21 @@ enum class BlendFactor : uint32_t
|
|||
BLEND_CLOLOR
|
||||
};
|
||||
|
||||
enum class ColorWriteMask: uint32_t
|
||||
enum class ColorWriteMask : uint32_t
|
||||
{
|
||||
NONE = 0x00000000,
|
||||
RED = 0x00000001,
|
||||
GREEN = 0x00000002,
|
||||
BLUE = 0x00000004,
|
||||
ALPHA = 0x00000008,
|
||||
RED_BIT = 0,
|
||||
GREEN_BIT = 1,
|
||||
BLUE_BIT = 2,
|
||||
ALPHA_BIT = 3,
|
||||
NONE = 0,
|
||||
RED = 1 << RED_BIT,
|
||||
GREEN = 1 << GREEN_BIT,
|
||||
BLUE = 1 << BLUE_BIT,
|
||||
ALPHA = 1 << ALPHA_BIT,
|
||||
ALL = 0x0000000F
|
||||
};
|
||||
CC_ENABLE_BITMASK_OPS(ColorWriteMask)
|
||||
CC_ENABLE_BITSHIFT_OPS(ColorWriteMask)
|
||||
|
||||
struct SamplerDescriptor
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2020 c4games.com.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -53,10 +54,10 @@ void RenderPipelineGL::updateBlendState(const BlendDescriptor& descriptor)
|
|||
auto destinationRGBBlendFactor = UtilsGL::toGLBlendFactor(descriptor.destinationRGBBlendFactor);
|
||||
auto sourceAlphaBlendFactor = UtilsGL::toGLBlendFactor(descriptor.sourceAlphaBlendFactor);
|
||||
auto destinationAlphaBlendFactor = UtilsGL::toGLBlendFactor(descriptor.destinationAlphaBlendFactor);
|
||||
auto writeMaskRed = (uint32_t)descriptor.writeMask & (uint32_t)ColorWriteMask::RED;
|
||||
auto writeMaskGreen = (uint32_t)descriptor.writeMask & (uint32_t)ColorWriteMask::GREEN;
|
||||
auto writeMaskBlue = (uint32_t)descriptor.writeMask & (uint32_t)ColorWriteMask::BLUE;
|
||||
auto writeMaskAlpha = (uint32_t)descriptor.writeMask & (uint32_t)ColorWriteMask::ALPHA;
|
||||
GLboolean writeMaskRed = (GLboolean)((descriptor.writeMask & ColorWriteMask::RED) >> ColorWriteMask::RED_BIT);
|
||||
GLboolean writeMaskGreen = (GLboolean)((descriptor.writeMask & ColorWriteMask::GREEN) >> ColorWriteMask::GREEN_BIT);
|
||||
GLboolean writeMaskBlue = (GLboolean)((descriptor.writeMask & ColorWriteMask::BLUE) >> ColorWriteMask::BLUE_BIT);
|
||||
GLboolean writeMaskAlpha = (GLboolean)((descriptor.writeMask & ColorWriteMask::ALPHA) >> ColorWriteMask::ALPHA_BIT);
|
||||
|
||||
if (blendEnabled)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue