Merge pull request #166 from dariomanesku/master

Added imguiCube().
This commit is contained in:
Branimir Karadžić 2014-10-02 21:18:23 -07:00
commit b2fae29cea
5 changed files with 213 additions and 23 deletions

View file

@ -1,20 +1,20 @@
static const uint8_t fs_imgui_image_glsl[310] =
{
0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x02, 0x00, 0x0a, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima
0x67, 0x65, 0x4c, 0x6f, 0x64, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, // geLod.......s_te
0x67, 0x65, 0x4c, 0x6f, 0x64, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x75, 0x5f, 0x74, 0x65, // geLod.......u_te
0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x05, 0x01, 0x00, 0x00, // xColor..........
0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x6d, 0x65, 0x64, 0x69, 0x75, 0x6d, 0x70, 0x20, // varying mediump
0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, // vec2 v_texcoord0
0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6d, 0x65, 0x64, 0x69, 0x75, 0x6d, // ;.uniform medium
0x70, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, // p float u_imageL
0x6f, 0x64, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, // od;.uniform samp
0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, // ler2D s_texColor
0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x75, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, // ler2D u_texColor
0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, // ;.void main ().{
0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, // . lowp vec4 tmp
0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // var_1;. tmpvar_
0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, // 1.w = 1.0;. tmp
0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, // var_1.xyz = text
0x75, 0x72, 0x65, 0x32, 0x44, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x20, 0x28, 0x73, 0x5f, 0x74, // ure2DLod (s_t
0x75, 0x72, 0x65, 0x32, 0x44, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x20, 0x28, 0x75, 0x5f, 0x74, // ure2DLod (u_t
0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, // exColor, v_texco
0x6f, 0x72, 0x64, 0x30, 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, // ord0, u_imageLod
0x29, 0x2e, 0x78, 0x79, 0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, // ).xyz;. gl_Frag
@ -27,12 +27,12 @@ static const uint8_t fs_imgui_image_dx9[342] =
0x67, 0x65, 0x4c, 0x6f, 0x64, 0x14, 0x01, 0x00, 0x00, 0x01, 0x00, 0x38, 0x01, 0x00, 0x03, 0xff, // geLod......8....
0xff, 0xfe, 0xff, 0x2e, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, // .....CTAB.......
0x00, 0x00, 0x03, 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, // ................
0x00, 0x7c, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, // .|...D..........
0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .P.......`......
0x00, 0x01, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x5f, 0x74, // .....l.......s_t
0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0x04, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x01, // exColor.........
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, // .........u_image
0x4c, 0x6f, 0x64, 0x00, 0xab, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, // Lod.............
0x00, 0x7c, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .|...D..........
0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .P.......`......
0x00, 0x01, 0x00, 0x02, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x69, // .....l.......u_i
0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x00, 0xab, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, // mageLod.........
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, // .........u_texCo
0x6c, 0x6f, 0x72, 0x00, 0xab, 0x04, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, // lor.............
0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, // .....ps_3_0.Micr
0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, // osoft (R) HLSL S
0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, // hader Compiler 9
@ -50,8 +50,8 @@ static const uint8_t fs_imgui_image_dx11[1321] =
{
0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x01, 0x00, 0x0a, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima
0x67, 0x65, 0x4c, 0x6f, 0x64, 0x14, 0x00, 0x24, 0x0a, 0x01, 0x00, 0x08, 0x05, 0x44, 0x58, 0x42, // geLod..$.....DXB
0x43, 0x0e, 0x5a, 0x0f, 0xd9, 0xa2, 0x1e, 0x38, 0x23, 0x8d, 0xd9, 0x66, 0x18, 0x80, 0x6b, 0xb8, // C.Z....8#..f..k.
0xe6, 0x01, 0x00, 0x00, 0x00, 0x08, 0x05, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, // .............4..
0x43, 0x75, 0xb5, 0x78, 0x5b, 0xc0, 0x89, 0x74, 0xe3, 0xd1, 0x10, 0xe5, 0x87, 0x5e, 0x12, 0xcb, // Cu.x[..t.....^..
0x02, 0x01, 0x00, 0x00, 0x00, 0x08, 0x05, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, // .............4..
0x00, 0x48, 0x03, 0x00, 0x00, 0xa0, 0x03, 0x00, 0x00, 0xd4, 0x03, 0x00, 0x00, 0x8c, 0x04, 0x00, // .H..............
0x00, 0x52, 0x44, 0x45, 0x46, 0x0c, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xbc, 0x00, 0x00, // .RDEF...........
0x00, 0x03, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x04, 0xff, 0xff, 0x00, 0x91, 0x00, // ................
@ -61,9 +61,9 @@ static const uint8_t fs_imgui_image_dx11[1321] =
0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // ................
0x00, 0x0d, 0x00, 0x00, 0x00, 0xb2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // ................
0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x73, // .....s_texColors
0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x75, // .....u_texColoru
0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x00, // _texColorampler.
0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, // s_texColors_texC
0x75, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x75, 0x5f, 0x74, 0x65, 0x78, 0x43, // u_texColoru_texC
0x6f, 0x6c, 0x6f, 0x72, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x00, 0x24, 0x47, 0x6c, 0x6f, 0x62, // olorexture.$Glob
0x61, 0x6c, 0x73, 0x00, 0xab, 0xb2, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, // als.............
0x00, 0x30, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x02, 0x00, // .0..............

View file

@ -8,10 +8,10 @@ $input v_texcoord0
#include <bgfx_shader.sh>
uniform float u_imageLod;
SAMPLER2D(s_texColor, 0);
SAMPLER2D(u_texColor, 0);
void main()
{
vec4 color = texture2DLod(s_texColor, v_texcoord0, u_imageLod);
vec4 color = texture2DLod(u_texColor, v_texcoord0, u_imageLod);
gl_FragColor = vec4(color.xyz, 1.0);
}

View file

@ -37,6 +37,8 @@
#include "fs_imgui_color.bin.h"
#include "vs_imgui_texture.bin.h"
#include "fs_imgui_texture.bin.h"
#include "vs_imgui_cubemap.bin.h"
#include "fs_imgui_cubemap.bin.h"
#include "vs_imgui_image.bin.h"
#include "fs_imgui_image.bin.h"
#include "fs_imgui_image_swizz.bin.h"
@ -79,6 +81,19 @@ static void imguiFree(void* _ptr, void* /*_userptr*/)
namespace
{
static uint32_t quad(uint16_t* _indices, uint16_t _idx0, uint16_t _idx1, uint16_t _idx2, uint16_t _idx3)
{
_indices[0] = _idx0;
_indices[1] = _idx3;
_indices[2] = _idx1;
_indices[3] = _idx1;
_indices[4] = _idx3;
_indices[5] = _idx2;
return 6;
}
float sign(float px, float py, float ax, float ay, float bx, float by)
{
return (px - bx) * (ay - by) - (ax - bx) * (py - by);
@ -255,6 +270,38 @@ namespace
bgfx::VertexDecl PosUvVertex::ms_decl;
struct PosNormalVertex
{
float m_x;
float m_y;
float m_z;
float m_nx;
float m_ny;
float m_nz;
static void init()
{
ms_decl.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.add(bgfx::Attrib::Normal, 3, bgfx::AttribType::Float)
.end();
}
void set(float _x, float _y, float _z, float _nx, float _ny, float _nz)
{
m_x = _x;
m_y = _y;
m_z = _z;
m_nx = _nx;
m_ny = _ny;
m_nz = _nz;
}
static bgfx::VertexDecl ms_decl;
};
bgfx::VertexDecl PosNormalVertex::ms_decl;
} // namespace
#if !USE_NANOVG_FONT
@ -335,11 +382,12 @@ struct Imgui
u_imageLod.idx = bgfx::invalidHandle;
u_imageSwizzle.idx = bgfx::invalidHandle;
s_texColor.idx = bgfx::invalidHandle;
u_texColor.idx = bgfx::invalidHandle;
m_missingTexture.idx = bgfx::invalidHandle;
m_colorProgram.idx = bgfx::invalidHandle;
m_textureProgram.idx = bgfx::invalidHandle;
m_cubeMapProgram.idx = bgfx::invalidHandle;
m_imageProgram.idx = bgfx::invalidHandle;
m_imageSwizzProgram.idx = bgfx::invalidHandle;
}
@ -408,15 +456,18 @@ struct Imgui
PosColorVertex::init();
PosColorUvVertex::init();
PosUvVertex::init();
PosNormalVertex::init();
u_imageLod = bgfx::createUniform("u_imageLod", bgfx::UniformType::Uniform1f);
u_imageSwizzle = bgfx::createUniform("u_swizzle", bgfx::UniformType::Uniform4fv);
s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Uniform1i);
u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Uniform1i);
const bgfx::Memory* vs_imgui_color;
const bgfx::Memory* fs_imgui_color;
const bgfx::Memory* vs_imgui_texture;
const bgfx::Memory* fs_imgui_texture;
const bgfx::Memory* vs_imgui_cubemap;
const bgfx::Memory* fs_imgui_cubemap;
const bgfx::Memory* vs_imgui_image;
const bgfx::Memory* fs_imgui_image;
const bgfx::Memory* fs_imgui_image_swizz;
@ -428,6 +479,8 @@ struct Imgui
fs_imgui_color = bgfx::makeRef(fs_imgui_color_dx9, sizeof(fs_imgui_color_dx9) );
vs_imgui_texture = bgfx::makeRef(vs_imgui_texture_dx9, sizeof(vs_imgui_texture_dx9) );
fs_imgui_texture = bgfx::makeRef(fs_imgui_texture_dx9, sizeof(fs_imgui_texture_dx9) );
vs_imgui_cubemap = bgfx::makeRef(vs_imgui_cubemap_dx9, sizeof(vs_imgui_cubemap_dx9) );
fs_imgui_cubemap = bgfx::makeRef(fs_imgui_cubemap_dx9, sizeof(fs_imgui_cubemap_dx9) );
vs_imgui_image = bgfx::makeRef(vs_imgui_image_dx9, sizeof(vs_imgui_image_dx9) );
fs_imgui_image = bgfx::makeRef(fs_imgui_image_dx9, sizeof(fs_imgui_image_dx9) );
fs_imgui_image_swizz = bgfx::makeRef(fs_imgui_image_swizz_dx9, sizeof(fs_imgui_image_swizz_dx9) );
@ -439,6 +492,8 @@ struct Imgui
fs_imgui_color = bgfx::makeRef(fs_imgui_color_dx11, sizeof(fs_imgui_color_dx11) );
vs_imgui_texture = bgfx::makeRef(vs_imgui_texture_dx11, sizeof(vs_imgui_texture_dx11) );
fs_imgui_texture = bgfx::makeRef(fs_imgui_texture_dx11, sizeof(fs_imgui_texture_dx11) );
vs_imgui_cubemap = bgfx::makeRef(vs_imgui_cubemap_dx11, sizeof(vs_imgui_cubemap_dx11) );
fs_imgui_cubemap = bgfx::makeRef(fs_imgui_cubemap_dx11, sizeof(fs_imgui_cubemap_dx11) );
vs_imgui_image = bgfx::makeRef(vs_imgui_image_dx11, sizeof(vs_imgui_image_dx11) );
fs_imgui_image = bgfx::makeRef(fs_imgui_image_dx11, sizeof(fs_imgui_image_dx11) );
fs_imgui_image_swizz = bgfx::makeRef(fs_imgui_image_swizz_dx11, sizeof(fs_imgui_image_swizz_dx11) );
@ -449,6 +504,8 @@ struct Imgui
fs_imgui_color = bgfx::makeRef(fs_imgui_color_glsl, sizeof(fs_imgui_color_glsl) );
vs_imgui_texture = bgfx::makeRef(vs_imgui_texture_glsl, sizeof(vs_imgui_texture_glsl) );
fs_imgui_texture = bgfx::makeRef(fs_imgui_texture_glsl, sizeof(fs_imgui_texture_glsl) );
vs_imgui_cubemap = bgfx::makeRef(vs_imgui_cubemap_glsl, sizeof(vs_imgui_cubemap_glsl) );
fs_imgui_cubemap = bgfx::makeRef(fs_imgui_cubemap_glsl, sizeof(fs_imgui_cubemap_glsl) );
vs_imgui_image = bgfx::makeRef(vs_imgui_image_glsl, sizeof(vs_imgui_image_glsl) );
fs_imgui_image = bgfx::makeRef(fs_imgui_image_glsl, sizeof(fs_imgui_image_glsl) );
fs_imgui_image_swizz = bgfx::makeRef(fs_imgui_image_swizz_glsl, sizeof(fs_imgui_image_swizz_glsl) );
@ -470,6 +527,12 @@ struct Imgui
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
vsh = bgfx::createShader(vs_imgui_cubemap);
fsh = bgfx::createShader(fs_imgui_cubemap);
m_cubeMapProgram = bgfx::createProgram(vsh, fsh);
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
vsh = bgfx::createShader(vs_imgui_image);
fsh = bgfx::createShader(fs_imgui_image);
m_imageProgram = bgfx::createProgram(vsh, fsh);
@ -496,7 +559,7 @@ struct Imgui
{
bgfx::destroyUniform(u_imageLod);
bgfx::destroyUniform(u_imageSwizzle);
bgfx::destroyUniform(s_texColor);
bgfx::destroyUniform(u_texColor);
#if !USE_NANOVG_FONT
for (uint16_t ii = 0; ii < IMGUI_CONFIG_MAX_FONTS; ++ii)
{
@ -509,6 +572,7 @@ struct Imgui
bgfx::destroyTexture(m_missingTexture);
bgfx::destroyProgram(m_colorProgram);
bgfx::destroyProgram(m_textureProgram);
bgfx::destroyProgram(m_cubeMapProgram);
bgfx::destroyProgram(m_imageProgram);
bgfx::destroyProgram(m_imageSwizzProgram);
nvgDelete(m_nvg);
@ -1487,7 +1551,7 @@ struct Imgui
screenQuad(xx, yy, _width, _height, _originBottomLeft);
bgfx::setUniform(u_imageLod, &_lod);
bgfx::setTexture(0, s_texColor, bgfx::isValid(_image) ? _image : m_missingTexture);
bgfx::setTexture(0, u_texColor, bgfx::isValid(_image) ? _image : m_missingTexture);
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
bgfx::setProgram(m_imageProgram);
setCurrentScissor();
@ -1540,7 +1604,7 @@ struct Imgui
swizz[_channel] = 1.0f;
bgfx::setUniform(u_imageSwizzle, swizz);
bgfx::setTexture(0, s_texColor, bgfx::isValid(_image) ? _image : m_missingTexture);
bgfx::setTexture(0, u_texColor, bgfx::isValid(_image) ? _image : m_missingTexture);
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
bgfx::setProgram(m_imageSwizzProgram);
setCurrentScissor();
@ -1555,6 +1619,123 @@ struct Imgui
imageChannel(_image, _channel, _lod, int32_t(width), int32_t(height), _align);
}
void cubeMap(bgfx::TextureHandle _cubemap, float _lod, bool _cross, ImguiAlign::Enum _align)
{
uint32_t numVertices = 14;
uint32_t numIndices = 36;
if (bgfx::checkAvailTransientBuffers(numVertices, PosNormalVertex::ms_decl, numIndices) )
{
bgfx::TransientVertexBuffer tvb;
bgfx::allocTransientVertexBuffer(&tvb, numVertices, PosNormalVertex::ms_decl);
bgfx::TransientIndexBuffer tib;
bgfx::allocTransientIndexBuffer(&tib, numIndices);
PosNormalVertex* vertex = (PosNormalVertex*)tvb.data;
uint16_t* indices = (uint16_t*)tib.data;
if (_cross)
{
vertex->set( 0.0f, 0.5f, 0.0f, -1.0f, 1.0f, -1.0f); ++vertex;
vertex->set( 0.0f, 1.0f, 0.0f, -1.0f, -1.0f, -1.0f); ++vertex;
vertex->set( 0.5f, 0.0f, 0.0f, -1.0f, 1.0f, -1.0f); ++vertex;
vertex->set( 0.5f, 0.5f, 0.0f, -1.0f, 1.0f, 1.0f); ++vertex;
vertex->set( 0.5f, 1.0f, 0.0f, -1.0f, -1.0f, 1.0f); ++vertex;
vertex->set( 0.5f, 1.5f, 0.0f, -1.0f, -1.0f, -1.0f); ++vertex;
vertex->set( 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, -1.0f); ++vertex;
vertex->set( 1.0f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f); ++vertex;
vertex->set( 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); ++vertex;
vertex->set( 1.0f, 1.5f, 0.0f, 1.0f, -1.0f, -1.0f); ++vertex;
vertex->set( 1.5f, 0.5f, 0.0f, 1.0f, 1.0f, -1.0f); ++vertex;
vertex->set( 1.5f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f); ++vertex;
vertex->set( 2.0f, 0.5f, 0.0f, -1.0f, 1.0f, -1.0f); ++vertex;
vertex->set( 2.0f, 1.0f, 0.0f, -1.0f, -1.0f, -1.0f); ++vertex;
indices += quad(indices, 0, 3, 4, 1);
indices += quad(indices, 2, 6, 7, 3);
indices += quad(indices, 3, 7, 8, 4);
indices += quad(indices, 4, 8, 9, 5);
indices += quad(indices, 7, 10, 11, 8);
indices += quad(indices, 10, 12, 13, 11);
}
else
{
vertex->set( 0.0f, 0.25f, 0.0f, -1.0f, 1.0f, -1.0f); ++vertex;
vertex->set( 0.0f, 0.75f, 0.0f, -1.0f, -1.0f, -1.0f); ++vertex;
vertex->set( 0.5f, 0.00f, 0.0f, -1.0f, 1.0f, 1.0f); ++vertex;
vertex->set( 0.5f, 0.50f, 0.0f, -1.0f, -1.0f, 1.0f); ++vertex;
vertex->set( 0.5f, 1.00f, 0.0f, 1.0f, -1.0f, -1.0f); ++vertex;
vertex->set( 1.0f, 0.25f, 0.0f, 1.0f, 1.0f, 1.0f); ++vertex;
vertex->set( 1.0f, 0.75f, 0.0f, 1.0f, -1.0f, 1.0f); ++vertex;
vertex->set( 1.0f, 0.25f, 0.0f, 1.0f, 1.0f, 1.0f); ++vertex;
vertex->set( 1.0f, 0.75f, 0.0f, 1.0f, -1.0f, 1.0f); ++vertex;
vertex->set( 1.5f, 0.00f, 0.0f, -1.0f, 1.0f, 1.0f); ++vertex;
vertex->set( 1.5f, 0.50f, 0.0f, 1.0f, 1.0f, -1.0f); ++vertex;
vertex->set( 1.5f, 1.00f, 0.0f, 1.0f, -1.0f, -1.0f); ++vertex;
vertex->set( 2.0f, 0.25f, 0.0f, -1.0f, 1.0f, -1.0f); ++vertex;
vertex->set( 2.0f, 0.75f, 0.0f, -1.0f, -1.0f, -1.0f); ++vertex;
indices += quad(indices, 0, 2, 3, 1);
indices += quad(indices, 1, 3, 6, 4);
indices += quad(indices, 2, 5, 6, 3);
indices += quad(indices, 7, 9, 12, 10);
indices += quad(indices, 7, 10, 11, 8);
indices += quad(indices, 10, 12, 13, 11);
}
Area& area = getCurrentArea();
int32_t xx;
int32_t width;
if (ImguiAlign::Left == _align)
{
xx = area.m_contentX + SCROLL_AREA_PADDING;
width = area.m_widgetW;
}
else if (ImguiAlign::LeftIndented == _align
|| ImguiAlign::Right == _align)
{
xx = area.m_widgetX;
width = area.m_widgetW-1; //TODO: -1 !
}
else //if (ImguiAlign::Center == _align
//|| ImguiAlign::CenterIndented == _align).
{
xx = area.m_widgetX;
width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
}
const uint32_t height = _cross ? (width*3)/4 : (width/2);
const int32_t yy = area.m_widgetY;
area.m_widgetY += height + DEFAULT_SPACING;
const float scale = float(width/2);
float mtx[16];
bx::mtxSRT(mtx, scale, scale, 1.0f, 0.0f, 0.0f, 0.0f, float(xx), float(yy), 0.0f);
bgfx::setTransform(mtx);
bgfx::setUniform(u_imageLod, &_lod);
bgfx::setTexture(0, u_texColor, _cubemap);
bgfx::setProgram(m_cubeMapProgram);
bgfx::setVertexBuffer(&tvb);
bgfx::setIndexBuffer(&tib);
bgfx::setState(0
| BGFX_STATE_RGB_WRITE
| BGFX_STATE_CULL_CW
);
bgfx::submit(m_view);
}
}
bool collapse(const char* _text, const char* _subtext, bool _checked, bool _enabled)
{
const uint32_t id = getId();
@ -2316,7 +2497,7 @@ struct Imgui
++_text;
}
bgfx::setTexture(0, s_texColor, m_fonts[m_currentFontIdx].m_texture);
bgfx::setTexture(0, u_texColor, m_fonts[m_currentFontIdx].m_texture);
bgfx::setVertexBuffer(&tvb);
bgfx::setState(0
| BGFX_STATE_RGB_WRITE
@ -2781,9 +2962,10 @@ struct Imgui
bgfx::UniformHandle u_imageLod;
bgfx::UniformHandle u_imageSwizzle;
bgfx::UniformHandle s_texColor;
bgfx::UniformHandle u_texColor;
bgfx::ProgramHandle m_colorProgram;
bgfx::ProgramHandle m_textureProgram;
bgfx::ProgramHandle m_cubeMapProgram;
bgfx::ProgramHandle m_imageProgram;
bgfx::ProgramHandle m_imageSwizzProgram;
bgfx::TextureHandle m_missingTexture;
@ -3088,6 +3270,11 @@ void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod,
s_imgui.imageChannel(_image, _channel, _lod, _width, _aspect, _align);
}
void imguiCube(bgfx::TextureHandle _cubemap, float _lod, bool _cross, ImguiAlign::Enum _align)
{
s_imgui.cubeMap(_cubemap, _lod, _cross, _align);
}
float imguiGetTextLength(const char* _text, ImguiFontHandle _handle)
{
#if !USE_NANOVG_FONT

View file

@ -178,6 +178,7 @@ void imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t
void imguiImage(bgfx::TextureHandle _image, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _originBottomLeft = false);
void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented);
void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented);
void imguiCube(bgfx::TextureHandle _cubemap, float _lod = 0.0f, bool _cross = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented);
float imguiGetTextLength(const char* _text, ImguiFontHandle _handle);
bool imguiMouseOverArea();

View file

@ -1,6 +1,8 @@
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
vec3 v_normal : NORMAL = vec3(0.0, 0.0, 1.0);
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
vec2 a_position : POSITION;
vec3 a_position : POSITION;
vec4 a_normal : NORMAL;
vec4 a_color0 : COLOR0;
vec2 a_texcoord0 : TEXCOORD0;