diff --git a/dlangui-msvc.visualdproj b/dlangui-msvc.visualdproj
index 18c6ca82..855550f2 100644
--- a/dlangui-msvc.visualdproj
+++ b/dlangui-msvc.visualdproj
@@ -174,7 +174,7 @@
0
0
- EmbedStandardResources ForceLogs
+ EmbedStandardResources ForceLogs USE_OPENGL
0
0
0
@@ -480,7 +480,7 @@
0
0
- EmbedStandardResources ForceLogs
+ EmbedStandardResources ForceLogs USE_OPENGL
0
0
0
@@ -779,8 +779,8 @@
-
+
diff --git a/examples/d3d/d3d-msvc.visualdproj b/examples/d3d/d3d-msvc.visualdproj
index ba2a9942..369a7246 100644
--- a/examples/d3d/d3d-msvc.visualdproj
+++ b/examples/d3d/d3d-msvc.visualdproj
@@ -174,7 +174,7 @@
0
0
- EmbedStandardResources
+ EmbedStandardResources USE_OPENGL
0
0
0
@@ -378,7 +378,7 @@
0
0
- EmbedStandardResources
+ EmbedStandardResources USE_OPENGL
0
0
0
diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d
index 0977a48d..9c46e632 100644
--- a/src/dlangui/graphics/gldrawbuf.d
+++ b/src/dlangui/graphics/gldrawbuf.d
@@ -793,6 +793,7 @@ public:
/// GL Texture object from image
static class GLTexture {
+ protected string _resourceId;
protected int _dx;
protected int _dy;
protected int _tdx;
@@ -831,6 +832,7 @@ static class GLTexture {
this(string resourceId) {
import dlangui.graphics.resources;
+ _resourceId = resourceId;
string path = drawableCache.findResource(resourceId);
this(cast(ColorDrawBuf)imageCache.get(path));
}
@@ -859,9 +861,40 @@ static class GLTexture {
}
~this() {
+ import std.string : empty;
+ if (!_resourceId.empty)
+ GLTextureCache.instance.onItemRemoved(_resourceId);
if (_texture && _texture.ID != 0) {
destroy(_texture);
_texture = null;
}
}
}
+
+/// Cache for GLTexture
+class GLTextureCache {
+ protected GLTexture[string] _map;
+
+ static __gshared GLTextureCache _instance;
+
+ static @property GLTextureCache instance() {
+ if (!_instance)
+ _instance = new GLTextureCache();
+ return _instance;
+ }
+
+ private void onItemRemoved(string resourceId) {
+ if (resourceId in _map) {
+ _map.remove(resourceId);
+ }
+ }
+
+ GLTexture get(string resourceId) {
+ if (auto p = resourceId in _map) {
+ return *p;
+ }
+ GLTexture tx = new GLTexture(resourceId);
+ _map[resourceId] = tx;
+ return tx;
+ }
+}
diff --git a/src/dlangui/graphics/glsupport.d b/src/dlangui/graphics/glsupport.d
index 2879fe11..4506993e 100644
--- a/src/dlangui/graphics/glsupport.d
+++ b/src/dlangui/graphics/glsupport.d
@@ -25,8 +25,9 @@ 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.gl3;
import derelict.opengl3.gl;
+//import derelict.opengl3.types;
import dlangui.core.types;
import std.conv;
import std.string;
@@ -114,6 +115,7 @@ 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;
diff --git a/src/dlangui/graphics/scene/material.d b/src/dlangui/graphics/scene/material.d
index 752033ab..8c22d7fc 100644
--- a/src/dlangui/graphics/scene/material.d
+++ b/src/dlangui/graphics/scene/material.d
@@ -1,4 +1,23 @@
module dlangui.graphics.scene.material;
-class Material {
+public import dlangui.core.config;
+
+import dlangui.core.types;
+import dlangui.core.logger;
+import dlangui.graphics.glsupport;
+import dlangui.graphics.gldrawbuf;
+import dlangui.graphics.scene.effect;
+
+/// Reference counted Material object
+alias MaterialRef = Ref!Material;
+
+class Material : RefCountedObject {
+ protected EffectRef _effect;
+ protected GLTexture _texture;
+
+ @property EffectRef effect() { return _effect; }
+ @property Material effect(EffectRef e) {
+ _effect = e;
+ return this;
+ }
}
diff --git a/src/dlangui/graphics/scene/mesh.d b/src/dlangui/graphics/scene/mesh.d
index 8b006f5c..fa74b03b 100644
--- a/src/dlangui/graphics/scene/mesh.d
+++ b/src/dlangui/graphics/scene/mesh.d
@@ -4,6 +4,9 @@ import dlangui.graphics.scene.material;
import dlangui.core.math3d;
import dlangui.core.types;
+/// Reference counted Mesh object
+alias MeshRef = Ref!Mesh;
+
/// vertex element type
enum VertexElementType : ubyte {
POSITION = 1,
@@ -157,7 +160,7 @@ struct IndexFragment {
}
/// Mesh
-class Mesh {
+class Mesh : RefCountedObject {
protected VertexFormat _vertexFormat;
protected int _vertexCount;
protected float[] _vertexData;