Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tales of MajEyal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
K'van
Tales of MajEyal
Commits
9259caf2
Commit
9259caf2
authored
10 years ago
by
DarkGod
Browse files
Options
Downloads
Patches
Plain Diff
plan for optimization
parent
97cb2741
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core_lua.c
+121
-0
121 additions, 0 deletions
src/core_lua.c
src/core_lua.h
+26
-17
26 additions, 17 deletions
src/core_lua.h
with
147 additions
and
17 deletions
src/core_lua.c
+
121
−
0
View file @
9259caf2
...
...
@@ -3093,6 +3093,117 @@ static int display_pause_anims(lua_State *L) {
return
0
;
}
/**************************************************************
* Vertex Objects
**************************************************************/
static
update_vertex_size
(
lua_vertexes
*
vx
,
int
size
)
{
if
(
size
<=
vx
->
size
)
return
;
vx
->
size
=
size
;
vx
->
vertices
=
realloc
(
vx
->
vertices
,
2
*
sizeof
(
GLfloat
)
*
size
);
vx
->
colors
=
realloc
(
vx
->
colors
,
4
*
sizeof
(
GLfloat
)
*
size
);
vx
->
textures
=
realloc
(
vx
->
textures
,
2
*
sizeof
(
GLfloat
)
*
size
);
}
static
int
gl_new_vertex
(
lua_State
*
L
)
{
const
char
*
mode
=
luaL_checkstring
(
L
,
1
);
int
size
=
lua_tonumber
(
L
,
2
);
if
(
!
size
)
size
=
4
;
lua_vertexes
*
vx
=
(
lua_vertexes
*
)
lua_newuserdata
(
L
,
sizeof
(
lua_vertexes
));
auxiliar_setclass
(
L
,
"gl{vertexes}"
,
-
1
);
vx
->
size
=
vx
->
nb
=
0
;
vx
->
vertices
=
NULL
;
vx
->
colors
=
NULL
;
vx
->
textures
=
NULL
;
update_vertex_size
(
vx
,
size
);
if
(
!
strcmp
(
mode
,
"line"
))
{
vx
->
mode
=
GL_LINE
;
}
else
{
vx
->
mode
=
GL_QUADS
;
}
return
1
;
}
static
int
gl_free_vertex
(
lua_State
*
L
)
{
lua_vertexes
*
vx
=
(
lua_vertexes
*
)
auxiliar_checkclass
(
L
,
"gl{vertexes}"
,
1
);
if
(
vx
->
size
>
0
)
{
free
(
vx
->
vertices
);
free
(
vx
->
colors
);
free
(
vx
->
textures
);
}
lua_pushnumber
(
L
,
1
);
return
1
;
}
static
int
gl_vertex_add
(
lua_State
*
L
)
{
lua_vertexes
*
vx
=
(
lua_vertexes
*
)
auxiliar_checkclass
(
L
,
"gl{vertexes}"
,
1
);
float
x
=
luaL_checknumber
(
L
,
2
);
float
y
=
luaL_checknumber
(
L
,
3
);
float
u
=
luaL_checknumber
(
L
,
4
);
float
v
=
luaL_checknumber
(
L
,
5
);
float
r
=
luaL_checknumber
(
L
,
6
);
float
g
=
luaL_checknumber
(
L
,
7
);
float
b
=
luaL_checknumber
(
L
,
8
);
float
a
=
luaL_checknumber
(
L
,
9
);
if
(
vx
->
nb
+
1
>
vx
->
size
)
update_vertex_size
(
vx
,
vx
->
nb
+
1
);
vx
->
vertices
[
vx
->
nb
*
2
+
0
]
=
x
;
vx
->
vertices
[
vx
->
nb
*
2
+
1
]
=
y
;
vx
->
textures
[
vx
->
nb
*
2
+
0
]
=
u
;
vx
->
textures
[
vx
->
nb
*
2
+
1
]
=
v
;
vx
->
colors
[
vx
->
nb
*
4
+
0
]
=
r
;
vx
->
colors
[
vx
->
nb
*
4
+
1
]
=
g
;
vx
->
colors
[
vx
->
nb
*
4
+
2
]
=
b
;
vx
->
colors
[
vx
->
nb
*
4
+
3
]
=
a
;
vx
->
nb
++
;
return
0
;
}
static
int
gl_vertex_toscreen
(
lua_State
*
L
)
{
lua_vertexes
*
vx
=
(
lua_vertexes
*
)
auxiliar_checkclass
(
L
,
"gl{vertexes}"
,
1
);
if
(
!
vx
->
nb
)
return
;
int
x
=
luaL_checknumber
(
L
,
2
);
int
y
=
luaL_checknumber
(
L
,
3
);
if
(
lua_isuserdata
(
L
,
4
))
{
GLuint
*
t
=
(
GLuint
*
)
auxiliar_checkclass
(
L
,
"gl{texture}"
,
4
);
tglBindTexture
(
GL_TEXTURE_2D
,
*
t
);
}
else
if
(
lua_toboolean
(
L
,
4
))
{
// Do nothing, we keep the currently bound texture
}
else
{
tglBindTexture
(
GL_TEXTURE_2D
,
gl_tex_white
);
}
float
r
=
1
,
g
=
1
,
b
=
1
,
a
=
1
;
if
(
lua_isnumber
(
L
,
5
))
{
r
=
luaL_checknumber
(
L
,
5
);
g
=
luaL_checknumber
(
L
,
5
);
b
=
luaL_checknumber
(
L
,
5
);
a
=
luaL_checknumber
(
L
,
5
);
}
tglColor4f
(
r
,
g
,
b
,
a
);
glTranslatef
(
x
,
y
,
0
);
glVertexPointer
(
2
,
GL_FLOAT
,
0
,
vx
->
vertices
);
glColorPointer
(
4
,
GL_FLOAT
,
0
,
vx
->
colors
);
glTexCoordPointer
(
2
,
GL_FLOAT
,
0
,
vx
->
textures
);
glDrawArrays
(
vx
->
mode
,
0
,
vx
->
nb
);
glTranslatef
(
-
x
,
-
y
,
0
);
return
0
;
}
static
const
struct
luaL_Reg
displaylib
[]
=
{
{
"setTextBlended"
,
set_text_aa
},
...
...
@@ -3104,6 +3215,7 @@ static const struct luaL_Reg displaylib[] =
{
"newSurface"
,
sdl_new_surface
},
{
"newTile"
,
sdl_new_tile
},
{
"newFBO"
,
gl_new_fbo
},
{
"newVO"
,
gl_new_vertex
},
{
"fboSupportsTransparency"
,
gl_fbo_supports_transparency
},
{
"newQuadratic"
,
gl_new_quadratic
},
{
"drawQuad"
,
gl_draw_quad
},
...
...
@@ -3157,6 +3269,14 @@ static const struct luaL_Reg sdl_surface_reg[] =
{
NULL
,
NULL
},
};
static
const
struct
luaL_Reg
gl_vertexes_reg
[]
=
{
{
"__gc"
,
gl_free_vertex
},
{
"addPoint"
,
gl_vertex_add
},
{
"toScreen"
,
gl_vertex_toscreen
},
{
NULL
,
NULL
},
};
static
const
struct
luaL_Reg
sdl_texture_reg
[]
=
{
{
"__gc"
,
sdl_free_texture
},
...
...
@@ -3680,6 +3800,7 @@ int luaopen_core(lua_State *L)
auxiliar_newclass
(
L
,
"gl{texture}"
,
sdl_texture_reg
);
auxiliar_newclass
(
L
,
"gl{fbo}"
,
gl_fbo_reg
);
auxiliar_newclass
(
L
,
"gl{quadratic}"
,
gl_quadratic_reg
);
auxiliar_newclass
(
L
,
"gl{vertexes}"
,
gl_vertexes_reg
);
auxiliar_newclass
(
L
,
"sdl{surface}"
,
sdl_surface_reg
);
auxiliar_newclass
(
L
,
"sdl{font}"
,
sdl_font_reg
);
luaL_openlib
(
L
,
"core.display"
,
displaylib
,
0
);
...
...
This diff is collapsed.
Click to expand it.
src/core_lua.h
+
26
−
17
View file @
9259caf2
/*
TE4 - T-Engine 4
Copyright (C) 2009 - 2015 Nicolas Casalini
TE4 - T-Engine 4
Copyright (C) 2009 - 2015 Nicolas Casalini
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Nicolas Casalini "DarkGod"
darkgod@te4.org
Nicolas Casalini "DarkGod"
darkgod@te4.org
*/
#ifndef _CORELUA_H_
#define _CORELUA_H_
...
...
@@ -25,11 +25,20 @@
typedef
struct
{
GLuint
fbo
;
GLuint
texture
;
int
w
,
h
;
GLuint
fbo
;
GLuint
texture
;
int
w
,
h
;
}
lua_fbo
;
typedef
struct
{
GLuint
mode
;
int
nb
,
size
;
GLfloat
*
vertices
;
GLfloat
*
colors
;
GLfloat
*
textures
;
}
lua_vertexes
;
extern
int
luaopen_core
(
lua_State
*
L
);
extern
int
init_blank_surface
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment