mirror of https://github.com/buggins/dlangui.git
fix mipmap levels support
This commit is contained in:
parent
0d3fc3b1b5
commit
e1b1056d31
|
@ -198,6 +198,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
updateMinerMesh();
|
||||
|
||||
Material minerMaterial = new Material(EffectId("textured.vert", "textured.frag", null), "blocks");
|
||||
minerMaterial.textureLinear = false;
|
||||
Model minerDrawable = new Model(minerMaterial, _minerMesh);
|
||||
Node3d minerNode = new Node3d("miner", minerDrawable);
|
||||
_scene.addChild(minerNode);
|
||||
|
|
|
@ -8,9 +8,9 @@ immutable string BLOCK_TEXTURE_FILENAME = "blocks";
|
|||
immutable int BLOCK_TEXTURE_DX = 1024;
|
||||
immutable int BLOCK_TEXTURE_DY = 1024;
|
||||
immutable int BLOCK_SPRITE_SIZE = 16;
|
||||
immutable int BLOCK_SPRITE_STEP = 20;
|
||||
immutable int BLOCK_SPRITE_OFFSET = 21;
|
||||
immutable int BLOCK_TEXTURE_SPRITES_PER_LINE = 50;
|
||||
immutable int BLOCK_SPRITE_STEP = 16;
|
||||
immutable int BLOCK_SPRITE_OFFSET = 0;
|
||||
immutable int BLOCK_TEXTURE_SPRITES_PER_LINE = 1024/16;
|
||||
immutable int VERTEX_COMPONENTS = 12;
|
||||
|
||||
enum BlockVisibility {
|
||||
|
@ -232,6 +232,24 @@ void registerBlockType(BlockDef def) {
|
|||
BLOCK_TERRAIN_SMOOTHING[def.id] = def.terrainSmoothing;
|
||||
}
|
||||
|
||||
enum BlockImage : int {
|
||||
stone,
|
||||
grass_top,
|
||||
grass_side,
|
||||
grass_top_footsteps,
|
||||
dirt,
|
||||
bedrock,
|
||||
sand,
|
||||
gravel,
|
||||
sandstone,
|
||||
clay,
|
||||
cobblestone,
|
||||
cobblestone_mossy,
|
||||
brick,
|
||||
stonebrick,
|
||||
red_sand,
|
||||
}
|
||||
|
||||
/// init block types array
|
||||
__gshared static this() {
|
||||
import std.string;
|
||||
|
@ -248,14 +266,14 @@ __gshared static this() {
|
|||
// empty cell
|
||||
registerBlockType(new BlockDef(0, "empty", BlockVisibility.INVISIBLE, 0));
|
||||
// standard block types
|
||||
registerBlockType(new BlockDef(1, "gray_brick", BlockVisibility.OPAQUE, 0));
|
||||
registerBlockType(new BlockDef(2, "brick", BlockVisibility.OPAQUE, 1));
|
||||
registerBlockType(new BlockDef(3, "bedrock", BlockVisibility.OPAQUE, 2));
|
||||
registerBlockType(new BlockDef(4, "clay", BlockVisibility.OPAQUE, 3));
|
||||
registerBlockType(new BlockDef(5, "cobblestone", BlockVisibility.OPAQUE, 4));
|
||||
registerBlockType(new BlockDef(6, "gravel", BlockVisibility.OPAQUE, 5));
|
||||
registerBlockType(new BlockDef(7, "red_sand", BlockVisibility.OPAQUE, 6));
|
||||
registerBlockType(new BlockDef(8, "sand", BlockVisibility.OPAQUE, 7));
|
||||
registerBlockType(new BlockDef(1, "gray_brick", BlockVisibility.OPAQUE, BlockImage.stonebrick));
|
||||
registerBlockType(new BlockDef(2, "brick", BlockVisibility.OPAQUE, BlockImage.brick));
|
||||
registerBlockType(new BlockDef(3, "bedrock", BlockVisibility.OPAQUE, BlockImage.bedrock));
|
||||
registerBlockType(new BlockDef(4, "clay", BlockVisibility.OPAQUE, BlockImage.clay));
|
||||
registerBlockType(new BlockDef(5, "cobblestone", BlockVisibility.OPAQUE, BlockImage.cobblestone));
|
||||
registerBlockType(new BlockDef(6, "gravel", BlockVisibility.OPAQUE, BlockImage.gravel));
|
||||
registerBlockType(new BlockDef(7, "red_sand", BlockVisibility.OPAQUE, BlockImage.red_sand));
|
||||
registerBlockType(new BlockDef(8, "sand", BlockVisibility.OPAQUE, BlockImage.sand));
|
||||
|
||||
registerBlockType(new BlockDef(50, "box", BlockVisibility.HALF_OPAQUE, 50));
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 31 KiB |
|
@ -833,14 +833,14 @@ static class GLTexture : RefCountedObject {
|
|||
return uv(_dx, _dy);
|
||||
}
|
||||
|
||||
this(string resourceId) {
|
||||
this(string resourceId, int mipmapLevels = 0) {
|
||||
import dlangui.graphics.resources;
|
||||
_resourceId = resourceId;
|
||||
string path = drawableCache.findResource(resourceId);
|
||||
this(cast(ColorDrawBuf)imageCache.get(path));
|
||||
this(cast(ColorDrawBuf)imageCache.get(path), mipmapLevels);
|
||||
}
|
||||
|
||||
this(ColorDrawBuf buf) {
|
||||
this(ColorDrawBuf buf, int mipmapLevels = 0) {
|
||||
if (buf) {
|
||||
_dx = buf.width;
|
||||
_dy = buf.height;
|
||||
|
@ -853,7 +853,7 @@ static class GLTexture : RefCountedObject {
|
|||
}
|
||||
uint * pixels = buf.scanLine(0);
|
||||
buf.invertAlpha();
|
||||
if (!glSupport.setTextureImage(_texture, buf.width, buf.height, cast(ubyte*)pixels, 10)) {
|
||||
if (!glSupport.setTextureImage(_texture, buf.width, buf.height, cast(ubyte*)pixels, mipmapLevels)) {
|
||||
destroy(_texture);
|
||||
_texture = null;
|
||||
buf.invertAlpha();
|
||||
|
@ -896,7 +896,7 @@ class GLTextureCache {
|
|||
if (auto p = resourceId in _map) {
|
||||
return *p;
|
||||
}
|
||||
GLTexture tx = new GLTexture(resourceId);
|
||||
GLTexture tx = new GLTexture(resourceId, 6);
|
||||
_map[resourceId] = tx;
|
||||
return tx;
|
||||
}
|
||||
|
|
|
@ -973,7 +973,7 @@ final class GLSupport {
|
|||
}
|
||||
srcptr += srcstride; // skip srcline
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, newdx, newdy, 0, GL_RGBA, GL_UNSIGNED_BYTE, dst.ptr);
|
||||
checkgl!glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, newdx, newdy, 0, GL_RGBA, GL_UNSIGNED_BYTE, dst.ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -983,8 +983,10 @@ final class GLSupport {
|
|||
checkgl!glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
texture.setSamplerParams(true, true);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipmapLevels > 0 ? mipmapLevels - 1 : 0);
|
||||
// ORIGINAL: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dx, dy, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dx, dy, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
checkgl!glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dx, dy, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
if (checkError("updateTexture - glTexImage2D")) {
|
||||
Log.e("Cannot set image for texture");
|
||||
return false;
|
||||
|
@ -1185,8 +1187,10 @@ class GLObject(GLObjectTypes type, GLuint target = 0) {
|
|||
static if(type == GLObjectTypes.Texture)
|
||||
{
|
||||
void setSamplerParams(bool linear, bool clamp = false, bool mipmap = false) {
|
||||
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, linear ? (!mipmap ? GL_LINEAR : GL_LINEAR_MIPMAP_LINEAR) : (!mipmap ? GL_NEAREST : GL_NEAREST_MIPMAP_NEAREST));
|
||||
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, linear ? (!mipmap ? GL_LINEAR : GL_LINEAR_MIPMAP_LINEAR) : (!mipmap ? GL_NEAREST : GL_NEAREST_MIPMAP_NEAREST));
|
||||
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, linear ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, linear ?
|
||||
(!mipmap ? GL_LINEAR : GL_LINEAR_MIPMAP_LINEAR) :
|
||||
(!mipmap ? GL_NEAREST : GL_LINEAR_MIPMAP_LINEAR)); //GL_NEAREST_MIPMAP_NEAREST
|
||||
checkError("filtering - glTexParameteri");
|
||||
if(clamp) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
|
|
|
@ -24,6 +24,7 @@ class Material : RefCountedObject {
|
|||
// textures
|
||||
protected TextureRef _texture;
|
||||
protected string _textureId;
|
||||
protected bool _textureLinear = true;
|
||||
|
||||
protected TextureRef _bumpTexture;
|
||||
protected string _bumpTextureId;
|
||||
|
@ -109,6 +110,8 @@ class Material : RefCountedObject {
|
|||
_textureId = resourceId;
|
||||
return this;
|
||||
}
|
||||
@property bool textureLinear() { return _textureLinear; }
|
||||
@property Material textureLinear(bool v) { _textureLinear = v; return this; }
|
||||
|
||||
|
||||
@property TextureRef bumpTexture() {
|
||||
|
@ -150,11 +153,11 @@ class Material : RefCountedObject {
|
|||
effect.bind();
|
||||
if (!texture.isNull) {
|
||||
texture.texture.setup();
|
||||
texture.texture.setSamplerParams(true, true, true);
|
||||
texture.texture.setSamplerParams(_textureLinear, true, true);
|
||||
}
|
||||
if (!bumpTexture.isNull) {
|
||||
bumpTexture.texture.setup(1);
|
||||
bumpTexture.texture.setSamplerParams(true, true, true);
|
||||
bumpTexture.texture.setSamplerParams(true, true, false);
|
||||
}
|
||||
// matrixes, positions uniforms
|
||||
if (_effect.hasUniform(DefaultUniform.u_worldViewProjectionMatrix))
|
||||
|
@ -221,6 +224,9 @@ class Material : RefCountedObject {
|
|||
if (!texture.isNull) {
|
||||
texture.texture.unbind();
|
||||
}
|
||||
if (!bumpTexture.isNull) {
|
||||
bumpTexture.texture.unbind();
|
||||
}
|
||||
effect.unbind();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue