Skip to content

Commit 73e55df

Browse files
author
Alex D
committed
progress of implementing open gl test app
1 parent 439a464 commit 73e55df

File tree

9 files changed

+254
-7
lines changed

9 files changed

+254
-7
lines changed

build-lua-opengl-debug.cmd

+10
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ rem Building GLUT
3838
cd experiments\WebGLAdapter
3939
@call build.cmd win64 Debug
4040
cd ..\..\..\..
41+
42+
rem Building FreeImage
43+
cd thirdparty\freeimage-build\
44+
@call build.cmd win64 Debug
45+
cd ..\..\..\..
46+
47+
rem Building FreeImage Adapter
48+
cd experiments\FreeImageAdapter
49+
@call build.cmd win64 Debug
50+
cd ..\..\..\..

build-lua-opengl.cmd

+10
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,13 @@ rem Building GLUT
4343
cd experiments\WebGLAdapter
4444
@call build.cmd win64 Release
4545
cd ..\..\..\..
46+
47+
rem Building FreeImage
48+
cd thirdparty\freeimage-build\
49+
@call build.cmd win64 Release
50+
cd ..\..\..\..
51+
52+
rem Building FreeImage Adapter
53+
cd experiments\FreeImageAdapter
54+
@call build.cmd win64 Release
55+
cd ..\..\..\..

experiments/BABYLON/Planet.png

304 KB
Loading

experiments/BABYLON/canvas.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export default class Canvas extends _gl implements WebGLRenderingContext {
230230

231231
// @ts-ignore
232232
activeTexture(texture: number): void {
233-
throw new Error('Method not implemented.');
233+
_gl.activeTexture(texture);
234234
}
235235

236236
// @ts-ignore
@@ -259,7 +259,7 @@ export default class Canvas extends _gl implements WebGLRenderingContext {
259259

260260
// @ts-ignore
261261
bindTexture(target: number, texture: WebGLTexture): void {
262-
throw new Error('Method not implemented.');
262+
_gl.bindTexture(target, texture ? (<any>texture).value : 0);
263263
}
264264

265265
// @ts-ignore
@@ -718,7 +718,12 @@ export default class Canvas extends _gl implements WebGLRenderingContext {
718718

719719
// @ts-ignore
720720
pixelStorei(pname: number, param: number): void {
721-
throw new Error('Method not implemented.');
721+
// tslint:disable-next-line:triple-equals
722+
if (pname == undefined) {
723+
return;
724+
}
725+
726+
_gl.pixelStorei(pname, param);
722727
}
723728

724729
// @ts-ignore
@@ -789,7 +794,12 @@ export default class Canvas extends _gl implements WebGLRenderingContext {
789794
source: ImageBitmap | ImageData | HTMLVideoElement | HTMLImageElement | HTMLCanvasElement): void;
790795
// @ts-ignore
791796
texImage2D(target: any, level: any, internalformat: any, width: any, height: any, border: any, format?: any, type?: any, pixels?: any) {
792-
throw new Error('Method not implemented.');
797+
if (format) {
798+
_gl.texImage2D(target, level, internalformat, width, height, border, format, type, (<any>pixels).buffer.bufferNativeInstance);
799+
} else {
800+
// border = source, width = format, height = type
801+
_gl.texImage2D(target, level, internalformat, border.width, border.height, 0, width, height, border.bits);
802+
}
793803
}
794804

795805
// @ts-ignore
@@ -799,7 +809,7 @@ export default class Canvas extends _gl implements WebGLRenderingContext {
799809

800810
// @ts-ignore
801811
texParameteri(target: number, pname: number, param: number): void {
802-
throw new Error('Method not implemented.');
812+
_gl.texParameteri(target, pname, param);
803813
}
804814

805815
// @ts-ignore

experiments/BABYLON/grass_texture.jpg

749 KB
Loading

experiments/BABYLON/image.ts

+48-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,55 @@
11
export default class Image {
2-
2+
private _src: string;
3+
private _imageData: object;
34
private events = {};
45

56
constructor() {
7+
if (!free_image) {
8+
// @ts-ignore
9+
import free_image from 'freeimageadapter';
10+
}
11+
12+
if (!free_image) {
13+
throw new Error('freeimageadapter module is not available');
14+
}
15+
}
16+
17+
public get src(): string {
18+
return this._src;
19+
}
20+
21+
public set src(val: string) {
22+
this._src = val;
23+
24+
// @ts-ignore
25+
this._imageData = free_image.loadImage(this._src);
26+
if (this._imageData) {
27+
const onloads = this.events['load'];
28+
if (onloads) {
29+
for (const onload of onloads) {
30+
onload();
31+
}
32+
}
33+
} else {
34+
const onerrors = this.events['error'];
35+
if (onerrors) {
36+
for (const onerror of onerrors) {
37+
onerror();
38+
}
39+
}
40+
}
41+
}
42+
43+
public get width(): number {
44+
return this._imageData ? this._imageData.width : 0;
45+
}
46+
47+
public get height(): number {
48+
return this._imageData ? this._imageData.height : 0;
49+
}
50+
51+
public get bits(): any {
52+
return this._imageData ? this._imageData.bits : 0;
653
}
754

855
public addEventListener(eventName: string, cb: any, flag: boolean): void {

experiments/BABYLON/text.jpg

27.8 KB
Loading

experiments/WebGLAdapter/gl.c

+160-1
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,107 @@ extern "C"
16661666
return 1;
16671667
}
16681668

1669+
static int activeTexture(lua_State *L)
1670+
{
1671+
const GLint tex = (GLint) luaL_checkinteger(L, 1);
1672+
glActiveTexture(tex);
1673+
1674+
int error = errorCheck(L);
1675+
if (error)
1676+
{
1677+
return error;
1678+
}
1679+
1680+
return 0;
1681+
}
1682+
1683+
static int bindTexture(lua_State *L)
1684+
{
1685+
const GLint target = (GLint) luaL_checkinteger(L, 1);
1686+
const GLint buffer = (GLint) luaL_checkinteger(L, 2);
1687+
glBindTexture(target, buffer);
1688+
1689+
int error = errorCheck(L);
1690+
if (error)
1691+
{
1692+
return error;
1693+
}
1694+
1695+
return 0;
1696+
}
1697+
1698+
static int pixelStorei(lua_State *L)
1699+
{
1700+
const GLint pname = (GLint) luaL_checkinteger(L, 1);
1701+
const GLint param = (GLint) luaL_checkinteger(L, 2);
1702+
glPixelStorei(pname, param);
1703+
1704+
int error = errorCheck(L);
1705+
if (error)
1706+
{
1707+
return error;
1708+
}
1709+
1710+
return 0;
1711+
}
1712+
1713+
static int texImage2D(lua_State *L)
1714+
{
1715+
const GLint target = (GLint) luaL_checkinteger(L, 1);
1716+
const GLint level = (GLint) luaL_checkinteger(L, 2);
1717+
const GLint internalformat = (GLint) luaL_checkinteger(L, 3);
1718+
const GLint width = (GLint) luaL_checkinteger(L, 4);
1719+
const GLint height = (GLint) luaL_checkinteger(L, 5);
1720+
const GLint border = (GLint) luaL_checkinteger(L, 6);
1721+
const GLint format = (GLint) luaL_checkinteger(L, 7);
1722+
const GLint type = (GLint) luaL_checkinteger(L, 8);
1723+
const void* pixels = NULL;
1724+
1725+
if (lua_islightuserdata(L, 9))
1726+
{
1727+
pixels = lua_topointer(L, 9);
1728+
}
1729+
else if (lua_type(L, 9) == LUA_TUSERDATA)
1730+
{
1731+
const ArrayContainer *userdata = lua_topointer(L, 9);
1732+
pixels = (const char*) &userdata->data;
1733+
}
1734+
else if (lua_isnoneornil(L, 9))
1735+
{
1736+
pixels = NULL;
1737+
}
1738+
else
1739+
{
1740+
return luaL_argerror(L, 9, "Bad argument");
1741+
}
1742+
1743+
glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
1744+
1745+
int error = errorCheck(L);
1746+
if (error)
1747+
{
1748+
return error;
1749+
}
1750+
1751+
return 0;
1752+
}
1753+
1754+
static int texParameteri(lua_State *L)
1755+
{
1756+
const GLint target = (GLint) luaL_checkinteger(L, 1);
1757+
const GLint pname = (GLint) luaL_checkinteger(L, 2);
1758+
const GLint param = (GLint) luaL_checkinteger(L, 3);
1759+
glTexParameteri(target, pname, param);
1760+
1761+
int error = errorCheck(L);
1762+
if (error)
1763+
{
1764+
return error;
1765+
}
1766+
1767+
return 0;
1768+
}
1769+
16691770
typedef struct ConstPair
16701771
{
16711772
const char *name;
@@ -1971,7 +2072,60 @@ extern "C"
19712072
{"VERTEX_ATTRIB_ARRAY_TYPE", GL_VERTEX_ATTRIB_ARRAY_TYPE},
19722073
{"VERTEX_SHADER", GL_VERTEX_SHADER},
19732074
{"VIEWPORT", GL_VIEWPORT},
1974-
{"ZERO", GL_ZERO}};
2075+
{"ZERO", GL_ZERO},
2076+
// added
2077+
{"ALPHA", GL_ALPHA},
2078+
{"LUMINANCE", GL_LUMINANCE},
2079+
{"LUMINANCE_ALPHA", GL_LUMINANCE_ALPHA},
2080+
{"R11F_G11F_B10F", GL_R11F_G11F_B10F},
2081+
{"R16F", GL_R16F},
2082+
{"R16I", GL_R16I},
2083+
{"R16UI", GL_R16UI},
2084+
{"R32F", GL_R32F},
2085+
{"R32I", GL_R32I},
2086+
{"R32UI", GL_R32UI},
2087+
{"R8", GL_R8},
2088+
{"R8_SNORM", GL_R8_SNORM},
2089+
{"R8I", GL_R8I},
2090+
{"R8UI", GL_R8UI},
2091+
{"RG16F", GL_RG16F},
2092+
{"RG16I", GL_RG16I},
2093+
{"RG16UI", GL_RG16UI},
2094+
{"RG32F", GL_RG32F},
2095+
{"RG32I", GL_RG32I},
2096+
{"RG32UI", GL_RG32UI},
2097+
{"RG8", GL_RG8},
2098+
{"RG8_SNORM", GL_RG8_SNORM},
2099+
{"RG8I", GL_RG8I},
2100+
{"RG8UI", GL_RG8UI},
2101+
{"RGB10_A2", GL_RGB10_A2},
2102+
{"RGB10_A2UI", GL_RGB10_A2UI},
2103+
{"RGB16F", GL_RGB16F},
2104+
{"RGB16I", GL_RGB16I},
2105+
{"RGB16UI", GL_RGB16UI},
2106+
{"RGB32F", GL_RGB32F},
2107+
{"RGB32I", GL_RGB32I},
2108+
{"RGB32UI", GL_RGB32UI},
2109+
{"RGB5_A1", GL_RGB5_A1},
2110+
{"RGB565", GL_RGB565},
2111+
{"RGB8", GL_RGB8},
2112+
{"RGB8_SNORM", GL_RGB8_SNORM},
2113+
{"RGB8I", GL_RGB8I},
2114+
{"RGB8UI", GL_RGB8UI},
2115+
{"RGB9_E5", GL_RGB9_E5},
2116+
{"RGBA", GL_RGBA},
2117+
{"RGBA16F", GL_RGBA16F},
2118+
{"RGBA16I", GL_RGBA16I},
2119+
{"RGBA16UI", GL_RGBA16UI},
2120+
{"RGBA32F", GL_RGBA32F},
2121+
{"RGBA32I", GL_RGBA32I},
2122+
{"RGBA32UI", GL_RGBA32UI},
2123+
{"RGBA4", GL_RGBA4},
2124+
{"RGBA8", GL_RGBA8},
2125+
{"RGBA8_SNORM", GL_RGBA8_SNORM},
2126+
{"RGBA8I", GL_RGBA8I},
2127+
{"RGBA8UI", GL_RGBA8UI}
2128+
};
19752129

19762130
static void AddConstsGL(lua_State *L)
19772131
{
@@ -2055,6 +2209,11 @@ extern "C"
20552209
{"drawElements", drawElements},
20562210
{"drawArrays", drawArrays},
20572211
{"createTexture", createTexture},
2212+
{"activeTexture", activeTexture},
2213+
{"bindTexture", bindTexture},
2214+
{"pixelStorei", pixelStorei},
2215+
{"texImage2D", texImage2D},
2216+
{"texParameteri", texParameteri},
20582217
{NULL, NULL} /* sentinel */
20592218
};
20602219

experiments/jslib/Array.ts

+11
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ module JS {
196196
return table.concat(this._values);
197197
}
198198

199+
public sort() {
200+
table.sort(this._values);
201+
}
202+
199203
public shift(): T {
200204
const v = table.remove(this._values, 1);
201205
// @ts-ignore
@@ -227,6 +231,13 @@ module JS {
227231
return retArr;
228232
}
229233

234+
public remove(obj: T) {
235+
const idx = this.indexOf(obj);
236+
if (idx !== -1) {
237+
table.remove(this._values, idx + 1);
238+
}
239+
}
240+
230241
public map(func: (currentValue: T, index: number, arr: T[]) => T, thisValue?: any): T[] {
231242
const retArr = new Array<T>();
232243

0 commit comments

Comments
 (0)