Skip to content

Commit 95b4f4f

Browse files
committed
Issue cocos2d#1615: port CCConfiguration.js and port some class for WEBGL
1 parent 13fa42e commit 95b4f4f

File tree

9 files changed

+1439
-770
lines changed

9 files changed

+1439
-770
lines changed

cocos2d/CCConfiguration.js

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/****************************************************************************
2+
Copyright (c) 2010-2012 cocos2d-x.org
3+
Copyright (c) 2008-2010 Ricardo Quesada
4+
Copyright (c) 2011 Zynga Inc.
5+
6+
http://www.cocos2d-x.org
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in
16+
all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
THE SOFTWARE.
25+
****************************************************************************/
26+
27+
/**
28+
* cc.Configuration contains some openGL variables
29+
* @class
30+
* @extends cc.Class
31+
*/
32+
cc.Configuration = cc.Class.extend(/** @lends cc.Configuration# */{
33+
_maxTextureSize:0,
34+
_maxModelviewStackDepth:0,
35+
_supportsPVRTC:false,
36+
_supportsNPOT:false,
37+
_supportsBGRA8888:false,
38+
_supportsDiscardFramebuffer:false,
39+
_supportsShareableVAO:false,
40+
_maxSamplesAllowed:0,
41+
_maxTextureUnits:0,
42+
_GlExtensions:"",
43+
44+
/**
45+
* OpenGL Max texture size.
46+
* @return {Number}
47+
*/
48+
getMaxTextureSize:function () {
49+
return this._maxTextureSize;
50+
},
51+
52+
/**
53+
* OpenGL Max Modelview Stack Depth.
54+
* @return {Number}
55+
*/
56+
getMaxModelviewStackDepth:function () {
57+
return this._maxModelviewStackDepth;
58+
},
59+
60+
/**
61+
* returns the maximum texture units
62+
* @return {Number}
63+
*/
64+
getMaxTextureUnits:function () {
65+
return this._maxTextureUnits;
66+
},
67+
68+
/**
69+
* Whether or not the GPU supports NPOT (Non Power Of Two) textures.
70+
* OpenGL ES 2.0 already supports NPOT (iOS).
71+
* @return {Boolean}
72+
*/
73+
supportsNPOT:function () {
74+
return this._supportsNPOT;
75+
},
76+
77+
/**
78+
* Whether or not PVR Texture Compressed is supported
79+
* @return {Boolean}
80+
*/
81+
supportsPVRTC:function () {
82+
return this._supportsPVRTC;
83+
},
84+
85+
/**
86+
* Whether or not BGRA8888 textures are supported.
87+
* @return {Boolean}
88+
*/
89+
supportsBGRA8888:function () {
90+
return this._supportsBGRA8888;
91+
},
92+
93+
/**
94+
* Whether or not glDiscardFramebufferEXT is supported
95+
* @return {Boolean}
96+
*/
97+
supportsDiscardFramebuffer:function () {
98+
return this._supportsDiscardFramebuffer;
99+
},
100+
101+
/**
102+
* Whether or not shareable VAOs are supported.
103+
* @return {Boolean}
104+
*/
105+
supportsShareableVAO:function () {
106+
return this._supportsShareableVAO;
107+
},
108+
109+
/**
110+
* returns whether or not an OpenGL is supported
111+
* @param {String} searchName
112+
*/
113+
checkForGLExtension:function (searchName) {
114+
return this._GlExtensions.indexOf(searchName) > -1;
115+
},
116+
117+
init:function () {
118+
var gl = cc.webglContext;
119+
cc.log("cocos2d: GL_VENDOR: " + gl.getParameter(gl.VENDOR));
120+
cc.log("cocos2d: GL_RENDERER: " + gl.getParameter(gl.RENDERER));
121+
cc.log("cocos2d: GL_VERSION: " + gl.getParameter(gl.VERSION));
122+
123+
this._GlExtensions = "";
124+
var extArr = gl.getSupportedExtensions();
125+
for (var i = 0; i < extArr.length; i++)
126+
this._GlExtensions += extArr[i] + " ";
127+
cc.log("cocos2d:GL_EXTENSIONS: " + this._GlExtensions);
128+
129+
this._maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
130+
this._maxTextureUnits = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
131+
132+
this._supportsPVRTC = this.checkForGLExtension("GL_IMG_texture_compression_pvrtc");
133+
this._supportsNPOT = true;
134+
this._supportsBGRA8888 = this.checkForGLExtension("GL_IMG_texture_format_BGRA888");
135+
this._supportsDiscardFramebuffer = this.checkForGLExtension("GL_EXT_discard_framebuffer");
136+
137+
this._supportsShareableVAO = this.checkForGLExtension("vertex_array_object");
138+
139+
cc.log("cocos2d: GL_MAX_TEXTURE_SIZE: " + this._maxTextureSize);
140+
cc.log("cocos2d: GL_MAX_TEXTURE_UNITS: " + this._maxTextureUnits);
141+
cc.log("cocos2d: GL supports PVRTC: " + (this._supportsPVRTC ? "YES" : "NO"));
142+
cc.log("cocos2d: GL supports BGRA8888 textures: " + (this._supportsBGRA8888 ? "YES" : "NO"));
143+
cc.log("cocos2d: GL supports NPOT textures: " + (this._supportsNPOT ? "YES" : "NO"));
144+
cc.log("cocos2d: GL supports discard_framebuffer: " + (this._supportsDiscardFramebuffer ? "YES" : "NO"));
145+
cc.log("cocos2d: GL supports shareable VAO: " + (this._supportsShareableVAO ? "YES" : "NO"));
146+
147+
if (cc.ENABLE_GL_STATE_CACHE == 0)
148+
cc.log("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it by editing ccConfig.h");
149+
150+
cc.CHECK_GL_ERROR_DEBUG();
151+
return true;
152+
}
153+
});
154+
155+
156+
cc.Configuration._sharedConfiguration = null;
157+
158+
/**
159+
* returns a shared instance of CCConfiguration
160+
* @return {cc.Configuration}
161+
*/
162+
cc.Configuration.getInstance = function () {
163+
if(!cc.Configuration._sharedConfiguration){
164+
cc.Configuration._sharedConfiguration = new cc.Configuration();
165+
cc.Configuration._sharedConfiguration.init();
166+
}
167+
return cc.Configuration._sharedConfiguration;
168+
};
169+
170+
/**
171+
* purge the shared instance of CCConfiguration
172+
*/
173+
cc.Configuration.purgeConfiguration = function () {
174+
cc.Configuration._sharedConfiguration = null;
175+
};

cocos2d/CCDrawingPrimitives.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ cc.DrawingPrimitiveWebGL = cc.DrawingPrimitive.extend({
563563
var pointBuffer = this._renderContext.createBuffer();
564564
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
565565
this._renderContext.bufferData(this._renderContext.ARRAY_BUFFER, new Float32Array([point.x, point.y]), this._renderContext.STATIC_DRAW);
566-
cc.glEnableVertexAttribs(cc.kCCVertexAttribFlag_Position);
566+
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIBFLAG_POSITION);
567567

568568
this._shader.use();
569569
this._shader.setUniformForModelViewProjectionMatrix();
@@ -594,7 +594,7 @@ cc.DrawingPrimitiveWebGL = cc.DrawingPrimitive.extend({
594594
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
595595
this._renderContext.bufferData(this._renderContext.ARRAY_BUFFER, this._pointsToTypeArray(points), this._renderContext.STATIC_DRAW);
596596

597-
cc.glEnableVertexAttribs(cc.kCCVertexAttribFlag_Position);
597+
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIBFLAG_POSITION);
598598
this._shader.use();
599599
this._shader.setUniformForModelViewProjectionMatrix();
600600

@@ -637,7 +637,7 @@ cc.DrawingPrimitiveWebGL = cc.DrawingPrimitive.extend({
637637
this._shader.setUniformLocationWith4fv(this._colorLocation, [this._color.r, this._color.g, this._color.b, this._color.a], 1);
638638
cc.CHECK_GL_ERROR_DEBUG();
639639

640-
cc.glEnableVertexAttribs(cc.kCCVertexAttribFlag_Position);
640+
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIBFLAG_POSITION);
641641
cc.CHECK_GL_ERROR_DEBUG();
642642

643643
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
@@ -694,7 +694,7 @@ cc.DrawingPrimitiveWebGL = cc.DrawingPrimitive.extend({
694694
var pointBuffer = this._renderContext.createBuffer();
695695
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
696696
this._renderContext.bufferData(this._renderContext.ARRAY_BUFFER, this._pointsToTypeArray(vertices), this._renderContext.STATIC_DRAW);
697-
cc.glEnableVertexAttribs(cc.kCCVertexAttribFlag_Position);
697+
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIBFLAG_POSITION);
698698

699699
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
700700
this._renderContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, this._renderContext.FLOAT, false, 0, 0);
@@ -725,7 +725,7 @@ cc.DrawingPrimitiveWebGL = cc.DrawingPrimitive.extend({
725725
var pointBuffer = this._renderContext.createBuffer();
726726
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
727727
this._renderContext.bufferData(this._renderContext.ARRAY_BUFFER, this._pointsToTypeArray(poli), this._renderContext.STATIC_DRAW);
728-
cc.glEnableVertexAttribs(cc.kCCVertexAttribFlag_Position);
728+
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIBFLAG_POSITION);
729729

730730
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
731731
this._renderContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, this._renderContext.FLOAT, false, 0, 0);
@@ -773,7 +773,7 @@ cc.DrawingPrimitiveWebGL = cc.DrawingPrimitive.extend({
773773
var pointBuffer = this._renderContext.createBuffer();
774774
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
775775
this._renderContext.bufferData(this._renderContext.ARRAY_BUFFER, vertices, this._renderContext.STATIC_DRAW);
776-
cc.glEnableVertexAttribs(cc.kCCVertexAttribFlag_Position);
776+
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIBFLAG_POSITION);
777777

778778
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
779779
this._renderContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, this._renderContext.FLOAT, false, 0, 0);
@@ -811,7 +811,7 @@ cc.DrawingPrimitiveWebGL = cc.DrawingPrimitive.extend({
811811
var pointBuffer = this._renderContext.createBuffer();
812812
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
813813
this._renderContext.bufferData(this._renderContext.ARRAY_BUFFER, vertices, this._renderContext.STATIC_DRAW);
814-
cc.glEnableVertexAttribs(cc.kCCVertexAttribFlag_Position);
814+
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIBFLAG_POSITION);
815815

816816
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
817817
this._renderContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, this._renderContext.FLOAT, false, 0, 0);
@@ -850,7 +850,7 @@ cc.DrawingPrimitiveWebGL = cc.DrawingPrimitive.extend({
850850
var pointBuffer = this._renderContext.createBuffer();
851851
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
852852
this._renderContext.bufferData(this._renderContext.ARRAY_BUFFER, vertices, this._renderContext.STATIC_DRAW);
853-
cc.glEnableVertexAttribs(cc.kCCVertexAttribFlag_Position);
853+
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIBFLAG_POSITION);
854854

855855
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
856856
this._renderContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, this._renderContext.FLOAT, false, 0, 0);
@@ -913,7 +913,7 @@ cc.DrawingPrimitiveWebGL = cc.DrawingPrimitive.extend({
913913
var pointBuffer = this._renderContext.createBuffer();
914914
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
915915
this._renderContext.bufferData(this._renderContext.ARRAY_BUFFER, vertices, this._renderContext.STATIC_DRAW);
916-
cc.glEnableVertexAttribs(cc.kCCVertexAttribFlag_Position);
916+
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIBFLAG_POSITION);
917917

918918
this._renderContext.bindBuffer(this._renderContext.ARRAY_BUFFER, pointBuffer);
919919
this._renderContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, this._renderContext.FLOAT, false, 0, 0);

cocos2d/actions/CCAction.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
* @constant
2929
* @type {Number}
3030
*/
31-
3231
cc.ACTION_TAG_INVALID = -1;
3332

3433
/**

0 commit comments

Comments
 (0)