Is it possible to specify the address returned by the address of operator?
schveiguy at yahoo.com
Thu Sep 28 12:47:17 UTC 2017
On 9/27/17 12:35 PM, DreadKyller wrote:
> Been using D for a couple years now, however one problem I've had, more
> so recently since I've been dealing a lot with OpenGL is related to
> I have a matrix object to aid with the matrix math required for working
> with 3D transforms. However OpenGL (I'm using DerelictGL3 bindings)
> requires pointers to the data. I am currently doing the following:
> Matrix!float ortho(float l, float r, float b, float t, float f, float n
> = -1)
> Matrix!float oMat = identity(); // Get default Identity Matrix
> oMat[0,0] = 2 / (r - l);
> oMat[1,1] = 2 / (t - b);
> oMat[2,2] = -2 / (f - n);
> oMat = [-(r+l)/(r-l), -(t+b)/(t-b), -(f+n)/(f-n), 1];
> return oMat;
> And then to use with OpenGL (passing as uniform into shader):
> glUniformMatrix4fv(transform_uniform, 1, GL_FALSE, matrix.addr );
> where addr is a property that returns the address of the first item in
> the Matrix's internal data. I know I can also use &matrix
This is what I would do. For each prototype that takes a matrix pointer,
I would create an overloaded prototype that takes a pointer to your
matrix type instead. The overloaded prototype would then simply call the
real function with the matrix.addr property.
Using metaprogramming, you could probably generate this based on the
current opengl module.
Then your ported code doesn't need to change.
More information about the Digitalmars-d-learn