2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** bitmap.cpp
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
|
|
**
|
|
|
|
** mkxp is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 2 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** mkxp is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bitmap.h"
|
|
|
|
|
|
|
|
#include "SDL2/SDL.h"
|
|
|
|
#include "SDL2/SDL_image.h"
|
|
|
|
#include "SDL2/SDL_ttf.h"
|
|
|
|
|
|
|
|
#include "gl-util.h"
|
|
|
|
#include "quad.h"
|
|
|
|
#include "quadarray.h"
|
|
|
|
#include "exception.h"
|
|
|
|
|
|
|
|
#include "globalstate.h"
|
|
|
|
#include "glstate.h"
|
|
|
|
#include "texpool.h"
|
|
|
|
#include "shader.h"
|
|
|
|
#include "filesystem.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "eventthread.h"
|
|
|
|
|
|
|
|
#define DISP_CLASS_NAME "bitmap"
|
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
#define GUARD_MEGA \
|
|
|
|
{ \
|
|
|
|
if (p->megaSurface) \
|
|
|
|
throw Exception(Exception::MKXPError, \
|
|
|
|
"Operation not supported for mega surfaces"); \
|
|
|
|
}
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
struct BitmapPrivate
|
|
|
|
{
|
2013-09-06 10:26:41 +00:00
|
|
|
TEXFBO tex;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
/* 'setPixel()' calls are cached and executed
|
|
|
|
* in batches on 'flush()' */
|
|
|
|
PointArray pointArray;
|
|
|
|
|
|
|
|
Font *font;
|
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
/* "Mega surfaces" are a hack to allow Tilesets to be used
|
|
|
|
* whose Bitmaps don't fit into a regular texture. They're
|
|
|
|
* kept in RAM and will throw an error if they're used in
|
|
|
|
* any context other than as Tilesets */
|
|
|
|
SDL_Surface *megaSurface;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
BitmapPrivate()
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
: megaSurface(0)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
|
|
|
font = &gState->defaultFont();
|
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
void bindTexture(ShaderBase &shader)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2013-09-06 10:26:41 +00:00
|
|
|
TEX::bind(tex.tex);
|
2013-09-23 05:15:01 +00:00
|
|
|
shader.setTexSize(Vec2i(tex.width, tex.height));
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bindFBO()
|
|
|
|
{
|
2013-09-06 12:56:30 +00:00
|
|
|
FBO::bind(tex.fbo, FBO::Draw);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
void pushSetViewport(ShaderBase &shader) const
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2013-09-23 05:15:01 +00:00
|
|
|
glState.viewport.pushSet(IntRect(0, 0, tex.width, tex.height));
|
|
|
|
shader.applyViewportProj();
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void popViewport() const
|
|
|
|
{
|
2013-09-23 05:15:01 +00:00
|
|
|
glState.viewport.pop();
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void blitQuad(Quad &quad)
|
|
|
|
{
|
|
|
|
glState.blendMode.pushSet(BlendNone);
|
|
|
|
quad.draw();
|
|
|
|
glState.blendMode.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void flushPoints()
|
|
|
|
{
|
|
|
|
if (pointArray.count() == 0)
|
|
|
|
return;
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
SimpleColorShader &shader = gState->simpleColorShader();
|
|
|
|
shader.bind();
|
|
|
|
shader.setTranslation(Vec2i());
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
bindFBO();
|
2013-09-23 05:15:01 +00:00
|
|
|
pushSetViewport(shader);
|
2013-09-01 14:27:21 +00:00
|
|
|
glState.blendMode.pushSet(BlendNone);
|
|
|
|
|
|
|
|
pointArray.commit();
|
|
|
|
pointArray.draw();
|
|
|
|
pointArray.reset();
|
|
|
|
|
|
|
|
glState.blendMode.pop();
|
|
|
|
popViewport();
|
|
|
|
}
|
|
|
|
|
|
|
|
void fillRect(const IntRect &rect,
|
|
|
|
const Vec4 &color)
|
|
|
|
{
|
|
|
|
flushPoints();
|
|
|
|
|
|
|
|
bindFBO();
|
|
|
|
|
|
|
|
glState.scissorTest.pushSet(true);
|
|
|
|
glState.scissorBox.pushSet(rect);
|
|
|
|
glState.clearColor.pushSet(color);
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
glState.clearColor.pop();
|
|
|
|
glState.scissorBox.pop();
|
|
|
|
glState.scissorTest.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ensureFormat(SDL_Surface *&surf, Uint32 format)
|
|
|
|
{
|
|
|
|
if (surf->format->format == format)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SDL_Surface *surfConv = SDL_ConvertSurfaceFormat(surf, format, 0);
|
|
|
|
SDL_FreeSurface(surf);
|
|
|
|
surf = surfConv;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Bitmap::Bitmap(const char *filename)
|
|
|
|
{
|
|
|
|
SDL_RWops ops;
|
|
|
|
gState->fileSystem().openRead(ops, filename, FileSystem::Image);
|
|
|
|
SDL_Surface *imgSurf = IMG_Load_RW(&ops, 1);
|
|
|
|
|
|
|
|
if (!imgSurf)
|
|
|
|
throw Exception(Exception::SDLError, "SDL: %s", SDL_GetError());
|
|
|
|
|
|
|
|
p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888);
|
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
if (imgSurf->w > glState.caps.maxTexSize || imgSurf->h > glState.caps.maxTexSize)
|
2013-09-06 13:52:45 +00:00
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
/* Mega surface */
|
|
|
|
p = new BitmapPrivate;
|
|
|
|
p->megaSurface = imgSurf;
|
2013-09-06 13:52:45 +00:00
|
|
|
}
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
else
|
2013-09-06 13:52:45 +00:00
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
/* Regular surface */
|
2013-09-04 16:11:16 +00:00
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
TEXFBO tex;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
tex = gState->texPool().request(imgSurf->w, imgSurf->h);
|
|
|
|
}
|
|
|
|
catch (const Exception &e)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(imgSurf);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = new BitmapPrivate;
|
|
|
|
p->tex = tex;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
TEX::bind(p->tex.tex);
|
|
|
|
TEX::uploadImage(p->tex.width, p->tex.height, imgSurf->pixels, GL_RGBA);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
SDL_FreeSurface(imgSurf);
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Bitmap::Bitmap(int width, int height)
|
|
|
|
{
|
2013-09-04 16:11:16 +00:00
|
|
|
if (width <= 0 || height <= 0)
|
|
|
|
throw Exception(Exception::RGSSError, "failed to create bitmap");
|
|
|
|
|
2013-09-06 10:26:41 +00:00
|
|
|
TEXFBO tex = gState->texPool().request(width, height);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-04 16:11:16 +00:00
|
|
|
p = new BitmapPrivate;
|
|
|
|
p->tex = tex;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
Bitmap::Bitmap(const Bitmap &other)
|
|
|
|
{
|
|
|
|
p = new BitmapPrivate;
|
|
|
|
|
|
|
|
p->tex = gState->texPool().request(other.width(), other.height());
|
|
|
|
|
|
|
|
other.flush();
|
|
|
|
blt(0, 0, other, rect());
|
|
|
|
}
|
|
|
|
|
|
|
|
Bitmap::~Bitmap()
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Bitmap::width() const
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
|
|
|
if (p->megaSurface)
|
|
|
|
return p->megaSurface->w;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
return p->tex.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Bitmap::height() const
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
|
|
|
if (p->megaSurface)
|
|
|
|
return p->megaSurface->h;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
return p->tex.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntRect Bitmap::rect() const
|
|
|
|
{
|
|
|
|
return IntRect(0, 0, width(), height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::blt(int x, int y,
|
|
|
|
const Bitmap &source, const IntRect &rect,
|
|
|
|
int opacity)
|
|
|
|
{
|
|
|
|
stretchBlt(IntRect(x, y, rect.w, rect.h),
|
|
|
|
source, rect, opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::stretchBlt(const IntRect &destRect,
|
|
|
|
const Bitmap &source, const IntRect &sourceRect,
|
|
|
|
int opacity)
|
|
|
|
{
|
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_MEGA;
|
|
|
|
|
2013-09-03 13:31:29 +00:00
|
|
|
opacity = clamp(opacity, 0, 255);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
if (opacity == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// else if (opacity == 255) /* Fast blit */
|
|
|
|
// {
|
|
|
|
// flush();
|
|
|
|
|
|
|
|
// FBO::bind(source.p->tex.fbo, FBO::Read);
|
|
|
|
// FBO::bind(p->tex.fbo, FBO::Draw);
|
|
|
|
|
|
|
|
// FBO::blit(sourceRect.x, sourceRect.y, sourceRect.w, sourceRect.h,
|
|
|
|
// destRect.x, destRect.y, destRect.w, destRect.h);
|
|
|
|
// }
|
|
|
|
else /* Fragment pipeline */
|
|
|
|
{
|
|
|
|
flush();
|
|
|
|
|
|
|
|
float normOpacity = (float) opacity / 255.0f;
|
|
|
|
|
2013-09-06 10:26:41 +00:00
|
|
|
TEXFBO &gpTex = gState->gpTexFBO(destRect.w, destRect.h);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
FBO::bind(gpTex.fbo, FBO::Draw);
|
|
|
|
FBO::bind(p->tex.fbo, FBO::Read);
|
|
|
|
FBO::blit(destRect.x, destRect.y, 0, 0, destRect.w, destRect.h);
|
|
|
|
|
|
|
|
FloatRect bltSubRect((float) sourceRect.x / source.width(),
|
|
|
|
(float) sourceRect.y / source.height(),
|
|
|
|
((float) source.width() / sourceRect.w) * ((float) destRect.w / gpTex.width),
|
|
|
|
((float) source.height() / sourceRect.h) * ((float) destRect.h / gpTex.height));
|
|
|
|
|
|
|
|
BltShader &shader = gState->bltShader();
|
|
|
|
shader.bind();
|
|
|
|
shader.setDestination(gpTex.tex);
|
|
|
|
shader.setSubRect(bltSubRect);
|
|
|
|
shader.setOpacity(normOpacity);
|
|
|
|
|
2013-09-04 17:07:28 +00:00
|
|
|
Quad &quad = gState->gpQuad();
|
2013-09-01 14:27:21 +00:00
|
|
|
quad.setTexPosRect(sourceRect, destRect);
|
|
|
|
quad.setColor(Vec4(1, 1, 1, normOpacity));
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
source.p->bindTexture(shader);
|
2013-09-01 14:27:21 +00:00
|
|
|
p->bindFBO();
|
2013-09-23 05:15:01 +00:00
|
|
|
p->pushSetViewport(shader);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
p->blitQuad(quad);
|
|
|
|
|
|
|
|
p->popViewport();
|
|
|
|
}
|
|
|
|
|
|
|
|
modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::fillRect(int x, int y,
|
|
|
|
int width, int height,
|
|
|
|
const Vec4 &color)
|
|
|
|
{
|
|
|
|
fillRect(IntRect(x, y, width, height), color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::fillRect(const IntRect &rect, const Vec4 &color)
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
|
|
|
GUARD_MEGA;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
p->fillRect(rect, color);
|
|
|
|
|
|
|
|
modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::gradientFillRect(int x, int y,
|
|
|
|
int width, int height,
|
|
|
|
const Vec4 &color1, const Vec4 &color2,
|
|
|
|
bool vertical)
|
|
|
|
{
|
|
|
|
gradientFillRect(IntRect(x, y, width, height), color1, color2, vertical);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::gradientFillRect(const IntRect &rect,
|
|
|
|
const Vec4 &color1, const Vec4 &color2,
|
|
|
|
bool vertical)
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
|
|
|
GUARD_MEGA;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
flush();
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
SimpleColorShader &shader = gState->simpleColorShader();
|
|
|
|
shader.bind();
|
|
|
|
shader.setTranslation(Vec2i());
|
|
|
|
|
2013-09-04 17:07:28 +00:00
|
|
|
Quad &quad = gState->gpQuad();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
if (vertical)
|
|
|
|
{
|
|
|
|
quad.vert[0].color = color2;
|
|
|
|
quad.vert[1].color = color2;
|
|
|
|
quad.vert[2].color = color1;
|
|
|
|
quad.vert[3].color = color1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
quad.vert[0].color = color1;
|
|
|
|
quad.vert[3].color = color1;
|
|
|
|
quad.vert[1].color = color2;
|
|
|
|
quad.vert[2].color = color2;
|
|
|
|
}
|
|
|
|
|
|
|
|
quad.setPosRect(rect);
|
|
|
|
|
|
|
|
p->bindFBO();
|
2013-09-23 05:15:01 +00:00
|
|
|
p->pushSetViewport(shader);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
p->blitQuad(quad);
|
|
|
|
|
|
|
|
p->popViewport();
|
|
|
|
|
|
|
|
modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::clearRect(int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
clearRect(IntRect(x, y, width, height));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::clearRect(const IntRect &rect)
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
|
|
|
GUARD_MEGA;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
p->fillRect(rect, Vec4());
|
|
|
|
|
|
|
|
modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::clear()
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
|
|
|
GUARD_MEGA;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
/* Any queued points won't be visible after this anyway */
|
|
|
|
p->pointArray.reset();
|
|
|
|
|
|
|
|
p->bindFBO();
|
|
|
|
|
|
|
|
glState.clearColor.pushSet(Vec4());
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
glState.clearColor.pop();
|
|
|
|
|
|
|
|
modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vec4 Bitmap::getPixel(int x, int y) const
|
|
|
|
{
|
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_MEGA;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
if (x < 0 || y < 0 || x >= width() || y >= height())
|
|
|
|
return Vec4();
|
|
|
|
|
|
|
|
flush();
|
|
|
|
|
|
|
|
p->bindFBO();
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
glState.viewport.pushSet(IntRect(0, 0, width(), height()));
|
|
|
|
Vec4 pixel = FBO::getPixel(x, y);
|
2013-09-01 14:27:21 +00:00
|
|
|
glState.viewport.pop();
|
|
|
|
|
|
|
|
return pixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::setPixel(int x, int y, const Vec4 &color)
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
|
|
|
GUARD_MEGA;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
p->pointArray.append(Vec2(x+.5, y+.5), color);
|
|
|
|
|
|
|
|
modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::hueChange(int hue)
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
|
|
|
GUARD_MEGA;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
if ((hue % 360) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
flush();
|
|
|
|
|
2013-09-06 10:26:41 +00:00
|
|
|
TEXFBO newTex = gState->texPool().request(width(), height());
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
FloatRect texRect(rect());
|
|
|
|
|
2013-09-04 17:07:28 +00:00
|
|
|
Quad &quad = gState->gpQuad();
|
2013-09-01 14:27:21 +00:00
|
|
|
quad.setTexPosRect(texRect, texRect);
|
2013-09-04 17:07:28 +00:00
|
|
|
quad.setColor(Vec4(1, 1, 1, 1));
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
/* Calculate hue parameter */
|
|
|
|
hue = wrapRange(hue, 0, 359);
|
|
|
|
float hueAdj = -((M_PI * 2) / 360) * hue;
|
|
|
|
|
|
|
|
HueShader &shader = gState->hueShader();
|
|
|
|
shader.bind();
|
|
|
|
shader.setHueAdjust(hueAdj);
|
|
|
|
|
2013-09-06 12:56:30 +00:00
|
|
|
FBO::bind(newTex.fbo, FBO::Draw);
|
2013-09-23 05:15:01 +00:00
|
|
|
p->pushSetViewport(shader);
|
|
|
|
p->bindTexture(shader);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
p->blitQuad(quad);
|
|
|
|
|
|
|
|
shader.unbind();
|
|
|
|
|
|
|
|
p->popViewport();
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
TEX::unbind();
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
gState->texPool().release(p->tex);
|
|
|
|
p->tex = newTex;
|
|
|
|
|
|
|
|
modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::drawText(int x, int y,
|
|
|
|
int width, int height,
|
|
|
|
const char *str, int align)
|
|
|
|
{
|
|
|
|
drawText(IntRect(x, y, width, height), str, align);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::drawText(const IntRect &rect, const char *str, int align)
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
|
|
|
GUARD_MEGA;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
if (*str == '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
flush();
|
|
|
|
|
|
|
|
TTF_Font *font = p->font->getSdlFont();
|
|
|
|
|
|
|
|
SDL_Color c;
|
|
|
|
p->font->getColor()->toSDLColor(c);
|
|
|
|
|
|
|
|
SDL_Surface *txtSurf;
|
|
|
|
|
|
|
|
if (gState->rtData().config.solidFonts)
|
|
|
|
txtSurf = TTF_RenderUTF8_Solid(font, str, c);
|
|
|
|
else
|
|
|
|
txtSurf = TTF_RenderUTF8_Blended(font, str, c);
|
|
|
|
|
|
|
|
p->ensureFormat(txtSurf, SDL_PIXELFORMAT_ARGB8888);
|
|
|
|
|
|
|
|
int alignX = rect.x;
|
|
|
|
|
|
|
|
switch (align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case Left :
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Center :
|
|
|
|
alignX += (rect.w - txtSurf->w) / 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Right :
|
|
|
|
alignX += rect.w - txtSurf->w;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alignX < rect.x)
|
|
|
|
alignX = rect.x;
|
|
|
|
|
|
|
|
int alignY = rect.y + (rect.h - txtSurf->h) / 2;
|
|
|
|
|
|
|
|
float squeeze = (float) rect.w / txtSurf->w;
|
|
|
|
|
|
|
|
if (squeeze > 1)
|
|
|
|
squeeze = 1;
|
|
|
|
|
|
|
|
FloatRect posRect(alignX, alignY, txtSurf->w * squeeze, txtSurf->h);
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
Vec2i gpTexSize;
|
2013-09-01 14:27:21 +00:00
|
|
|
gState->ensureTexSize(txtSurf->w, txtSurf->h, gpTexSize);
|
|
|
|
|
|
|
|
// if (str[1] != '\0')
|
|
|
|
{
|
|
|
|
/* Aquire a partial copy of the destination
|
|
|
|
* buffer we're about to render to */
|
2013-09-06 10:26:41 +00:00
|
|
|
TEXFBO &gpTex2 = gState->gpTexFBO(posRect.w, posRect.h);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
FBO::bind(gpTex2.fbo, FBO::Draw);
|
|
|
|
FBO::bind(p->tex.fbo, FBO::Read);
|
|
|
|
FBO::blit(posRect.x, posRect.y, 0, 0, posRect.w, posRect.h);
|
|
|
|
|
|
|
|
FloatRect bltRect(0, 0,
|
2013-09-23 05:15:01 +00:00
|
|
|
(float) gpTexSize.x / gpTex2.width,
|
|
|
|
(float) gpTexSize.y / gpTex2.height);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
BltShader &shader = gState->bltShader();
|
|
|
|
shader.bind();
|
2013-09-23 05:15:01 +00:00
|
|
|
shader.setTexSize(gpTexSize);
|
2013-09-01 14:27:21 +00:00
|
|
|
shader.setSource();
|
|
|
|
shader.setDestination(gpTex2.tex);
|
|
|
|
shader.setSubRect(bltRect);
|
|
|
|
shader.setOpacity(p->font->getColor()->norm.w);
|
|
|
|
}
|
|
|
|
|
|
|
|
gState->bindTex();
|
2013-09-06 12:37:28 +00:00
|
|
|
TEX::uploadSubImage(0, 0, txtSurf->w, txtSurf->h, txtSurf->pixels, GL_BGRA_EXT);
|
2013-09-06 10:26:41 +00:00
|
|
|
TEX::setSmooth(true);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-04 17:07:28 +00:00
|
|
|
Quad &quad = gState->gpQuad();
|
2013-09-01 14:27:21 +00:00
|
|
|
quad.setTexRect(FloatRect(0, 0, txtSurf->w, txtSurf->h));
|
|
|
|
quad.setPosRect(posRect);
|
|
|
|
SDL_FreeSurface(txtSurf);
|
|
|
|
|
|
|
|
p->bindFBO();
|
2013-09-23 05:15:01 +00:00
|
|
|
p->pushSetViewport(gState->bltShader());
|
2013-09-01 14:27:21 +00:00
|
|
|
glState.blendMode.pushSet(BlendNone);
|
|
|
|
|
|
|
|
quad.draw();
|
|
|
|
|
|
|
|
glState.blendMode.pop();
|
|
|
|
p->popViewport();
|
|
|
|
|
|
|
|
modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
IntRect Bitmap::textSize(const char *str)
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_DISPOSED;
|
|
|
|
|
|
|
|
GUARD_MEGA;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
TTF_Font *font = p->font->getSdlFont();
|
|
|
|
|
|
|
|
int w, h;
|
|
|
|
TTF_SizeUTF8(font, str, &w, &h);
|
|
|
|
|
|
|
|
// if (strlen(str) == 1)
|
|
|
|
// TTF_GlyphMetrics(font, *str, 0, 0, 0, 0, &w);
|
|
|
|
|
|
|
|
return IntRect(0, 0, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_ATTR_SIMPLE(Bitmap, Font, Font*, p->font)
|
|
|
|
|
|
|
|
void Bitmap::flush() const
|
|
|
|
{
|
2013-09-23 05:15:01 +00:00
|
|
|
if (isDisposed())
|
|
|
|
return;
|
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
if (p->megaSurface)
|
|
|
|
return;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
p->flushPoints();
|
|
|
|
}
|
|
|
|
|
2013-09-06 10:26:41 +00:00
|
|
|
TEXFBO &Bitmap::getGLTypes()
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
|
|
|
return p->tex;
|
|
|
|
}
|
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
SDL_Surface *Bitmap::megaSurface()
|
|
|
|
{
|
|
|
|
return p->megaSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::ensureNonMega()
|
|
|
|
{
|
2013-09-24 20:42:10 +00:00
|
|
|
if (isDisposed())
|
|
|
|
return;
|
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
GUARD_MEGA;
|
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
void Bitmap::bindTex(ShaderBase &shader)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2013-09-23 05:15:01 +00:00
|
|
|
p->bindTexture(shader);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Bitmap::releaseResources()
|
|
|
|
{
|
Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.
Various other minor changes and fixes are included.
2013-09-23 20:21:58 +00:00
|
|
|
if (p->megaSurface)
|
|
|
|
SDL_FreeSurface(p->megaSurface);
|
|
|
|
else
|
|
|
|
gState->texPool().release(p->tex);
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
delete p;
|
|
|
|
}
|