This commit is contained in:
Vadim Lopatin 2016-03-29 16:37:58 +03:00
parent cccdc605ce
commit 84c9dc4e4e
4 changed files with 31 additions and 8 deletions

View File

@ -27,6 +27,9 @@ import dlangui.core.logger;
private import dlangui.graphics.glsupport;
private import std.algorithm;
/// Reference counted GLTexture object
alias TextureRef = Ref!GLTexture;
interface GLConfigCallback {
void saveConfiguration();
void restoreConfiguration();
@ -792,7 +795,7 @@ public:
}
/// GL Texture object from image
static class GLTexture {
static class GLTexture : RefCountedObject {
protected string _resourceId;
protected int _dx;
protected int _dy;

View File

@ -25,9 +25,7 @@ static if (ENABLE_OPENGL):
public import dlangui.core.math3d;
import dlangui.graphics.scene.mesh;
import dlangui.core.logger;
//import derelict.opengl3.gl3;
import derelict.opengl3.gl;
//import derelict.opengl3.types;
import dlangui.core.types;
import std.conv;
import std.string;
@ -115,7 +113,6 @@ string glerrorToString(in GLenum err) pure nothrow {
class GLProgram : GraphicsEffect {
import derelict.opengl3.types;
@property abstract string vertexSource();
@property abstract string fragmentSource();
protected GLuint program;
@ -990,6 +987,8 @@ enum GLObjectTypes { Buffer, VertexArray, Texture, Framebuffer };
* Note: on construction it binds itself to the target, and it binds 0 to target on destruction.
* All methods (except ctor, dtor, bind(), unbind() and setup()) does not perform binding.
*/
class GLObject(GLObjectTypes type, GLuint target = 0) {
immutable GLuint ID;
//alias ID this; // good, but it confuses destroy()
@ -1061,6 +1060,7 @@ class GLObject(GLObjectTypes type, GLuint target = 0) {
}
}
}
alias VAO = GLObject!(GLObjectTypes.VertexArray);
alias VBO = GLObject!(GLObjectTypes.Buffer, GL_ARRAY_BUFFER);
alias Tex2D = GLObject!(GLObjectTypes.Texture, GL_TEXTURE_2D);

View File

@ -62,7 +62,7 @@ class Effect : GLProgram {
}
~this() {
_instance.onObjectDestroyed(_id);
EffectCache.instance.onObjectDestroyed(_id);
}
protected void init() {
@ -151,6 +151,8 @@ class Effect : GLProgram {
class EffectCache {
private Effect[EffectId] _map;
private static __gshared EffectCache _instance;
/// returns effect cache singleton instance
static @property EffectCache instance() {
if (!_instance)
@ -179,4 +181,3 @@ class EffectCache {
}
}
private __gshared EffectCache _instance;

View File

@ -13,11 +13,30 @@ alias MaterialRef = Ref!Material;
class Material : RefCountedObject {
protected EffectRef _effect;
protected GLTexture _texture;
protected TextureRef _texture;
// TODO: more material properties
@property EffectRef effect() { return _effect; }
@property Material effect(EffectRef e) {
/// set as effect instance
@property Material effect(EffectRef e) {
_effect = e;
return this;
}
/// set as effect id
@property Material effect(EffectId effectId) {
_effect = EffectCache.instance.get(effectId);
return this;
}
@property TextureRef texture() { return _texture; }
/// set texture
@property Material texture(TextureRef e) {
_texture = e;
return this;
}
/// set texture from resourceId
@property Material texture(string resourceId) {
_texture = GLTextureCache.instance.get(resourceId);
return this;
}
}