Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/backend/BlendState.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "BlendState.h"

CC_BACKEND_BEGIN

BlendState::BlendState(const BlendDescriptor& descriptor)
: _blendDescriptor(descriptor)
{
}
CC_BACKEND_END
3 changes: 3 additions & 0 deletions src/backend/BlendState.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class BlendState : public cocos2d::Ref
{
protected:
virtual ~BlendState() = default;
BlendState(const BlendDescriptor& descriptor);
Comment thread
Mee-gu marked this conversation as resolved.

BlendDescriptor _blendDescriptor;
};

CC_BACKEND_END
16 changes: 16 additions & 0 deletions src/backend/RenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,20 @@ RenderPass::RenderPass(const RenderPassDescriptor& descriptor)
RenderPass::~RenderPass()
{}

bool RenderPass::Find(const RenderPassDescriptor& descriptor) const
{
if(_colorAttachmentsSet != descriptor.getColorAttachmentSet() ||
_depthStencilAttachmentSet != descriptor.getDepthStencilAttachmentSet())
return false;

const RenderPassColorAttachments colorAttachment = descriptor.getColorAttachments();
const RenderPassDepthStencilAttachment depthStencilAttachment = descriptor.getDepthStencilAttachment();

if(_colorAttachments == colorAttachment &&
_depthStencilAttachment == depthStencilAttachment)
return true;

return false;
}

CC_BACKEND_END
1 change: 1 addition & 0 deletions src/backend/RenderPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class RenderPass : public cocos2d::Ref

inline const RenderPassDepthStencilAttachment& getDepthStencilAttachment() const { return _depthStencilAttachment; }
inline const RenderPassColorAttachments& getColorAttachments() const { return _colorAttachments; }
bool Find(const RenderPassDescriptor& descriptor) const;

protected:
RenderPass(const RenderPassDescriptor& descriptor);
Expand Down
25 changes: 25 additions & 0 deletions src/backend/RenderPassDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ void RenderPassColorAttachments::retainTextures() const
CC_SAFE_RETAIN(texture);
}

bool RenderPassColorAttachments::operator==(const RenderPassColorAttachments& colorAttachment) const
{
if(needClearColor != colorAttachment.needClearColor ||
clearColor != colorAttachment.clearColor)
return false;

return textures == colorAttachment.textures;
}

RenderPassDepthStencilAttachment::RenderPassDepthStencilAttachment(const RenderPassDepthStencilAttachment& rhs)
{
*this = rhs;
Expand All @@ -75,6 +84,22 @@ RenderPassDepthStencilAttachment& RenderPassDepthStencilAttachment::operator=(co
return *this;
}

bool RenderPassDepthStencilAttachment::operator==(const RenderPassDepthStencilAttachment& renderAttachment) const
{
if(needClearDepth != renderAttachment.needClearDepth ||
clearDepth != renderAttachment.clearDepth ||
needClearStencil != renderAttachment.needClearStencil ||
clearStencil != renderAttachment.clearStencil)
return false;

if(texture && renderAttachment.texture)
return texture->getTextureHashCode()?texture->getTextureHashCode() == renderAttachment.texture->getTextureHashCode():false;
else if(!texture && !(renderAttachment.texture))
return true;

return false;
}

void RenderPassDescriptor::setColorAttachment(uint32_t attachment, Texture* texture)
{
assert(TextureUsage::RENDER_TARGET == texture->getTextureUsage());
Expand Down
4 changes: 4 additions & 0 deletions src/backend/RenderPassDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct RenderPassColorAttachments
~RenderPassColorAttachments();
RenderPassColorAttachments& operator=(const RenderPassColorAttachments& rhs);
void setTexture(uint32_t attachment, Texture* texture);
bool operator==(const RenderPassColorAttachments& colorAttachment) const;

std::vector<Texture*> textures;

Expand All @@ -35,6 +36,7 @@ struct RenderPassDepthStencilAttachment
RenderPassDepthStencilAttachment(const RenderPassDepthStencilAttachment& rhs);
~RenderPassDepthStencilAttachment();
RenderPassDepthStencilAttachment& operator =(const RenderPassDepthStencilAttachment& rhs);
bool operator==(const RenderPassDepthStencilAttachment& renderAttachment) const;

float clearDepth = 1.f;
bool needClearDepth = false;
Expand All @@ -58,6 +60,8 @@ class RenderPassDescriptor

inline const RenderPassDepthStencilAttachment& getDepthStencilAttachment() const { return _depthStencilAttachment; }
inline const RenderPassColorAttachments& getColorAttachments() const { return _colorAttachments; }
inline bool getColorAttachmentSet() const {return _colorAttachmentsSet;}
inline bool getDepthStencilAttachmentSet() const {return _depthStencilAttachmentSet;}

private:
bool _colorAttachmentsSet = false;
Expand Down
200 changes: 200 additions & 0 deletions src/backend/StringUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
//
// StringUtils.cpp
// Test
//
// Created by Cocos on 2018/11/2.
// Copyright © 2018 cocos. All rights reserved.
//

#include "StringUtils.h"

CC_BACKEND_BEGIN

std::string StringUtils::TextureFormat2String(const TextureFormat& textureFormat)
{
switch (textureFormat) {
case TextureFormat::R8G8B8A8:
return "R8G8B8A8";
case TextureFormat::R8G8B8:
return "R8G8B8";
case TextureFormat::A8:
return "A8";
default:
return "";
}
}

std::string StringUtils::TextureType2String(const TextureType& textureType)
{
switch (textureType) {
case TextureType::TEXTURE_2D:
return "TEXTURE_2D";
case TextureType::TEXTURE_CUBE:
return "TEXTURE_CUBE";
default:
return "";
}
}

std::string StringUtils::TextureUsage2String(const TextureUsage& textureUsage)
{
switch (textureUsage) {
case TextureUsage::READ:
return "READ";
case TextureUsage::WRITE:
return "WRITE";
case TextureUsage::RENDER_TARGET:
return "RENDER_TARGET";
default:
return "";
}
}

std::string StringUtils::SamplerFilterType2String(const SamplerFilter& filterType)
{
switch (filterType) {
case SamplerFilter::LINEAR:
return "LINEAR";
case SamplerFilter::NEAREST:
return "NEAREST";
default:
return "";
}
}

std::string StringUtils::SamplerAddressMode2String(const SamplerAddressMode& addressMode)
{
switch (addressMode) {
case SamplerAddressMode::REPEAT:
return "REPEAT";
case SamplerAddressMode::MIRROR_REPEAT:
return "MIRROR_REPEAT";
case SamplerAddressMode::CLAMP_TO_EDGE:
return "CLAMP_TO_EDGE";
default:
return "";
}
}

std::string StringUtils::SamplerDescriptor2String(const SamplerDescriptor& descriptor)
{
std::string samplerInfo = descriptor.mipmapEnabled ? "mipmapEnable":"mipmapDisable";
samplerInfo += SamplerFilterType2String(descriptor.magFilter);
samplerInfo += SamplerFilterType2String(descriptor.minFilter);
samplerInfo += SamplerFilterType2String(descriptor.mipmapFilter);
samplerInfo += SamplerAddressMode2String(descriptor.sAddressMode);
samplerInfo += SamplerAddressMode2String(descriptor.tAddressMode);
return samplerInfo;
}

std::string StringUtils::StencilOperation2String(const StencilOperation& operation)
{
switch (operation) {
case StencilOperation::KEEP:
return "KEEP";
case StencilOperation::ZERO:
return "ZERO";
case StencilOperation::REPLACE:
return "REPLACE";
case StencilOperation::INVERT:
return "INVERT";
case StencilOperation::INCREMENT_WRAP:
return "INCREMENT_WRAP";
case StencilOperation::DECREMENT_WRAP:
return "DECREMENT_WRAP";
default:
return "";
}
}

std::string StringUtils::CompareFunction2String(const CompareFunction& compareFunction)
{
switch (compareFunction) {
case CompareFunction::NEVER:
return "NEVER";
case CompareFunction::LESS:
return "LESS";
case CompareFunction::LESS_EQUAL:
return "LESS_EQUAL";
case CompareFunction::GREATER:
return "GREATER";
case CompareFunction::GREATER_EQUAL:
return "GREATER_EQUAL";
case CompareFunction::EQUAL:
return "EQUAL";
case CompareFunction::NOT_EQUAL:
return "NOT_EQUAL";
case CompareFunction::ALWAYS:
return "ALWAYS";
default:
return "";
}
}

std::string StringUtils::ColorWriteMask2String(const ColorWriteMask& colorWriteMask)
{
switch (colorWriteMask) {
case ColorWriteMask::NONE:
return "NONE";
case ColorWriteMask::RED:
return "RED";
case ColorWriteMask::GREEN:
return "GREEN";
case ColorWriteMask::BLUE:
return "BLUE";
case ColorWriteMask::ALPHA:
return "ALPHA";
case ColorWriteMask::ALL:
return "ALL";
default:
return "";
}
}

std::string StringUtils::BlendOperation2String(const BlendOperation& blendOperation)
{
switch (blendOperation) {
case BlendOperation::ADD:
return "ADD";
case BlendOperation::SUBTRACT:
return "SUBTRACT";
case BlendOperation::RESERVE_SUBTRACT:
return "RESERVE_SUBTRACT";
default:
return "";
}
}

std::string StringUtils::BlendFactor2String(const BlendFactor& blendFactor)
{
switch (blendFactor) {
case BlendFactor::ZERO:
return "ZERO";
case BlendFactor::ONE:
return "ONE";
case BlendFactor::SRC_COLOR:
return "SRC_COLOR";
case BlendFactor::ONE_MINUS_SRC_COLOR:
return "ONE_MINUS_SRC_COLOR";
case BlendFactor::SRC_ALPHA:
return "SRC_ALPHA";
case BlendFactor::ONE_MINUS_SRC_ALPHA:
return "ONE_MINUS_SRC_ALPHA";
case BlendFactor::DST_COLOR:
return "DST_COLOR";
case BlendFactor::ONE_MINUS_DST_COLOR:
return "ONE_MINUS_DST_COLOR";
case BlendFactor::DST_ALPHA:
return "DST_ALPHA";
case BlendFactor::ONE_MINUS_DST_ALPHA:
return "ONE_MINUS_DST_ALPHA";
case BlendFactor::SRC_ALPHA_SATURATE:
return "SRC_ALPHA_SATURATE";
case BlendFactor::BLEND_CLOLOR:
return "BLEND_CLOLOR";
default:
return "";
}
}

CC_BACKEND_END
33 changes: 33 additions & 0 deletions src/backend/StringUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// StringUtils.hpp
// Test
//
// Created by Cocos on 2018/11/2.
// Copyright © 2018 cocos. All rights reserved.
//

#ifndef StringUtils_hpp
#define StringUtils_hpp

#include <string>
#include "Types.h"
CC_BACKEND_BEGIN

class StringUtils
{
public:
static std::string TextureFormat2String(const TextureFormat& textureFormat);
static std::string TextureType2String(const TextureType& textureType);
static std::string TextureUsage2String(const TextureUsage& textureUsage);
static std::string SamplerFilterType2String(const SamplerFilter& filterType);
static std::string SamplerAddressMode2String(const SamplerAddressMode& addressMode);
static std::string SamplerDescriptor2String(const SamplerDescriptor& descriptor);
static std::string StencilOperation2String(const StencilOperation& operation);
static std::string CompareFunction2String(const CompareFunction& compareFunction);
static std::string ColorWriteMask2String(const ColorWriteMask& colorWriteMask);
static std::string BlendOperation2String(const BlendOperation& blendOperation);
static std::string BlendFactor2String(const BlendFactor& blendFactor);
};

CC_BACKEND_END
#endif /* StringUtils_hpp */
3 changes: 3 additions & 0 deletions src/backend/Texture.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "Texture.h"
#include "StringUtils.h"

#include <string>

CC_BACKEND_BEGIN

Expand Down
3 changes: 2 additions & 1 deletion src/backend/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Texture : public cocos2d::Ref
inline TextureUsage getTextureUsage() const { return _textureUsage; }
inline uint32_t getWidth() const { return _width; }
inline uint32_t getHeight() const { return _height; }

inline size_t getTextureHashCode() const {return _textureHashCode;}
protected:
Texture(const TextureDescriptor& descriptor);
virtual ~Texture();
Expand All @@ -40,6 +40,7 @@ class Texture : public cocos2d::Ref
TextureFormat _textureFormat = TextureFormat::R8G8B8;
TextureUsage _textureUsage = TextureUsage::READ;
bool _isMipmapEnabled = false;
size_t _textureHashCode = 0;
};

CC_BACKEND_END
2 changes: 1 addition & 1 deletion src/backend/metal/BlendStateMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BlendStateMTL : public BlendState
BlendStateMTL(const BlendDescriptor& descriptor);

inline const BlendDescriptorMTL& getBlendDescriptorMTL() const { return _blendDescriptorMTL; }

inline const BlendDescriptor& getBlendDescriptor() const {return _blendDescriptor;}
private:
BlendDescriptorMTL _blendDescriptorMTL;
};
Expand Down
1 change: 1 addition & 0 deletions src/backend/metal/BlendStateMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ MTLBlendOperation toMTLBlendOperation(BlendOperation operation)
}

BlendStateMTL::BlendStateMTL(const BlendDescriptor& descriptor)
: BlendState(descriptor)
{
_blendDescriptorMTL.writeMask = toMTLColorWriteMask(descriptor.writeMask);
_blendDescriptorMTL.blendEnabled = descriptor.blendEnabled;
Expand Down
1 change: 1 addition & 0 deletions src/backend/metal/DepthStencilStateMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class DepthStencilStateMTL : public DepthStencilState
~DepthStencilStateMTL();

inline id<MTLDepthStencilState> getMTLDepthStencilState() const { return _mtlDepthStencilState; }
inline const DepthStencilDescriptor& getDepthStencilDescriptor() const {return _depthStencilInfo;}

private:
id<MTLDepthStencilState> _mtlDepthStencilState = nil;
Expand Down
Loading