mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-10 08:55:33 +02:00
Add Bitmap constructors that take a TEXFBO or an SDL_Surface
Refactor snapToBitmap to use it, and add ability to dump VX Atlas with it.
This commit is contained in:
parent
6f20252e04
commit
7032dccbc7
7 changed files with 133 additions and 54 deletions
|
@ -452,4 +452,10 @@
|
||||||
// "x": ...
|
// "x": ...
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// Dump tile atlas (for debugging purposes)
|
||||||
|
// (default: false)
|
||||||
|
//
|
||||||
|
// "dumpAtlas": false,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,7 @@ void Config::read(int argc, char *argv[]) {
|
||||||
{"JITMaxCache", 100},
|
{"JITMaxCache", 100},
|
||||||
{"JITMinCalls", 10000},
|
{"JITMinCalls", 10000},
|
||||||
{"YJITEnable", false},
|
{"YJITEnable", false},
|
||||||
|
{"dumpAtlas", false},
|
||||||
{"bindingNames", json::object({
|
{"bindingNames", json::object({
|
||||||
{"a", "A"},
|
{"a", "A"},
|
||||||
{"b", "B"},
|
{"b", "B"},
|
||||||
|
@ -295,6 +296,7 @@ try { exp } catch (...) {}
|
||||||
SET_OPT_CUSTOMKEY(BGM.trackCount, BGMTrackCount, integer);
|
SET_OPT_CUSTOMKEY(BGM.trackCount, BGMTrackCount, integer);
|
||||||
SET_STRINGOPT(customScript, customScript);
|
SET_STRINGOPT(customScript, customScript);
|
||||||
SET_OPT(useScriptNames, boolean);
|
SET_OPT(useScriptNames, boolean);
|
||||||
|
SET_OPT(dumpAtlas, boolean);
|
||||||
|
|
||||||
fillStringVec(opts["preloadScript"], preloadScripts);
|
fillStringVec(opts["preloadScript"], preloadScripts);
|
||||||
fillStringVec(opts["RTP"], rtps);
|
fillStringVec(opts["RTP"], rtps);
|
||||||
|
|
|
@ -110,7 +110,7 @@ struct Config {
|
||||||
std::vector<std::string> fontSubs;
|
std::vector<std::string> fontSubs;
|
||||||
|
|
||||||
std::vector<std::string> rubyLoadpaths;
|
std::vector<std::string> rubyLoadpaths;
|
||||||
|
|
||||||
/* Editor flags */
|
/* Editor flags */
|
||||||
struct {
|
struct {
|
||||||
bool debug;
|
bool debug;
|
||||||
|
@ -136,6 +136,8 @@ struct Config {
|
||||||
bool enabled;
|
bool enabled;
|
||||||
} yjit;
|
} yjit;
|
||||||
|
|
||||||
|
bool dumpAtlas;
|
||||||
|
|
||||||
// Keybinding action name mappings
|
// Keybinding action name mappings
|
||||||
struct {
|
struct {
|
||||||
std::string a;
|
std::string a;
|
||||||
|
|
|
@ -618,49 +618,10 @@ Bitmap::Bitmap(const char *filename)
|
||||||
p->addTaintedArea(rect());
|
p->addTaintedArea(rect());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface *imgSurf = handler.surface;
|
SDL_Surface *imgSurf = handler.surface;
|
||||||
|
|
||||||
|
initFromSurface(imgSurf, hiresBitmap, true);
|
||||||
p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888);
|
|
||||||
|
|
||||||
if (imgSurf->w > glState.caps.maxTexSize || imgSurf->h > glState.caps.maxTexSize)
|
|
||||||
{
|
|
||||||
/* Mega surface */
|
|
||||||
p = new BitmapPrivate(this);
|
|
||||||
p->selfHires = hiresBitmap;
|
|
||||||
p->megaSurface = imgSurf;
|
|
||||||
SDL_SetSurfaceBlendMode(p->megaSurface, SDL_BLENDMODE_NONE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Regular surface */
|
|
||||||
TEXFBO tex;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
tex = shState->texPool().request(imgSurf->w, imgSurf->h);
|
|
||||||
}
|
|
||||||
catch (const Exception &e)
|
|
||||||
{
|
|
||||||
SDL_FreeSurface(imgSurf);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = new BitmapPrivate(this);
|
|
||||||
p->selfHires = hiresBitmap;
|
|
||||||
p->gl = tex;
|
|
||||||
if (p->selfHires != nullptr) {
|
|
||||||
p->gl.selfHires = &p->selfHires->getGLTypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEX::bind(p->gl.tex);
|
|
||||||
TEX::uploadImage(p->gl.width, p->gl.height, imgSurf->pixels, GL_RGBA);
|
|
||||||
|
|
||||||
SDL_FreeSurface(imgSurf);
|
|
||||||
}
|
|
||||||
|
|
||||||
p->addTaintedArea(rect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap::Bitmap(int width, int height, bool isHires)
|
Bitmap::Bitmap(int width, int height, bool isHires)
|
||||||
|
@ -683,10 +644,10 @@ Bitmap::Bitmap(int width, int height, bool isHires)
|
||||||
|
|
||||||
p = new BitmapPrivate(this);
|
p = new BitmapPrivate(this);
|
||||||
p->gl = tex;
|
p->gl = tex;
|
||||||
|
p->selfHires = hiresBitmap;
|
||||||
if (p->selfHires != nullptr) {
|
if (p->selfHires != nullptr) {
|
||||||
p->gl.selfHires = &p->selfHires->getGLTypes();
|
p->gl.selfHires = &p->selfHires->getGLTypes();
|
||||||
}
|
}
|
||||||
p->selfHires = hiresBitmap;
|
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
@ -798,11 +759,104 @@ Bitmap::Bitmap(const Bitmap &other, int frame)
|
||||||
p->addTaintedArea(rect());
|
p->addTaintedArea(rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bitmap::Bitmap(TEXFBO &other)
|
||||||
|
{
|
||||||
|
Bitmap *hiresBitmap = nullptr;
|
||||||
|
|
||||||
|
if (other.selfHires != nullptr) {
|
||||||
|
// Create a high-res version as well.
|
||||||
|
hiresBitmap = new Bitmap(*other.selfHires);
|
||||||
|
hiresBitmap->setLores(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
p = new BitmapPrivate(this);
|
||||||
|
|
||||||
|
p->gl = shState->texPool().request(other.width, other.height);
|
||||||
|
|
||||||
|
p->selfHires = hiresBitmap;
|
||||||
|
if (p->selfHires != nullptr) {
|
||||||
|
p->gl.selfHires = &p->selfHires->getGLTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip blitting to lores texture, since only the hires one will be displayed.
|
||||||
|
if (p->selfHires == nullptr) {
|
||||||
|
GLMeta::blitBegin(p->gl);
|
||||||
|
GLMeta::blitSource(other);
|
||||||
|
GLMeta::blitRectangle(rect(), rect(), true);
|
||||||
|
GLMeta::blitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
p->addTaintedArea(rect());
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap::Bitmap(SDL_Surface *imgSurf, SDL_Surface *imgSurfHires)
|
||||||
|
{
|
||||||
|
Bitmap *hiresBitmap = nullptr;
|
||||||
|
|
||||||
|
if (imgSurfHires != nullptr) {
|
||||||
|
// Create a high-res version as well.
|
||||||
|
hiresBitmap = new Bitmap(imgSurfHires, nullptr);
|
||||||
|
hiresBitmap->setLores(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
initFromSurface(imgSurf, hiresBitmap, false);
|
||||||
|
}
|
||||||
|
|
||||||
Bitmap::~Bitmap()
|
Bitmap::~Bitmap()
|
||||||
{
|
{
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bitmap::initFromSurface(SDL_Surface *imgSurf, Bitmap *hiresBitmap, bool freeSurface)
|
||||||
|
{
|
||||||
|
p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888);
|
||||||
|
|
||||||
|
if (imgSurf->w > glState.caps.maxTexSize || imgSurf->h > glState.caps.maxTexSize)
|
||||||
|
{
|
||||||
|
/* Mega surface */
|
||||||
|
|
||||||
|
if(!freeSurface) {
|
||||||
|
throw Exception(Exception::RGSSError, "Cloning Mega Bitmap from Surface not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
p = new BitmapPrivate(this);
|
||||||
|
p->selfHires = hiresBitmap;
|
||||||
|
p->megaSurface = imgSurf;
|
||||||
|
SDL_SetSurfaceBlendMode(p->megaSurface, SDL_BLENDMODE_NONE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Regular surface */
|
||||||
|
TEXFBO tex;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tex = shState->texPool().request(imgSurf->w, imgSurf->h);
|
||||||
|
}
|
||||||
|
catch (const Exception &e)
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(imgSurf);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = new BitmapPrivate(this);
|
||||||
|
p->selfHires = hiresBitmap;
|
||||||
|
p->gl = tex;
|
||||||
|
if (p->selfHires != nullptr) {
|
||||||
|
p->gl.selfHires = &p->selfHires->getGLTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEX::bind(p->gl.tex);
|
||||||
|
TEX::uploadImage(p->gl.width, p->gl.height, imgSurf->pixels, GL_RGBA);
|
||||||
|
|
||||||
|
if (freeSurface) {
|
||||||
|
SDL_FreeSurface(imgSurf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p->addTaintedArea(rect());
|
||||||
|
}
|
||||||
|
|
||||||
int Bitmap::width() const
|
int Bitmap::width() const
|
||||||
{
|
{
|
||||||
guardDisposed();
|
guardDisposed();
|
||||||
|
|
|
@ -40,13 +40,18 @@ class Bitmap : public Disposable
|
||||||
public:
|
public:
|
||||||
Bitmap(const char *filename);
|
Bitmap(const char *filename);
|
||||||
Bitmap(int width, int height, bool isHires = false);
|
Bitmap(int width, int height, bool isHires = false);
|
||||||
Bitmap(void *pixeldata, int width, int height);
|
Bitmap(void *pixeldata, int width, int height);
|
||||||
|
Bitmap(TEXFBO &other);
|
||||||
|
Bitmap(SDL_Surface *imgSurf, SDL_Surface *imgSurfHires);
|
||||||
|
|
||||||
/* Clone constructor */
|
/* Clone constructor */
|
||||||
|
|
||||||
// frame is -2 for "any and all", -1 for "current", anything else for a specific frame
|
// frame is -2 for "any and all", -1 for "current", anything else for a specific frame
|
||||||
Bitmap(const Bitmap &other, int frame = -2);
|
Bitmap(const Bitmap &other, int frame = -2);
|
||||||
~Bitmap();
|
~Bitmap();
|
||||||
|
|
||||||
|
void initFromSurface(SDL_Surface *imgSurf, Bitmap *hiresBitmap, bool freeSurface);
|
||||||
|
|
||||||
int width() const;
|
int width() const;
|
||||||
int height() const;
|
int height() const;
|
||||||
bool hasHires() const;
|
bool hasHires() const;
|
||||||
|
|
|
@ -1403,17 +1403,17 @@ void Graphics::fadein(int duration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap *Graphics::snapToBitmap() {
|
Bitmap *Graphics::snapToBitmap() {
|
||||||
Bitmap *bitmap = new Bitmap(width(), height());
|
if (shState->config().enableHires) {
|
||||||
|
// TODO: Maybe don't reconstruct this struct every time?
|
||||||
if (bitmap->hasHires()) {
|
TEXFBO tf;
|
||||||
p->compositeToBufferScaled(bitmap->getHires()->getGLTypes(), bitmap->getHires()->width(), bitmap->getHires()->height());
|
tf.width = width();
|
||||||
|
tf.height = height();
|
||||||
|
tf.selfHires = &p->screen.getPP().frontBuffer();
|
||||||
|
|
||||||
|
return new Bitmap(tf);
|
||||||
}
|
}
|
||||||
|
|
||||||
p->compositeToBufferScaled(bitmap->getGLTypes(), bitmap->width(), bitmap->height());
|
return new Bitmap(p->screen.getPP().frontBuffer());
|
||||||
|
|
||||||
/* Taint entire bitmap */
|
|
||||||
bitmap->taintArea(IntRect(0, 0, width(), height()));
|
|
||||||
return bitmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Graphics::width() const { return p->scResLores.x; }
|
int Graphics::width() const { return p->scResLores.x; }
|
||||||
|
|
|
@ -190,6 +190,16 @@ struct TilemapVXPrivate : public ViewportElement, TileAtlasVX::Reader
|
||||||
void rebuildAtlas()
|
void rebuildAtlas()
|
||||||
{
|
{
|
||||||
TileAtlasVX::build(atlas, bitmaps);
|
TileAtlasVX::build(atlas, bitmaps);
|
||||||
|
|
||||||
|
if (shState->config().dumpAtlas)
|
||||||
|
{
|
||||||
|
Bitmap dump(atlas);
|
||||||
|
dump.saveToFile("dumped_atlas.png");
|
||||||
|
if (dump.hasHires())
|
||||||
|
{
|
||||||
|
dump.getHires()->saveToFile("dumped_atlas_hires.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateMapViewport()
|
void updateMapViewport()
|
||||||
|
|
Loading…
Add table
Reference in a new issue