hedgewars/uTextures.pas
changeset 6580 6155187bf599
parent 6467 090269e528df
child 6700 e04da46ee43c
equal deleted inserted replaced
6579:fc52f7c22c9b 6580:6155187bf599
    37 
    37 
    38 
    38 
    39 procedure SetTextureParameters(enableClamp: Boolean);
    39 procedure SetTextureParameters(enableClamp: Boolean);
    40 begin
    40 begin
    41     if enableClamp and ((cReducedQuality and rqClampLess) = 0) then
    41     if enableClamp and ((cReducedQuality and rqClampLess) = 0) then
    42     begin
    42         begin
    43         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    43         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    44         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
    44         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
    45     end;
    45         end;
    46     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    46     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    47     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    47     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    48 end;
    48 end;
    49 
    49 
    50 procedure ResetVertexArrays(texture: PTexture);
    50 procedure ResetVertexArrays(texture: PTexture);
   154 if SDL_MustLock(surf) then
   154 if SDL_MustLock(surf) then
   155     SDLTry(SDL_LockSurface(surf) >= 0, true);
   155     SDLTry(SDL_LockSurface(surf) >= 0, true);
   156 
   156 
   157 fromP4:= Surf^.pixels;
   157 fromP4:= Surf^.pixels;
   158 
   158 
   159 if cGrayScale then Surface2GrayScale(Surf);
   159 if cGrayScale then
       
   160     Surface2GrayScale(Surf);
   160 
   161 
   161 if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then
   162 if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then
   162     begin
   163     begin
   163     tw:= toPowerOf2(Surf^.w);
   164     tw:= toPowerOf2(Surf^.w);
   164     th:= toPowerOf2(Surf^.h);
   165     th:= toPowerOf2(Surf^.h);
   171     fromP4:= Surf^.pixels;
   172     fromP4:= Surf^.pixels;
   172     toP4:= tmpp;
   173     toP4:= tmpp;
   173 
   174 
   174     for y:= 0 to Pred(Surf^.h) do
   175     for y:= 0 to Pred(Surf^.h) do
   175         begin
   176         begin
   176         for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x];
   177         for x:= 0 to Pred(Surf^.w) do
   177         for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0;
   178             toP4^[x]:= fromP4^[x];
       
   179         for x:= Surf^.w to Pred(tw) do
       
   180             toP4^[x]:= 0;
   178         toP4:= @(toP4^[tw]);
   181         toP4:= @(toP4^[tw]);
   179         fromP4:= @(fromP4^[Surf^.pitch div 4])
   182         fromP4:= @(fromP4^[Surf^.pitch div 4])
   180         end;
   183         end;
   181 
   184 
   182     for y:= Surf^.h to Pred(th) do
   185     for y:= Surf^.h to Pred(th) do
   183         begin
   186         begin
   184         for x:= 0 to Pred(tw) do toP4^[x]:= 0;
   187         for x:= 0 to Pred(tw) do
       
   188             toP4^[x]:= 0;
   185         toP4:= @(toP4^[tw])
   189         toP4:= @(toP4^[tw])
   186         end;
   190         end;
   187 
   191 
   188     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp);
   192     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp);
   189 
   193 
   206 
   210 
   207 // deletes texture and frees the memory allocated for it.
   211 // deletes texture and frees the memory allocated for it.
   208 // if nil is passed nothing is done
   212 // if nil is passed nothing is done
   209 procedure FreeTexture(tex: PTexture);
   213 procedure FreeTexture(tex: PTexture);
   210 begin
   214 begin
   211     if tex <> nil then
   215 if tex <> nil then
   212         begin
   216     begin
   213         if tex^.NextTexture <> nil then
   217     if tex^.NextTexture <> nil then
   214             tex^.NextTexture^.PrevTexture:= tex^.PrevTexture;
   218         tex^.NextTexture^.PrevTexture:= tex^.PrevTexture;
   215         if tex^.PrevTexture <> nil then
   219     if tex^.PrevTexture <> nil then
   216             tex^.PrevTexture^.NextTexture:= tex^.NextTexture
   220         tex^.PrevTexture^.NextTexture:= tex^.NextTexture
   217         else
   221     else
   218             TextureList:= tex^.NextTexture;
   222         TextureList:= tex^.NextTexture;
   219         glDeleteTextures(1, @tex^.id);
   223     glDeleteTextures(1, @tex^.id);
   220         Dispose(tex);
   224     Dispose(tex);
   221         end
   225     end
   222 end;
   226 end;
   223 
   227 
   224 procedure initModule;
   228 procedure initModule;
   225 begin
   229 begin
   226 TextureList:= nil;
   230 TextureList:= nil;
   227 end;
   231 end;
   228 
   232 
   229 procedure freeModule;
   233 procedure freeModule;
   230 begin
   234 begin
   231     if TextureList <> nil then WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem');
   235 if TextureList <> nil then
       
   236     WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem');
   232     while TextureList <> nil do 
   237     while TextureList <> nil do 
   233         begin
   238         begin
   234         AddFileLog('Texture not freed: width='+inttostr(LongInt(TextureList^.w))+' height='+inttostr(LongInt(TextureList^.h))+' priority='+inttostr(round(TextureList^.priority*1000)));
   239         AddFileLog('Texture not freed: width='+inttostr(LongInt(TextureList^.w))+' height='+inttostr(LongInt(TextureList^.h))+' priority='+inttostr(round(TextureList^.priority*1000)));
   235         FreeTexture(TextureList);
   240         FreeTexture(TextureList);
   236         end
   241         end