This commit is contained in:
Vadim Lopatin 2016-03-29 15:36:54 +03:00
parent b3da543c8c
commit cccdc605ce
6 changed files with 65 additions and 8 deletions

View File

@ -174,7 +174,7 @@
<debuglevel>0</debuglevel>
<debugids />
<versionlevel>0</versionlevel>
<versionids>EmbedStandardResources ForceLogs</versionids>
<versionids>EmbedStandardResources ForceLogs USE_OPENGL</versionids>
<dump_source>0</dump_source>
<mapverbosity>0</mapverbosity>
<createImplib>0</createImplib>
@ -480,7 +480,7 @@
<debuglevel>0</debuglevel>
<debugids />
<versionlevel>0</versionlevel>
<versionids>EmbedStandardResources ForceLogs</versionids>
<versionids>EmbedStandardResources ForceLogs USE_OPENGL</versionids>
<dump_source>0</dump_source>
<mapverbosity>0</mapverbosity>
<createImplib>0</createImplib>
@ -779,8 +779,8 @@
<File path="src\dlangui\graphics\scene\transform.d" />
</Folder>
<Folder name="xpm">
<File path="src\dlangui\graphics\xpm\xpmcolors.d" />
<File path="src\dlangui\graphics\xpm\reader.d" />
<File path="src\dlangui\graphics\xpm\xpmcolors.d" />
</Folder>
<File path="src\dlangui\graphics\colors.d" />
<File path="src\dlangui\graphics\domrender.d" />

View File

@ -174,7 +174,7 @@
<debuglevel>0</debuglevel>
<debugids />
<versionlevel>0</versionlevel>
<versionids> EmbedStandardResources</versionids>
<versionids> EmbedStandardResources USE_OPENGL</versionids>
<dump_source>0</dump_source>
<mapverbosity>0</mapverbosity>
<createImplib>0</createImplib>
@ -378,7 +378,7 @@
<debuglevel>0</debuglevel>
<debugids />
<versionlevel>0</versionlevel>
<versionids> EmbedStandardResources</versionids>
<versionids> EmbedStandardResources USE_OPENGL</versionids>
<dump_source>0</dump_source>
<mapverbosity>0</mapverbosity>
<createImplib>0</createImplib>

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;