1
0

Implement LOAD GRPF

This commit is contained in:
otya128
2017-07-09 23:25:09 +09:00
parent e10c6fb0d8
commit 2d2c09e38b
3 changed files with 70 additions and 17 deletions

View File

@@ -660,11 +660,11 @@ class BuiltinFunction
int colorflag = flagOrPalette.castInteger; int colorflag = flagOrPalette.castInteger;
if (ary.type == ValueType.IntegerArray) if (ary.type == ValueType.IntegerArray)
{ {
p.graphic.gload(x, y, w, h, ary.integerArray.array, colorflag, copymode); p.graphic.gload(p.graphic.useGRP, x, y, w, h, ary.integerArray.array, colorflag, copymode);
} }
if (ary.type == ValueType.DoubleArray) if (ary.type == ValueType.DoubleArray)
{ {
p.graphic.gload(x, y, w, h, ary.doubleArray.array, colorflag, copymode); p.graphic.gload(p.graphic.useGRP, x, y, w, h, ary.doubleArray.array, colorflag, copymode);
} }
} }
else if (flagOrPalette.isNumberArray) else if (flagOrPalette.isNumberArray)
@@ -2879,8 +2879,15 @@ class BuiltinFunction
p.program.slot[lot].load(filename, txt); p.program.slot[lot].load(filename, txt);
return; return;
} }
if(file.resource == Resource.graphic) if(file.resource == Resource.graphic || file.resource == Resource.graphicFont)
{ {
auto r = file.resourceNumber;
if (file.resource == Resource.graphicFont)
{
r = -1;
}
else if (!file.hasResourceNumber)
throw new IllegalFunctionCall("LOAD");
import otya.smilebasic.data; import otya.smilebasic.data;
DataHeader header; DataHeader header;
Value data = Value(new Array!int([0, 0])); Value data = Value(new Array!int([0, 0]));
@@ -2888,7 +2895,7 @@ class BuiltinFunction
return; return;
if (header.type == DataType.double_) if (header.type == DataType.double_)
throw new IllegalFileFormat("LOAD"); throw new IllegalFileFormat("LOAD");
GLOAD(p, 0, 0, data.integerArray.dim[0], data.integerArray.dim[1], data, Value(1), 1); p.graphic.gload(r, 0, 0, data.integerArray.dim[0], data.integerArray.dim[1], data.integerArray.array, 1, 1);
return; return;
} }
throw new IllegalFunctionCall("LOAD"); throw new IllegalFunctionCall("LOAD");

View File

@@ -635,6 +635,13 @@ class Console
buffer[x + font.x + (font.y + y) * w] = Graphic.RGBA16ToARGB32Color(cast(int)array[x + y * font.w]); buffer[x + font.x + (font.y + y) * w] = Graphic.RGBA16ToARGB32Color(cast(int)array[x + y * font.w]);
} }
} }
updateTexture;
}
public void updateTexture()
{
auto buffer = cast(int*)GRPF.surface.pixels;
auto w = GRPF.surface.w;
auto h = GRPF.surface.h;
//update texture //update texture
glBindTexture(GL_TEXTURE_2D, GRPF.glTexture); glBindTexture(GL_TEXTURE_2D, GRPF.glTexture);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, buffer); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, buffer);

View File

@@ -304,8 +304,8 @@ class Graphic
abstract int gspoit(int page, int x, int y); abstract int gspoit(int page, int x, int y);
abstract void gsave(int savepage, int x, int y, int w, int h, double[] array, int flag); abstract void gsave(int savepage, int x, int y, int w, int h, double[] array, int flag);
abstract void gsave(int savepage, int x, int y, int w, int h, int[] array, int flag); abstract void gsave(int savepage, int x, int y, int w, int h, int[] array, int flag);
abstract void gload(int x, int y, int w, int h, int[] array, int flag, int copymode); abstract void gload(int page, int x, int y, int w, int h, int[] array, int flag, int copymode);
abstract void gload(int x, int y, int w, int h, double[] array, int flag, int copymode); abstract void gload(int page, int x, int y, int w, int h, double[] array, int flag, int copymode);
void gloadPalette(T, T2)(int x, int y, int w, int h, T[] array, T2[] palette, int copymode) void gloadPalette(T, T2)(int x, int y, int w, int h, T[] array, T2[] palette, int copymode)
if ((is(T == int) || is(T == double)) && (is(T2 == int) || is(T2 == double))) if ((is(T == int) || is(T == double)) && (is(T2 == int) || is(T2 == double)))
{ {
@@ -691,7 +691,7 @@ class GraphicFBO : Graphic
} }
} }
} }
override void gload(int x, int y, int w, int h, int[] array, int flag, int copymode) override void gload(int page, int x, int y, int w, int h, int[] array, int flag, int copymode)
{ {
if (w * h > array.length) if (w * h > array.length)
return; return;
@@ -699,6 +699,19 @@ class GraphicFBO : Graphic
{ {
glEnable(GL_ALPHA_TEST); glEnable(GL_ALPHA_TEST);
} }
auto oldPage = useGRP;
if (page == -1)
{
glBindFramebufferEXT(GL_FRAMEBUFFER, petitcom.console.GRPF.buffer);
}
else
{
useGRP = page;
}
scope (exit)
{
useGRP = oldPage;
}
glRasterPos2i(x, y); glRasterPos2i(x, y);
//convertColor //convertColor
if (flag) if (flag)
@@ -719,13 +732,13 @@ class GraphicFBO : Graphic
glDisable(GL_ALPHA_TEST); glDisable(GL_ALPHA_TEST);
} }
} }
override void gload(int x, int y, int w, int h, double[] array, int flag, int copymode) override void gload(int page, int x, int y, int w, int h, double[] array, int flag, int copymode)
{ {
for (int i = 0; i < array.length; i++) for (int i = 0; i < array.length; i++)
{ {
paint.buffer[i] = cast(int)array[i]; paint.buffer[i] = cast(int)array[i];
} }
gload(x, y, w, h, cast(int[])paint.buffer, flag, copymode); gload(useGRP, x, y, w, h, cast(int[])paint.buffer, flag, copymode);
} }
void gloadPalette(T, T2)(int x, int y, int w, int h, T[] array, T2[] palette, int copymode) void gloadPalette(T, T2)(int x, int y, int w, int h, T[] array, T2[] palette, int copymode)
if ((is(T == int) || is(T == double)) && (is(T2 == int) || is(T2 == double))) if ((is(T == int) || is(T == double)) && (is(T2 == int) || is(T2 == double)))
@@ -734,7 +747,7 @@ class GraphicFBO : Graphic
{ {
paint.buffer[i] = cast(int)palette[cast(int)array[i]]; paint.buffer[i] = cast(int)palette[cast(int)array[i]];
} }
gload(x, y, w, h, cast(int[])paint.buffer, 0, copymode); gload(useGRP, x, y, w, h, cast(int[])paint.buffer, 0, copymode);
} }
} }
@@ -782,6 +795,12 @@ class Graphic2 : Graphic
} }
bool df; bool df;
void updateTexture(int page)
{
glBindTexture(GL_TEXTURE_2D, this.GRP[page].glTexture);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, this.GRP[page].surface.pixels);
glFlush();
}
void updateTexture() void updateTexture()
{ {
glBindTexture(GL_TEXTURE_2D, this.GRP[useGRP].glTexture); glBindTexture(GL_TEXTURE_2D, this.GRP[useGRP].glTexture);
@@ -1238,12 +1257,19 @@ class Graphic2 : Graphic
gsaveTempl(savepage, x, y, w, h, array, flag); gsaveTempl(savepage, x, y, w, h, array, flag);
} }
void gloadTempl(T)(int x, int y, int w, int h, T array, int flag, int copymode) void gloadTempl(T)(int page, int x, int y, int w, int h, T array, int flag, int copymode)
{ {
int arrayH = h, arrayW = w; int arrayH = h, arrayW = w;
int sx, sy; int sx, sy;
if (clipXYWH(writeArea[petitcom.displaynum], x, y, w, h, sx, sy, w, h)) if (clipXYWH(writeArea[petitcom.displaynum], x, y, w, h, sx, sy, w, h))
return; return;
int* buffer;
if (page == -1)
{
buffer = cast(int*)petitcom.console.GRPF.surface.pixels;
}
else
buffer = cast(int*)GRP[page].surface.pixels;
for (int iy = sy; iy < sy + h; iy++) for (int iy = sy; iy < sy + h; iy++)
{ {
for (int ix = sx; ix < sx + w; ix++) for (int ix = sx; ix < sx + w; ix++)
@@ -1256,17 +1282,30 @@ class Graphic2 : Graphic
*(buffer + (iy + y) * width + (x + ix)) = c; *(buffer + (iy + y) * width + (x + ix)) = c;
} }
} }
if (page == -1)
{
petitcom.console.updateTexture();
}
else if (useGRP == page)
{
df = true; df = true;
} }
else
override void gload(int x, int y, int w, int h, int[] array, int flag, int copymode)
{ {
gloadTempl(x, y, w, h, array, flag, copymode); //ここに到達するときはLOAD関数なのでオーバーヘッドを考える必要が薄いので何も考えずupdateTexture
updateTexture(page);
} }
override void gload(int x, int y, int w, int h, double[] array, int flag, int copymode) }
override void gload(int page, int x, int y, int w, int h, int[] array, int flag, int copymode)
{ {
gloadTempl(x, y, w, h, array, flag, copymode); gloadTempl(page, x, y, w, h, array, flag, copymode);
}
override void gload(int page, int x, int y, int w, int h, double[] array, int flag, int copymode)
{
gloadTempl(page, x, y, w, h, array, flag, copymode);
} }
void gloadPalette(T, T2)(int x, int y, int w, int h, T[] array, T2[] palette, int copymode) void gloadPalette(T, T2)(int x, int y, int w, int h, T[] array, T2[] palette, int copymode)
@@ -1299,7 +1338,7 @@ class Graphic2 : Graphic
swap(y1, y2); swap(y1, y2);
int w = x2 - x1 + 1, h = y2 - y1 + 1; int w = x2 - x1 + 1, h = y2 - y1 + 1;
gsaveTempl(srcpage, x1, y1, w, h, tempbuffer, 0); gsaveTempl(srcpage, x1, y1, w, h, tempbuffer, 0);
gloadTempl(x3, y3, w, h, tempbuffer, 0, cpmode); gloadTempl(useGRP, x3, y3, w, h, tempbuffer, 0, cpmode);
} }
override void gtri(int x1, int y1, int x2, int y2, int x3, int y3, int color) override void gtri(int x1, int y1, int x2, int y2, int x3, int y3, int color)
{ {