modify skybox

This commit is contained in:
yangxiao 2015-04-01 17:34:57 +08:00
parent 6cd1697240
commit 9540fd590f
2 changed files with 54 additions and 1 deletions

View File

@ -22,6 +22,14 @@
THE SOFTWARE.
****************************************************************************/
#include "base/ccMacros.h"
#include "base/CCConfiguration.h"
#include "base/CCDirector.h"
#include "renderer/ccGLStateCache.h"
#include "renderer/CCGLProgram.h"
#include "renderer/CCGLProgramCache.h"
#include "renderer/CCGLProgramState.h"
#include "renderer/CCRenderer.h"
#include "3d/CCSkybox.h"
#include "3d/CCTextureCube.h"
@ -53,6 +61,17 @@ Skybox::~Skybox()
_texture->release();
}
Skybox* Skybox::create(const std::string& positive_x, const std::string& negative_x,
const std::string& positive_y, const std::string& negative_y,
const std::string& positive_z, const std::string& negative_z)
{
auto ret = new (std::nothrow) Skybox();
ret->init(positive_x, negative_x, positive_y, negative_y, positive_z, negative_z);
ret->autorelease();
return ret;
}
bool Skybox::init()
{
// create and set our custom shader
@ -68,6 +87,17 @@ bool Skybox::init()
return true;
}
bool Skybox::init(const std::string& positive_x, const std::string& negative_x,
const std::string& positive_y, const std::string& negative_y,
const std::string& positive_z, const std::string& negative_z)
{
init();
auto texture = TextureCube::create(positive_x, negative_x, positive_y, negative_y, positive_z, negative_z);
setTexture(texture);
return true;
}
void Skybox::initBuffers()
{
if (Configuration::getInstance()->supportsShareableVAO())

View File

@ -25,7 +25,10 @@
#ifndef __SKYBOX_H__
#define __SKYBOX_H__
#include "cocos2d.h"
#include "base/ccTypes.h"
#include "platform/CCPlatformMacros.h"
#include "renderer/CCCustomCommand.h"
#include "2d/CCNode.h"
NS_CC_BEGIN
@ -39,6 +42,19 @@ class CC_DLL Skybox : public Node
public:
CREATE_FUNC(Skybox);
/** create skybox from 6 textures.
@param positive_x texture for the right side of the texture cube face.
@param negative_x texture for the up side of the texture cube face.
@param positive_y texture for the top side of the texture cube face
@param negative_y texture for the bottom side of the texture cube face
@param positive_z texture for the forward side of the texture cube face.
@param negative_z texture for the rear side of the texture cube face.
@return A new skybox inited with given parameters.
*/
static Skybox* create(const std::string& positive_x, const std::string& negative_x,
const std::string& positive_y, const std::string& negative_y,
const std::string& positive_z, const std::string& negative_z);
/**texture getter and setter*/
void setTexture(TextureCube*);
@ -64,6 +80,13 @@ CC_CONSTRUCTOR_ACCESS:
*/
virtual bool init();
/**
* initialize with texture path
*/
bool init(const std::string& positive_x, const std::string& negative_x,
const std::string& positive_y, const std::string& negative_y,
const std::string& positive_z, const std::string& negative_z);
protected:
/**