Skip to content

Commit 8fea223

Browse files
committed
Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (cocos2d#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h
1 parent 387b9d6 commit 8fea223

17 files changed

+319
-260
lines changed

build/cocos2d_libs.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -2992,6 +2992,9 @@
29922992
ED5C8CBC21C0B3C100F280A7 /* label_distanceFieldGlow.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = label_distanceFieldGlow.frag; sourceTree = "<group>"; };
29932993
ED5C8CBD21C0B5B700F280A7 /* positionColor.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = positionColor.frag; sourceTree = "<group>"; };
29942994
ED5C8CBE21C0B5B800F280A7 /* positionColor.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = positionColor.vert; sourceTree = "<group>"; };
2995+
ED5C8CBF21C0BB3200F280A7 /* positionColorTextureAsPointsize.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = positionColorTextureAsPointsize.vert; sourceTree = "<group>"; };
2996+
ED5C8CC021C0BB3200F280A7 /* positionColorLengthTexture.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = positionColorLengthTexture.frag; sourceTree = "<group>"; };
2997+
ED5C8CC121C0BB3300F280A7 /* positionColorLengthTexture.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = positionColorLengthTexture.vert; sourceTree = "<group>"; };
29952998
ED682BB9213F5FC6001BF6CB /* libuv_a.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libuv_a.a; path = ../external/uv/prebuilt/mac/libuv_a.a; sourceTree = "<group>"; };
29962999
ED682BC0213F63CB001BF6CB /* libuv_a.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libuv_a.a; path = ../external/uv/prebuilt/ios/libuv_a.a; sourceTree = "<group>"; };
29973000
ED682BC2213F6C7A001BF6CB /* libwebsockets.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libwebsockets.a; path = ../external/websockets/prebuilt/tvos/libwebsockets.a; sourceTree = "<group>"; };
@@ -4011,6 +4014,9 @@
40114014
EDF9D8A621AE9678004374AB /* positionTextureColor.vert */,
40124015
ED5C8CBD21C0B5B700F280A7 /* positionColor.frag */,
40134016
ED5C8CBE21C0B5B800F280A7 /* positionColor.vert */,
4017+
ED5C8CC021C0BB3200F280A7 /* positionColorLengthTexture.frag */,
4018+
ED5C8CC121C0BB3300F280A7 /* positionColorLengthTexture.vert */,
4019+
ED5C8CBF21C0BB3200F280A7 /* positionColorTextureAsPointsize.vert */,
40144020
);
40154021
path = shaders;
40164022
sourceTree = "<group>";

cocos/2d/CCDrawNode.cpp

+133-242
Large diffs are not rendered by default.

cocos/2d/CCDrawNode.h

+4-14
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,6 @@ class CC_DLL DrawNode : public Node
286286
* @lua NA
287287
*/
288288
void setBlendFunc(const BlendFunc &blendFunc);
289-
290-
/**
291-
* @js NA
292-
*/
293-
virtual void onDraw(const Mat4 &transform, uint32_t flags);
294-
/**
295-
* @js NA
296-
*/
297-
virtual void onDrawGLLine(const Mat4 &transform, uint32_t flags);
298-
/**
299-
* @js NA
300-
*/
301-
virtual void onDrawGLPoint(const Mat4 &transform, uint32_t flags);
302289

303290
// Overrides
304291
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
@@ -328,7 +315,10 @@ class CC_DLL DrawNode : public Node
328315
void ensureCapacityGLPoint(int count);
329316
void ensureCapacityGLLine(int count);
330317

331-
void setupBuffer();
318+
void updateShader();
319+
void setVertexLayout(CustomCommand& cmd);
320+
void updateBlendState(CustomCommand& cmd);
321+
void updateUniforms(const Mat4 &transform, CustomCommand& cmd);
332322

333323
GLuint _vao = 0;
334324
GLuint _vbo = 0;

cocos/2d/CCLabel.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@
4444
#include "base/CCEventCustom.h"
4545
#include "base/ccUtils.h"
4646
#include "2d/CCFontFNT.h"
47-
#include "renderer/backend/Device.h"
4847
#include "renderer/ccShaders.h"
4948
#include "renderer/backend/ShaderModule.h"
5049
#include "renderer/CCShaderCache.h"
51-
#include "renderer/backend/Buffer.h"
5250

5351
NS_CC_BEGIN
5452
/**

cocos/renderer/CCCustomCommand.h

+6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class CC_DLL CustomCommand : public RenderCommand
9393
inline backend::Buffer* getIndexBuffer() const { assert(_indexBuffer); return _indexBuffer; }
9494
inline size_t getIndexCount() const { return _indexCount; }
9595
inline size_t getVertexCount() const { return _vertexCount; }
96+
inline void setVertexCount(size_t count) { _vertexCount = count; }
9697

9798
inline void setVertexDrawInfo(size_t vertexStart, size_t count) { _vertexStart = vertexStart; _vertexDrawCount = count; }
9899
inline size_t getVertexDrawStart() const { return _vertexStart; }
@@ -108,6 +109,9 @@ class CC_DLL CustomCommand : public RenderCommand
108109
// void execute();
109110
// /**Callback function.*/
110111
std::function<void()> func;
112+
113+
inline void setLineWidth(float_t lineWidth) { _lineWidth = lineWidth; }
114+
inline float_t getLineWidth() const { return _lineWidth; }
111115

112116
protected:
113117
backend::Buffer* _vertexBuffer = nullptr;
@@ -123,6 +127,8 @@ class CC_DLL CustomCommand : public RenderCommand
123127

124128
DrawType _drawType = DrawType::ELEMENT;
125129
PrimitiveType _primitiveType = PrimitiveType::TRIANGLE;
130+
131+
float_t _lineWidth = 0.0;
126132
};
127133

128134
NS_CC_END

cocos/renderer/CCRenderer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ void Renderer::drawCustomCommand(RenderCommand *command)
562562
_commandBuffer->setBindGroup( &(cmd->getPipelineDescriptor().bindGroup) );
563563

564564
auto drawType = cmd->getDrawType();
565+
_commandBuffer->setLineWidth(cmd->getLineWidth());
565566
if (CustomCommand::DrawType::ELEMENT == drawType)
566567
{
567568
_commandBuffer->setIndexBuffer(cmd->getIndexBuffer());

cocos/renderer/backend/CommandBuffer.h

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class CommandBuffer : public cocos2d::Ref
3131
virtual void endRenderPass() = 0;
3232
virtual void endFrame() = 0;
3333

34+
virtual void setLineWidth(float_t lineWidth) = 0;
35+
3436
void setStencilReferenceValue(uint32_t value);
3537
void setStencilReferenceValue(uint32_t frontRef, uint32_t backRef);
3638

cocos/renderer/backend/metal/CommandBufferMTL.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class CommandBufferMTL : public CommandBuffer
2626
virtual void endRenderPass() override;
2727
virtual void endFrame() override;
2828

29+
virtual void setLineWidth(float_t lineWidth) override;
30+
2931
private:
3032
void prepareDrawing() const;
3133
void setTextures() const;

cocos/renderer/backend/metal/CommandBufferMTL.mm

+4
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,8 @@ MTLCullMode toMTLCullMode(CullMode mode)
353353
return offset;
354354
}
355355

356+
void CommandBufferMTL::setLineWidth(float_t lineWidth)
357+
{
358+
}
359+
356360
CC_BACKEND_END

cocos/renderer/backend/opengl/BufferGL.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void BufferGL::updateData(void* data, size_t offset, size_t size)
2929
}
3030
else
3131
{
32-
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
32+
glBufferData(GL_ARRAY_BUFFER, _size, data, GL_STATIC_DRAW);
3333
}
3434
}
3535
else
@@ -41,7 +41,7 @@ void BufferGL::updateData(void* data, size_t offset, size_t size)
4141
}
4242
else
4343
{
44-
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
44+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _size, data, GL_STATIC_DRAW);
4545
}
4646
}
4747
}

cocos/renderer/backend/opengl/CommandBufferGL.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,10 @@ void CommandBufferGL::cleanResources()
498498
_vertexBuffers.clear();
499499
}
500500

501+
void CommandBufferGL::setLineWidth(float_t lineWidth)
502+
{
503+
if(lineWidth > 0.0f)
504+
glLineWidth(lineWidth);
505+
}
506+
501507
CC_BACKEND_END

cocos/renderer/backend/opengl/CommandBufferGL.h

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class CommandBufferGL : public CommandBuffer
3232
virtual void endRenderPass() override;
3333
virtual void endFrame() override;
3434

35+
virtual void setLineWidth(float_t lineWidth) override;
36+
3537
private:
3638
struct Viewport
3739
{

cocos/renderer/ccShaders.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,8 @@ NS_CC_BEGIN
110110
#include "renderer/shaders/label_distanceNormal.frag"
111111
#include "renderer/shaders/label_outline.frag"
112112
#include "renderer/shaders/label_distanceFieldGlow.frag"
113+
#include "renderer/shaders/positionColorLengthTexture.vert"
114+
#include "renderer/shaders/positionColorLengthTexture.frag"
115+
#include "renderer/shaders/positionColorTextureAsPointsize.vert"
113116

114117
NS_CC_END

cocos/renderer/ccShaders.h

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ extern CC_DLL const GLchar * label_normal_frag;
110110
extern CC_DLL const GLchar * label_distanceNormal_frag;
111111
extern CC_DLL const GLchar * labelOutline_frag;
112112
extern CC_DLL const GLchar * labelDistanceFieldGlow_frag;
113+
extern CC_DLL const GLchar * positionColorLengthTexture_vert;
114+
extern CC_DLL const GLchar * positionColorLengthTexture_frag;
115+
extern CC_DLL const GLchar * positionColorTextureAsPointsize_vert;
113116

114117
NS_CC_END
115118
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright (c) 2012 Scott Lembcke and Howling Moon Software
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
* SOFTWARE.
20+
*/
21+
22+
const char* positionColorLengthTexture_frag = R"(
23+
24+
#ifdef GL_ES
25+
// #extension GL_OES_standard_derivatives : enable
26+
27+
varying mediump vec4 v_color;
28+
varying mediump vec2 v_texcoord;
29+
#else
30+
varying vec4 v_color;
31+
varying vec2 v_texcoord;
32+
#endif
33+
34+
void main()
35+
{
36+
// #if defined GL_OES_standard_derivatives
37+
// gl_FragColor = v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0 - length(v_texcoord));
38+
// #else
39+
gl_FragColor = v_color*step(0.0, 1.0 - length(v_texcoord));
40+
// #endif
41+
}
42+
)";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* Copyright (c) 2012 Scott Lembcke and Howling Moon Software
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
* SOFTWARE.
20+
*/
21+
22+
const char* positionColorLengthTexture_vert = R"(
23+
24+
#ifdef GL_ES
25+
precision lowp float;
26+
#endif
27+
28+
#ifdef GL_ES
29+
attribute mediump vec4 a_position;
30+
attribute mediump vec2 a_texCoord;
31+
attribute mediump vec4 a_color;
32+
33+
varying mediump vec4 v_color;
34+
varying mediump vec2 v_texcoord;
35+
36+
#else
37+
38+
attribute vec4 a_position;
39+
attribute vec2 a_texCoord;
40+
attribute vec4 a_color;
41+
42+
varying vec4 v_color;
43+
varying vec2 v_texcoord;
44+
45+
#endif
46+
47+
uniform float u_alpha;
48+
uniform mat4 u_MVPMatrix;
49+
50+
void main()
51+
{
52+
v_color = vec4(a_color.rgb * a_color.a * u_alpha, a_color.a * u_alpha);
53+
v_texcoord = a_texCoord;
54+
55+
gl_Position = u_MVPMatrix * a_position;
56+
}
57+
)";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2013-2017 Chukong Technologies Inc.
3+
*
4+
* http://www.cocos2d-x.org
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
const char* positionColorTextureAsPointsize_vert = R"(
26+
27+
attribute vec4 a_position;
28+
attribute vec4 a_color;
29+
30+
attribute vec2 a_texCoord;
31+
32+
#ifdef GL_ES
33+
varying lowp vec4 v_fragmentColor;
34+
#else
35+
varying vec4 v_fragmentColor;
36+
#endif
37+
uniform float u_alpha;
38+
uniform mat4 u_MVPMatrix;
39+
40+
void main()
41+
{
42+
gl_Position = u_MVPMatrix * a_position;
43+
gl_PointSize = a_texCoord.x;
44+
v_fragmentColor = vec4(a_color.rgb * a_color.a * u_alpha, a_color.a * u_alpha);
45+
}
46+
)";

0 commit comments

Comments
 (0)