mirror of https://github.com/axmolengine/axmol.git
fix memory leak
This commit is contained in:
parent
d04b3feb50
commit
d6c3320d49
|
@ -29,36 +29,36 @@ static const char * vertex_shader = "\
|
|||
";
|
||||
|
||||
static const char * fragment_shader_RGB_4_DETAIL ="\n#ifdef GL_ES\n\
|
||||
precision lowp float;\
|
||||
\n#endif\n\
|
||||
uniform vec3 u_color;\
|
||||
varying vec2 v_texCoord;\
|
||||
varying vec3 v_normal;\
|
||||
uniform int u_has_alpha;\
|
||||
uniform sampler2D u_alphaMap;\
|
||||
uniform sampler2D u_texture0;\
|
||||
uniform sampler2D u_texture1;\
|
||||
uniform sampler2D u_texture2;\
|
||||
uniform sampler2D u_texture3;\
|
||||
uniform float u_detailSize[4];\
|
||||
void main()\
|
||||
{\
|
||||
vec3 light_direction = vec3(-1,-1,0);\
|
||||
float lightFactor = dot(-light_direction,v_normal);\
|
||||
if(u_has_alpha<=0)\
|
||||
{\
|
||||
gl_FragColor = texture2D(u_texture0, v_texCoord)*lightFactor;\
|
||||
}else\
|
||||
{\
|
||||
vec4 blendFactor =texture2D(u_alphaMap,v_texCoord);\
|
||||
vec4 color = vec4(0,0,0,0);\
|
||||
color = texture2D(u_texture0, v_texCoord*u_detailSize[0])*blendFactor.r +\
|
||||
texture2D(u_texture1, v_texCoord*u_detailSize[1])*blendFactor.g + texture2D(u_texture2, v_texCoord*u_detailSize[2])*blendFactor.b;\n\
|
||||
float grayFactor =dot(blendFactor.rgb, vec3(1, 1, 1));\
|
||||
color +=texture2D(u_texture3, v_texCoord*u_detailSize[3])*(1.0-grayFactor);\
|
||||
gl_FragColor = color*lightFactor;\
|
||||
}\
|
||||
}";
|
||||
precision lowp float;\
|
||||
\n#endif\n\
|
||||
uniform vec3 u_color;\
|
||||
varying vec2 v_texCoord;\
|
||||
varying vec3 v_normal;\
|
||||
uniform int u_has_alpha;\
|
||||
uniform sampler2D u_alphaMap;\
|
||||
uniform sampler2D u_texture0;\
|
||||
uniform sampler2D u_texture1;\
|
||||
uniform sampler2D u_texture2;\
|
||||
uniform sampler2D u_texture3;\
|
||||
uniform float u_detailSize[4];\
|
||||
void main()\
|
||||
{\
|
||||
vec3 light_direction = vec3(-1,-1,0);\
|
||||
float lightFactor = dot(-light_direction,v_normal);\
|
||||
if(u_has_alpha<=0)\
|
||||
{\
|
||||
gl_FragColor = texture2D(u_texture0, v_texCoord)*lightFactor;\
|
||||
}else\
|
||||
{\
|
||||
vec4 blendFactor =texture2D(u_alphaMap,v_texCoord);\
|
||||
vec4 color = vec4(0,0,0,0);\
|
||||
color = texture2D(u_texture0, v_texCoord*u_detailSize[0])*blendFactor.r +\
|
||||
texture2D(u_texture1, v_texCoord*u_detailSize[1])*blendFactor.g + texture2D(u_texture2, v_texCoord*u_detailSize[2])*blendFactor.b;\n\
|
||||
float grayFactor =dot(blendFactor.rgb, vec3(1, 1, 1));\
|
||||
color +=texture2D(u_texture3, v_texCoord*u_detailSize[3])*(1.0-grayFactor);\
|
||||
gl_FragColor = color*lightFactor;\
|
||||
}\
|
||||
}";
|
||||
NS_CC_BEGIN
|
||||
Terrain * Terrain::create(TerrainData ¶meter)
|
||||
{
|
||||
|
@ -377,6 +377,14 @@ void Terrain::setIsEnableFrustumCull(bool bool_value)
|
|||
Terrain::~Terrain()
|
||||
{
|
||||
free(_data);
|
||||
for(int i = 0;i<MAX_CHUNKES;i++)
|
||||
{
|
||||
for(int j = 0;j<MAX_CHUNKES;j++)
|
||||
{
|
||||
delete _chunkesArray[i][j];
|
||||
}
|
||||
}
|
||||
free(_chunkesArray);
|
||||
}
|
||||
|
||||
void Terrain::Chunk::finish()
|
||||
|
@ -709,6 +717,11 @@ void Terrain::Chunk::updateVerticesForLOD()
|
|||
|
||||
}
|
||||
|
||||
Terrain::Chunk::~Chunk()
|
||||
{
|
||||
glDeleteBuffers(2,vbo);
|
||||
}
|
||||
|
||||
Terrain::QuadTree::QuadTree(int x,int y,int width,int height,Terrain * terrain)
|
||||
{
|
||||
_needDraw = true;
|
||||
|
|
|
@ -112,6 +112,7 @@ private:
|
|||
{
|
||||
/*Constructor*/
|
||||
Chunk();
|
||||
~Chunk();
|
||||
/*vertices*/
|
||||
std::vector<TerrainVertexData> vertices;
|
||||
/*LOD indices*/
|
||||
|
@ -226,7 +227,7 @@ private:
|
|||
GLuint vbo[2];
|
||||
QuadTree * quad;
|
||||
int detailSize[4];
|
||||
Chunk * _chunkesArray[256][256];
|
||||
Chunk * _chunkesArray[MAX_CHUNKES][MAX_CHUNKES];
|
||||
std::vector<TerrainVertexData> vertices;
|
||||
std::vector<GLushort > indices;
|
||||
int imageWidth;
|
||||
|
|
Loading…
Reference in New Issue