use placeholder logic to generate material id

This commit is contained in:
Nite Luo 2013-11-06 14:24:56 -08:00
parent 51fb1edc0c
commit 3108d499e5
11 changed files with 275 additions and 15 deletions

View File

@ -1 +1 @@
66497ec4f15de06d504b96da6ade60c7ad59ab44 a8deccd72bda63a9abc1fd55c4812468dc021fa8

View File

@ -47,8 +47,9 @@ void NewSprite::draw(void)
kmMat4 transform; kmMat4 transform;
kmGLGetMatrix(KM_GL_MODELVIEW, &transform); kmGLGetMatrix(KM_GL_MODELVIEW, &transform);
RenderCommand* renderCommand = new RenderCommand(); RenderCommand* renderCommand = new RenderCommand();
renderCommand->setData(0, true, false, _ZOrder); renderCommand->setKeyData(0, true, false, _ZOrder);
renderCommand->setQuadData(&transform, _quad, _texture->getName(), 0, 0); renderCommand->setMaterialData(_texture->getName(), _shaderProgram->getProgram(), _blendFunc);
renderCommand->setQuadData(&transform, _quad);
Renderer::getInstance()->addRenderCommand(renderCommand); Renderer::getInstance()->addRenderCommand(renderCommand);
} }

View File

@ -329,6 +329,16 @@ struct BlendFunc
const static BlendFunc ALPHA_NON_PREMULTIPLIED; const static BlendFunc ALPHA_NON_PREMULTIPLIED;
//! Enables Additive blending. Uses {GL_SRC_ALPHA, GL_ONE} //! Enables Additive blending. Uses {GL_SRC_ALPHA, GL_ONE}
const static BlendFunc ADDITIVE; 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 // Label::VAlignment

View File

@ -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

View File

@ -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_

View File

@ -0,0 +1,6 @@
//
// Created by NiTe Luo on 11/6/13.
//
#include "QuadCommand.h"

View File

@ -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_

View File

@ -21,6 +21,40 @@ void RenderCommand::generateID()
{ {
_renderCommandId = 0; _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 _renderCommandId = (int64_t)_viewport << 61
| (int64_t)_isTranslucent << 60 | (int64_t)_isTranslucent << 60
| (int64_t)_isCommand << 59 | (int64_t)_isCommand << 59
@ -53,7 +87,7 @@ void RenderCommand::printID()
printf("\n"); 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; _viewport = viewport;
_isTranslucent = isTranslucent; _isTranslucent = isTranslucent;
@ -61,13 +95,17 @@ void RenderCommand::setData(int viewport, bool isTranslucent, bool isCommand, in
_depth = depth; _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; _textureID = textureID;
_shaderID = shaderID; _shaderID = shaderID;
_blendType = blendType; _blendType = blendType;
} }
void RenderCommand::setQuadData(kmMat4 *transform, V3F_C4B_T2F_Quad quad)
{
kmMat4Assign(&_transform, transform);
_quad = quad;
}
NS_CC_END NS_CC_END

View File

@ -14,13 +14,25 @@
NS_CC_BEGIN NS_CC_BEGIN
class RenderCommandID
{
public:
virtual int64_t generateID() = 0;
inline int64_t getID() { return _id; }
protected:
int64_t _id;
};
class RenderCommand class RenderCommand
{ {
public: public:
RenderCommand(); RenderCommand();
void setData(int viewport, bool isTranslucent, bool isCommand, int32_t depth); void setKeyData(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 setMaterialData( GLuint textureID, GLuint shaderID, BlendFunc blendType);
void setQuadData(kmMat4* transform, V3F_C4B_T2F_Quad quad);
void generateID(); void generateID();
@ -35,8 +47,8 @@ public:
inline GLuint getTextureID() { return _textureID; } inline GLuint getTextureID() { return _textureID; }
inline kmMat4* getTransform() { return &_transform; } inline kmMat4* getTransform() { return &_transform; }
inline V3F_C4B_T2F_Quad* getQuad() { return &_quad; } inline V3F_C4B_T2F_Quad* getQuad() { return &_quad; }
inline int getShaderID() { return _shaderID; } inline GLuint getShaderID() { return _shaderID; }
inline int getBlendType() { return _blendType; } inline BlendFunc getBlendType() { return _blendType; }
protected: protected:
void printID(); void printID();
@ -46,17 +58,18 @@ protected:
int64_t _renderCommandId; /// used for sorting render commands int64_t _renderCommandId; /// used for sorting render commands
int32_t _materialID; int32_t _materialID;
//Data //Key Data
int _viewport; /// Which view port it belongs to int _viewport; /// Which view port it belongs to
bool _isTranslucent; /// Is it translucent, if it is we will have to render it bool _isTranslucent; /// Is it translucent, if it is we will have to render it
bool _isCommand; bool _isCommand;
int32_t _depth; int32_t _depth;
//Maternal
GLuint _textureID;
GLuint _shaderID;
BlendFunc _blendType;
kmMat4 _transform; kmMat4 _transform;
V3F_C4B_T2F_Quad _quad; V3F_C4B_T2F_Quad _quad;
GLuint _textureID;
int _shaderID;
int _blendType;
}; };
NS_CC_END NS_CC_END

View File

@ -0,0 +1,6 @@
//
// Created by NiTe Luo on 11/6/13.
//
#include "RenderMaterial.h"

View File

@ -0,0 +1,17 @@
//
// Created by NiTe Luo on 11/6/13.
//
#ifndef __RenderMaterial_H_
#define __RenderMaterial_H_
class RenderMaterial
{
};
#endif //__RenderMaterial_H_