mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3FrameBufferObject' into v3
This commit is contained in:
commit
22ddf53539
|
@ -1860,6 +1860,10 @@
|
|||
B230ED7219B417AE00364AA8 /* CCTrianglesCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B230ED6F19B417AE00364AA8 /* CCTrianglesCommand.cpp */; };
|
||||
B230ED7319B417AE00364AA8 /* CCTrianglesCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = B230ED7019B417AE00364AA8 /* CCTrianglesCommand.h */; };
|
||||
B230ED7419B417AE00364AA8 /* CCTrianglesCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = B230ED7019B417AE00364AA8 /* CCTrianglesCommand.h */; };
|
||||
B240C5E91B09DFB000137F50 /* CCFrameBufferObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B240C5E71B09DFB000137F50 /* CCFrameBufferObject.cpp */; };
|
||||
B240C5EA1B09DFB000137F50 /* CCFrameBufferObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B240C5E71B09DFB000137F50 /* CCFrameBufferObject.cpp */; };
|
||||
B240C5EB1B09DFB000137F50 /* CCFrameBufferObject.h in Headers */ = {isa = PBXBuildFile; fileRef = B240C5E81B09DFB000137F50 /* CCFrameBufferObject.h */; };
|
||||
B240C5EC1B09DFB000137F50 /* CCFrameBufferObject.h in Headers */ = {isa = PBXBuildFile; fileRef = B240C5E81B09DFB000137F50 /* CCFrameBufferObject.h */; };
|
||||
B24AA985195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B24AA981195A675C007B4522 /* CCFastTMXLayer.cpp */; };
|
||||
B24AA986195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B24AA981195A675C007B4522 /* CCFastTMXLayer.cpp */; };
|
||||
B24AA987195A675C007B4522 /* CCFastTMXLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = B24AA982195A675C007B4522 /* CCFastTMXLayer.h */; };
|
||||
|
@ -4508,6 +4512,8 @@
|
|||
B217704C1977ED8B009EE11B /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; };
|
||||
B230ED6F19B417AE00364AA8 /* CCTrianglesCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTrianglesCommand.cpp; sourceTree = "<group>"; };
|
||||
B230ED7019B417AE00364AA8 /* CCTrianglesCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTrianglesCommand.h; sourceTree = "<group>"; };
|
||||
B240C5E71B09DFB000137F50 /* CCFrameBufferObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCFrameBufferObject.cpp; sourceTree = "<group>"; };
|
||||
B240C5E81B09DFB000137F50 /* CCFrameBufferObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCFrameBufferObject.h; sourceTree = "<group>"; };
|
||||
B241A6E21AFB0BE700C5623C /* ccShader_CameraClear.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_CameraClear.frag; sourceTree = "<group>"; };
|
||||
B241A6E31AFB0BE700C5623C /* ccShader_CameraClear.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_CameraClear.vert; sourceTree = "<group>"; };
|
||||
B24AA981195A675C007B4522 /* CCFastTMXLayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCFastTMXLayer.cpp; sourceTree = "<group>"; };
|
||||
|
@ -7193,6 +7199,8 @@
|
|||
500DC89819105D41007B91BF /* renderer */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B240C5E71B09DFB000137F50 /* CCFrameBufferObject.cpp */,
|
||||
B240C5E81B09DFB000137F50 /* CCFrameBufferObject.h */,
|
||||
5034CA5D191D591900CE6051 /* shaders */,
|
||||
B276EF5B1988D1D500CD400F /* CCVertexIndexData.h */,
|
||||
B276EF5C1988D1D500CD400F /* CCVertexIndexData.cpp */,
|
||||
|
@ -9071,6 +9079,7 @@
|
|||
501216A21AC473AD009A4BEA /* CCMaterial.h in Headers */,
|
||||
50ABC05D1926664800A911A9 /* CCApplication-mac.h in Headers */,
|
||||
B6CAB2871AF9AA1A00B9B856 /* btBvhTriangleMeshShape.h in Headers */,
|
||||
B240C5EB1B09DFB000137F50 /* CCFrameBufferObject.h in Headers */,
|
||||
B6CAB51D1AF9AA1A00B9B856 /* btPoolAllocator.h in Headers */,
|
||||
B6CAB3EB1AF9AA1A00B9B856 /* btDynamicsWorld.h in Headers */,
|
||||
B6CAB29D1AF9AA1A00B9B856 /* btConeShape.h in Headers */,
|
||||
|
@ -9642,6 +9651,7 @@
|
|||
50ABBE501925AB6F00A911A9 /* CCEventCustom.h in Headers */,
|
||||
15AE1AD719AAD40300C27E9E /* b2WheelJoint.h in Headers */,
|
||||
B665E3311AA80A6500DDB1C5 /* CCPUOnCountObserverTranslator.h in Headers */,
|
||||
B240C5EC1B09DFB000137F50 /* CCFrameBufferObject.h in Headers */,
|
||||
B6CAB41C1AF9AA1A00B9B856 /* btDantzigLCP.h in Headers */,
|
||||
B665E2051AA80A6500DDB1C5 /* CCPUAlignAffectorTranslator.h in Headers */,
|
||||
1A570070180BC5A10088DEC7 /* CCActionEase.h in Headers */,
|
||||
|
@ -10627,6 +10637,7 @@
|
|||
15AE188C19AAD33D00C27E9E /* CCLabelBMFontLoader.cpp in Sources */,
|
||||
B6CAAFE21AF9A9E100B9B856 /* CCPhysics3D.cpp in Sources */,
|
||||
DA8C62A219E52C6400000516 /* ioapi_mem.cpp in Sources */,
|
||||
B240C5E91B09DFB000137F50 /* CCFrameBufferObject.cpp in Sources */,
|
||||
B68779001A8CA82E00643ABF /* CCParticle3DRender.cpp in Sources */,
|
||||
1A570069180BC5A10088DEC7 /* CCActionCatmullRom.cpp in Sources */,
|
||||
B257B44E1989D5E800D9A687 /* CCPrimitive.cpp in Sources */,
|
||||
|
@ -11689,6 +11700,7 @@
|
|||
B665E34F1AA80A6500DDB1C5 /* CCPUOnPositionObserverTranslator.cpp in Sources */,
|
||||
1A5701EF180BCB8C0088DEC7 /* CCTransitionProgress.cpp in Sources */,
|
||||
B6D38B8B1AC3AFAC00043997 /* CCSkybox.cpp in Sources */,
|
||||
B240C5EA1B09DFB000137F50 /* CCFrameBufferObject.cpp in Sources */,
|
||||
1A5701F8180BCBAD0088DEC7 /* CCMenu.cpp in Sources */,
|
||||
382384141A259092002C4610 /* NodeReaderProtocol.cpp in Sources */,
|
||||
50ABBD511925AB0000A911A9 /* Quaternion.cpp in Sources */,
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "renderer/CCQuadCommand.h"
|
||||
#include "renderer/CCGLProgramCache.h"
|
||||
#include "renderer/ccGLStateCache.h"
|
||||
#include "renderer/CCFrameBufferObject.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -88,13 +89,14 @@ Camera::Camera()
|
|||
, _cameraFlag(1)
|
||||
, _frustumDirty(true)
|
||||
, _depth(-1)
|
||||
, _fbo(nullptr)
|
||||
{
|
||||
_frustum.setClipZ(true);
|
||||
}
|
||||
|
||||
Camera::~Camera()
|
||||
{
|
||||
|
||||
CC_SAFE_RELEASE_NULL(_fbo);
|
||||
}
|
||||
|
||||
const Mat4& Camera::getProjectionMatrix() const
|
||||
|
@ -303,7 +305,7 @@ float Camera::getDepthInView(const Mat4& transform) const
|
|||
return depth;
|
||||
}
|
||||
|
||||
void Camera::setDepth(int depth)
|
||||
void Camera::setDepth(int8_t depth)
|
||||
{
|
||||
if (_depth != depth)
|
||||
{
|
||||
|
@ -437,4 +439,42 @@ void Camera::clearBackground(float depth)
|
|||
}
|
||||
}
|
||||
|
||||
void Camera::setFrameBufferObject(FrameBufferObject *fbo)
|
||||
{
|
||||
CC_SAFE_RETAIN(fbo);
|
||||
CC_SAFE_RELEASE_NULL(_fbo);
|
||||
_fbo = fbo;
|
||||
if(_scene)
|
||||
{
|
||||
_scene->setCameraOrderDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void Camera::applyFrameBufferObject()
|
||||
{
|
||||
if(nullptr == _fbo)
|
||||
{
|
||||
FrameBufferObject::applyDefaultFBO();
|
||||
}
|
||||
else
|
||||
{
|
||||
_fbo->applyFBO();
|
||||
}
|
||||
}
|
||||
|
||||
int Camera::getRenderOrder() const
|
||||
{
|
||||
int result(0);
|
||||
if(_fbo)
|
||||
{
|
||||
result = _fbo->getFID()<<8;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 127 <<8;
|
||||
}
|
||||
result += _depth;
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
|||
NS_CC_BEGIN
|
||||
|
||||
class Scene;
|
||||
|
||||
class FrameBufferObject;
|
||||
/**
|
||||
* Note:
|
||||
* Scene creates a default camera. And the default camera mask of Node is 1, therefore it can be seen by the default camera.
|
||||
|
@ -165,12 +165,17 @@ public:
|
|||
/**
|
||||
* set depth, camera with larger depth is drawn on top of camera with smaller depth, the depth of camera with CameraFlag::DEFAULT is 0, user defined camera is -1 by default
|
||||
*/
|
||||
void setDepth(int depth);
|
||||
void setDepth(int8_t depth);
|
||||
|
||||
/**
|
||||
* get depth, camera with larger depth is drawn on top of camera with smaller depth, the depth of camera with CameraFlag::DEFAULT is 0, user defined camera is -1 by default
|
||||
*/
|
||||
int getDepth() const { return _depth; }
|
||||
int8_t getDepth() const { return _depth; }
|
||||
|
||||
/**
|
||||
get rendered order
|
||||
*/
|
||||
int getRenderOrder() const;
|
||||
|
||||
/**
|
||||
* Get the frustum's far plane.
|
||||
|
@ -198,6 +203,8 @@ public:
|
|||
|
||||
void clearBackground(float depth);
|
||||
|
||||
void setFrameBufferObject(FrameBufferObject* fbo);
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Camera();
|
||||
~Camera();
|
||||
|
@ -214,7 +221,7 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
bool initDefault();
|
||||
bool initPerspective(float fieldOfView, float aspectRatio, float nearPlane, float farPlane);
|
||||
bool initOrthographic(float zoomX, float zoomY, float nearPlane, float farPlane);
|
||||
|
||||
void applyFrameBufferObject();
|
||||
protected:
|
||||
|
||||
Scene* _scene; //Scene camera belongs to
|
||||
|
@ -233,10 +240,12 @@ protected:
|
|||
unsigned short _cameraFlag; // camera flag
|
||||
mutable Frustum _frustum; // camera frustum
|
||||
mutable bool _frustumDirty;
|
||||
int _depth; //camera depth, the depth of camera with CameraFlag::DEFAULT flag is 0 by default, a camera with larger depth is drawn on top of camera with smaller detph
|
||||
int8_t _depth; //camera depth, the depth of camera with CameraFlag::DEFAULT flag is 0 by default, a camera with larger depth is drawn on top of camera with smaller detph
|
||||
static Camera* _visitingCamera;
|
||||
|
||||
friend class Director;
|
||||
|
||||
FrameBufferObject* _fbo;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -31,6 +31,7 @@ THE SOFTWARE.
|
|||
#include "base/CCEventDispatcher.h"
|
||||
#include "base/CCEventListenerCustom.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCFrameBufferObject.h"
|
||||
#include "deprecated/CCString.h"
|
||||
|
||||
#if CC_USE_PHYSICS
|
||||
|
@ -136,7 +137,7 @@ void Scene::onProjectionChanged(EventCustom* event)
|
|||
|
||||
static bool camera_cmp(const Camera* a, const Camera* b)
|
||||
{
|
||||
return a->getDepth() < b->getDepth();
|
||||
return a->getRenderOrder() < b->getRenderOrder();
|
||||
}
|
||||
|
||||
void Scene::render(Renderer* renderer)
|
||||
|
@ -163,7 +164,7 @@ void Scene::render(Renderer* renderer)
|
|||
|
||||
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
|
||||
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix());
|
||||
|
||||
camera->applyFrameBufferObject();
|
||||
//clear background with max depth
|
||||
camera->clearBackground(1.0);
|
||||
//visit the scene
|
||||
|
@ -186,6 +187,7 @@ void Scene::render(Renderer* renderer)
|
|||
#endif
|
||||
|
||||
Camera::_visitingCamera = nullptr;
|
||||
FrameBufferObject::applyDefaultFBO();
|
||||
}
|
||||
|
||||
void Scene::removeAllChildren()
|
||||
|
|
|
@ -593,6 +593,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
|
|||
<ClCompile Include="..\platform\win32\CCStdC-win32.cpp" />
|
||||
<ClCompile Include="..\renderer\CCBatchCommand.cpp" />
|
||||
<ClCompile Include="..\renderer\CCCustomCommand.cpp" />
|
||||
<ClCompile Include="..\renderer\CCFrameBufferObject.cpp" />
|
||||
<ClCompile Include="..\renderer\CCGLProgram.cpp" />
|
||||
<ClCompile Include="..\renderer\CCGLProgramCache.cpp" />
|
||||
<ClCompile Include="..\renderer\CCGLProgramState.cpp" />
|
||||
|
@ -1190,6 +1191,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
|
|||
<ClInclude Include="..\platform\win32\compat\stdint.h" />
|
||||
<ClInclude Include="..\renderer\CCBatchCommand.h" />
|
||||
<ClInclude Include="..\renderer\CCCustomCommand.h" />
|
||||
<ClInclude Include="..\renderer\CCFrameBufferObject.h" />
|
||||
<ClInclude Include="..\renderer\CCGLProgram.h" />
|
||||
<ClInclude Include="..\renderer\CCGLProgramCache.h" />
|
||||
<ClInclude Include="..\renderer\CCGLProgramState.h" />
|
||||
|
|
|
@ -1872,8 +1872,8 @@
|
|||
<ClCompile Include="..\renderer\CCVertexAttribBinding.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\base\CCNinePatchImageParser.cpp">
|
||||
<Filter>base</Filter>
|
||||
<ClCompile Include="..\renderer\CCFrameBufferObject.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -3665,8 +3665,8 @@
|
|||
<ClInclude Include="..\renderer\CCVertexAttribBinding.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\base\CCNinePatchImageParser.h">
|
||||
<Filter>base</Filter>
|
||||
<ClInclude Include="..\renderer\CCFrameBufferObject.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -495,6 +495,7 @@
|
|||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\winrt\WICImageLoader-winrt.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCBatchCommand.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCCustomCommand.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCFrameBufferObject.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCGLProgram.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCGLProgramCache.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCGLProgramState.h" />
|
||||
|
@ -1077,6 +1078,7 @@
|
|||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\winrt\WICImageLoader-winrt.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCBatchCommand.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCCustomCommand.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCFrameBufferObject.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCGLProgram.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCGLProgramCache.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCGLProgramState.cpp" />
|
||||
|
|
|
@ -1791,41 +1791,8 @@
|
|||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCVertexAttribBinding.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3D.h">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DComponent.h">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DConstraint.h">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DDebugDrawer.h">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DObject.h">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DShape.h">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DWorld.h">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysicsSprite3D.h">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\include\AudioEngine.h">
|
||||
<Filter>audioengine</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\winrt\AudioCachePlayer.h">
|
||||
<Filter>audioengine</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\winrt\AudioEngine-winrt.h">
|
||||
<Filter>audioengine</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\winrt\AudioSourceReader.h">
|
||||
<Filter>audioengine</Filter>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCFrameBufferObject.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCNinePatchImageParser.h" />
|
||||
</ItemGroup>
|
||||
|
@ -2813,6 +2780,9 @@
|
|||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\ccTypes.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCUserDefault.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\ccUTF8.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
|
@ -3439,44 +3409,8 @@
|
|||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCVertexAttribBinding.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\AudioEngine.cpp">
|
||||
<Filter>audioengine</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\winrt\AudioCachePlayer.cpp">
|
||||
<Filter>audioengine</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\winrt\AudioEngine-winrt.cpp">
|
||||
<Filter>audioengine</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\winrt\AudioSourceReader.cpp">
|
||||
<Filter>audioengine</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3D.cpp">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DComponent.cpp">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DConstraint.cpp">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DDebugDrawer.cpp">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DObject.cpp">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DShape.cpp">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DWorld.cpp">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysicsSprite3D.cpp">
|
||||
<Filter>physics3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCUserDefault-winrt.cpp">
|
||||
<Filter>base</Filter>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCFrameBufferObject.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCNinePatchImageParser.cpp" />
|
||||
</ItemGroup>
|
||||
|
@ -3736,12 +3670,6 @@
|
|||
<Filter Include="external\poly2tri\sweep">
|
||||
<UniqueIdentifier>{932c5f6e-07b3-4b34-97ae-2f3d42024149}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="audioengine">
|
||||
<UniqueIdentifier>{bd1a6214-d6e0-4341-a1fc-79da99b55e35}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="physics3d">
|
||||
<UniqueIdentifier>{e6f8ab69-f66f-48be-a40f-e33c08e77516}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="$(MSBuildThisFileDirectory)..\..\..\cocos2d.def" />
|
||||
|
@ -3857,9 +3785,4 @@
|
|||
<Filter>3d</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CMakeLists.txt">
|
||||
<Filter>physics3d</Filter>
|
||||
</Text>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -183,6 +183,7 @@ renderer/CCVertexAttribBinding.cpp \
|
|||
renderer/CCVertexIndexBuffer.cpp \
|
||||
renderer/CCVertexIndexData.cpp \
|
||||
renderer/ccGLStateCache.cpp \
|
||||
renderer/CCFrameBufferObject.cpp \
|
||||
renderer/ccShaders.cpp \
|
||||
deprecated/CCArray.cpp \
|
||||
deprecated/CCDeprecated.cpp \
|
||||
|
|
|
@ -48,6 +48,7 @@ THE SOFTWARE.
|
|||
#include "renderer/ccGLStateCache.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCRenderState.h"
|
||||
#include "renderer/CCFrameBufferObject.h"
|
||||
#include "2d/CCCamera.h"
|
||||
#include "base/CCUserDefault.h"
|
||||
#include "base/ccFPSImages.h"
|
||||
|
@ -278,7 +279,7 @@ void Director::drawScene()
|
|||
}
|
||||
|
||||
_renderer->clear();
|
||||
|
||||
FrameBufferObject::clearAllFBOs();
|
||||
/* to avoid flickr, nextScene MUST be here: after tick and before draw.
|
||||
* FIXME: Which bug is this one. It seems that it can't be reproduced with v0.9
|
||||
*/
|
||||
|
@ -415,6 +416,8 @@ void Director::setOpenGLView(GLView *openGLView)
|
|||
{
|
||||
_eventDispatcher->setEnabled(true);
|
||||
}
|
||||
|
||||
FrameBufferObject::initDefaultFBO();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -167,6 +167,14 @@ THE SOFTWARE.
|
|||
#include "renderer/CCVertexAttribBinding.h"
|
||||
#include "renderer/CCVertexIndexBuffer.h"
|
||||
#include "renderer/CCVertexIndexData.h"
|
||||
#include "renderer/CCPrimitive.h"
|
||||
#include "renderer/CCPrimitiveCommand.h"
|
||||
#include "renderer/CCTrianglesCommand.h"
|
||||
#include "renderer/CCMaterial.h"
|
||||
#include "renderer/CCTechnique.h"
|
||||
#include "renderer/CCPass.h"
|
||||
#include "renderer/CCRenderState.h"
|
||||
#include "renderer/CCFrameBufferObject.h"
|
||||
#include "renderer/ccGLStateCache.h"
|
||||
#include "renderer/ccShaders.h"
|
||||
|
||||
|
|
|
@ -0,0 +1,350 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2015 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "renderer/CCFrameBufferObject.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "base/CCEventCustom.h"
|
||||
#include "base/CCEventListenerCustom.h"
|
||||
#include "base/CCEventDispatcher.h"
|
||||
#include "base/CCEventType.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
GLuint FrameBufferObject::_defaultFBO(0);
|
||||
std::set<FrameBufferObject*> FrameBufferObject::_frameBufferObjects;
|
||||
|
||||
RenderTargetBase::RenderTargetBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RenderTargetBase::~RenderTargetBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool RenderTargetBase::init(unsigned int width, unsigned int height)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
RenderTarget* RenderTarget::create(unsigned int width, unsigned int height, Texture2D::PixelFormat format/* = Texture2D::PixelFormat::RGBA8888*/)
|
||||
{
|
||||
auto result = new (std::nothrow) RenderTarget();
|
||||
if(result && result->init(width, height,format))
|
||||
{
|
||||
result->autorelease();
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(result);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderTarget::init(unsigned int width, unsigned int height, Texture2D::PixelFormat format)
|
||||
{
|
||||
if(!RenderTargetBase::init(width, height))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_texture = new (std::nothrow) Texture2D();
|
||||
if(nullptr == _texture) return false;
|
||||
//TODO: FIX me, get the correct bit depth for pixelformat
|
||||
auto dataLen = width * height * 4;
|
||||
auto data = malloc(dataLen);
|
||||
if( nullptr == data) return false;
|
||||
|
||||
memset(data, 0, dataLen);
|
||||
if(_texture->initWithData(data, dataLen, format, width, height, Size(width, height)))
|
||||
{
|
||||
_texture->autorelease();
|
||||
CC_SAFE_RETAIN(_texture);
|
||||
free(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(_texture);
|
||||
free(data);
|
||||
return false;
|
||||
}
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
_rebuildTextureListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom* event){
|
||||
auto dataLen = _width * _height * 4;
|
||||
auto data = malloc(dataLen);
|
||||
_texture->initWithData(data, dataLen,_texture->getPixelFormat(), _width, _height, Size(_width, _height));
|
||||
free(data);
|
||||
CCLOG("RenderTarget Texture recreated is %d", _texture->getName());
|
||||
});
|
||||
|
||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_rebuildTextureListener, -1);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
RenderTarget::RenderTarget()
|
||||
: _texture(nullptr)
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
, _rebuildTextureListener(nullptr)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
RenderTarget::~RenderTarget()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_texture);
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
Director::getInstance()->getEventDispatcher()->removeEventListener(_rebuildTextureListener);
|
||||
#endif
|
||||
}
|
||||
|
||||
RenderTargetDepthStencil::RenderTargetDepthStencil()
|
||||
: _depthStencilBuffer(0)
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
, _reBuildDepthStencilListener(nullptr)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
RenderTargetDepthStencil::~RenderTargetDepthStencil()
|
||||
{
|
||||
if(glIsRenderbuffer(_depthStencilBuffer))
|
||||
{
|
||||
glDeleteRenderbuffers(1, &_depthStencilBuffer);
|
||||
_depthStencilBuffer = 0;
|
||||
}
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
Director::getInstance()->getEventDispatcher()->removeEventListener(_reBuildDepthStencilListener);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RenderTargetDepthStencil::init(unsigned int width, unsigned int height)
|
||||
{
|
||||
if(!RenderTargetBase::init(width, height)) return false;
|
||||
GLint oldRenderBuffer(0);
|
||||
glGetIntegerv(GL_RENDERBUFFER_BINDING, &oldRenderBuffer);
|
||||
|
||||
//generate depthStencil
|
||||
glGenRenderbuffers(1, &_depthStencilBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, _depthStencilBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, oldRenderBuffer);
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
_reBuildDepthStencilListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom* event){
|
||||
/** listen the event that renderer was recreated on Android/WP8 */
|
||||
GLint oldRenderBuffer(0);
|
||||
glGetIntegerv(GL_RENDERBUFFER_BINDING, &oldRenderBuffer);
|
||||
|
||||
glGenRenderbuffers(1, &_depthStencilBuffer);
|
||||
//generate depthStencil
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, _depthStencilBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, _width, _height);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, oldRenderBuffer);
|
||||
CCLOG("RenderTargetDepthStencil recreated, _depthStencilBuffer is %d", _depthStencilBuffer);
|
||||
});
|
||||
|
||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_reBuildDepthStencilListener, -1);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
RenderTargetDepthStencil* RenderTargetDepthStencil::create(unsigned int width, unsigned int height)
|
||||
{
|
||||
auto result = new (std::nothrow) RenderTargetDepthStencil();
|
||||
|
||||
if(result && result->init(width, height))
|
||||
{
|
||||
result->autorelease();
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(result);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void FrameBufferObject::initDefaultFBO()
|
||||
{
|
||||
GLint fbo;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
|
||||
_defaultFBO = fbo;
|
||||
}
|
||||
|
||||
void FrameBufferObject::applyDefaultFBO()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _defaultFBO);
|
||||
}
|
||||
|
||||
void FrameBufferObject::clearAllFBOs()
|
||||
{
|
||||
for (auto fbo : _frameBufferObjects)
|
||||
{
|
||||
fbo->clearFBO();
|
||||
}
|
||||
}
|
||||
|
||||
FrameBufferObject* FrameBufferObject::create(uint8_t fid, unsigned int width, unsigned int height)
|
||||
{
|
||||
auto result = new (std::nothrow) FrameBufferObject();
|
||||
if(result && result->init(fid, width, height))
|
||||
{
|
||||
result->autorelease();
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(result);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool FrameBufferObject::init(uint8_t fid, unsigned int width, unsigned int height)
|
||||
{
|
||||
_fid = fid;
|
||||
_width = width;
|
||||
_height = height;
|
||||
|
||||
GLint oldfbo;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldfbo);
|
||||
|
||||
glGenFramebuffers(1, &_fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, oldfbo);
|
||||
|
||||
// _rt = RenderTarget::create(width, height);
|
||||
// if(nullptr == _rt) return false;
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
_dirtyFBOListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom* event){
|
||||
GLint oldfbo;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldfbo);
|
||||
|
||||
glGenFramebuffers(1, &_fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, oldfbo);
|
||||
CCLOG("Recreate FrameBufferObject _fbo is %d", _fbo);
|
||||
_fboBindingDirty = true;
|
||||
});
|
||||
|
||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_dirtyFBOListener, -1);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
FrameBufferObject::FrameBufferObject()
|
||||
: _clearColor(Color4F(0, 0, 0, 1))
|
||||
, _clearDepth(1.0)
|
||||
, _clearStencil(0)
|
||||
, _fbo(0)
|
||||
, _rt(nullptr)
|
||||
, _rtDepthStencil(nullptr)
|
||||
, _fboBindingDirty(true)
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
, _dirtyFBOListener(nullptr)
|
||||
#endif
|
||||
{
|
||||
_frameBufferObjects.insert(this);
|
||||
}
|
||||
|
||||
FrameBufferObject::~FrameBufferObject()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_rt);
|
||||
CC_SAFE_RELEASE_NULL(_rtDepthStencil);
|
||||
glDeleteFramebuffers(1, &_fbo);
|
||||
_fbo = 0;
|
||||
_frameBufferObjects.erase(this);
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
Director::getInstance()->getEventDispatcher()->removeEventListener(_dirtyFBOListener);
|
||||
#endif
|
||||
}
|
||||
|
||||
void FrameBufferObject::clearFBO()
|
||||
{
|
||||
applyFBO();
|
||||
glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a);
|
||||
glClearDepth(_clearDepth);
|
||||
glClearStencil(_clearStencil);
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
|
||||
applyDefaultFBO();
|
||||
}
|
||||
|
||||
void FrameBufferObject::AttachRenderTarget(RenderTarget* rt)
|
||||
{
|
||||
CC_ASSERT(rt);
|
||||
if(rt->getWidth() != _width || rt->getHeight() != _height)
|
||||
{
|
||||
CCLOG("Error, attach a render target with different size, Skip.");
|
||||
return;
|
||||
}
|
||||
CC_SAFE_RETAIN(rt);
|
||||
CC_SAFE_RELEASE(_rt);
|
||||
_rt = rt;
|
||||
_fboBindingDirty = true;
|
||||
}
|
||||
|
||||
void FrameBufferObject::applyFBO()
|
||||
{
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
if(_fboBindingDirty)
|
||||
{
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _rt->getTexture()->getName(), 0);
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, nullptr == _rtDepthStencil ? 0 : _rtDepthStencil->getDepthStencilBuffer());
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, nullptr == _rtDepthStencil ? 0 : _rtDepthStencil->getDepthStencilBuffer());
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CCLOG("FBO is %d _fbo %d color, %d ds", _fbo, _rt->getTexture()->getName(), _rtDepthStencil->getDepthStencilBuffer());
|
||||
_fboBindingDirty = false;
|
||||
}
|
||||
if(GL_FRAMEBUFFER_COMPLETE != glCheckFramebufferStatus(GL_FRAMEBUFFER))
|
||||
{
|
||||
CCLOG("FrameBuffer Status Error %d", (int)glCheckFramebufferStatus(GL_FRAMEBUFFER));
|
||||
}
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
}
|
||||
|
||||
void FrameBufferObject::AttachDepthStencilTarget(RenderTargetDepthStencil* rt)
|
||||
{
|
||||
if(nullptr != rt && (rt->getWidth() != _width || rt->getHeight() != _height))
|
||||
{
|
||||
CCLOG("Error, attach a render target Depth stencil with different size, Skip.");
|
||||
return;
|
||||
}
|
||||
CC_SAFE_RETAIN(rt);
|
||||
CC_SAFE_RELEASE(_rtDepthStencil);
|
||||
_rtDepthStencil = rt;
|
||||
_fboBindingDirty = true;
|
||||
}
|
||||
NS_CC_END
|
|
@ -0,0 +1,152 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2015 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_FRAME_BUFFER_H__
|
||||
#define __CC_FRAME_BUFFER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "platform/CCGL.h"
|
||||
#include "renderer/CCTexture2D.h"
|
||||
#include <set>
|
||||
|
||||
NS_CC_BEGIN
|
||||
class EventListenerCustom;
|
||||
|
||||
class RenderTargetBase : public Ref
|
||||
{
|
||||
protected:
|
||||
RenderTargetBase();
|
||||
virtual ~RenderTargetBase();
|
||||
bool init(unsigned int width, unsigned int height);
|
||||
|
||||
public:
|
||||
unsigned int getWidth() const { return _width; }
|
||||
unsigned int getHeight() const { return _height; }
|
||||
|
||||
protected:
|
||||
unsigned int _width;
|
||||
unsigned int _height;
|
||||
|
||||
};
|
||||
|
||||
class RenderTarget : public RenderTargetBase
|
||||
{
|
||||
public:
|
||||
|
||||
static RenderTarget* create(unsigned int width, unsigned int height, Texture2D::PixelFormat format = Texture2D::PixelFormat::RGBA8888);
|
||||
|
||||
bool init(unsigned int width, unsigned int height, Texture2D::PixelFormat format);
|
||||
|
||||
Texture2D* getTexture() const { return _texture; }
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
RenderTarget();
|
||||
virtual ~RenderTarget();
|
||||
|
||||
protected:
|
||||
Texture2D* _texture;
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
EventListenerCustom* _rebuildTextureListener;
|
||||
#endif
|
||||
};
|
||||
|
||||
class RenderTargetDepthStencil : public RenderTargetBase
|
||||
{
|
||||
public:
|
||||
|
||||
static RenderTargetDepthStencil* create(unsigned int width, unsigned int height);
|
||||
|
||||
bool init(unsigned int width, unsigned int height);
|
||||
|
||||
GLuint getDepthStencilBuffer() const { return _depthStencilBuffer; }
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
RenderTargetDepthStencil();
|
||||
virtual ~RenderTargetDepthStencil();
|
||||
|
||||
protected:
|
||||
|
||||
GLuint _depthStencilBuffer;
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
EventListenerCustom* _reBuildDepthStencilListener;
|
||||
#endif
|
||||
};
|
||||
|
||||
class CC_DLL FrameBufferObject : public Ref
|
||||
{
|
||||
public:
|
||||
static FrameBufferObject* create(uint8_t fid, unsigned int width, unsigned int height);
|
||||
|
||||
bool init(uint8_t fid, unsigned int width, unsigned int height);
|
||||
public:
|
||||
GLuint getFBO() const { return _fbo; }
|
||||
GLuint getFID() const { return _fid; }
|
||||
//call glclear to clear frame buffer object
|
||||
void clearFBO();
|
||||
void applyFBO();
|
||||
void setClearColor(const Color4F& color) { _clearColor = color;}
|
||||
void setClearDepth(float depth) { _clearDepth = depth; }
|
||||
void setClearStencil(int8_t stencil) { _clearStencil = stencil; }
|
||||
const Color4F& getClearColor() const { return _clearColor; }
|
||||
float getClearDepth() const { return _clearDepth; }
|
||||
int8_t getClearStencil() const { return _clearStencil; }
|
||||
|
||||
RenderTarget* getRenderTarget() const { return _rt; }
|
||||
RenderTargetDepthStencil* getDepthStencilTarget() const { return _rtDepthStencil; }
|
||||
void AttachRenderTarget(RenderTarget* rt);
|
||||
void AttachDepthStencilTarget(RenderTargetDepthStencil* rt);
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
FrameBufferObject();
|
||||
virtual ~FrameBufferObject();
|
||||
private:
|
||||
//openGL content for FrameBuffer
|
||||
GLuint _fbo;
|
||||
//dirty flag for fbo binding
|
||||
bool _fboBindingDirty;
|
||||
//
|
||||
uint8_t _fid;
|
||||
//
|
||||
Color4F _clearColor;
|
||||
float _clearDepth;
|
||||
int8_t _clearStencil;
|
||||
int _width;
|
||||
int _height;
|
||||
RenderTarget* _rt;
|
||||
RenderTargetDepthStencil* _rtDepthStencil;
|
||||
public:
|
||||
static void initDefaultFBO();
|
||||
static void applyDefaultFBO();
|
||||
static void clearAllFBOs();
|
||||
private:
|
||||
static GLuint _defaultFBO;
|
||||
static std::set<FrameBufferObject*> _frameBufferObjects;
|
||||
|
||||
private:
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
EventListenerCustom* _dirtyFBOListener;
|
||||
#endif
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(__CC_FRAME_BUFFER_H__) */
|
|
@ -693,6 +693,7 @@ void Renderer::clear()
|
|||
{
|
||||
//Enable Depth mask to make sure glClear clear the depth buffer correctly
|
||||
glDepthMask(true);
|
||||
glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glDepthMask(false);
|
||||
|
||||
|
@ -1060,7 +1061,6 @@ bool Renderer::checkVisibility(const Mat4 &transform, const Size &size)
|
|||
void Renderer::setClearColor(const Color4F &clearColor)
|
||||
{
|
||||
_clearColor = clearColor;
|
||||
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -26,4 +26,5 @@ set(COCOS_RENDERER_SRC
|
|||
renderer/CCVertexIndexData.cpp
|
||||
renderer/ccGLStateCache.cpp
|
||||
renderer/ccShaders.cpp
|
||||
renderer/CCFrameBufferObject.cpp
|
||||
)
|
||||
|
|
|
@ -24,6 +24,7 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
|
||||
#include "Camera3DTest.h"
|
||||
#include "testResource.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
|
@ -41,6 +42,7 @@ Camera3DTests::Camera3DTests()
|
|||
ADD_TEST_CASE(CameraCullingDemo);
|
||||
ADD_TEST_CASE(FogTestDemo);
|
||||
ADD_TEST_CASE(CameraArcBallDemo);
|
||||
ADD_TEST_CASE(CameraFrameBufferObjectTest);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -1410,3 +1412,69 @@ void FogTestDemo::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Ev
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
CameraFrameBufferObjectTest::CameraFrameBufferObjectTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CameraFrameBufferObjectTest::~CameraFrameBufferObjectTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string CameraFrameBufferObjectTest::title() const
|
||||
{
|
||||
return "Camera FrameBuffer Object Test";
|
||||
}
|
||||
|
||||
void CameraFrameBufferObjectTest::onEnter()
|
||||
{
|
||||
auto sizeInpixels = Director::getInstance()->getWinSizeInPixels();
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
auto fboSize = Size(sizeInpixels.width * 1, sizeInpixels.height * 1.5);
|
||||
auto fbo = FrameBufferObject::create(1, fboSize.width, fboSize.height);
|
||||
|
||||
CameraBaseTest::onEnter();
|
||||
//auto sprite = Sprite::createWithTexture(fbo);
|
||||
//sprite->setPosition(Vec2(100,100));
|
||||
//std::string filename = "Sprite3DTest/girl.c3b";
|
||||
//auto sprite = Sprite3D::create(filename);
|
||||
//sprite->setScale(1.0);
|
||||
//auto animation = Animation3D::create(filename);
|
||||
//if (animation)
|
||||
//{
|
||||
// auto animate = Animate3D::create(animation);
|
||||
|
||||
// sprite->runAction(RepeatForever::create(animate));
|
||||
//}
|
||||
//sprite->setPosition(Vec2(100,100));
|
||||
auto rt = RenderTarget::create(fboSize.width, fboSize.height);
|
||||
auto rtDS = RenderTargetDepthStencil::create(fboSize.width, fboSize.height);
|
||||
fbo->AttachRenderTarget(rt);
|
||||
fbo->AttachDepthStencilTarget(rtDS);
|
||||
auto sprite = Sprite::createWithTexture(fbo->getRenderTarget()->getTexture());
|
||||
sprite->setScale(0.3);
|
||||
sprite->runAction(RepeatForever::create(RotateBy::create(1, 90)));
|
||||
sprite->setPosition(size.width/2, size.height/2);
|
||||
addChild(sprite);
|
||||
|
||||
auto sprite2 = Sprite::create(s_pathGrossini);
|
||||
sprite2->setPosition(Vec2(size.width/5,size.height/5));
|
||||
addChild(sprite2);
|
||||
sprite2->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
auto move = MoveBy::create(1.0, Vec2(100,100));
|
||||
sprite2->runAction(
|
||||
RepeatForever::create(
|
||||
Sequence::createWithTwoActions(
|
||||
move, move->reverse())
|
||||
)
|
||||
);
|
||||
|
||||
auto camera = Camera::create();
|
||||
camera->setCameraFlag(CameraFlag::USER1);
|
||||
camera->setDepth(-1);
|
||||
camera->setFrameBufferObject(fbo);
|
||||
fbo->setClearColor(Color4F(1,1,1,1));
|
||||
addChild(camera);
|
||||
}
|
||||
|
|
|
@ -255,5 +255,16 @@ protected:
|
|||
#endif
|
||||
};
|
||||
|
||||
class CameraFrameBufferObjectTest : public CameraBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(CameraFrameBufferObjectTest);
|
||||
CameraFrameBufferObjectTest(void);
|
||||
virtual ~CameraFrameBufferObjectTest(void);
|
||||
// overrides
|
||||
virtual std::string title() const override;
|
||||
|
||||
virtual void onEnter() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue