Either I'm just too stupid, or D is lacking something
Wolfgang Draxinger
wdraxinger at darkstargames.de
Mon Jul 24 13:14:30 PDT 2006
As some might know I'm currently converting my 3D engine's source
code from C++ to D. But now I'm stuck with something of which I
can't believe that it might not be possible with D:
As one might expect the engine also manages textures, and OpenGL
textures have so called parameters. Now counting 2 and 2 I
thought: "OpenGL Texture parameters, hmm D supports parameter
assignment syntax, too, that makes things look much nicer":
class GLTexture : Texture
{
GLint min_filter(GLint _filter) {
glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, _filter);
return _filter;
}
GLint min_filter() {
GLint _filter;
glGetTexParameteri(Target, GL_TEXTURE_MIN_FILTER, &_filter);
return _filter;
}
GLint mag_filter(GLint _filter) {
glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, _filter);
return _filter;
}
GLint mag_filter() {
GLint _filter;
glGetTexParameteri(Target, GL_TEXTURE_MAG_FILTER, &_filter);
return _filter;
}
/*
...
*/
private:
const GLenum Target;
}
However this looks rather crude and shouts for generic
programming. Instead just writing
mixin GLTemplateParameter!(GL_TEXTURE_MIN_FILTER, min_filter);
or something similair would be much nicer, shorter and less error
prone. But there's the problem, that I don't know (or that there
might not be the possibility) to give a name as parameter, that
will be used for declaration naming.
Probably I'm just too stupid, but if that's really a missing
feature, then I plead to add it.
Wolfgang Draxinger
More information about the Digitalmars-d-learn
mailing list