mirror of https://github.com/buggins/dlangui.git
fixes for #183
This commit is contained in:
parent
cccdc605ce
commit
84c9dc4e4e
|
|
@ -27,6 +27,9 @@ import dlangui.core.logger;
|
||||||
private import dlangui.graphics.glsupport;
|
private import dlangui.graphics.glsupport;
|
||||||
private import std.algorithm;
|
private import std.algorithm;
|
||||||
|
|
||||||
|
/// Reference counted GLTexture object
|
||||||
|
alias TextureRef = Ref!GLTexture;
|
||||||
|
|
||||||
interface GLConfigCallback {
|
interface GLConfigCallback {
|
||||||
void saveConfiguration();
|
void saveConfiguration();
|
||||||
void restoreConfiguration();
|
void restoreConfiguration();
|
||||||
|
|
@ -792,7 +795,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GL Texture object from image
|
/// GL Texture object from image
|
||||||
static class GLTexture {
|
static class GLTexture : RefCountedObject {
|
||||||
protected string _resourceId;
|
protected string _resourceId;
|
||||||
protected int _dx;
|
protected int _dx;
|
||||||
protected int _dy;
|
protected int _dy;
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,7 @@ static if (ENABLE_OPENGL):
|
||||||
public import dlangui.core.math3d;
|
public import dlangui.core.math3d;
|
||||||
import dlangui.graphics.scene.mesh;
|
import dlangui.graphics.scene.mesh;
|
||||||
import dlangui.core.logger;
|
import dlangui.core.logger;
|
||||||
//import derelict.opengl3.gl3;
|
|
||||||
import derelict.opengl3.gl;
|
import derelict.opengl3.gl;
|
||||||
//import derelict.opengl3.types;
|
|
||||||
import dlangui.core.types;
|
import dlangui.core.types;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
import std.string;
|
import std.string;
|
||||||
|
|
@ -115,7 +113,6 @@ string glerrorToString(in GLenum err) pure nothrow {
|
||||||
|
|
||||||
|
|
||||||
class GLProgram : GraphicsEffect {
|
class GLProgram : GraphicsEffect {
|
||||||
import derelict.opengl3.types;
|
|
||||||
@property abstract string vertexSource();
|
@property abstract string vertexSource();
|
||||||
@property abstract string fragmentSource();
|
@property abstract string fragmentSource();
|
||||||
protected GLuint program;
|
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.
|
* 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.
|
* All methods (except ctor, dtor, bind(), unbind() and setup()) does not perform binding.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
class GLObject(GLObjectTypes type, GLuint target = 0) {
|
class GLObject(GLObjectTypes type, GLuint target = 0) {
|
||||||
immutable GLuint ID;
|
immutable GLuint ID;
|
||||||
//alias ID this; // good, but it confuses destroy()
|
//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 VAO = GLObject!(GLObjectTypes.VertexArray);
|
||||||
alias VBO = GLObject!(GLObjectTypes.Buffer, GL_ARRAY_BUFFER);
|
alias VBO = GLObject!(GLObjectTypes.Buffer, GL_ARRAY_BUFFER);
|
||||||
alias Tex2D = GLObject!(GLObjectTypes.Texture, GL_TEXTURE_2D);
|
alias Tex2D = GLObject!(GLObjectTypes.Texture, GL_TEXTURE_2D);
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class Effect : GLProgram {
|
||||||
}
|
}
|
||||||
|
|
||||||
~this() {
|
~this() {
|
||||||
_instance.onObjectDestroyed(_id);
|
EffectCache.instance.onObjectDestroyed(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
|
|
@ -151,6 +151,8 @@ class Effect : GLProgram {
|
||||||
class EffectCache {
|
class EffectCache {
|
||||||
private Effect[EffectId] _map;
|
private Effect[EffectId] _map;
|
||||||
|
|
||||||
|
private static __gshared EffectCache _instance;
|
||||||
|
|
||||||
/// returns effect cache singleton instance
|
/// returns effect cache singleton instance
|
||||||
static @property EffectCache instance() {
|
static @property EffectCache instance() {
|
||||||
if (!_instance)
|
if (!_instance)
|
||||||
|
|
@ -179,4 +181,3 @@ class EffectCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private __gshared EffectCache _instance;
|
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,30 @@ alias MaterialRef = Ref!Material;
|
||||||
|
|
||||||
class Material : RefCountedObject {
|
class Material : RefCountedObject {
|
||||||
protected EffectRef _effect;
|
protected EffectRef _effect;
|
||||||
protected GLTexture _texture;
|
protected TextureRef _texture;
|
||||||
|
// TODO: more material properties
|
||||||
|
|
||||||
@property EffectRef effect() { return _effect; }
|
@property EffectRef effect() { return _effect; }
|
||||||
@property Material effect(EffectRef e) {
|
/// set as effect instance
|
||||||
|
@property Material effect(EffectRef e) {
|
||||||
_effect = e;
|
_effect = e;
|
||||||
return this;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue