remove EMSCRIPTEN related code

This commit is contained in:
andyque 2015-07-16 14:15:41 +08:00
parent 40f4e0b27b
commit 7c665e6447
8 changed files with 3 additions and 167 deletions

View File

@ -70,32 +70,6 @@ static Color4F s_color(1.0f,1.0f,1.0f,1.0f);
static int s_pointSizeLocation = -1;
static GLfloat s_pointSize = 1.0f;
#ifdef EMSCRIPTEN
static GLuint s_bufferObject = 0;
static GLuint s_bufferSize = 0;
static void setGLBufferData(void *buf, GLuint bufSize)
{
if(s_bufferSize < bufSize)
{
if(s_bufferObject)
{
glDeleteBuffers(1, &s_bufferObject);
}
glGenBuffers(1, &s_bufferObject);
s_bufferSize = bufSize;
glBindBuffer(GL_ARRAY_BUFFER, s_bufferObject);
glBufferData(GL_ARRAY_BUFFER, bufSize, buf, GL_DYNAMIC_DRAW);
}
else
{
glBindBuffer(GL_ARRAY_BUFFER, s_bufferObject);
glBufferSubData(GL_ARRAY_BUFFER, 0, bufSize, buf);
}
}
#endif // EMSCRIPTEN
static void lazy_init()
{
@ -143,12 +117,7 @@ void drawPoint(const Vec2& point)
s_shader->setUniformLocationWith4fv(s_colorLocation, (GLfloat*) &s_color.r, 1);
s_shader->setUniformLocationWith1f(s_pointSizeLocation, s_pointSize);
#ifdef EMSCRIPTEN
setGLBufferData(&p, 8);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, &p);
#endif // EMSCRIPTEN
glDrawArrays(GL_POINTS, 0, 1);
@ -171,12 +140,7 @@ void drawPoints( const Vec2 *points, unsigned int numberOfPoints )
// iPhone and 32-bit machines optimization
if( sizeof(Vec2) == sizeof(Vec2) )
{
#ifdef EMSCRIPTEN
setGLBufferData((void*) points, numberOfPoints * sizeof(Vec2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, points);
#endif // EMSCRIPTEN
}
else
{
@ -185,14 +149,7 @@ void drawPoints( const Vec2 *points, unsigned int numberOfPoints )
newPoints[i].x = points[i].x;
newPoints[i].y = points[i].y;
}
#ifdef EMSCRIPTEN
// Suspect Emscripten won't be emitting 64-bit code for a while yet,
// but want to make sure this continues to work even if they do.
setGLBufferData(newPoints, numberOfPoints * sizeof(Vec2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, newPoints);
#endif // EMSCRIPTEN
}
glDrawArrays(GL_POINTS, 0, (GLsizei) numberOfPoints);
@ -217,12 +174,7 @@ void drawLine(const Vec2& origin, const Vec2& destination)
s_shader->setUniformLocationWith4fv(s_colorLocation, (GLfloat*) &s_color.r, 1);
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
#ifdef EMSCRIPTEN
setGLBufferData(vertices, 16);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#endif // EMSCRIPTEN
glDrawArrays(GL_LINES, 0, 2);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,2);
@ -261,12 +213,7 @@ void drawPoly(const Vec2 *poli, unsigned int numberOfPoints, bool closePolygon)
// iPhone and 32-bit machines optimization
if( sizeof(Vec2) == sizeof(Vec2) )
{
#ifdef EMSCRIPTEN
setGLBufferData((void*) poli, numberOfPoints * sizeof(Vec2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, poli);
#endif // EMSCRIPTEN
if( closePolygon )
glDrawArrays(GL_LINE_LOOP, 0, (GLsizei) numberOfPoints);
@ -282,12 +229,7 @@ void drawPoly(const Vec2 *poli, unsigned int numberOfPoints, bool closePolygon)
newPoli[i].x = poli[i].x;
newPoli[i].y = poli[i].y;
}
#ifdef EMSCRIPTEN
setGLBufferData(newPoli, numberOfPoints * sizeof(Vec2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, newPoli);
#endif // EMSCRIPTEN
if( closePolygon )
glDrawArrays(GL_LINE_LOOP, 0, (GLsizei) numberOfPoints);
@ -316,12 +258,7 @@ void drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, Color4F color)
// iPhone and 32-bit machines optimization
if (sizeof(Vec2) == sizeof(Vec2))
{
#ifdef EMSCRIPTEN
setGLBufferData((void*) poli, numberOfPoints * sizeof(Vec2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, poli);
#endif // EMSCRIPTEN
}
else
{
@ -330,12 +267,7 @@ void drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, Color4F color)
{
newPoli[i].set(poli[i].x, poli[i].y);
}
#ifdef EMSCRIPTEN
setGLBufferData(newPoli, numberOfPoints * sizeof(Vec2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, newPoli);
#endif // EMSCRIPTEN
}
glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) numberOfPoints);
@ -375,12 +307,7 @@ void drawCircle( const Vec2& center, float radius, float angle, unsigned int seg
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
#ifdef EMSCRIPTEN
setGLBufferData(vertices, sizeof(GLfloat)*2*(segments+2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#endif // EMSCRIPTEN
glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segments+additionalSegment);
::free( vertices );
@ -420,12 +347,7 @@ void drawSolidCircle( const Vec2& center, float radius, float angle, unsigned in
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
#ifdef EMSCRIPTEN
setGLBufferData(vertices, sizeof(GLfloat)*2*(segments+2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#endif // EMSCRIPTEN
glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) segments+1);
@ -461,12 +383,7 @@ void drawQuadBezier(const Vec2& origin, const Vec2& control, const Vec2& destina
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
#ifdef EMSCRIPTEN
setGLBufferData(vertices, (segments + 1) * sizeof(Vec2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#endif // EMSCRIPTEN
glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segments + 1);
CC_SAFE_DELETE_ARRAY(vertices);
@ -518,12 +435,7 @@ void drawCardinalSpline( PointArray *config, float tension, unsigned int segmen
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
#ifdef EMSCRIPTEN
setGLBufferData(vertices, (segments + 1) * sizeof(Vec2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#endif // EMSCRIPTEN
glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segments + 1);
CC_SAFE_DELETE_ARRAY(vertices);
@ -552,12 +464,7 @@ void drawCubicBezier(const Vec2& origin, const Vec2& control1, const Vec2& contr
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
#ifdef EMSCRIPTEN
setGLBufferData(vertices, (segments + 1) * sizeof(Vec2));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#endif // EMSCRIPTEN
glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segments + 1);
CC_SAFE_DELETE_ARRAY(vertices);

View File

@ -600,17 +600,9 @@ void LayerColor::onDraw(const Mat4& transform, uint32_t flags)
//
// Attributes
//
#ifdef EMSCRIPTEN
setGLBufferData(_noMVPVertices, 4 * sizeof(Vec3), 0);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, 0, 0);
setGLBufferData(_squareColors, 4 * sizeof(Color4F), 1);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, 0);
#else
glBindBuffer(GL_ARRAY_BUFFER, 0);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, 0, _noMVPVertices);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, _squareColors);
#endif // EMSCRIPTEN
GL::blendFunc( _blendFunc.src, _blendFunc.dst );

View File

@ -386,21 +386,9 @@ void MotionStreak::onDraw(const Mat4 &transform, uint32_t flags)
GL::bindTexture2D( _texture->getName() );
#ifdef EMSCRIPTEN
// Size calculations from ::initWithFade
setGLBufferData(_vertices, (sizeof(Vec2) * _maxPoints * 2), 0);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
setGLBufferData(_texCoords, (sizeof(Tex2F) * _maxPoints * 2), 1);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, 0);
setGLBufferData(_colorPointer, (sizeof(GLubyte) * _maxPoints * 2 * 4), 2);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, _vertices);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, _texCoords);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, _colorPointer);
#endif // EMSCRIPTEN
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)_nuPoints*2);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _nuPoints*2);

View File

@ -410,11 +410,7 @@ TextureCache* Director::getTextureCache() const
void Director::initTextureCache()
{
#ifdef EMSCRIPTEN
_textureCache = new (std::nothrow) TextureCacheEmscripten();
#else
_textureCache = new (std::nothrow) TextureCache();
#endif // EMSCRIPTEN
}
void Director::destroyTextureCache()

View File

@ -486,33 +486,12 @@ bool Image::initWithImageFile(const std::string& path)
bool ret = false;
_filePath = FileUtils::getInstance()->fullPathForFilename(path);
#ifdef EMSCRIPTEN
// Emscripten includes a re-implementation of SDL that uses HTML5 canvas
// operations underneath. Consequently, loading images via IMG_Load (an SDL
// API) will be a lot faster than running libpng et al as compiled with
// Emscripten.
SDL_Surface *iSurf = IMG_Load(fullPath.c_str());
int size = 4 * (iSurf->w * iSurf->h);
ret = initWithRawData((const unsigned char*)iSurf->pixels, size, iSurf->w, iSurf->h, 8, true);
unsigned int *tmp = (unsigned int *)_data;
int nrPixels = iSurf->w * iSurf->h;
for(int i = 0; i < nrPixels; i++)
{
unsigned char *p = _data + i * 4;
tmp[i] = CC_RGB_PREMULTIPLY_ALPHA( p[0], p[1], p[2], p[3] );
}
SDL_FreeSurface(iSurf);
#else
Data data = FileUtils::getInstance()->getDataFromFile(_filePath);
if (!data.isNull())
{
ret = initWithImageData(data.getBytes(), data.getSize());
}
#endif // EMSCRIPTEN
return ret;
}

View File

@ -1164,16 +1164,8 @@ void Texture2D::drawAtPoint(const Vec2& point)
GL::bindTexture2D( _name );
#ifdef EMSCRIPTEN
setGLBufferData(vertices, 8 * sizeof(GLfloat), 0);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
setGLBufferData(coordinates, 8 * sizeof(GLfloat), 1);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, coordinates);
#endif // EMSCRIPTEN
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
@ -1197,16 +1189,8 @@ void Texture2D::drawInRect(const Rect& rect)
GL::bindTexture2D( _name );
#ifdef EMSCRIPTEN
setGLBufferData(vertices, 8 * sizeof(GLfloat), 0);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
setGLBufferData(coordinates, 8 * sizeof(GLfloat), 1);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, coordinates);
#endif // EMSCRIPTEN
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

View File

@ -34,9 +34,6 @@ THE SOFTWARE.
#include "base/CCRef.h"
#include "math/CCGeometry.h"
#include "base/ccTypes.h"
#ifdef EMSCRIPTEN
#include "CCGLBufferedNode.h"
#endif // EMSCRIPTEN
NS_CC_BEGIN
@ -68,9 +65,6 @@ class GLProgram;
* Be aware that the content of the generated textures will be upside-down!
*/
class CC_DLL Texture2D : public Ref
#ifdef EMSCRIPTEN
, public GLBufferedNode
#endif // EMSCRIPTEN
{
public:
/** @typedef Texture2D::PixelFormat

View File

@ -43,10 +43,6 @@ THE SOFTWARE.
#include "base/CCNinePatchImageParser.h"
#ifdef EMSCRIPTEN
#include <emscripten/emscripten.h>
#include "platform/emscripten/CCTextureCacheEmscripten.h"
#endif // EMSCRIPTEN
using namespace std;