mirror of https://github.com/axmolengine/axmol.git
use placeholder logic to generate material id
This commit is contained in:
parent
51fb1edc0c
commit
3108d499e5
|
@ -1 +1 @@
|
|||
66497ec4f15de06d504b96da6ade60c7ad59ab44
|
||||
a8deccd72bda63a9abc1fd55c4812468dc021fa8
|
|
@ -47,8 +47,9 @@ void NewSprite::draw(void)
|
|||
kmMat4 transform;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &transform);
|
||||
RenderCommand* renderCommand = new RenderCommand();
|
||||
renderCommand->setData(0, true, false, _ZOrder);
|
||||
renderCommand->setQuadData(&transform, _quad, _texture->getName(), 0, 0);
|
||||
renderCommand->setKeyData(0, true, false, _ZOrder);
|
||||
renderCommand->setMaterialData(_texture->getName(), _shaderProgram->getProgram(), _blendFunc);
|
||||
renderCommand->setQuadData(&transform, _quad);
|
||||
|
||||
Renderer::getInstance()->addRenderCommand(renderCommand);
|
||||
}
|
||||
|
|
|
@ -329,6 +329,16 @@ struct BlendFunc
|
|||
const static BlendFunc ALPHA_NON_PREMULTIPLIED;
|
||||
//! Enables Additive blending. Uses {GL_SRC_ALPHA, GL_ONE}
|
||||
const static BlendFunc ADDITIVE;
|
||||
|
||||
bool const operator==(const BlendFunc &a)
|
||||
{
|
||||
return src == a.src && dst == a.dst;
|
||||
}
|
||||
|
||||
bool const operator<(const BlendFunc &a)
|
||||
{
|
||||
return src < a.src || (src < a.src && dst < a.dst);
|
||||
}
|
||||
};
|
||||
|
||||
// Label::VAlignment
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
#include "MaterialManager.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
using namespace std;
|
||||
|
||||
static MaterialManager* s_instance = 0;
|
||||
|
||||
MaterialManager *MaterialManager::getInstance()
|
||||
{
|
||||
if(!s_instance)
|
||||
{
|
||||
s_instance = new MaterialManager();
|
||||
if(!s_instance->init())
|
||||
{
|
||||
CC_SAFE_DELETE(s_instance);
|
||||
}
|
||||
}
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void MaterialManager::destroyInstance()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(s_instance);
|
||||
}
|
||||
|
||||
void MaterialManager::getMaterialID(GLuint textureID, GLuint shaderID, BlendFunc blendFunc)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MaterialManager::registerTexture(GLuint textureID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MaterialManager::unregisterTexture(GLuint textureID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MaterialManager::registerShader(GLuint shaderID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MaterialManager::unregisterShader(GLuint shaderID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MaterialManager::MaterialManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MaterialManager::~MaterialManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool MaterialManager::init()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int MaterialManager::getTextureID(GLuint textureID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MaterialManager::getShaderID(GLuint shaderID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MaterialManager::getBlendFuncID(GLint blendFunc)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef _CC_MATERIALMANAGER_H_
|
||||
#define _CC_MATERIALMANAGER_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include "ccTypes.h"
|
||||
#include <map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
using namespace std;
|
||||
|
||||
class MaterialManager : public Object
|
||||
{
|
||||
public:
|
||||
static MaterialManager* getInstance();
|
||||
static void destroyInstance();
|
||||
|
||||
|
||||
void getMaterialID(GLuint textureID, GLuint shaderID, BlendFunc blendFunc);
|
||||
|
||||
void registerTexture(GLuint textureID);
|
||||
void unregisterTexture(GLuint textureID);
|
||||
|
||||
void registerShader(GLuint shaderID);
|
||||
void unregisterShader(GLuint shaderID);
|
||||
|
||||
protected:
|
||||
MaterialManager();
|
||||
virtual ~MaterialManager();
|
||||
|
||||
bool init();
|
||||
|
||||
int getTextureID(GLuint textureID);
|
||||
int getShaderID(GLuint shaderID);
|
||||
int getBlendFuncID(GLint blendFunc);
|
||||
|
||||
map<GLuint, int> _textureIDMapping;
|
||||
map<GLuint, int> _shaderIDMapping;
|
||||
map<BlendFunc, int> _blendFuncMapping;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //_CC_MATERIALMANAGER_H_
|
|
@ -0,0 +1,6 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
#include "QuadCommand.h"
|
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef _CC_QUADCOMMAND_H_
|
||||
#define _CC_QUADCOMMAND_H_
|
||||
|
||||
#include "RenderCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
// +----------+----------+-----+-----------------------------------+
|
||||
// | | | | | |
|
||||
// | ViewPort | Transluc | Cmd | Depth | Material ID |
|
||||
// | 3 bits | 1 bit | 1 | 24 bits | 24 bit2 |
|
||||
// +----------+----------+-----+----------------+------------------+
|
||||
class QuadCommandID : public RenderCommandID
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class QuadCommand : public RenderCommand
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //_CC_QUADCOMMAND_H_
|
|
@ -21,6 +21,40 @@ void RenderCommand::generateID()
|
|||
{
|
||||
_renderCommandId = 0;
|
||||
|
||||
//Generate Material ID
|
||||
//TODO fix shader ID generation
|
||||
CCASSERT(_shaderID < 64, "ShaderID is greater than 64");
|
||||
//TODO fix texture ID generation
|
||||
CCASSERT(_textureID < 1024, "TextureID is greater than 1024");
|
||||
|
||||
//TODO fix blend id generation
|
||||
int blendID = 0;
|
||||
if(_blendType == BlendFunc::DISABLE)
|
||||
{
|
||||
blendID = 0;
|
||||
}
|
||||
else if(_blendType == BlendFunc::ALPHA_PREMULTIPLIED)
|
||||
{
|
||||
blendID = 1;
|
||||
}
|
||||
else if(_blendType == BlendFunc::ALPHA_NON_PREMULTIPLIED)
|
||||
{
|
||||
blendID = 2;
|
||||
}
|
||||
else if(_blendType == BlendFunc::ADDITIVE)
|
||||
{
|
||||
blendID = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
blendID = 4;
|
||||
}
|
||||
|
||||
_materialID = (int32_t)_shaderID << 28
|
||||
| (int32_t)blendID << 24
|
||||
| (int32_t)_textureID << 14;
|
||||
|
||||
//Generate RenderCommandID
|
||||
_renderCommandId = (int64_t)_viewport << 61
|
||||
| (int64_t)_isTranslucent << 60
|
||||
| (int64_t)_isCommand << 59
|
||||
|
@ -53,7 +87,7 @@ void RenderCommand::printID()
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
void RenderCommand::setData(int viewport, bool isTranslucent, bool isCommand, int32_t depth)
|
||||
void RenderCommand::setKeyData(int viewport, bool isTranslucent, bool isCommand, int32_t depth)
|
||||
{
|
||||
_viewport = viewport;
|
||||
_isTranslucent = isTranslucent;
|
||||
|
@ -61,13 +95,17 @@ void RenderCommand::setData(int viewport, bool isTranslucent, bool isCommand, in
|
|||
_depth = depth;
|
||||
}
|
||||
|
||||
void RenderCommand::setQuadData(kmMat4 *transform, V3F_C4B_T2F_Quad quad, GLuint textureID, int shaderID, int blendType)
|
||||
void RenderCommand::setMaterialData(GLuint textureID, GLuint shaderID, BlendFunc blendType)
|
||||
{
|
||||
kmMat4Assign(&_transform, transform);
|
||||
_quad = quad;
|
||||
_textureID = textureID;
|
||||
_shaderID = shaderID;
|
||||
_blendType = blendType;
|
||||
}
|
||||
|
||||
void RenderCommand::setQuadData(kmMat4 *transform, V3F_C4B_T2F_Quad quad)
|
||||
{
|
||||
kmMat4Assign(&_transform, transform);
|
||||
_quad = quad;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -14,13 +14,25 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class RenderCommandID
|
||||
{
|
||||
public:
|
||||
virtual int64_t generateID() = 0;
|
||||
inline int64_t getID() { return _id; }
|
||||
|
||||
protected:
|
||||
int64_t _id;
|
||||
|
||||
};
|
||||
|
||||
class RenderCommand
|
||||
{
|
||||
public:
|
||||
|
||||
RenderCommand();
|
||||
void setData(int viewport, bool isTranslucent, bool isCommand, int32_t depth);
|
||||
void setQuadData(kmMat4* transform, V3F_C4B_T2F_Quad quad, GLuint textureID, int shaderID, int blendType);
|
||||
void setKeyData(int viewport, bool isTranslucent, bool isCommand, int32_t depth);
|
||||
void setMaterialData( GLuint textureID, GLuint shaderID, BlendFunc blendType);
|
||||
void setQuadData(kmMat4* transform, V3F_C4B_T2F_Quad quad);
|
||||
|
||||
void generateID();
|
||||
|
||||
|
@ -35,8 +47,8 @@ public:
|
|||
inline GLuint getTextureID() { return _textureID; }
|
||||
inline kmMat4* getTransform() { return &_transform; }
|
||||
inline V3F_C4B_T2F_Quad* getQuad() { return &_quad; }
|
||||
inline int getShaderID() { return _shaderID; }
|
||||
inline int getBlendType() { return _blendType; }
|
||||
inline GLuint getShaderID() { return _shaderID; }
|
||||
inline BlendFunc getBlendType() { return _blendType; }
|
||||
|
||||
protected:
|
||||
void printID();
|
||||
|
@ -46,17 +58,18 @@ protected:
|
|||
int64_t _renderCommandId; /// used for sorting render commands
|
||||
int32_t _materialID;
|
||||
|
||||
//Data
|
||||
//Key Data
|
||||
int _viewport; /// Which view port it belongs to
|
||||
bool _isTranslucent; /// Is it translucent, if it is we will have to render it
|
||||
bool _isCommand;
|
||||
int32_t _depth;
|
||||
//Maternal
|
||||
GLuint _textureID;
|
||||
GLuint _shaderID;
|
||||
BlendFunc _blendType;
|
||||
|
||||
kmMat4 _transform;
|
||||
V3F_C4B_T2F_Quad _quad;
|
||||
GLuint _textureID;
|
||||
int _shaderID;
|
||||
int _blendType;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
#include "RenderMaterial.h"
|
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef __RenderMaterial_H_
|
||||
#define __RenderMaterial_H_
|
||||
|
||||
|
||||
class RenderMaterial
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //__RenderMaterial_H_
|
Loading…
Reference in New Issue