473 |
473 |
474 Surface2Tex^.w:= surf^.w; |
474 Surface2Tex^.w:= surf^.w; |
475 Surface2Tex^.h:= surf^.h; |
475 Surface2Tex^.h:= surf^.h; |
476 |
476 |
477 if (surf^.format^.BytesPerPixel <> 4) then |
477 if (surf^.format^.BytesPerPixel <> 4) then |
478 begin |
478 begin |
479 TryDo(false, 'Surface2Tex failed, expecting 32 bit surface', true); |
479 TryDo(false, 'Surface2Tex failed, expecting 32 bit surface', true); |
480 Surface2Tex^.id:= 0; |
480 Surface2Tex^.id:= 0; |
481 exit |
481 exit |
482 end; |
482 end; |
483 |
483 |
484 |
484 |
485 glGenTextures(1, @Surface2Tex^.id); |
485 glGenTextures(1, @Surface2Tex^.id); |
486 |
486 |
487 glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
487 glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
488 |
488 |
489 if SDL_MustLock(surf) then |
489 if SDL_MustLock(surf) then |
490 SDLTry(SDL_LockSurface(surf) >= 0, true); |
490 SDLTry(SDL_LockSurface(surf) >= 0, true); |
491 |
491 |
492 if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then |
492 if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then |
493 begin |
493 begin |
494 tw:= toPowerOf2(Surf^.w); |
494 tw:= toPowerOf2(Surf^.w); |
495 th:= toPowerOf2(Surf^.h); |
495 th:= toPowerOf2(Surf^.h); |
496 |
496 |
497 Surface2Tex^.rx:= Surf^.w / tw; |
497 Surface2Tex^.rx:= Surf^.w / tw; |
498 Surface2Tex^.ry:= Surf^.h / th; |
498 Surface2Tex^.ry:= Surf^.h / th; |
499 |
499 |
500 GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
500 GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
501 |
501 |
502 fromP4:= Surf^.pixels; |
502 fromP4:= Surf^.pixels; |
503 toP4:= tmpp; |
503 toP4:= tmpp; |
504 |
504 |
505 for y:= 0 to Pred(Surf^.h) do |
505 for y:= 0 to Pred(Surf^.h) do |
506 begin |
506 begin |
507 for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x]; |
507 for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x]; |
508 for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0; |
508 for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0; |
509 toP4:= @(toP4^[tw]); |
509 toP4:= @(toP4^[tw]); |
510 fromP4:= @(fromP4^[Surf^.pitch div 4]); |
510 fromP4:= @(fromP4^[Surf^.pitch div 4]) |
511 end; |
511 end; |
512 |
512 |
513 for y:= Surf^.h to Pred(th) do |
513 for y:= Surf^.h to Pred(th) do |
514 begin |
514 begin |
515 for x:= 0 to Pred(tw) do toP4^[x]:= 0; |
515 for x:= 0 to Pred(tw) do toP4^[x]:= 0; |
516 toP4:= @(toP4^[tw]); |
516 toP4:= @(toP4^[tw]) |
517 end; |
517 end; |
518 |
518 |
519 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp); |
519 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp); |
520 |
520 |
521 FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
521 FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
522 end |
522 end |
523 else |
523 else |
524 begin |
524 begin |
525 Surface2Tex^.rx:= 1.0; |
525 Surface2Tex^.rx:= 1.0; |
526 Surface2Tex^.ry:= 1.0; |
526 Surface2Tex^.ry:= 1.0; |
527 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf^.w, surf^.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf^.pixels); |
527 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf^.w, surf^.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf^.pixels); |
528 end; |
528 end; |
529 |
529 |
530 ResetVertexArrays(Surface2Tex); |
530 ResetVertexArrays(Surface2Tex); |
531 |
531 |
532 if SDL_MustLock(surf) then |
532 if SDL_MustLock(surf) then |
533 SDL_UnlockSurface(surf); |
533 SDL_UnlockSurface(surf); |