d-gamedev-team / gfm Goto Github PK
View Code? Open in Web Editor NEW3D maths for D gamedev. This library is deprecated, see README.md
Home Page: http://gfm.dpldocs.info/gfm.html
License: The Unlicense
3D maths for D gamedev. This library is deprecated, see README.md
Home Page: http://gfm.dpldocs.info/gfm.html
License: The Unlicense
Change common/ini.d:39 to size_t (or const or something)
Looks like this bit-shift is wrong.
As stated in http://3d.benjamin-thaut.de/?p=20, homogeneous variadic function allocate for each call.
This is unacceptable in performance sensitive contexts.
The matrix.lookAt did not behave as I expected.
It seems this returns a column-major result, instead of row-major.
Therefore I have to always transpose the result before passing it to shaders.
This seems inconsistent, because the other matrices in gfm are all row-major.
Yours:
static Matrix lookAt(vec3!T eye, vec3!T target, vec3!T up) pure nothrow
{
vec3!T Z = (eye - target).normalized();
vec3!T X = cross(up, Z).normalized();
vec3!T Y = cross(Z, X);
return Matrix( X.x, Y.x, Z.x, 0,
X.y, Y.y, Z.y, 0,
X.z, Y.z, Z.z, 0,
dot(X, eye), dot(Y, eye), dot(Z, eye), 1);
}
Mine:
return Matrix( X.x, X.y, X.z, -dot(X, eye),
Y.x, Y.y, Y.z, -dot(Y, eye),
Z.x, Z.y, Z.z, -dot(Z, eye),
0, 0, 0, 1);
Also note the minus for the dot products.
https://github.com/d-gamedev-team/gfm/blob/master/opengl/gfm/opengl/textureunit.d#L82
If you create a texture, destroy it (automatically unbinds it according to https://www.opengl.org/sdk/docs/man/html/glDeleteTextures.xhtml) and recreate it, this piece of code then incorrectly skips binding it.
Merge solver.d with a generic polynomial class.
The D version is buggy, at least in uniform distribution. Make it work more with std.random.
Objects with resource semantics should probably be structs.
Examples: filled circle, triangle, etc... also with alpha coverage if possible.
https://github.com/p0nce/gfm/blob/master/sdl2/gfm/sdl2/sdl.d
line 185 & 199
Doesn't this code call updateState() and dispatchEvent() twice in a row, with no apparent reason?
PS: this should be a question but I can't find how to tag it as such...
They're marked as nothrow, yet they throw ;)
Also, in pop()
if (top <= 0)
should be
if (_top <= 0)
From drey08
well I wouldn't want invalid data to be silently thrown away, that would sound like a bug in the C library that should be filed.
Patapom says that the XYZ colorspace is defined absolutely.
Looks like a new feature of SDL 2.x
http://wiki.libsdl.org/SDL_SetAssertionHandler
From http://dlang.org/attribute.html
Our align(1) attribute is at the wrong place for all gfm.math structs.
(Thx Kelet)
Another issue from a workmate:
Original /gfm/sdl2/sdl.d
info: Platform: Linux, 4 CPU, L1 cacheline size: 64b
error: SDL (category error, priority error): Invalid window
info: Available driver: x11
info: Available driver: dummy
error: SDL (category error, priority error): Passed a NULL mutex
error: SDL (category error, priority error): Passed a NULL mutex
error: SDL (category error, priority error): Invalid window
info: Running using video driver: x11
info: 1 video display(s) detected.
info: OpenGL loaded, version 11
info: OpenGL reloaded, version 33
info: Version: 3.3.0 NVIDIA 304.43
info: Renderer: GeForce GT 330M/PCIe/SSE2
info: Vendor: NVIDIA Corporation
info: GLSL version: 3.30 NVIDIA via Cg compiler
info: Extensions: 252 found
info: - EXT_texture_filter_anisotropic is supported
info: - EXT_framebuffer_object is supported
Forcing video subsystem initilisation directly after SDL load in constructor:
final class SDL2
{
public
{
this(Log log)
{
_log = log;
_SDLInitialized = false;
_SDL2LoggingRedirected = false;
try
{
// in debug builds, use a debug version of SDL2
debug
// DerelictSDL2.load("SDL2d.dll");
DerelictSDL2.load("libSDL2.so");
else
DerelictSDL2.load();
SDL_InitSubSystem(SDL_INIT_VIDEO); // NEW
}
catch(DerelictException e)
{
throw new SDL2Exception(e.msg);
}
...
Removes the first Invalid window error, indicating a different result for:
subSystemInit(SDL_INIT_VIDEO);
info: Platform: Linux, 4 CPU, L1 cacheline size: 64b
info: Available driver: x11
info: Available driver: dummy
error: SDL (category error, priority error): Passed a NULL mutex
error: SDL (category error, priority error): Passed a NULL mutex
error: SDL (category error, priority error): Invalid window
info: Running using video driver: x11
info: 1 video display(s) detected.
info: OpenGL loaded, version 11
info: OpenGL reloaded, version 33
info: Version: 3.3.0 NVIDIA 304.43
info: Renderer: GeForce GT 330M/PCIe/SSE2
info: Vendor: NVIDIA Corporation
info: GLSL version: 3.30 NVIDIA via Cg compiler
info: Extensions: 252 found
info: - EXT_texture_filter_anisotropic is supported
info: - EXT_framebuffer_object is supported
I've tried several minimal VBO examples online, but I just cannot get it to render..
The basics are pretty simple:
vec3f[3] vertices = [
vec3f(-1.0f, -1.0f, 0.0f),
vec3f( 1.0f, -1.0f, 0.0f),
vec3f( 0.0f, 1.0f, 0.0f)
];
GLuint VBO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vec3f.sizeof*vertices.length, vertices.ptr, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, cast(void*)0);
glDrawArrays(GL_TRIANGLES, 0, 3); // nothing
//glDrawArrays(GL_POINTS, 0, 3); // single white point ca. in the middle
glDisableVertexAttribArray(0);
How would a minimal VBO triangle look like?
Here's the full program (slightly modified simplegl.d):
import gfm.sdl2.all;
import gfm.common.all;
import gfm.opengl.all;
class MyWindow : SDL2Window
{
this(SDL2 sdl2, box2i position, bool fullscreen)
{
super(sdl2, position, fullscreen, true, false);
}
}
void main()
{
auto log = new ConsoleLog();
auto sdl2 = new SDL2(log);
scope(exit) sdl2.close();
auto gl = new OpenGL(log);
scope(exit) gl.close();
auto displays = sdl2.getDisplays();
if (displays.length == 0)
return; // no display
auto bounds = displays[0].bounds().shrink(vec2i(40));
auto window = new MyWindow(sdl2, bounds, false);
scope(exit) window.close();
auto eventQueue = new SDL2EventQueue(sdl2);
eventQueue.registerWindow(window);
gl.reload();
auto shader = new GLShader(gl, GL_FRAGMENT_SHADER,
[
r"uniform vec4 col;
void main()
{
gl_FragColor = col;
}
"]);
auto program = new GLProgram(gl, shader);
vec3f[3] vertices = [
vec3f(-1.0f, -1.0f, 0.0f),
vec3f( 1.0f, -1.0f, 0.0f),
vec3f( 0.0f, 1.0f, 0.0f)
];
GLuint VBO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vec3f.sizeof*vertices.length, vertices.ptr, GL_STATIC_DRAW);
glClearColor(0, 0, 0, 0);
while(!eventQueue.keyboard().isPressed(SDLK_ESCAPE))
{
eventQueue.processEvents();
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, bounds.width, bounds.height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
program.uniform("col").set(vec4f(1.0f, 1.0f, 1.0f, 0.0f));
program.use();
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, cast(void*)0);
glDrawArrays(GL_TRIANGLES, 0, 3); // nothing
//glDrawArrays(GL_POINTS, 0, 3); // single white point ca. in the middle
glDisableVertexAttribArray(0);
program.unuse();
window.swapBuffers();
}
}
This will allow to transition to DerelictOrg, which will allow to mix gfm with derelict_extras packages.
Open question.
We have two alternatives:
../../../.dub/packages/gfm-master/net/gfm/net/cbor.d(609): Error: variable hu used before set
tried fixing it, not experienced in that sorta thing, mind fixing it, because it breaks the release builds of anyone who uses gfm.
Outputs:
info: Platform: [87, 105, 110, 100, 111, 119, 115], 2 CPU, L1 cacheline size: 64b
info: Available driver: [119, 105, 110, 100, 111, 119, 115]
Expected:
info: Platform: Windows, 2 CPU, L1 cacheline size: 64b
info: Available driver: windows
TODO: define precisely what do we want and what we should obtain
Put your wishes here.
I thought I need them when I wrote them, but now I'm not so sure.
Simple cast.
module main;
import gfm.math.quaternion;
import gfm.math.matrix;
void main()
{
quaternionf quat = quaternionf.IDENTITY;
mat4f mat = cast(mat4f)quat;
}
Results in:
\src\main.d(21): Error: template gfm.math.quaternion.Quaternion!(float).Quaternion.opCast does not match any function template declaration
\imports\gfm\math\quaternion.d(109): Error: template gfm.math.quaternion.Quaternion!(float).Quaternion.opCast cannot deduce template function from argument types !(Matrix!(float,4u,4u))()
Compile & run example/simplegl.d results in, on esc:
error: SDL (category error, priority error): wglMakeCurrent(): The handle is invalid.
Ie.
info: ÿ'*
info: ÿ&*
info: ÿ&*
info: ÿ%*
info: ÿ'3��É�
info: ÿ&3��É�
info: ÿ&3��É�
info: ÿ%3��É�
info: ÿ$3��É�
info: ÿ#3��É�
../../../.dub/packages/gfm-master/opengl/gfm/opengl/program.d(257): Error: function pointer glGetActiveUniformsiv (uint, int, const(uint)*, uint, int*) is not callable using argument types (uint, uint*, uint*, uint, int*)
For some reason dub can't see the subpackages when it's looking for dependencies.
$ dub build -v
Using dub registry url 'http://code.dlang.org/'
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Determined package version using GIT: gfm ~master
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Version selection for dependency gfm:enet of gfm is missing.
Version selection for dependency gfm:math of gfm is missing.
Version selection for dependency gfm:net of gfm is missing.
Version selection for dependency gfm:core of gfm is missing.
Version selection for dependency gfm:assimp of gfm is missing.
Version selection for dependency gfm:freeimage of gfm is missing.
Version selection for dependency gfm:image of gfm is missing.
Version selection for dependency gfm:opengl of gfm is missing.
Version selection for dependency gfm:sdl2 of gfm is missing.
Checking for missing dependencies.
Search for versions of gfm (1 package suppliers)
Search for versions of derelict_extras-enet (1 package suppliers)
Search for versions of derelict-util (1 package suppliers)
Search for versions of derelict-assimp3 (1 package suppliers)
Search for versions of derelict-fi (1 package suppliers)
Search for versions of derelict-gl3 (1 package suppliers)
Search for versions of derelict-sdl2 (1 package suppliers)
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Version selection for dependency gfm:enet of gfm is missing.
Version selection for dependency gfm:math of gfm is missing.
Version selection for dependency gfm:net of gfm is missing.
Version selection for dependency gfm:core of gfm is missing.
Version selection for dependency gfm:assimp of gfm is missing.
Version selection for dependency gfm:freeimage of gfm is missing.
Version selection for dependency gfm:image of gfm is missing.
Version selection for dependency gfm:opengl of gfm is missing.
Version selection for dependency gfm:sdl2 of gfm is missing.
Checking for upgrades.
Search for versions of gfm (1 package suppliers)
Search for versions of derelict_extras-enet (1 package suppliers)
Search for versions of derelict-util (1 package suppliers)
Search for versions of derelict-assimp3 (1 package suppliers)
Search for versions of derelict-fi (1 package suppliers)
Search for versions of derelict-gl3 (1 package suppliers)
Search for versions of derelict-sdl2 (1 package suppliers)
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Version selection for dependency gfm:enet of gfm is missing.
Version selection for dependency gfm:math of gfm is missing.
Version selection for dependency gfm:net of gfm is missing.
Version selection for dependency gfm:core of gfm is missing.
Version selection for dependency gfm:assimp of gfm is missing.
Version selection for dependency gfm:freeimage of gfm is missing.
Version selection for dependency gfm:image of gfm is missing.
Version selection for dependency gfm:opengl of gfm is missing.
Version selection for dependency gfm:sdl2 of gfm is missing.
WARNING: A deprecated branch based version specification is used for the dependency gfm:enet. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:math. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:net. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:core. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:assimp. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:freeimage. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:image. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:opengl. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:sdl2. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
Error executing command build: Unknown dependency: gfm:enet
Full exception: object.Exception@source/dub/project.d(156): Unknown dependency: gfm:enet
Because an OpenGL context can only be tied to a single thread, and the GC could call destructors from anywhere, this is very dangerous.
To reproduce: a toy project using gfm:sdl2.
Since a long time I've thought that caching the bounded object to avoid a rebind might gain speed, but I'm not so sure nowadays.
I know that Ogre binds 0 after each object change, dunno why.
Should bindings be cached or kept as much as possible?
Awaiting the move of DerelictFreeImage and DerelictAssimp3 so that DerelictUtil bindings can be used along gfm.
gfm.sdl2.sdl.SDL2Exception@../gfm/sdl2/sdl.d(24): Failed to load symbol SDL_GetTouch from shared library libSDL2.so
Seems SDL2 has been frozen, but Derelict3 haven't pulled in the changes yet.
Refs: mdparker/Derelict3#94
The std.logger proposal landed in the DUB registry with the name "logger". It looks like the most promising logger package available.
Someone I work with has asked me to tell you the following:
Linux/ OS issue:
In /gfm/sdl2/sdl.d, constructor holds a Windows specific call.
debug
DerelictSDL2.load("SDL2d.dll");
Can be fixed by OS checks, as done elsewhere already:
DerelictSDL2.load("SDL2d.dll");
DerelictSDL2.load("libSDL2.so");
Issues with 64-bit compile:
Use of size_t and array.lenght, which on 32-bit will 4 bytes in size (int), for 64-bit these are 8 bytes, (ulong).
This causes compile time errors like:
/gfm/opengl/uniform.d(139): Error: function pointer glUniform1fv (int, int, const(float)*) is not callable using argument types (int,ulong,float*)
A possible fix would be to compile gfm (and the code using it) using the '-m32' copile flag.
However, than the libSDL2.so (and any other library) will have to be 32-bit also.
This is not true by default for any 64-bit linux system, as it will use 64-bit libs.
A better solution is to use int instead of size_t/length, as, in gfm, size_t is often used for 'size parameters' to gl functions.
These take GLints as input, irrespective of architecture, so invariably feeding them ints would seem a reasonable choice.
Some affected classes, probably many more:
gfm/opengl/shader.d
gfm/opengl/textureunit.d
gfm/opengl/uniform.d
gfm/opengl/vbo.d
gfm/sdl2/renderer.d
DISCLAIMER, below are quick hacks to get a 64-bit compile (no proper diff, sorry):
gfm/opengl/shader.d
- lengths[i] = localLines[i].length;
+ lengths[i] = cast(int)localLines[i].length;
gfm/opengl/textureunit.d
- int index = targetToIndex(cast(Target)target);
+ int index = cast(int)targetToIndex(cast(Target)target);
gfm/opengl/uniform.d
- size_t _size;
+ int _size;
gfm/opengl/vbo.d
- glVertexPointer(n, glType, sizeOfVertex, cast(GLvoid *) offset);
+ glVertexPointer(n, glType, cast(int)sizeOfVertex, cast(GLvoid *) offset);
break;
case Role.COLOR:
glEnableClientState(GL_COLOR_ARRAY);
- glColorPointer(n, glType, sizeOfVertex, cast(GLvoid *) offset);
+ glColorPointer(n, glType, cast(int)sizeOfVertex, cast(GLvoid *) offset);
break;
case Role.TEX_COORD:
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(n, glType, sizeOfVertex, cast(GLvoid *) offset);
+ glTexCoordPointer(n, glType, cast(int)sizeOfVertex, cast(GLvoid *) offset);
break;
case Role.NORMAL:
glEnableClientState(GL_NORMAL_ARRAY);
assert(n == 3);
- glNormalPointer(glType, sizeOfVertex, cast(GLvoid *) offset);
+ glNormalPointer(glType, cast(int)sizeOfVertex, cast(GLvoid *) offset);
break;
}
}
else
{
glEnableVertexAttribArray(index);
- glVertexAttribPointer(index, n, glType, GL_FALSE, sizeOfVertex, cast(GLvoid *) offset);
+ glVertexAttribPointer(index, n, glType, GL_FALSE, cast(int)sizeOfVertex, cast(GLvoid *) offset);
gfm/sdl2/renderer.d
@@ -150,7 +150,7 @@ final class SDL2Renderer
void drawLines(vec2i[] points)
{
- SDL_RenderDrawLines(_renderer, cast(SDL_Point*)(points.ptr), points.length);
+ SDL_RenderDrawLines(_renderer, cast(SDL_Point*)(points.ptr), cast(int)points.length);
}
@@ -160,7 +160,7 @@ final class SDL2Renderer
void drawPoints(vec2i[] points)
{
- SDL_RenderDrawPoints(_renderer, cast(SDL_Point*)(points.ptr), points.length);
+ SDL_RenderDrawPoints(_renderer, cast(SDL_Point*)(points.ptr), cast(int)points.length);
The cross product is different from what I believe is correct (and wiki agrees with me)
Fixed:
Vector!(T, 3u) cross(T)(const Vector!(T, 3u) a, const Vector!(T, 3u) b) pure nothrow
{
return Vector!(T, 3u)(a.y * b.z - a.z * b.y,
a.z * b.x - a.x * b.z,
a.x * b.y - a.y * b.x);
}
TODO: test with a color matrix shader
Ok, this is actually a DMD bug, but I wasn't able to reproduce it with a simple testcase.
Adding the bug here hoping that you can reproduce it with a smaller testcase.
Compiling the shader example with dub --build=release
gives this error:
../../../.dub/packages/gfm-master/net/gfm/net/cbor.d(609): Error: variable hu used before set
This simple testcase doesn't reproduce it though:
union U {
int i;
float f;
}
void main() {
U u = void;
u.i = 1;
}
Using dmd 2.064 on GNU/Linux x64.
Wrong links and lacking volume.
Idea suggested in http://forum.dlang.org/post/[email protected]
Like in Wild Magic engines, orientation of triangle, segments, etc... should be well defined.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.