handle other texture formats

This commit is contained in:
tildearrow 2024-05-15 04:08:50 -05:00
parent f51ad1cf1f
commit a4cba0f05c
16 changed files with 135 additions and 2 deletions

View file

@ -101,6 +101,44 @@ FurnaceGUIImage* FurnaceGUI::getImage(FurnaceGUIImages image) {
}
#endif
if (ret->ch==4) {
size_t total=ret->width*ret->height*ret->ch;
switch (bestTexFormat) {
case GUI_TEXFORMAT_ARGB32:
for (size_t i=0; i<total; i+=4) {
ret->data[i]^=ret->data[i|2];
ret->data[i|2]^=ret->data[i];
ret->data[i]^=ret->data[i|2];
}
break;
case GUI_TEXFORMAT_BGRA32:
for (size_t i=0; i<total; i+=4) {
ret->data[i]^=ret->data[i|3];
ret->data[i|3]^=ret->data[i];
ret->data[i]^=ret->data[i|3];
ret->data[i|1]^=ret->data[i|2];
ret->data[i|2]^=ret->data[i|1];
ret->data[i|1]^=ret->data[i|2];
ret->data[i|1]^=ret->data[i|3];
ret->data[i|3]^=ret->data[i|1];
ret->data[i|1]^=ret->data[i|3];
}
break;
case GUI_TEXFORMAT_RGBA32:
for (size_t i=0; i<total; i+=4) {
ret->data[i]^=ret->data[i|3];
ret->data[i|3]^=ret->data[i];
ret->data[i]^=ret->data[i|3];
ret->data[i|1]^=ret->data[i|2];
ret->data[i|2]^=ret->data[i|1];
ret->data[i|1]^=ret->data[i|2];
}
break;
default:
break;
}
}
images[image]=ret;
}

View file

@ -75,6 +75,7 @@ class FurnaceDXTexture: public FurnaceGUITexture {
ID3D11Texture2D* tex;
ID3D11ShaderResourceView* view;
int width, height;
FurnaceGUITextureFormat format;
unsigned char* lockedData;
bool dynamic;
FurnaceDXTexture():
@ -82,6 +83,7 @@ class FurnaceDXTexture: public FurnaceGUITexture {
view(NULL),
width(0),
height(0),
format(GUI_TEXFORMAT_UNKNOWN),
lockedData(NULL),
dynamic(false) {}
};
@ -147,6 +149,11 @@ ImTextureID FurnaceGUIRenderDX11::getTextureID(FurnaceGUITexture* which) {
return (ImTextureID)t->view;
}
FurnaceGUITextureFormat FurnaceGUIRenderDX11::getTextureFormat(FurnaceGUITexture* which) {
FurnaceDXTexture* t=(FurnaceDXTexture*)which;
return t->format;
}
bool FurnaceGUIRenderDX11::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) {
FurnaceDXTexture* t=(FurnaceDXTexture*)which;
if (t->lockedData!=NULL) return false;
@ -256,6 +263,7 @@ FurnaceGUITexture* FurnaceGUIRenderDX11::createTexture(bool dynamic, int width,
ret->tex=tex;
ret->view=view;
ret->dynamic=dynamic;
ret->format=format;
return ret;
}

View file

@ -64,6 +64,7 @@ class FurnaceGUIRenderDX11: public FurnaceGUIRender {
public:
ImTextureID getTextureID(FurnaceGUITexture* which);
FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which);
bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch);
bool unlockTexture(FurnaceGUITexture* which);
bool updateTexture(FurnaceGUITexture* which, void* data, int pitch);

View file

@ -30,6 +30,7 @@ class FurnaceDX9Texture: public FurnaceGUITexture {
IDirect3DTexture9* tex;
IDirect3DTexture9* texPre;
int width, height, widthReal, heightReal;
FurnaceGUITextureFormat format;
unsigned char* lockedData;
bool dynamic;
FurnaceDX9Texture():
@ -39,6 +40,7 @@ class FurnaceDX9Texture: public FurnaceGUITexture {
height(0),
widthReal(0),
heightReal(0),
format(GUI_TEXFORMAT_UNKNOWN),
lockedData(NULL),
dynamic(false) {}
};
@ -62,6 +64,11 @@ float FurnaceGUIRenderDX9::getTextureV(FurnaceGUITexture* which) {
return (float)t->height/(float)t->heightReal;
}
FurnaceGUITextureFormat FurnaceGUIRenderDX9::getTextureFormat(FurnaceGUITexture* which) {
FurnaceDX9Texture* t=(FurnaceDX9Texture*)which;
return t->format;
}
bool FurnaceGUIRenderDX9::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) {
FurnaceDX9Texture* t=(FurnaceDX9Texture*)which;
D3DLOCKED_RECT lockedRect;
@ -198,6 +205,7 @@ FurnaceGUITexture* FurnaceGUIRenderDX9::createTexture(bool dynamic, int width, i
ret->tex=tex;
ret->texPre=texPre;
ret->dynamic=dynamic;
ret->format=format;
return ret;
}

View file

@ -49,6 +49,7 @@ class FurnaceGUIRenderDX9: public FurnaceGUIRender {
ImTextureID getTextureID(FurnaceGUITexture* which);
float getTextureU(FurnaceGUITexture* which);
float getTextureV(FurnaceGUITexture* which);
FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which);
bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch);
bool unlockTexture(FurnaceGUITexture* which);
bool updateTexture(FurnaceGUITexture* which, void* data, int pitch);

View file

@ -65,11 +65,13 @@ class FurnaceGLTexture: public FurnaceGUITexture {
public:
GLuint id;
int width, height;
FurnaceGUITextureFormat format;
unsigned char* lockedData;
FurnaceGLTexture():
id(0),
width(0),
height(0),
format(GUI_TEXFORMAT_UNKNOWN),
lockedData(NULL) {}
};
@ -281,6 +283,11 @@ ImTextureID FurnaceGUIRenderGL::getTextureID(FurnaceGUITexture* which) {
return (ImTextureID)ret;
}
FurnaceGUITextureFormat FurnaceGUIRenderGL::getTextureFormat(FurnaceGUITexture* which) {
FurnaceGLTexture* t=(FurnaceGLTexture*)which;
return t->format;
}
bool FurnaceGUIRenderGL::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) {
FurnaceGLTexture* t=(FurnaceGLTexture*)which;
if (t->lockedData!=NULL) return false;
@ -334,6 +341,7 @@ FurnaceGUITexture* FurnaceGUIRenderGL::createTexture(bool dynamic, int width, in
C(furActiveTexture(GL_TEXTURE0));
t->width=width;
t->height=height;
t->format=format;
return t;
}

View file

@ -56,6 +56,7 @@ class FurnaceGUIRenderGL: public FurnaceGUIRender {
public:
ImTextureID getTextureID(FurnaceGUITexture* which);
FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which);
bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch);
bool unlockTexture(FurnaceGUITexture* which);
bool updateTexture(FurnaceGUITexture* which, void* data, int pitch);

View file

@ -29,6 +29,7 @@ class FurnaceGL1Texture: public FurnaceGUITexture {
public:
GLuint id;
int width, height, widthReal, heightReal;
FurnaceGUITextureFormat format;
unsigned char* lockedData;
FurnaceGL1Texture():
id(0),
@ -36,6 +37,7 @@ class FurnaceGL1Texture: public FurnaceGUITexture {
height(0),
widthReal(0),
heightReal(0),
format(GUI_TEXFORMAT_UNKNOWN),
lockedData(NULL) {}
};
@ -56,6 +58,11 @@ float FurnaceGUIRenderGL1::getTextureV(FurnaceGUITexture* which) {
return (float)t->height/(float)t->heightReal;
}
FurnaceGUITextureFormat FurnaceGUIRenderGL1::getTextureFormat(FurnaceGUITexture* which) {
FurnaceGL1Texture* t=(FurnaceGL1Texture*)which;
return t->format;
}
bool FurnaceGUIRenderGL1::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) {
FurnaceGL1Texture* t=(FurnaceGL1Texture*)which;
if (t->lockedData!=NULL) return false;
@ -125,6 +132,7 @@ FurnaceGUITexture* FurnaceGUIRenderGL1::createTexture(bool dynamic, int width, i
t->height=height;
t->widthReal=widthReal;
t->heightReal=heightReal;
t->format=format;
return t;
}

View file

@ -32,6 +32,7 @@ class FurnaceGUIRenderGL1: public FurnaceGUIRender {
ImTextureID getTextureID(FurnaceGUITexture* which);
float getTextureU(FurnaceGUITexture* which);
float getTextureV(FurnaceGUITexture* which);
FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which);
bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch);
bool unlockTexture(FurnaceGUITexture* which);
bool updateTexture(FurnaceGUITexture* which, void* data, int pitch);

View file

@ -28,6 +28,7 @@ class FurnaceGUIRenderMetal: public FurnaceGUIRender {
String vendorName, deviceName, apiVersion;
public:
ImTextureID getTextureID(FurnaceGUITexture* which);
FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which);
bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch);
bool unlockTexture(FurnaceGUITexture* which);
bool updateTexture(FurnaceGUITexture* which, void* data, int pitch);

View file

@ -44,11 +44,13 @@ class FurnaceMetalTexture: public FurnaceGUITexture {
public:
id<MTLTexture> tex;
int width, height;
FurnaceGUITextureFormat format;
unsigned char* lockedData;
FurnaceMetalTexture():
tex(NULL),
width(0),
height(0),
format(GUI_TEXFORMAT_UNKNOWN),
lockedData(NULL) {}
};
@ -57,6 +59,11 @@ ImTextureID FurnaceGUIRenderMetal::getTextureID(FurnaceGUITexture* which) {
return t->tex;
}
FurnaceGUITextureFormat FurnaceGUIRenderMetal::getTextureFormat(FurnaceGUITexture* which) {
FurnaceMetalTexture* t=(FurnaceMetalTexture*)which;
return t->format;
}
bool FurnaceGUIRenderMetal::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) {
FurnaceMetalTexture* t=(FurnaceMetalTexture*)which;
if (t->lockedData!=NULL) return false;

View file

@ -24,8 +24,10 @@
class FurnaceSDLTexture: public FurnaceGUITexture {
public:
SDL_Texture* tex;
FurnaceGUITextureFormat format;
FurnaceSDLTexture():
tex(NULL) {}
tex(NULL),
format(GUI_TEXFORMAT_UNKNOWN) {}
};
ImTextureID FurnaceGUIRenderSDL::getTextureID(FurnaceGUITexture* which) {
@ -33,6 +35,11 @@ ImTextureID FurnaceGUIRenderSDL::getTextureID(FurnaceGUITexture* which) {
return t->tex;
}
FurnaceGUITextureFormat FurnaceGUIRenderSDL::getTextureFormat(FurnaceGUITexture* which) {
FurnaceSDLTexture* t=(FurnaceSDLTexture*)which;
return t->format;
}
bool FurnaceGUIRenderSDL::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) {
FurnaceSDLTexture* t=(FurnaceSDLTexture*)which;
return SDL_LockTexture(t->tex,NULL,data,pitch)==0;
@ -61,6 +68,7 @@ FurnaceGUITexture* FurnaceGUIRenderSDL::createTexture(bool dynamic, int width, i
if (t==NULL) return NULL;
FurnaceSDLTexture* ret=new FurnaceSDLTexture;
ret->tex=t;
ret->format=format;
return ret;
}

View file

@ -26,6 +26,7 @@ class FurnaceGUIRenderSDL: public FurnaceGUIRender {
bool swapIntervalSet;
public:
ImTextureID getTextureID(FurnaceGUITexture* which);
FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which);
bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch);
bool unlockTexture(FurnaceGUITexture* which);
bool updateTexture(FurnaceGUITexture* which, void* data, int pitch);

View file

@ -24,8 +24,10 @@
class FurnaceSoftwareTexture: public FurnaceGUITexture {
public:
SWTexture* tex;
FurnaceGUITextureFormat format;
FurnaceSoftwareTexture():
tex(NULL) {}
tex(NULL),
format(GUI_TEXFORMAT_UNKNOWN) {}
};
ImTextureID FurnaceGUIRenderSoftware::getTextureID(FurnaceGUITexture* which) {
@ -33,6 +35,11 @@ ImTextureID FurnaceGUIRenderSoftware::getTextureID(FurnaceGUITexture* which) {
return t->tex;
}
FurnaceGUITextureFormat FurnaceGUIRenderSoftware::getTextureFormat(FurnaceGUITexture* which) {
FurnaceSoftwareTexture* t=(FurnaceSoftwareTexture*)which;
return t->format;
}
bool FurnaceGUIRenderSoftware::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) {
FurnaceSoftwareTexture* t=(FurnaceSoftwareTexture*)which;
if (!t->tex->managed) return false;
@ -59,6 +66,7 @@ FurnaceGUITexture* FurnaceGUIRenderSoftware::createTexture(bool dynamic, int wid
}
FurnaceSoftwareTexture* ret=new FurnaceSoftwareTexture;
ret->tex=new SWTexture(width,height);
ret->format=format;
return ret;
}

View file

@ -23,6 +23,7 @@ class FurnaceGUIRenderSoftware: public FurnaceGUIRender {
SDL_Window* sdlWin;
public:
ImTextureID getTextureID(FurnaceGUITexture* which);
FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which);
bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch);
bool unlockTexture(FurnaceGUITexture* which);
bool updateTexture(FurnaceGUITexture* which, void* data, int pitch);

View file

@ -31,6 +31,15 @@
#include "sampleUtil.h"
#include "util.h"
#define SWAP_COLOR_ARGB(x) \
x=(x&0xff00ff00)|((x&0xff)<<16)|((x&0xff0000)>>16);
#define SWAP_COLOR_BGRA(x) \
x=((x&0xff0000000)>>24)|((x&0xffffff)<<8);
#define SWAP_COLOR_RGBA(x) \
x=((x&0xff)<<24)|((x&0xff00)<<8)|((x&0xff0000)>>8)|((x&0xff000000)>>24);
const double timeDivisors[10]={
1000.0, 500.0, 200.0, 100.0, 50.0, 20.0, 10.0, 5.0, 2.0, 1.0
};
@ -1501,6 +1510,30 @@ void FurnaceGUI::drawSampleEdit() {
ImU32 bgColorLoop=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP]);
ImU32 lineColor=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_FG]);
ImU32 centerLineColor=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_CENTER]);
switch (rend->getTextureFormat(sampleTex)) {
case GUI_TEXFORMAT_ARGB32:
SWAP_COLOR_ARGB(bgColor);
SWAP_COLOR_ARGB(bgColorLoop);
SWAP_COLOR_ARGB(lineColor);
SWAP_COLOR_ARGB(centerLineColor);
break;
case GUI_TEXFORMAT_BGRA32:
SWAP_COLOR_BGRA(bgColor);
SWAP_COLOR_BGRA(bgColorLoop);
SWAP_COLOR_BGRA(lineColor);
SWAP_COLOR_BGRA(centerLineColor);
break;
case GUI_TEXFORMAT_RGBA32:
SWAP_COLOR_RGBA(bgColor);
SWAP_COLOR_RGBA(bgColorLoop);
SWAP_COLOR_RGBA(lineColor);
SWAP_COLOR_RGBA(centerLineColor);
break;
default:
break;
}
int ij=0;
for (int i=0; i<availY; i++) {
for (int j=0; j<availX; j++) {