1
0

Fix graphic

This commit is contained in:
otya128
2016-12-13 20:31:48 +09:00
parent d68cd3e878
commit ccc09093b0
2 changed files with 44 additions and 217 deletions

View File

@@ -78,10 +78,7 @@ class Graphic
{ {
width = w; width = w;
height = h; height = h;
initGraphicPages();/* initGraphicPages();
DrawMessage dm;
dm.type = DrawType.INIT;
sendDrawMessage(dm);*/
} }
void getSize(out int w, out int h) void getSize(out int w, out int h)
{ {
@@ -92,18 +89,21 @@ class Graphic
{ {
if (GRP.length != 0 && GRP[0].glTexture/*TODO:gl texture 0?*/) if (GRP.length != 0 && GRP[0].glTexture/*TODO:gl texture 0?*/)
{ {
oldGRP = GRP; foreach(g; GRP)
{
g.deleteGL();
}
}
else
{
GRP = new GraphicPage[6];
} }
GRP = new GraphicPage[6];
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
GRP[i] = createEmptyPage(); GRP[i] = createEmptyPage();
} }
GRP[4] = createGRPF(petitcom.spriteFile); GRP[4] = createGRPF(petitcom.spriteFile);
GRP[5] = createGRPF(petitcom.BGFile); GRP[5] = createGRPF(petitcom.BGFile);
}
void initGLGraphicPages()
{
foreach(g; GRP) foreach(g; GRP)
{ {
g.createTexture(petitcom.renderer, petitcom.textureScaleMode); g.createTexture(petitcom.renderer, petitcom.textureScaleMode);
@@ -448,138 +448,6 @@ class Graphic
chScreen(writeArea[display].x, writeArea[display].y, writeArea[display].w, writeArea[display].h); chScreen(writeArea[display].x, writeArea[display].y, writeArea[display].w, writeArea[display].h);
glBindFramebufferEXT(GL_FRAMEBUFFER, this.GRP[usePage[display]].buffer); glBindFramebufferEXT(GL_FRAMEBUFFER, this.GRP[usePage[display]].buffer);
} }
void draw2()
{
if (!GRP[0].glTexture)
{
if (oldGRP.length)
{
foreach (i; oldGRP)
{
i.deleteGL;
}
oldGRP = null;
}
initGLGraphicPages();
}
//betuni kouzoutai demo sonnnani sokudo kawaranasasou
auto len = drawMessageLength;
GLint old;
int oldpage = drawMessageQueue[0].page;
glBindFramebufferEXT(GL_FRAMEBUFFER, this.GRP[oldpage].buffer);
//glAlphaFunc(GL_GEQUAL, 0.0);
void chScreen(int x, int y, int w, int h)
{
glViewport(x, y, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(x, x + w - 1, y, y + h - 1, -256, 1024);//wakaranai
}
DrawType dt;
static const size = 255.5f;
DrawMessage dm = drawMessageQueue[0];
int display = dm.display;
chScreen(writeArea[display].x, writeArea[display].y, writeArea[display].w, writeArea[display].h);
switch(dm.type)
{
case DrawType.CLIPWRITE:
writeArea[display].x = dm.x;
writeArea[display].y = dm.y;
writeArea[display].w = dm.w;
writeArea[display].h = dm.h;
break;
case DrawType.PSET:
glBegin(GL_POINTS);
glColor4ubv(cast(ubyte*)&dm.color);
glVertex2f(dm.x, dm.y);
glEnd();
break;
case DrawType.LINE:
{
glBegin(GL_LINES);
glColor4ubv(cast(ubyte*)&dm.color);
glVertex2f(dm.x, dm.y);
glVertex2f(dm.x2, dm.y2);
//glFlush();
glEnd();
}
break;
case DrawType.FILL:
{
glBegin(GL_QUADS);
glColor4ubv(cast(ubyte*)&dm.color);
glVertex2f(dm.x, dm.y);
glVertex2f(dm.x, dm.y2);
glVertex2f(dm.x2, dm.y2);
glVertex2f(dm.x2, dm.y);
glEnd();
}
break;
case DrawType.BOX:
{
glBegin(GL_LINE_LOOP);
glColor4ubv(cast(ubyte*)&dm.color);
glVertex2f(dm.x, dm.y);
glVertex2f(dm.x, dm.y2);
glVertex2f(dm.x2, dm.y2);
glVertex2f(dm.x2, dm.y);
glEnd();
}
break;
case DrawType.PAINT:
{
glBindTexture(GL_TEXTURE_2D, GRP[oldpage].glTexture);
if(dt != DrawType.PAINT)
{
glFinish();
//glGetTexImage(GL_TEXTURE_2D,0,GRP[oldpage].textureFormat,GL_UNSIGNED_BYTE,buffer.ptr);
glReadPixels(0, 0, width, height, GRP[oldpage].textureFormat, GL_UNSIGNED_BYTE, paint.buffer.ptr);
}
paint.gpaintBuffer(paint.buffer.ptr, dm.x, dm.y, dm.color, GRP[oldpage].textureFormat);
//gpaintBufferExW(oldpage, dm.x, dm.y, dm.color);
}
break;
case DrawType.CIRCLE1:
{
glColor4ubv(cast(ubyte*)&dm.color);
drawCircle(dm.x, dm.y, dm.circle.r);
}
break;
case DrawType.CIRCLE2:
{
glColor4ubv(cast(ubyte*)&dm.color);
drawCircle(dm.x, dm.y, dm.circle.r, dm.circle.startr, dm.circle.endr, dm.circle.flag);
}
break;
case DrawType.PUTCHR:
{
glColor4ubv(cast(ubyte*)&dm.color);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glBindTexture(GL_TEXTURE_2D, petitcom.console.GRPF.glTexture);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(dm.x, dm.y, 0);
glScalef(dm.character.scalex, dm.character.scaley, 1);
glBegin(GL_QUADS);
drawText(dm.character.text);
glEnd();
glPopMatrix();
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
}
break;
default:
}
glDisable(GL_TEXTURE_2D);
glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST);
drc++;
}
DrawMessage[] drawMessageQueue = new DrawMessage[1];
int drawMessageLength;
bool drawflag;
bool flushRequired; bool flushRequired;
void updateVM() void updateVM()
{ {
@@ -587,44 +455,10 @@ class Graphic
glFlush(); glFlush();
drc = 0; drc = 0;
} }
void sendDrawMessage(DrawMessage dm)
{
if (dm.type != DrawType.CLIPWRITE)
{
dm.color = petitcom.toGLColor(this.GRP[0].textureFormat, dm.color & 0xFFF8F8F8);
}
drawMessageQueue[0] = dm;
draw2();
}
void sendDrawMessage(DrawType type, byte page, short x, short y, uint color)
{
DrawMessage dm;
dm.type = type;
dm.page = page;
dm.x = x;
dm.y = y;
dm.color = color;
dm.display = cast(byte)petitcom.displaynum;
sendDrawMessage(dm);
}
void sendDrawMessage(DrawType type, byte page, short x, short y, short x2, short y2, uint color)
{
DrawMessage dm;
dm.type = type;
dm.page = page;
dm.x = x;
dm.y = y;
dm.x2 = x2;
dm.y2 = y2;
dm.color = color;
dm.display = cast(byte)petitcom.displaynum;
sendDrawMessage(dm);
}
uint convertColor(uint color) uint convertColor(uint color)
{ {
return petitcom.toGLColor(this.GRP[0].textureFormat, color & 0xFFF8F8F8); return petitcom.toGLColor(this.GRP[0].textureFormat, color & 0xFFF8F8F8);
} }
//TODO:範囲チェック
void gpset(int page, int x, int y, uint color) void gpset(int page, int x, int y, uint color)
{ {
color = convertColor(color); color = convertColor(color);
@@ -674,34 +508,25 @@ class Graphic
} }
void gpaint(int page, int x, int y, uint color) void gpaint(int page, int x, int y, uint color)
{ {
sendDrawMessage(DrawType.PAINT, cast(byte)page, cast(short)x, cast(short)y, color); color = convertColor(color);
updateVM();
//glGetTexImage(GL_TEXTURE_2D,0,GRP[oldpage].textureFormat,GL_UNSIGNED_BYTE,buffer.ptr);
glReadPixels(0, 0, width, height, GRP[useGRP].textureFormat, GL_UNSIGNED_BYTE, paint.buffer.ptr);
paint.gpaintBuffer(paint.buffer.ptr, x, y, color, GRP[useGRP].textureFormat);
} }
void gcircle(int page, int x, int y, int r, uint color) void gcircle(int page, int x, int y, int r, uint color)
{ {
DrawMessage dm; color = convertColor(color);
dm.page = cast(byte)page; glColor4ubv(cast(ubyte*)&color);
dm.x = cast(short)x; drawCircle(x, y, r);
dm.y = cast(short)y; drc++;
dm.circle.r = cast(short)r;
dm.color = color;
dm.type = DrawType.CIRCLE1;
dm.display = cast(byte)petitcom.displaynum;
sendDrawMessage(dm);
} }
void gcircle(int page, int x, int y, int r, int startr, int endr, int flag, uint color) void gcircle(int page, int x, int y, int r, int startr, int endr, int flag, uint color)
{ {
DrawMessage dm; color = convertColor(color);
dm.page = cast(byte)page; glColor4ubv(cast(ubyte*)&color);
dm.x = cast(short)x; drawCircle(x, y, r, startr, endr, flag);
dm.y = cast(short)y; drc++;
dm.circle.r = cast(short)r;
dm.circle.startr = cast(short)startr;
dm.circle.endr = cast(short)endr;
dm.circle.flag = cast(short)flag;
dm.color = color;
dm.type = DrawType.CIRCLE2;
dm.display = cast(byte)petitcom.displaynum;
sendDrawMessage(dm);
} }
void gputchr(int page, int x, int y, int text, int scalex, int scaley, uint color) void gputchr(int page, int x, int y, int text, int scalex, int scaley, uint color)
{ {
@@ -710,17 +535,22 @@ class Graphic
} }
void gputchr(int page, int x, int y, wstring text, int scalex, int scaley, uint color) void gputchr(int page, int x, int y, wstring text, int scalex, int scaley, uint color)
{ {
DrawMessage dm; color = convertColor(color);
dm.page = cast(byte)page; glColor4ubv(cast(ubyte*)&color);
dm.x = cast(short)x; glEnable(GL_TEXTURE_2D);
dm.y = cast(short)y; glEnable(GL_ALPHA_TEST);
dm.character.scalex = scalex; glBindTexture(GL_TEXTURE_2D, petitcom.console.GRPF.glTexture);
dm.character.scaley = scaley; glMatrixMode(GL_MODELVIEW);
dm.character.text = text; glPushMatrix();
dm.color = color; glTranslatef(x, y, 0);
dm.type = DrawType.PUTCHR; glScalef(scalex, scaley, 1);
dm.display = cast(byte)petitcom.displaynum; glBegin(GL_QUADS);
sendDrawMessage(dm); drawText(text);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glDisable(GL_ALPHA_TEST);
drc++;
} }
int gspoit(int page, int x, int y) int gspoit(int page, int x, int y)
{ {
@@ -781,14 +611,11 @@ class Graphic
{ {
if (clipmode) if (clipmode)
{ {
DrawMessage dm; writeArea[petitcom.displaynum].x = x;
dm.display = cast(byte)petitcom.displaynum; writeArea[petitcom.displaynum].y = y;
dm.x = cast(short)x; writeArea[petitcom.displaynum].w = w;
dm.y = cast(short)y; writeArea[petitcom.displaynum].h = h;
dm.w = cast(short)w; this.display(petitcom.displaynum);
dm.h = cast(short)h;
dm.type = DrawType.CLIPWRITE;
sendDrawMessage(dm);
} }
else else
{ {

View File

@@ -567,7 +567,6 @@ class PetitComputer
{ {
DerelictSDL2.load(); DerelictSDL2.load();
DerelictSDL2Image.load(); DerelictSDL2Image.load();
graphic.initGraphicPages();
sprite.sppage[] = 4; sprite.sppage[] = 4;
bgpage[] = 5; bgpage[] = 5;
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
@@ -650,6 +649,7 @@ class PetitComputer
} }
int loopcnt; int loopcnt;
DerelictGL3.reload(); DerelictGL3.reload();
graphic.initGraphicPages();
//3graphic.initGLGraphicPages(); //3graphic.initGLGraphicPages();
//glEnable(GL_BLEND); //glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);