This commit is contained in:
Branimir Karadžić 2014-05-03 15:18:28 -07:00
Родитель 6dc6dd6148
Коммит ac925b00c8
30 изменённых файлов: 842 добавлений и 1851 удалений

18
3rdparty/freetype/freetype.h поставляемый
Просмотреть файл

@ -39760,7 +39760,7 @@ FT_END_HEADER
}
/* An empty string for empty fields. */
/* XXX eliminate this */
static const char empty[1] = { 0 };
static const char ft_empty[1] = { 0 };
static char *
_bdf_list_join( _bdf_list_t* list,
int c,
@ -39780,7 +39780,7 @@ FT_END_HEADER
if ( i + 1 < list->used )
dp[j++] = (char)c;
}
if ( dp != empty )
if ( dp != ft_empty )
dp[j] = 0;
*alen = j;
return dp;
@ -39802,11 +39802,11 @@ FT_END_HEADER
list->used = 0;
if ( list->size )
{
list->field[0] = (char*)empty;
list->field[1] = (char*)empty;
list->field[2] = (char*)empty;
list->field[3] = (char*)empty;
list->field[4] = (char*)empty;
list->field[0] = (char*)ft_empty;
list->field[1] = (char*)ft_empty;
list->field[2] = (char*)ft_empty;
list->field[3] = (char*)ft_empty;
list->field[4] = (char*)ft_empty;
}
/* If the line is empty, then simply return. */
if ( linelen == 0 || line[0] == 0 )
@ -39846,7 +39846,7 @@ FT_END_HEADER
goto Exit;
}
/* Assign the field appropriately. */
list->field[list->used++] = ( ep > sp ) ? sp : (char*)empty;
list->field[list->used++] = ( ep > sp ) ? sp : (char*)ft_empty;
sp = ep;
if ( mult )
{
@ -39870,7 +39870,7 @@ FT_END_HEADER
goto Exit;
}
if ( final_empty )
list->field[list->used++] = (char*)empty;
list->field[list->used++] = (char*)ft_empty;
list->field[list->used] = 0;
Exit:
return error;

4
3rdparty/sdf/sdf.h поставляемый
Просмотреть файл

@ -203,7 +203,7 @@ void sdfBuildNoAlloc(unsigned char* out, int outstride, float maxdist,
for (y = 1; y < height-1; y++) {
for (x = 1; x < width-1; x++) {
int k = x+y*width, kn, ch = 0;
struct SDFpoint c = { (float)x, (float)y }, pt;
struct SDFpoint c = { (float)x, (float)y }, pt = { 0.0f, 0.0f };
float pd = tdist[k], d;
// (-1,-1)
kn = k - 1 - width;
@ -257,7 +257,7 @@ void sdfBuildNoAlloc(unsigned char* out, int outstride, float maxdist,
for (y = height-2; y > 0 ; y--) {
for (x = width-2; x > 0; x--) {
int k = x+y*width, kn, ch = 0;
struct SDFpoint c = { (float)x, (float)y }, pt;
struct SDFpoint c = { (float)x, (float)y }, pt = { 0.0f, 0.0f };
float pd = tdist[k], d;
// (1,0)
kn = k + 1;

Просмотреть файл

@ -4,9 +4,7 @@
*/
#include "common.h"
#include <bgfx.h>
#include "entry/entry.h"
int _main_(int /*_argc*/, char** /*_argv*/)
{

Просмотреть файл

@ -4,14 +4,7 @@
*/
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include "entry/entry.h"
#include "fpumath.h"
#include <stdio.h>
#include <string.h>
#include "bgfx_utils.h"
struct PosColorVertex
{
@ -19,9 +12,19 @@ struct PosColorVertex
float m_y;
float m_z;
uint32_t m_abgr;
static void init()
{
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.end();
};
static bgfx::VertexDecl ms_decl;
};
static bgfx::VertexDecl s_PosColorDecl;
bgfx::VertexDecl PosColorVertex::ms_decl;
static PosColorVertex s_cubeVertices[8] =
{
@ -51,48 +54,6 @@ static const uint16_t s_cubeIndices[36] =
6, 3, 7,
};
static const char* s_shaderPath = NULL;
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
int _main_(int /*_argc*/, char** /*_argv*/)
{
uint32_t width = 1280;
@ -114,61 +75,24 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, 0
);
// Setup root path for binary shaders. Shader binaries are different
// for each renderer.
switch (bgfx::getRendererType() )
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
break;
}
// Create vertex stream declaration.
s_PosColorDecl.begin();
s_PosColorDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
s_PosColorDecl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
s_PosColorDecl.end();
const bgfx::Memory* mem;
PosColorVertex::init();
// Create static vertex buffer.
mem = bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) );
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(mem, s_PosColorDecl);
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(
// Static data can be passed with bgfx::makeRef
bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) )
, PosColorVertex::ms_decl
);
// Create static index buffer.
mem = bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) );
bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(mem);
// Load vertex shader.
mem = loadShader("vs_cubes");
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
// Load fragment shader.
mem = loadShader("fs_cubes");
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(
// Static data can be passed with bgfx::makeRef
bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) )
);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
bgfx::ProgramHandle program = loadProgram("vs_cubes", "fs_cubes");
float at[3] = { 0.0f, 0.0f, 0.0f };
float eye[3] = { 0.0f, 0.0f, -35.0f };

Просмотреть файл

@ -4,28 +4,32 @@
*/
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include "entry/entry.h"
#include "fpumath.h"
#include <stdio.h>
#include <string.h>
// embedded shaders
#include "vs_metaballs.bin.h"
#include "fs_metaballs.bin.h"
bgfx::VertexDecl s_PosNormalColorDecl;
struct PosNormalColorVertex
{
float m_pos[3];
float m_normal[3];
uint32_t m_abgr;
static void init()
{
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Normal, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.end();
};
static bgfx::VertexDecl ms_decl;
};
bgfx::VertexDecl PosNormalColorVertex::ms_decl;
struct Grid
{
Grid()
@ -477,11 +481,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
);
// Create vertex stream declaration.
s_PosNormalColorDecl.begin();
s_PosNormalColorDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
s_PosNormalColorDecl.add(bgfx::Attrib::Normal, 3, bgfx::AttribType::Float);
s_PosNormalColorDecl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
s_PosNormalColorDecl.end();
PosNormalColorVertex::init();
const bgfx::Memory* vs_metaballs;
const bgfx::Memory* fs_metaballs;
@ -508,14 +508,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::ShaderHandle fsh = bgfx::createShader(fs_metaballs);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
#define DIMS 32
@ -568,7 +561,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Allocate 32K vertices in transient vertex buffer.
uint32_t maxVertices = (32<<10);
bgfx::TransientVertexBuffer tvb;
bgfx::allocTransientVertexBuffer(&tvb, maxVertices, s_PosNormalColorDecl);
bgfx::allocTransientVertexBuffer(&tvb, maxVertices, PosNormalColorVertex::ms_decl);
const uint32_t numSpheres = 16;
float sphere[numSpheres][4];
@ -684,7 +677,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
&grid[xoffset ],
};
uint32_t num = triangulate( (uint8_t*)vertex, s_PosNormalColorDecl.m_stride, rgb, pos, val, 0.5f);
uint32_t num = triangulate( (uint8_t*)vertex, PosNormalColorVertex::ms_decl.getStride(), rgb, pos, val, 0.5f);
vertex += num;
numVertices += num;
}

Просмотреть файл

@ -4,14 +4,7 @@
*/
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include "entry/entry.h"
#include "fpumath.h"
#include <stdio.h>
#include <string.h>
#include "bgfx_utils.h"
struct PosColorTexCoord0Vertex
{
@ -21,77 +14,22 @@ struct PosColorTexCoord0Vertex
uint32_t m_abgr;
float m_u;
float m_v;
};
static bgfx::VertexDecl s_PosColorTexCoord0Decl;
static const char* s_shaderPath = NULL;
static bool s_flipV = false;
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
static void init()
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
ms_decl.end();
}
return NULL;
}
static bgfx::VertexDecl ms_decl;
};
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
bgfx::VertexDecl PosColorTexCoord0Vertex::ms_decl;
static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
{
const bgfx::Memory* mem;
// Load vertex shader.
mem = loadShader(_vsName);
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
// Load fragment shader.
mem = loadShader(_fsName);
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
return program;
}
static bool s_flipV = false;
bool allocTransientBuffers(bgfx::TransientVertexBuffer* _tvb, const bgfx::VertexDecl& _decl, uint16_t _numVertices, bgfx::TransientIndexBuffer* _tib, uint16_t _numIndices)
{
@ -111,7 +49,7 @@ void renderScreenSpaceQuad(uint32_t _view, bgfx::ProgramHandle _program, float _
bgfx::TransientVertexBuffer tvb;
bgfx::TransientIndexBuffer tib;
if (allocTransientBuffers(&tvb, s_PosColorTexCoord0Decl, 4, &tib, 6) )
if (allocTransientBuffers(&tvb, PosColorTexCoord0Vertex::ms_decl, 4, &tib, 6) )
{
PosColorTexCoord0Vertex* vertex = (PosColorTexCoord0Vertex*)tvb.data;
@ -198,36 +136,22 @@ int _main_(int /*_argc*/, char** /*_argv*/)
switch (bgfx::getRendererType() )
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
s_flipV = true;
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
s_flipV = true;
break;
}
// Create vertex stream declaration.
s_PosColorTexCoord0Decl.begin();
s_PosColorTexCoord0Decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
s_PosColorTexCoord0Decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
s_PosColorTexCoord0Decl.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
s_PosColorTexCoord0Decl.end();
PosColorTexCoord0Vertex::init();
bgfx::UniformHandle u_time = bgfx::createUniform("u_time", bgfx::UniformType::Uniform1f);
bgfx::UniformHandle u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Uniform4x4fv);
bgfx::UniformHandle u_time = bgfx::createUniform("u_time", bgfx::UniformType::Uniform1f);
bgfx::UniformHandle u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Uniform4x4fv);
bgfx::UniformHandle u_lightDir = bgfx::createUniform("u_lightDir", bgfx::UniformType::Uniform3fv);
// Create program from shaders.
bgfx::ProgramHandle raymarching = loadProgram("vs_raymarching", "fs_raymarching");
int64_t timeOffset = bx::getHPCounter();

Просмотреть файл

@ -3,279 +3,8 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include <string>
#include <vector>
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/readerwriter.h>
#include "entry/entry.h"
#include "fpumath.h"
#include <stdio.h>
#include <string.h>
static const char* s_shaderPath = NULL;
static bool s_flipV = false;
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
{
const bgfx::Memory* mem;
// Load vertex shader.
mem = loadShader(_vsName);
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
// Load fragment shader.
mem = loadShader(_fsName);
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
return program;
}
struct Aabb
{
float m_min[3];
float m_max[3];
};
struct Obb
{
float m_mtx[16];
};
struct Sphere
{
float m_center[3];
float m_radius;
};
struct Primitive
{
uint32_t m_startIndex;
uint32_t m_numIndices;
uint32_t m_startVertex;
uint32_t m_numVertices;
Sphere m_sphere;
Aabb m_aabb;
Obb m_obb;
};
typedef std::vector<Primitive> PrimitiveArray;
struct Group
{
Group()
{
reset();
}
void reset()
{
m_vbh.idx = bgfx::invalidHandle;
m_ibh.idx = bgfx::invalidHandle;
m_prims.clear();
}
bgfx::VertexBufferHandle m_vbh;
bgfx::IndexBufferHandle m_ibh;
Sphere m_sphere;
Aabb m_aabb;
Obb m_obb;
PrimitiveArray m_prims;
};
struct Mesh
{
void load(const char* _filePath)
{
#define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x0)
#define BGFX_CHUNK_MAGIC_IB BX_MAKEFOURCC('I', 'B', ' ', 0x0)
#define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0)
bx::CrtFileReader reader;
reader.open(_filePath);
Group group;
uint32_t chunk;
while (4 == bx::read(&reader, chunk) )
{
switch (chunk)
{
case BGFX_CHUNK_MAGIC_VB:
{
bx::read(&reader, group.m_sphere);
bx::read(&reader, group.m_aabb);
bx::read(&reader, group.m_obb);
bx::read(&reader, m_decl);
uint16_t stride = m_decl.getStride();
uint16_t numVertices;
bx::read(&reader, numVertices);
const bgfx::Memory* mem = bgfx::alloc(numVertices*stride);
bx::read(&reader, mem->data, mem->size);
group.m_vbh = bgfx::createVertexBuffer(mem, m_decl);
}
break;
case BGFX_CHUNK_MAGIC_IB:
{
uint32_t numIndices;
bx::read(&reader, numIndices);
const bgfx::Memory* mem = bgfx::alloc(numIndices*2);
bx::read(&reader, mem->data, mem->size);
group.m_ibh = bgfx::createIndexBuffer(mem);
}
break;
case BGFX_CHUNK_MAGIC_PRI:
{
uint16_t len;
bx::read(&reader, len);
std::string material;
material.resize(len);
bx::read(&reader, const_cast<char*>(material.c_str() ), len);
uint16_t num;
bx::read(&reader, num);
for (uint32_t ii = 0; ii < num; ++ii)
{
bx::read(&reader, len);
std::string name;
name.resize(len);
bx::read(&reader, const_cast<char*>(name.c_str() ), len);
Primitive prim;
bx::read(&reader, prim.m_startIndex);
bx::read(&reader, prim.m_numIndices);
bx::read(&reader, prim.m_startVertex);
bx::read(&reader, prim.m_numVertices);
bx::read(&reader, prim.m_sphere);
bx::read(&reader, prim.m_aabb);
bx::read(&reader, prim.m_obb);
group.m_prims.push_back(prim);
}
m_groups.push_back(group);
group.reset();
}
break;
default:
DBG("%08x at %d", chunk, reader.seek() );
break;
}
}
reader.close();
}
void unload()
{
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
{
const Group& group = *it;
bgfx::destroyVertexBuffer(group.m_vbh);
if (bgfx::isValid(group.m_ibh) )
{
bgfx::destroyIndexBuffer(group.m_ibh);
}
}
m_groups.clear();
}
void submit(bgfx::ProgramHandle _program, float* _mtx)
{
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
{
const Group& group = *it;
// Set model matrix for rendering.
bgfx::setTransform(_mtx);
bgfx::setProgram(_program);
bgfx::setIndexBuffer(group.m_ibh);
bgfx::setVertexBuffer(group.m_vbh);
// Set render states.
bgfx::setState(0
|BGFX_STATE_RGB_WRITE
|BGFX_STATE_ALPHA_WRITE
|BGFX_STATE_DEPTH_WRITE
|BGFX_STATE_DEPTH_TEST_LESS
|BGFX_STATE_CULL_CCW
|BGFX_STATE_MSAA
);
// Submit primitive for rendering to view 0.
bgfx::submit(0);
}
}
bgfx::VertexDecl m_decl;
typedef std::vector<Group> GroupArray;
GroupArray m_groups;
};
#include "bgfx_utils.h"
int _main_(int /*_argc*/, char** /*_argv*/)
{
@ -298,36 +27,12 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, 0
);
// Setup root path for binary shaders. Shader binaries are different
// for each renderer.
switch (bgfx::getRendererType() )
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
s_flipV = true;
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
s_flipV = true;
break;
}
bgfx::UniformHandle u_time = bgfx::createUniform("u_time", bgfx::UniformType::Uniform1f);
// Create program from shaders.
bgfx::ProgramHandle program = loadProgram("vs_mesh", "fs_mesh");
Mesh mesh;
mesh.load("meshes/bunny.bin");
Mesh* mesh = meshLoad("meshes/bunny.bin");
int64_t timeOffset = bx::getHPCounter();
@ -372,14 +77,14 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, time*0.37f
);
mesh.submit(program, mtx);
meshSubmit(mesh, 0, program, mtx);
// Advance to next frame. Rendering thread will be kicked to
// process submitted rendering primitives.
bgfx::frame();
}
mesh.unload();
meshUnload(mesh);
// Cleanup.
bgfx::destroyProgram(program);

Просмотреть файл

@ -4,13 +4,7 @@
*/
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include "fpumath.h"
#include <stdio.h>
#include <string.h>
#include "bgfx_utils.h"
struct PosColorVertex
{
@ -18,9 +12,19 @@ struct PosColorVertex
float m_y;
float m_z;
uint32_t m_abgr;
static void init()
{
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.end();
};
static bgfx::VertexDecl ms_decl;
};
static bgfx::VertexDecl s_PosColorDecl;
bgfx::VertexDecl PosColorVertex::ms_decl;
static PosColorVertex s_cubeVertices[8] =
{
@ -50,48 +54,6 @@ static const uint16_t s_cubeIndices[36] =
6, 3, 7,
};
static const char* s_shaderPath = NULL;
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
int _main_(int /*_argc*/, char** /*_argv*/)
{
uint32_t width = 1280;
@ -116,61 +78,21 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Get renderer capabilities info.
const bgfx::Caps* caps = bgfx::getCaps();
// Setup root path for binary shaders. Shader binaries are different
// for each renderer.
switch (caps->rendererType)
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
break;
}
// Create vertex stream declaration.
s_PosColorDecl.begin();
s_PosColorDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
s_PosColorDecl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
s_PosColorDecl.end();
PosColorVertex::init();
const bgfx::Memory* mem;
// Create static vertex buffer.
mem = bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) );
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(mem, s_PosColorDecl);
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(mem, PosColorVertex::ms_decl);
// Create static index buffer.
mem = bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) );
bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(mem);
// Load vertex shader.
mem = loadShader("vs_instancing");
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
// Load fragment shader.
mem = loadShader("fs_instancing");
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
bgfx::ProgramHandle program = loadProgram("vs_instancing", "fs_instancing");
int64_t timeOffset = bx::getHPCounter();

Просмотреть файл

@ -4,13 +4,7 @@
*/
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include "fpumath.h"
#include <stdio.h>
#include <string.h>
#include "bgfx_utils.h"
struct PosNormalTangentTexcoordVertex
{
@ -21,9 +15,21 @@ struct PosNormalTangentTexcoordVertex
uint32_t m_tangent;
int16_t m_u;
int16_t m_v;
static void init()
{
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
ms_decl.add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true);
ms_decl.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Int16, true, true);
ms_decl.end();
}
static bgfx::VertexDecl ms_decl;
};
static bgfx::VertexDecl s_PosNormalTangentTexcoordDecl;
bgfx::VertexDecl PosNormalTangentTexcoordVertex::ms_decl;
uint32_t packUint32(uint8_t _x, uint8_t _y, uint8_t _z, uint8_t _w)
{
@ -96,157 +102,6 @@ static const uint16_t s_cubeIndices[36] =
21, 23, 22,
};
static const char* s_shaderPath = NULL;
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
static const bgfx::Memory* loadTexture(const char* _name)
{
char filePath[512];
strcpy(filePath, "textures/");
strcat(filePath, _name);
return load(filePath);
}
void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices)
{
struct PosTexcoord
{
float m_x;
float m_y;
float m_z;
float m_pad0;
float m_u;
float m_v;
float m_pad1;
float m_pad2;
};
float* tangents = new float[6*_numVertices];
memset(tangents, 0, 6*_numVertices*sizeof(float) );
PosTexcoord v0;
PosTexcoord v1;
PosTexcoord v2;
for (uint32_t ii = 0, num = _numIndices/3; ii < num; ++ii)
{
const uint16_t* indices = &_indices[ii*3];
uint32_t i0 = indices[0];
uint32_t i1 = indices[1];
uint32_t i2 = indices[2];
bgfx::vertexUnpack(&v0.m_x, bgfx::Attrib::Position, _decl, _vertices, i0);
bgfx::vertexUnpack(&v0.m_u, bgfx::Attrib::TexCoord0, _decl, _vertices, i0);
bgfx::vertexUnpack(&v1.m_x, bgfx::Attrib::Position, _decl, _vertices, i1);
bgfx::vertexUnpack(&v1.m_u, bgfx::Attrib::TexCoord0, _decl, _vertices, i1);
bgfx::vertexUnpack(&v2.m_x, bgfx::Attrib::Position, _decl, _vertices, i2);
bgfx::vertexUnpack(&v2.m_u, bgfx::Attrib::TexCoord0, _decl, _vertices, i2);
const float bax = v1.m_x - v0.m_x;
const float bay = v1.m_y - v0.m_y;
const float baz = v1.m_z - v0.m_z;
const float bau = v1.m_u - v0.m_u;
const float bav = v1.m_v - v0.m_v;
const float cax = v2.m_x - v0.m_x;
const float cay = v2.m_y - v0.m_y;
const float caz = v2.m_z - v0.m_z;
const float cau = v2.m_u - v0.m_u;
const float cav = v2.m_v - v0.m_v;
const float det = (bau * cav - bav * cau);
const float invDet = 1.0f / det;
const float tx = (bax * cav - cax * bav) * invDet;
const float ty = (bay * cav - cay * bav) * invDet;
const float tz = (baz * cav - caz * bav) * invDet;
const float bx = (cax * bau - bax * cau) * invDet;
const float by = (cay * bau - bay * cau) * invDet;
const float bz = (caz * bau - baz * cau) * invDet;
for (uint32_t jj = 0; jj < 3; ++jj)
{
float* tanu = &tangents[indices[jj]*6];
float* tanv = &tanu[3];
tanu[0] += tx;
tanu[1] += ty;
tanu[2] += tz;
tanv[0] += bx;
tanv[1] += by;
tanv[2] += bz;
}
}
for (uint32_t ii = 0; ii < _numVertices; ++ii)
{
const float* tanu = &tangents[ii*6];
const float* tanv = &tangents[ii*6 + 3];
float normal[4];
bgfx::vertexUnpack(normal, bgfx::Attrib::Normal, _decl, _vertices, ii);
float ndt = vec3Dot(normal, tanu);
float nxt[3];
vec3Cross(nxt, normal, tanu);
float tmp[3];
tmp[0] = tanu[0] - normal[0] * ndt;
tmp[1] = tanu[1] - normal[1] * ndt;
tmp[2] = tanu[2] - normal[2] * ndt;
float tangent[4];
vec3Norm(tangent, tmp);
tangent[3] = vec3Dot(nxt, tanv) < 0.0f ? -1.0f : 1.0f;
bgfx::vertexPack(tangent, true, bgfx::Attrib::Tangent, _decl, _vertices, ii);
}
delete [] tangents;
}
int _main_(int /*_argc*/, char** /*_argv*/)
{
uint32_t width = 1280;
@ -270,50 +125,26 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Get renderer capabilities info.
const bgfx::Caps* caps = bgfx::getCaps();
bool instancingSupported = 0 != (caps->supported & BGFX_CAPS_INSTANCING);
// Setup root path for binary shaders. Shader binaries are different
// for each renderer.
switch (caps->rendererType)
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
break;
}
// Create vertex stream declaration.
s_PosNormalTangentTexcoordDecl.begin();
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true);
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Int16, true, true);
s_PosNormalTangentTexcoordDecl.end();
PosNormalTangentTexcoordVertex::init();
const bgfx::Memory* mem;
calcTangents(s_cubeVertices, BX_COUNTOF(s_cubeVertices), s_PosNormalTangentTexcoordDecl, s_cubeIndices, BX_COUNTOF(s_cubeIndices) );
calcTangents(s_cubeVertices
, BX_COUNTOF(s_cubeVertices)
, PosNormalTangentTexcoordVertex::ms_decl
, s_cubeIndices
, BX_COUNTOF(s_cubeIndices)
);
// Create static vertex buffer.
mem = bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) );
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(mem, s_PosNormalTangentTexcoordDecl);
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(
bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) )
, PosNormalTangentTexcoordVertex::ms_decl
);
// Create static index buffer.
mem = bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) );
bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(mem);
bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) ) );
// Create texture sampler uniforms.
bgfx::UniformHandle u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Uniform1iv);
@ -323,31 +154,14 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::UniformHandle u_lightPosRadius = bgfx::createUniform("u_lightPosRadius", bgfx::UniformType::Uniform4fv, numLights);
bgfx::UniformHandle u_lightRgbInnerR = bgfx::createUniform("u_lightRgbInnerR", bgfx::UniformType::Uniform4fv, numLights);
// Load vertex shader.
mem = loadShader(instancingSupported ? "vs_bump_instanced" : "vs_bump");
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
// Load fragment shader.
mem = loadShader("fs_bump");
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
bgfx::ProgramHandle program = loadProgram(instancingSupported ? "vs_bump_instanced" : "vs_bump", "fs_bump");
// Load diffuse texture.
mem = loadTexture("fieldstone-rgba.dds");
bgfx::TextureHandle textureColor = bgfx::createTexture(mem);
bgfx::TextureHandle textureColor = loadTexture("fieldstone-rgba.dds");
// Load normal texture.
mem = loadTexture("fieldstone-n.dds");
bgfx::TextureHandle textureNormal = bgfx::createTexture(mem);
bgfx::TextureHandle textureNormal = loadTexture("fieldstone-n.dds");
int64_t timeOffset = bx::getHPCounter();
@ -447,11 +261,11 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Set render states.
bgfx::setState(0
|BGFX_STATE_RGB_WRITE
|BGFX_STATE_ALPHA_WRITE
|BGFX_STATE_DEPTH_WRITE
|BGFX_STATE_DEPTH_TEST_LESS
|BGFX_STATE_MSAA
| BGFX_STATE_RGB_WRITE
| BGFX_STATE_ALPHA_WRITE
| BGFX_STATE_DEPTH_WRITE
| BGFX_STATE_DEPTH_TEST_LESS
| BGFX_STATE_MSAA
);
// Submit primitive for rendering to view 0.
@ -487,11 +301,11 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Set render states.
bgfx::setState(0
|BGFX_STATE_RGB_WRITE
|BGFX_STATE_ALPHA_WRITE
|BGFX_STATE_DEPTH_WRITE
|BGFX_STATE_DEPTH_TEST_LESS
|BGFX_STATE_MSAA
| BGFX_STATE_RGB_WRITE
| BGFX_STATE_ALPHA_WRITE
| BGFX_STATE_DEPTH_WRITE
| BGFX_STATE_DEPTH_TEST_LESS
| BGFX_STATE_MSAA
);
// Submit primitive for rendering to view 0.

Просмотреть файл

@ -4,18 +4,13 @@
*/
#include "common.h"
#include "bgfx_utils.h"
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/readerwriter.h>
#include <bx/allocator.h>
#include <bx/string.h>
#include "fpumath.h"
#include "aviwriter.h"
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
struct PosColorVertex
{
@ -23,9 +18,19 @@ struct PosColorVertex
float m_y;
float m_z;
uint32_t m_abgr;
static void init()
{
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.end();
};
static bgfx::VertexDecl ms_decl;
};
static bgfx::VertexDecl s_PosColorDecl;
bgfx::VertexDecl PosColorVertex::ms_decl;
static PosColorVertex s_cubeVertices[8] =
{
@ -55,48 +60,6 @@ static const uint16_t s_cubeIndices[36] =
6, 3, 7,
};
static const char* s_shaderPath = NULL;
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src, bool _grayscale, bool _yflip)
{
FILE* file = fopen(_filePath, "wb");
@ -148,6 +111,15 @@ void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t
}
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
struct BgfxCallback : public bgfx::CallbackI
{
virtual ~BgfxCallback()
@ -283,7 +255,7 @@ struct BgfxCallback : public bgfx::CallbackI
virtual void captureBegin(uint32_t _width, uint32_t _height, uint32_t /*_pitch*/, bgfx::TextureFormat::Enum /*_format*/, bool _yflip) BX_OVERRIDE
{
m_writer = new AviWriter;
m_writer = new AviWriter(entry::getFileWriter() );
if (!m_writer->open("temp/capture.avi", _width, _height, 60, _yflip) )
{
delete m_writer;
@ -410,61 +382,20 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, 0
);
// Setup root path for binary shaders. Shader binaries are different
// for each renderer.
switch (bgfx::getRendererType() )
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
break;
}
// Create vertex stream declaration.
s_PosColorDecl.begin();
s_PosColorDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
s_PosColorDecl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
s_PosColorDecl.end();
const bgfx::Memory* mem;
PosColorVertex::init();
// Create static vertex buffer.
mem = bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) );
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(mem, s_PosColorDecl);
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(
bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) )
, PosColorVertex::ms_decl
);
// Create static index buffer.
mem = bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) );
bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(mem);
// Load vertex shader.
mem = loadShader("vs_callback");
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
// Load fragment shader.
mem = loadShader("fs_callback");
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) ) );
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
bgfx::ProgramHandle program = loadProgram("vs_callback", "fs_callback");
float time = 0.0f;

Просмотреть файл

@ -4,18 +4,14 @@
*/
#include "common.h"
#include "bgfx_utils.h"
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/uint32_t.h>
#include "fpumath.h"
#include "packrect.h"
#include <stdio.h>
#include <string.h>
#include <list>
struct PosColorVertex
struct PosTexcoordVertex
{
float m_x;
float m_y;
@ -23,11 +19,21 @@ struct PosColorVertex
float m_u;
float m_v;
float m_w;
static void init()
{
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::TexCoord0, 3, bgfx::AttribType::Float);
ms_decl.end();
};
static bgfx::VertexDecl ms_decl;
};
static bgfx::VertexDecl s_PosTexcoordDecl;
bgfx::VertexDecl PosTexcoordVertex::ms_decl;
static PosColorVertex s_cubeVertices[28] =
static PosTexcoordVertex s_cubeVertices[28] =
{
{-1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f },
@ -86,79 +92,6 @@ static const uint16_t s_cubeIndices[36] =
21, 22, 23,
};
static const char* s_shaderPath = NULL;
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
static bgfx::ProgramHandle loadProgram(const char* _vshName, const char* _fshName)
{
const bgfx::Memory* mem;
mem = loadShader(_vshName);
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
mem = loadShader(_fshName);
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
return program;
}
static const bgfx::Memory* loadTexture(const char* _name)
{
char filePath[512];
strcpy(filePath, "textures/");
strcat(filePath, _name);
return load(filePath);
}
static void updateTextureCubeRectBgra8(bgfx::TextureHandle _handle, uint8_t _side, uint32_t _x, uint32_t _y, uint32_t _width, uint32_t _height, uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 0xff)
{
bgfx::TextureInfo ti;
@ -199,63 +132,34 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, 0
);
// Setup root path for binary shaders. Shader binaries are different
// for each renderer.
switch (bgfx::getRendererType() )
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
break;
}
// Create vertex stream declaration.
s_PosTexcoordDecl.begin();
s_PosTexcoordDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
s_PosTexcoordDecl.add(bgfx::Attrib::TexCoord0, 3, bgfx::AttribType::Float);
s_PosTexcoordDecl.end();
PosTexcoordVertex::init();
bgfx::TextureHandle textures[] =
{
bgfx::createTexture(loadTexture("texture_compression_bc1.dds"), BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP),
bgfx::createTexture(loadTexture("texture_compression_bc2.dds"), BGFX_TEXTURE_U_CLAMP),
bgfx::createTexture(loadTexture("texture_compression_bc3.dds"), BGFX_TEXTURE_V_CLAMP),
bgfx::createTexture(loadTexture("texture_compression_etc1.ktx") ),
bgfx::createTexture(loadTexture("texture_compression_etc2.ktx") ),
bgfx::createTexture(loadTexture("texture_compression_ptc12.pvr") ),
bgfx::createTexture(loadTexture("texture_compression_ptc14.pvr") ),
bgfx::createTexture(loadTexture("texture_compression_ptc22.pvr") ),
bgfx::createTexture(loadTexture("texture_compression_ptc24.pvr") ),
loadTexture("texture_compression_bc1.dds", BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP),
loadTexture("texture_compression_bc2.dds", BGFX_TEXTURE_U_CLAMP),
loadTexture("texture_compression_bc3.dds", BGFX_TEXTURE_V_CLAMP),
loadTexture("texture_compression_etc1.ktx"),
loadTexture("texture_compression_etc2.ktx"),
loadTexture("texture_compression_ptc12.pvr"),
loadTexture("texture_compression_ptc14.pvr"),
loadTexture("texture_compression_ptc22.pvr"),
loadTexture("texture_compression_ptc24.pvr"),
};
const bgfx::Memory* mem;
// Create static vertex buffer.
mem = bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) );
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(mem, s_PosTexcoordDecl);
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) ), PosTexcoordVertex::ms_decl);
// Create static index buffer.
mem = bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) );
bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(mem);
bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) ) );
// Create texture sampler uniforms.
bgfx::UniformHandle u_texCube = bgfx::createUniform("u_texCube", bgfx::UniformType::Uniform1iv);
bgfx::UniformHandle u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Uniform1iv);
bgfx::ProgramHandle program = loadProgram("vs_update", "fs_update");
bgfx::ProgramHandle program = loadProgram("vs_update", "fs_update");
bgfx::ProgramHandle programCmp = loadProgram("vs_update", "fs_update_cmp");
const uint32_t textureSide = 2048;

Просмотреть файл

@ -3,276 +3,10 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include <vector>
#include <string>
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/readerwriter.h>
#include "fpumath.h"
#include "bgfx_utils.h"
#include "imgui/imgui.h"
#include <string.h>
static const char* s_shaderPath = NULL;
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
static bgfx::ProgramHandle loadProgram(const char* _vshName, const char* _fshName)
{
const bgfx::Memory* mem;
mem = loadShader(_vshName);
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
mem = loadShader(_fshName);
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
return program;
}
static const bgfx::Memory* loadTexture(const char* _name)
{
char filePath[512];
strcpy(filePath, "textures/");
strcat(filePath, _name);
return load(filePath);
}
struct Aabb
{
float m_min[3];
float m_max[3];
};
struct Obb
{
float m_mtx[16];
};
struct Sphere
{
float m_center[3];
float m_radius;
};
struct Primitive
{
uint32_t m_startIndex;
uint32_t m_numIndices;
uint32_t m_startVertex;
uint32_t m_numVertices;
Sphere m_sphere;
Aabb m_aabb;
Obb m_obb;
};
typedef std::vector<Primitive> PrimitiveArray;
struct Group
{
Group()
{
reset();
}
void reset()
{
m_vbh.idx = bgfx::invalidHandle;
m_ibh.idx = bgfx::invalidHandle;
m_prims.clear();
}
bgfx::VertexBufferHandle m_vbh;
bgfx::IndexBufferHandle m_ibh;
Sphere m_sphere;
Aabb m_aabb;
Obb m_obb;
PrimitiveArray m_prims;
};
struct Mesh
{
void load(const char* _filePath)
{
#define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x0)
#define BGFX_CHUNK_MAGIC_IB BX_MAKEFOURCC('I', 'B', ' ', 0x0)
#define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0)
bx::CrtFileReader reader;
reader.open(_filePath);
Group group;
uint32_t chunk;
while (4 == bx::read(&reader, chunk) )
{
switch (chunk)
{
case BGFX_CHUNK_MAGIC_VB:
{
bx::read(&reader, group.m_sphere);
bx::read(&reader, group.m_aabb);
bx::read(&reader, group.m_obb);
bx::read(&reader, m_decl);
uint16_t stride = m_decl.getStride();
uint16_t numVertices;
bx::read(&reader, numVertices);
const bgfx::Memory* mem = bgfx::alloc(numVertices*stride);
bx::read(&reader, mem->data, mem->size);
group.m_vbh = bgfx::createVertexBuffer(mem, m_decl);
}
break;
case BGFX_CHUNK_MAGIC_IB:
{
uint32_t numIndices;
bx::read(&reader, numIndices);
const bgfx::Memory* mem = bgfx::alloc(numIndices*2);
bx::read(&reader, mem->data, mem->size);
group.m_ibh = bgfx::createIndexBuffer(mem);
}
break;
case BGFX_CHUNK_MAGIC_PRI:
{
uint16_t len;
bx::read(&reader, len);
std::string material;
material.resize(len);
bx::read(&reader, const_cast<char*>(material.c_str() ), len);
uint16_t num;
bx::read(&reader, num);
for (uint32_t ii = 0; ii < num; ++ii)
{
bx::read(&reader, len);
std::string name;
name.resize(len);
bx::read(&reader, const_cast<char*>(name.c_str() ), len);
Primitive prim;
bx::read(&reader, prim.m_startIndex);
bx::read(&reader, prim.m_numIndices);
bx::read(&reader, prim.m_startVertex);
bx::read(&reader, prim.m_numVertices);
bx::read(&reader, prim.m_sphere);
bx::read(&reader, prim.m_aabb);
bx::read(&reader, prim.m_obb);
group.m_prims.push_back(prim);
}
m_groups.push_back(group);
group.reset();
}
break;
default:
DBG("%08x at %d", chunk, reader.seek() );
break;
}
}
reader.close();
}
void unload()
{
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
{
const Group& group = *it;
bgfx::destroyVertexBuffer(group.m_vbh);
if (bgfx::isValid(group.m_ibh) )
{
bgfx::destroyIndexBuffer(group.m_ibh);
}
}
m_groups.clear();
}
void submit(uint8_t _view, bgfx::ProgramHandle _program, float* _mtx)
{
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
{
const Group& group = *it;
// Set model matrix for rendering.
bgfx::setTransform(_mtx);
bgfx::setProgram(_program);
bgfx::setIndexBuffer(group.m_ibh);
bgfx::setVertexBuffer(group.m_vbh);
// Set render states.
bgfx::setState(0
| BGFX_STATE_RGB_WRITE
| BGFX_STATE_ALPHA_WRITE
| BGFX_STATE_DEPTH_WRITE
| BGFX_STATE_DEPTH_TEST_LESS
| BGFX_STATE_CULL_CCW
| BGFX_STATE_MSAA
);
// Submit primitive for rendering to view 0.
bgfx::submit(_view);
}
}
bgfx::VertexDecl m_decl;
typedef std::vector<Group> GroupArray;
GroupArray m_groups;
};
static bool s_flipV = false;
static float s_texelHalf = 0.0f;
@ -288,8 +22,8 @@ struct PosColorTexCoord0Vertex
static void init()
{
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
ms_decl.end();
}
@ -324,7 +58,10 @@ void screenSpaceQuad(float _textureWidth, float _textureHeight, bool _originBott
if (_originBottomLeft)
{
std::swap(minv, maxv);
float temp = minv;
minv = maxv;
maxv = temp;
minv -= 1.0f;
maxv -= 1.0f;
}
@ -424,35 +161,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, 0
);
// Setup root path for binary shaders. Shader binaries are different
// for each renderer.
switch (bgfx::getRendererType() )
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
s_texelHalf = 0.5f;
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
s_flipV = true;
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
s_flipV = true;
break;
}
const bgfx::Memory* mem;
mem = loadTexture("uffizi.dds");
bgfx::TextureHandle uffizi = bgfx::createTexture(mem, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP);
bgfx::TextureHandle uffizi = loadTexture("uffizi.dds", BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP);
bgfx::ProgramHandle skyProgram = loadProgram("vs_hdr_skybox", "fs_hdr_skybox");
bgfx::ProgramHandle lumProgram = loadProgram("vs_hdr_lum", "fs_hdr_lum");
@ -471,8 +180,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::UniformHandle u_tonemap = bgfx::createUniform("u_tonemap", bgfx::UniformType::Uniform4fv);
bgfx::UniformHandle u_offset = bgfx::createUniform("u_offset", bgfx::UniformType::Uniform4fv, 16);
Mesh mesh;
mesh.load("meshes/bunny.bin");
Mesh* mesh = meshLoad("meshes/bunny.bin");
bgfx::FrameBufferHandle fbh;
bgfx::TextureHandle fbtextures[] =
@ -495,15 +203,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::FrameBufferHandle blur;
blur = bgfx::createFrameBuffer(width/8, height/8, bgfx::TextureFormat::BGRA8);
FILE* file = fopen("font/droidsans.ttf", "rb");
uint32_t size = (uint32_t)fsize(file);
void* data = malloc(size);
size_t ignore = fread(data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
imguiCreate(data, size);
void* data = load("font/droidsans.ttf");
imguiCreate(data);
free(data);
float speed = 0.37f;
@ -666,7 +367,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Render mesh into view 1
bgfx::setTexture(0, u_texCube, uffizi);
mesh.submit(1, meshProgram, NULL);
meshSubmit(mesh, 1, meshProgram, NULL);
// Calculate luminance.
setOffsets2x2Lum(u_offset, 128, 128);
@ -744,7 +445,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Cleanup.
imguiDestroy();
mesh.unload();
meshUnload(mesh);
for (uint32_t ii = 0; ii < BX_COUNTOF(lum); ++ii)
{

Просмотреть файл

@ -92,7 +92,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
BX_UNUSED(ignore);
fclose(file);
imguiCreate(data, size);
imguiCreate(data);
free(data);

Просмотреть файл

@ -7,18 +7,10 @@
#include <vector>
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/readerwriter.h>
#include "fpumath.h"
#include "bgfx_utils.h"
#include "imgui/imgui.h"
#include <stdio.h>
#include <string.h>
static const char* s_shaderPath = NULL;
static bool s_flipV = false;
#include <bx/readerwriter.h>
struct KnightPos
{
@ -34,79 +26,6 @@ KnightPos knightTour[8*4] =
{7,1}, {6,3}, {5,1}, {7,0}, {6,2}, {4,3}, {3,1}, {2,3}
};
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadTexture(const char* _name)
{
char filePath[512];
strcpy(filePath, "textures/");
strcat(filePath, _name);
return load(filePath);
}
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
{
const bgfx::Memory* mem;
// Load vertex shader.
mem = loadShader(_vsName);
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
// Load fragment shader.
mem = loadShader(_fsName);
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
return program;
}
struct Aabb
{
float m_min[3];
@ -281,13 +200,13 @@ struct Mesh
// Set render states.
bgfx::setState(0
|BGFX_STATE_RGB_WRITE
|BGFX_STATE_ALPHA_WRITE
|(_blend?0:BGFX_STATE_DEPTH_WRITE)
|BGFX_STATE_DEPTH_TEST_LESS
|BGFX_STATE_CULL_CCW
|BGFX_STATE_MSAA
|(_blend?BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA):0)
| BGFX_STATE_RGB_WRITE
| BGFX_STATE_ALPHA_WRITE
| (_blend?0:BGFX_STATE_DEPTH_WRITE)
| BGFX_STATE_DEPTH_TEST_LESS
| BGFX_STATE_CULL_CCW
| BGFX_STATE_MSAA
| (_blend?BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA):0)
);
// Submit primitive for rendering to view 0.
@ -320,30 +239,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, 1.0f
, 0
);
// Setup root path for binary shaders. Shader binaries are different
// for each renderer.
switch (bgfx::getRendererType() )
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
s_flipV = true;
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
s_flipV = true;
break;
}
bgfx::UniformHandle u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Uniform1iv);
bgfx::UniformHandle u_stipple = bgfx::createUniform("u_stipple", bgfx::UniformType::Uniform3fv);
@ -351,12 +246,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::ProgramHandle program = loadProgram("vs_tree", "fs_tree");
const bgfx::Memory* mem;
mem = loadTexture("leafs1.dds");
bgfx::TextureHandle textureLeafs = bgfx::createTexture(mem);
mem = loadTexture("bark1.dds");
bgfx::TextureHandle textureBark = bgfx::createTexture(mem);
bgfx::TextureHandle textureLeafs = loadTexture("leafs1.dds");
bgfx::TextureHandle textureBark = loadTexture("bark1.dds");
bgfx::TextureHandle textureStipple;
@ -380,15 +271,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
mesh_trunk[1].load("meshes/tree1b_lod1_2.bin");
mesh_trunk[2].load("meshes/tree1b_lod2_2.bin");
FILE* file = fopen("font/droidsans.ttf", "rb");
uint32_t size = (uint32_t)fsize(file);
void* data = malloc(size);
size_t ignore = fread(data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
imguiCreate(data, size);
// Imgui.
void* data = load("font/droidsans.ttf");
imguiCreate(data);
free(data);
int32_t scrollArea = 0;

Просмотреть файл

@ -203,16 +203,7 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
return program;
return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
}
void mtxScaleRotateTranslate(float* _result
@ -947,7 +938,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
BX_UNUSED(ignore);
fclose(file);
imguiCreate(data, size);
imguiCreate(data);
free(data);

Просмотреть файл

@ -173,16 +173,7 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
return program;
return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
}
void mtxScaleRotateTranslate(float* _result
@ -1970,7 +1961,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
BX_UNUSED(ignore);
fclose(file);
imguiCreate(data, size);
imguiCreate(data);
free(data);

Просмотреть файл

@ -130,16 +130,7 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
return program;
return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
}
void mtxScaleRotateTranslate(float* _result
@ -372,13 +363,13 @@ struct Mesh
// Set render states.
bgfx::setState(0
|BGFX_STATE_RGB_WRITE
|BGFX_STATE_ALPHA_WRITE
|BGFX_STATE_DEPTH_WRITE
|BGFX_STATE_DEPTH_TEST_LESS
|BGFX_STATE_CULL_CCW
|BGFX_STATE_MSAA
);
| BGFX_STATE_RGB_WRITE
| BGFX_STATE_ALPHA_WRITE
| BGFX_STATE_DEPTH_WRITE
| BGFX_STATE_DEPTH_TEST_LESS
| BGFX_STATE_CULL_CCW
| BGFX_STATE_MSAA
);
// Submit primitive for rendering.
bgfx::submit(_view);
@ -399,12 +390,12 @@ struct Mesh
// Set render states.
bgfx::setState(0
|BGFX_STATE_RGB_WRITE
|BGFX_STATE_ALPHA_WRITE
|BGFX_STATE_DEPTH_WRITE
|BGFX_STATE_DEPTH_TEST_LESS
|BGFX_STATE_CULL_CCW
|BGFX_STATE_MSAA
| BGFX_STATE_RGB_WRITE
| BGFX_STATE_ALPHA_WRITE
| BGFX_STATE_DEPTH_WRITE
| BGFX_STATE_DEPTH_TEST_LESS
| BGFX_STATE_CULL_CCW
| BGFX_STATE_MSAA
);
// Submit primitive for rendering.

Просмотреть файл

@ -320,16 +320,7 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
return program;
return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
}
void mtxScaleRotateTranslate(float* _result
@ -1488,7 +1479,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
BX_UNUSED(ignore);
fclose(file);
imguiCreate(data, size);
imguiCreate(data);
free(data);

Просмотреть файл

@ -3,16 +3,11 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/uint32_t.h>
#include "fpumath.h"
#include "imgui/imgui.h"
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "imgui/imgui.h"
// embedded shaders
#include "vs_drawstress.bin.h"
@ -31,9 +26,19 @@ struct PosColorVertex
float m_y;
float m_z;
uint32_t m_abgr;
static void init()
{
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.end();
}
static bgfx::VertexDecl ms_decl;
};
static bgfx::VertexDecl s_PosColorDecl;
bgfx::VertexDecl PosColorVertex::ms_decl;
static PosColorVertex s_cubeVertices[8] =
{
@ -264,10 +269,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
);
// Create vertex stream declaration.
s_PosColorDecl.begin();
s_PosColorDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
s_PosColorDecl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
s_PosColorDecl.end();
PosColorVertex::init();
const bgfx::Memory* vs_drawstress;
const bgfx::Memory* fs_drawstress;
@ -300,7 +302,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Create static vertex buffer.
mem = bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) );
vbh = bgfx::createVertexBuffer(mem, s_PosColorDecl);
vbh = bgfx::createVertexBuffer(mem, PosColorVertex::ms_decl);
// Create static index buffer.
mem = bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) );
@ -313,7 +315,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
imguiCreate(s_droidSansTtf, sizeof(s_droidSansTtf) );
imguiCreate(s_droidSansTtf);
#if BX_PLATFORM_EMSCRIPTEN
emscripten_set_main_loop(&loop, -1, 1);

Просмотреть файл

@ -3,88 +3,18 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include <string>
#include <vector>
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/readerwriter.h>
#include "entry/entry.h"
#include "fpumath.h"
#include "bgfx_utils.h"
#include "imgui/imgui.h"
#include <stdio.h>
#include <string.h>
#include <bx/readerwriter.h>
#include <vector>
#include <string>
static const char* s_shaderPath = NULL;
static bool s_flipV = false;
static float s_texelHalf = 0.0f;
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
{
const bgfx::Memory* mem;
mem = loadShader(_vsName);
bgfx::ShaderHandle vs = bgfx::createShader(mem);
mem = loadShader(_fsName);
bgfx::ShaderHandle fs = bgfx::createShader(mem);
bgfx::ProgramHandle program = bgfx::createProgram(vs, fs);
bgfx::destroyShader(vs);
bgfx::destroyShader(fs);
return program;
}
static const bgfx::Memory* loadTexture(const char* _name)
{
char filePath[512];
strcpy(filePath, "textures/");
strcat(filePath, _name);
return load(filePath);
}
struct Uniforms
{
void init()
@ -512,33 +442,18 @@ int _main_(int /*_argc*/, char** /*_argv*/)
switch (bgfx::getRendererType() )
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
s_flipV = true;
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
s_flipV = true;
break;
}
// Imgui.
FILE* file = fopen("font/droidsans.ttf", "rb");
uint32_t size = (uint32_t)fsize(file);
void* data = malloc(size);
size_t ignore = fread(data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
imguiCreate(data, size);
void* data = load("font/droidsans.ttf");
imguiCreate(data);
free(data);
// Uniforms.
s_uniforms.init();
@ -550,16 +465,15 @@ int _main_(int /*_argc*/, char** /*_argv*/)
{
void load(const char* _name)
{
const uint32_t texFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP;
char filePath[512];
strcpy(filePath, _name);
strcat(filePath, "_lod.dds");
m_tex = bgfx::createTexture(loadTexture(filePath), texFlags);
m_tex = loadTexture(filePath, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP);
strcpy(filePath, _name);
strcat(filePath, "_irr.dds");
m_texIrr = bgfx::createTexture(loadTexture(filePath), texFlags);
m_texIrr = loadTexture(filePath, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP);
}
void destroy()

Просмотреть файл

@ -4,15 +4,9 @@
*/
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include "fpumath.h"
#include "bgfx_utils.h"
#include "imgui/imgui.h"
#include <stdio.h>
#include <string.h>
struct PosColorVertex
{
float m_x;
@ -24,7 +18,7 @@ struct PosColorVertex
{
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.end();
}
@ -45,8 +39,8 @@ struct PosColorTexCoord0Vertex
static void init()
{
ms_decl.begin();
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
ms_decl.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true);
ms_decl.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
ms_decl.end();
}
@ -84,61 +78,6 @@ static const uint16_t s_cubeIndices[36] =
6, 3, 7,
};
static const char* s_shaderPath = NULL;
static void shaderFilePath(char* _out, const char* _name)
{
strcpy(_out, s_shaderPath);
strcat(_out, _name);
strcat(_out, ".bin");
}
long int fsize(FILE* _file)
{
long int pos = ftell(_file);
fseek(_file, 0L, SEEK_END);
long int size = ftell(_file);
fseek(_file, pos, SEEK_SET);
return size;
}
static const bgfx::Memory* load(const char* _filePath)
{
FILE* file = fopen(_filePath, "rb");
if (NULL != file)
{
uint32_t size = (uint32_t)fsize(file);
const bgfx::Memory* mem = bgfx::alloc(size+1);
size_t ignore = fread(mem->data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadShader(const char* _name)
{
char filePath[512];
shaderFilePath(filePath, _name);
return load(filePath);
}
static bgfx::ProgramHandle loadProgram(const char* _vshName, const char* _fshName)
{
const bgfx::Memory* mem;
mem = loadShader(_vshName);
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
mem = loadShader(_fshName);
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
return bgfx::createProgram(vsh, fsh, true);
}
static float s_texelHalf = 0.0f;
static bool s_flipV = false;
@ -225,34 +164,18 @@ int _main_(int /*_argc*/, char** /*_argv*/)
switch (caps->rendererType)
{
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
s_texelHalf = 0.5f;
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
s_flipV = true;
break;
case bgfx::RendererType::OpenGLES:
s_shaderPath = "shaders/gles/";
s_flipV = true;
break;
}
// Imgui.
FILE* file = fopen("font/droidsans.ttf", "rb");
uint32_t size = (uint32_t)fsize(file);
void* data = malloc(size);
size_t ignore = fread(data, 1, size, file);
BX_UNUSED(ignore);
fclose(file);
imguiCreate(data, size);
void* data = load("font/droidsans.ttf");
imguiCreate(data);
free(data);
const bgfx::Memory* mem;

Просмотреть файл

@ -13,8 +13,9 @@
// enough for an example.
struct AviWriter
{
AviWriter()
: m_frame(NULL)
AviWriter(bx::FileWriterI* _writer)
: m_writer(_writer)
, m_frame(NULL)
, m_frameSize(0)
, m_numFrames(0)
, m_width(0)
@ -25,7 +26,7 @@ struct AviWriter
bool open(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _fps, bool _yflip)
{
if (0 != m_writer.open(_filePath) )
if (0 != m_writer->open(_filePath) )
{
return false;
}
@ -45,88 +46,88 @@ struct AviWriter
bx::write(&mem, BX_MAKEFOURCC('0', '0', 'd', 'b') );
bx::write(&mem, m_frameSize);
bx::write(&m_writer, BX_MAKEFOURCC('R', 'I', 'F', 'F') );
m_riffSizeOffset = m_writer.seek();
bx::write(&m_writer, UINT32_C(0) );
bx::write(m_writer, BX_MAKEFOURCC('R', 'I', 'F', 'F') );
m_riffSizeOffset = m_writer->seek();
bx::write(m_writer, UINT32_C(0) );
bx::write(&m_writer, BX_MAKEFOURCC('A', 'V', 'I', ' ') );
bx::write(m_writer, BX_MAKEFOURCC('A', 'V', 'I', ' ') );
// AVI RIFF Form http://msdn.microsoft.com/en-us/library/ms899422.aspx
bx::write(&m_writer, BX_MAKEFOURCC('L', 'I', 'S', 'T') );
bx::write(&m_writer, UINT32_C(192) );
bx::write(&m_writer, BX_MAKEFOURCC('h', 'd', 'r', 'l') );
bx::write(m_writer, BX_MAKEFOURCC('L', 'I', 'S', 'T') );
bx::write(m_writer, UINT32_C(192) );
bx::write(m_writer, BX_MAKEFOURCC('h', 'd', 'r', 'l') );
// AVI Main Header http://msdn.microsoft.com/en-us/library/ms779632.aspx
bx::write(&m_writer, BX_MAKEFOURCC('a', 'v', 'i', 'h') );
bx::write(&m_writer, UINT32_C(56) );
bx::write(&m_writer, UINT32_C(0) ); // dwMicroSecPerFrame
bx::write(&m_writer, UINT32_C(0) ); // dwMaxBytesPerSec
bx::write(&m_writer, UINT32_C(0) ); // dwPaddingGranularity
bx::write(&m_writer, UINT32_C(0x101) ); // dwFlags
bx::write(m_writer, BX_MAKEFOURCC('a', 'v', 'i', 'h') );
bx::write(m_writer, UINT32_C(56) );
bx::write(m_writer, UINT32_C(0) ); // dwMicroSecPerFrame
bx::write(m_writer, UINT32_C(0) ); // dwMaxBytesPerSec
bx::write(m_writer, UINT32_C(0) ); // dwPaddingGranularity
bx::write(m_writer, UINT32_C(0x101) ); // dwFlags
m_totalFramesOffset = m_writer.seek();
bx::write(&m_writer, UINT32_C(0) ); // dwTotalFrames
m_totalFramesOffset = m_writer->seek();
bx::write(m_writer, UINT32_C(0) ); // dwTotalFrames
bx::write(&m_writer, UINT32_C(0) ); // dwInitialFrames
bx::write(&m_writer, UINT32_C(1) ); // dwStreams
bx::write(&m_writer, UINT32_C(0) ); // dwSuggestedBufferSize
bx::write(&m_writer, _width); // dwWidth
bx::write(&m_writer, _height); // dwHeight
bx::write(&m_writer, UINT32_C(0) ); // dwReserved0
bx::write(&m_writer, UINT32_C(0) ); // dwReserved1
bx::write(&m_writer, UINT32_C(0) ); // dwReserved2
bx::write(&m_writer, UINT32_C(0) ); // dwReserved3
bx::write(m_writer, UINT32_C(0) ); // dwInitialFrames
bx::write(m_writer, UINT32_C(1) ); // dwStreams
bx::write(m_writer, UINT32_C(0) ); // dwSuggestedBufferSize
bx::write(m_writer, _width); // dwWidth
bx::write(m_writer, _height); // dwHeight
bx::write(m_writer, UINT32_C(0) ); // dwReserved0
bx::write(m_writer, UINT32_C(0) ); // dwReserved1
bx::write(m_writer, UINT32_C(0) ); // dwReserved2
bx::write(m_writer, UINT32_C(0) ); // dwReserved3
bx::write(&m_writer, BX_MAKEFOURCC('L', 'I', 'S', 'T') );
bx::write(&m_writer, UINT32_C(116) );
bx::write(&m_writer, BX_MAKEFOURCC('s', 't', 'r', 'l') );
bx::write(m_writer, BX_MAKEFOURCC('L', 'I', 'S', 'T') );
bx::write(m_writer, UINT32_C(116) );
bx::write(m_writer, BX_MAKEFOURCC('s', 't', 'r', 'l') );
// AVISTREAMHEADER Structure http://msdn.microsoft.com/en-us/library/ms779638.aspx
bx::write(&m_writer, BX_MAKEFOURCC('s', 't', 'r', 'h') );
bx::write(&m_writer, UINT32_C(56) );
bx::write(m_writer, BX_MAKEFOURCC('s', 't', 'r', 'h') );
bx::write(m_writer, UINT32_C(56) );
// AVI Stream Headers http://msdn.microsoft.com/en-us/library/ms899423.aspx
bx::write(&m_writer, BX_MAKEFOURCC('v', 'i', 'd', 's') ); // fccType
bx::write(&m_writer, BX_MAKEFOURCC('D', 'I', 'B', ' ') ); // fccHandler
bx::write(&m_writer, UINT32_C(0) ); // dwFlags
bx::write(&m_writer, UINT16_C(0) ); // wPriority
bx::write(&m_writer, UINT16_C(0) ); // wLanguage
bx::write(&m_writer, UINT32_C(0) ); // dwInitialFrames
bx::write(&m_writer, UINT32_C(1) ); // dwScale
bx::write(&m_writer, _fps); // dwRate
bx::write(&m_writer, UINT32_C(0) ); // dwStart
bx::write(m_writer, BX_MAKEFOURCC('v', 'i', 'd', 's') ); // fccType
bx::write(m_writer, BX_MAKEFOURCC('D', 'I', 'B', ' ') ); // fccHandler
bx::write(m_writer, UINT32_C(0) ); // dwFlags
bx::write(m_writer, UINT16_C(0) ); // wPriority
bx::write(m_writer, UINT16_C(0) ); // wLanguage
bx::write(m_writer, UINT32_C(0) ); // dwInitialFrames
bx::write(m_writer, UINT32_C(1) ); // dwScale
bx::write(m_writer, _fps); // dwRate
bx::write(m_writer, UINT32_C(0) ); // dwStart
m_lengthOffset = m_writer.seek();
bx::write(&m_writer, UINT32_C(0) ); // dwLength
m_lengthOffset = m_writer->seek();
bx::write(m_writer, UINT32_C(0) ); // dwLength
bx::write(&m_writer, m_frameSize); // dwSuggestedBufferSize
bx::write(&m_writer, UINT32_MAX); // dwQuality
bx::write(&m_writer, UINT32_C(0) ); // dwSampleSize
bx::write(&m_writer, INT16_C(0) ); // rcFrame.left
bx::write(&m_writer, INT16_C(0) ); // rcFrame.top
bx::write(&m_writer, uint16_t(_width) ); // rcFrame.right
bx::write(&m_writer, uint16_t(_height) );// rcFrame.bottom
bx::write(m_writer, m_frameSize); // dwSuggestedBufferSize
bx::write(m_writer, UINT32_MAX); // dwQuality
bx::write(m_writer, UINT32_C(0) ); // dwSampleSize
bx::write(m_writer, INT16_C(0) ); // rcFrame.left
bx::write(m_writer, INT16_C(0) ); // rcFrame.top
bx::write(m_writer, uint16_t(_width) ); // rcFrame.right
bx::write(m_writer, uint16_t(_height) );// rcFrame.bottom
bx::write(&m_writer, BX_MAKEFOURCC('s', 't', 'r', 'f') );
bx::write(&m_writer, UINT32_C(40) );
bx::write(m_writer, BX_MAKEFOURCC('s', 't', 'r', 'f') );
bx::write(m_writer, UINT32_C(40) );
// BITMAPINFOHEADER structure http://msdn.microsoft.com/en-us/library/windows/desktop/dd318229%28v=vs.85%29.aspx
bx::write(&m_writer, UINT32_C(40) ); // biSize
bx::write(&m_writer, _width); // biWidth
bx::write(&m_writer, _height); // biHeight
bx::write(&m_writer, UINT16_C(1) ); // biPlanes
bx::write(&m_writer, UINT16_C(24) ); // biBitCount
bx::write(&m_writer, UINT32_C(0) ); // biCompression
bx::write(&m_writer, m_frameSize); // biSizeImage
bx::write(&m_writer, UINT32_C(0) ); // biXPelsPerMeter
bx::write(&m_writer, UINT32_C(0) ); // biYPelsPerMeter
bx::write(&m_writer, UINT32_C(0) ); // biClrUsed
bx::write(&m_writer, UINT32_C(0) ); // biClrImportant
bx::write(m_writer, UINT32_C(40) ); // biSize
bx::write(m_writer, _width); // biWidth
bx::write(m_writer, _height); // biHeight
bx::write(m_writer, UINT16_C(1) ); // biPlanes
bx::write(m_writer, UINT16_C(24) ); // biBitCount
bx::write(m_writer, UINT32_C(0) ); // biCompression
bx::write(m_writer, m_frameSize); // biSizeImage
bx::write(m_writer, UINT32_C(0) ); // biXPelsPerMeter
bx::write(m_writer, UINT32_C(0) ); // biYPelsPerMeter
bx::write(m_writer, UINT32_C(0) ); // biClrUsed
bx::write(m_writer, UINT32_C(0) ); // biClrImportant
bx::write(&m_writer, BX_MAKEFOURCC('L', 'I', 'S', 'T') );
bx::write(m_writer, BX_MAKEFOURCC('L', 'I', 'S', 'T') );
m_moviListOffset = m_writer.seek();
bx::write(&m_writer, UINT32_C(0) );
bx::write(&m_writer, BX_MAKEFOURCC('m', 'o', 'v', 'i') );
m_moviListOffset = m_writer->seek();
bx::write(m_writer, UINT32_C(0) );
bx::write(m_writer, BX_MAKEFOURCC('m', 'o', 'v', 'i') );
return true;
}
@ -135,34 +136,34 @@ struct AviWriter
{
if (NULL != m_frame)
{
int64_t pos = m_writer.seek();
m_writer.seek(m_moviListOffset, bx::Whence::Begin);
bx::write(&m_writer, uint32_t(pos-m_moviListOffset-4) );
m_writer.seek(pos, bx::Whence::Begin);
int64_t pos = m_writer->seek();
m_writer->seek(m_moviListOffset, bx::Whence::Begin);
bx::write(m_writer, uint32_t(pos-m_moviListOffset-4) );
m_writer->seek(pos, bx::Whence::Begin);
bx::write(&m_writer, BX_MAKEFOURCC('i', 'd', 'x', '1') );
bx::write(&m_writer, m_numFrames*16);
bx::write(m_writer, BX_MAKEFOURCC('i', 'd', 'x', '1') );
bx::write(m_writer, m_numFrames*16);
for (uint32_t ii = 0, offset = 4; ii < m_numFrames; ++ii)
{
bx::write(&m_writer, BX_MAKEFOURCC('0', '0', 'd', 'b') );
bx::write(&m_writer, UINT32_C(16) );
bx::write(&m_writer, offset);
bx::write(&m_writer, m_frameSize);
bx::write(m_writer, BX_MAKEFOURCC('0', '0', 'd', 'b') );
bx::write(m_writer, UINT32_C(16) );
bx::write(m_writer, offset);
bx::write(m_writer, m_frameSize);
offset += m_frameSize + 8;
}
pos = m_writer.seek();
m_writer.seek(m_riffSizeOffset, bx::Whence::Begin);
bx::write(&m_writer, uint32_t(pos-m_riffSizeOffset-4) );
pos = m_writer->seek();
m_writer->seek(m_riffSizeOffset, bx::Whence::Begin);
bx::write(m_writer, uint32_t(pos-m_riffSizeOffset-4) );
m_writer.seek(m_totalFramesOffset, bx::Whence::Begin);
bx::write(&m_writer, m_numFrames);
m_writer->seek(m_totalFramesOffset, bx::Whence::Begin);
bx::write(m_writer, m_numFrames);
m_writer.seek(m_lengthOffset, bx::Whence::Begin);
bx::write(&m_writer, m_numFrames);
m_writer->seek(m_lengthOffset, bx::Whence::Begin);
bx::write(m_writer, m_numFrames);
m_writer.close();
m_writer->close();
delete [] m_frame;
m_frame = NULL;
@ -209,11 +210,11 @@ struct AviWriter
}
}
bx::write(&m_writer, m_frame, m_frameSize+8);
bx::write(m_writer, m_frame, m_frameSize+8);
}
}
bx::CrtFileWriter m_writer;
bx::FileWriterI* m_writer;
int64_t m_riffSizeOffset;
int64_t m_totalFramesOffset;
int64_t m_lengthOffset;

Просмотреть файл

@ -0,0 +1,429 @@
/*
* Copyright 2011-2014 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include <vector>
#include <string>
#include <bgfx.h>
#include <bx/readerwriter.h>
#include "fpumath.h"
#include "entry/entry.h"
void* load(bx::FileReaderI* _reader, const char* _filePath)
{
if (0 == bx::open(_reader, _filePath) )
{
uint32_t size = (uint32_t)bx::getSize(_reader);
void* data = malloc(size);
bx::read(_reader, data, size);
bx::close(_reader);
return data;
}
return NULL;
}
void* load(const char* _filePath)
{
return load(entry::getFileReader(), _filePath);
}
static const bgfx::Memory* loadMem(bx::FileReaderI* _reader, const char* _filePath)
{
if (0 == bx::open(_reader, _filePath) )
{
uint32_t size = (uint32_t)bx::getSize(_reader);
const bgfx::Memory* mem = bgfx::alloc(size+1);
bx::read(_reader, mem->data, size);
bx::close(_reader);
mem->data[mem->size-1] = '\0';
return mem;
}
return NULL;
}
static const bgfx::Memory* loadShader(bx::FileReaderI* _reader, const char* _name)
{
char filePath[512];
const char* shaderPath = "shaders/dx9/";
switch (bgfx::getRendererType() )
{
case bgfx::RendererType::Direct3D11:
shaderPath = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
shaderPath = "shaders/glsl/";
break;
case bgfx::RendererType::OpenGLES:
shaderPath = "shaders/gles/";
break;
default:
break;
}
strcpy(filePath, shaderPath);
strcat(filePath, _name);
strcat(filePath, ".bin");
return loadMem(_reader, filePath);
}
bgfx::ProgramHandle loadProgram(bx::FileReaderI* _reader, const char* _vsName, const char* _fsName)
{
const bgfx::Memory* mem;
// Load vertex shader.
mem = loadShader(_reader, _vsName);
bgfx::ShaderHandle vsh = bgfx::createShader(mem);
// Load fragment shader.
mem = loadShader(_reader, _fsName);
bgfx::ShaderHandle fsh = bgfx::createShader(mem);
// Create program from shaders.
return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
}
bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
{
return loadProgram(entry::getFileReader(), _vsName, _fsName);
}
bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _name, uint32_t _flags, uint8_t _skip, bgfx::TextureInfo* _info)
{
char filePath[512];
strcpy(filePath, "textures/");
strcat(filePath, _name);
const bgfx::Memory* mem = loadMem(_reader, filePath);
return bgfx::createTexture(mem, _flags, _skip, _info);
}
bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags, uint8_t _skip, bgfx::TextureInfo* _info)
{
return loadTexture(entry::getFileReader(), _name, _flags, _skip, _info);
}
void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices)
{
struct PosTexcoord
{
float m_x;
float m_y;
float m_z;
float m_pad0;
float m_u;
float m_v;
float m_pad1;
float m_pad2;
};
float* tangents = new float[6*_numVertices];
memset(tangents, 0, 6*_numVertices*sizeof(float) );
PosTexcoord v0;
PosTexcoord v1;
PosTexcoord v2;
for (uint32_t ii = 0, num = _numIndices/3; ii < num; ++ii)
{
const uint16_t* indices = &_indices[ii*3];
uint32_t i0 = indices[0];
uint32_t i1 = indices[1];
uint32_t i2 = indices[2];
bgfx::vertexUnpack(&v0.m_x, bgfx::Attrib::Position, _decl, _vertices, i0);
bgfx::vertexUnpack(&v0.m_u, bgfx::Attrib::TexCoord0, _decl, _vertices, i0);
bgfx::vertexUnpack(&v1.m_x, bgfx::Attrib::Position, _decl, _vertices, i1);
bgfx::vertexUnpack(&v1.m_u, bgfx::Attrib::TexCoord0, _decl, _vertices, i1);
bgfx::vertexUnpack(&v2.m_x, bgfx::Attrib::Position, _decl, _vertices, i2);
bgfx::vertexUnpack(&v2.m_u, bgfx::Attrib::TexCoord0, _decl, _vertices, i2);
const float bax = v1.m_x - v0.m_x;
const float bay = v1.m_y - v0.m_y;
const float baz = v1.m_z - v0.m_z;
const float bau = v1.m_u - v0.m_u;
const float bav = v1.m_v - v0.m_v;
const float cax = v2.m_x - v0.m_x;
const float cay = v2.m_y - v0.m_y;
const float caz = v2.m_z - v0.m_z;
const float cau = v2.m_u - v0.m_u;
const float cav = v2.m_v - v0.m_v;
const float det = (bau * cav - bav * cau);
const float invDet = 1.0f / det;
const float tx = (bax * cav - cax * bav) * invDet;
const float ty = (bay * cav - cay * bav) * invDet;
const float tz = (baz * cav - caz * bav) * invDet;
const float bx = (cax * bau - bax * cau) * invDet;
const float by = (cay * bau - bay * cau) * invDet;
const float bz = (caz * bau - baz * cau) * invDet;
for (uint32_t jj = 0; jj < 3; ++jj)
{
float* tanu = &tangents[indices[jj]*6];
float* tanv = &tanu[3];
tanu[0] += tx;
tanu[1] += ty;
tanu[2] += tz;
tanv[0] += bx;
tanv[1] += by;
tanv[2] += bz;
}
}
for (uint32_t ii = 0; ii < _numVertices; ++ii)
{
const float* tanu = &tangents[ii*6];
const float* tanv = &tangents[ii*6 + 3];
float normal[4];
bgfx::vertexUnpack(normal, bgfx::Attrib::Normal, _decl, _vertices, ii);
float ndt = vec3Dot(normal, tanu);
float nxt[3];
vec3Cross(nxt, normal, tanu);
float tmp[3];
tmp[0] = tanu[0] - normal[0] * ndt;
tmp[1] = tanu[1] - normal[1] * ndt;
tmp[2] = tanu[2] - normal[2] * ndt;
float tangent[4];
vec3Norm(tangent, tmp);
tangent[3] = vec3Dot(nxt, tanv) < 0.0f ? -1.0f : 1.0f;
bgfx::vertexPack(tangent, true, bgfx::Attrib::Tangent, _decl, _vertices, ii);
}
delete [] tangents;
}
struct Aabb
{
float m_min[3];
float m_max[3];
};
struct Obb
{
float m_mtx[16];
};
struct Sphere
{
float m_center[3];
float m_radius;
};
struct Primitive
{
uint32_t m_startIndex;
uint32_t m_numIndices;
uint32_t m_startVertex;
uint32_t m_numVertices;
Sphere m_sphere;
Aabb m_aabb;
Obb m_obb;
};
typedef std::vector<Primitive> PrimitiveArray;
struct Group
{
Group()
{
reset();
}
void reset()
{
m_vbh.idx = bgfx::invalidHandle;
m_ibh.idx = bgfx::invalidHandle;
m_prims.clear();
}
bgfx::VertexBufferHandle m_vbh;
bgfx::IndexBufferHandle m_ibh;
Sphere m_sphere;
Aabb m_aabb;
Obb m_obb;
PrimitiveArray m_prims;
};
struct Mesh
{
void load(bx::ReaderSeekerI* _reader)
{
#define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x0)
#define BGFX_CHUNK_MAGIC_IB BX_MAKEFOURCC('I', 'B', ' ', 0x0)
#define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0)
Group group;
uint32_t chunk;
while (4 == bx::read(_reader, chunk) )
{
switch (chunk)
{
case BGFX_CHUNK_MAGIC_VB:
{
bx::read(_reader, group.m_sphere);
bx::read(_reader, group.m_aabb);
bx::read(_reader, group.m_obb);
bx::read(_reader, m_decl);
uint16_t stride = m_decl.getStride();
uint16_t numVertices;
bx::read(_reader, numVertices);
const bgfx::Memory* mem = bgfx::alloc(numVertices*stride);
bx::read(_reader, mem->data, mem->size);
group.m_vbh = bgfx::createVertexBuffer(mem, m_decl);
}
break;
case BGFX_CHUNK_MAGIC_IB:
{
uint32_t numIndices;
bx::read(_reader, numIndices);
const bgfx::Memory* mem = bgfx::alloc(numIndices*2);
bx::read(_reader, mem->data, mem->size);
group.m_ibh = bgfx::createIndexBuffer(mem);
}
break;
case BGFX_CHUNK_MAGIC_PRI:
{
uint16_t len;
bx::read(_reader, len);
std::string material;
material.resize(len);
bx::read(_reader, const_cast<char*>(material.c_str() ), len);
uint16_t num;
bx::read(_reader, num);
for (uint32_t ii = 0; ii < num; ++ii)
{
bx::read(_reader, len);
std::string name;
name.resize(len);
bx::read(_reader, const_cast<char*>(name.c_str() ), len);
Primitive prim;
bx::read(_reader, prim.m_startIndex);
bx::read(_reader, prim.m_numIndices);
bx::read(_reader, prim.m_startVertex);
bx::read(_reader, prim.m_numVertices);
bx::read(_reader, prim.m_sphere);
bx::read(_reader, prim.m_aabb);
bx::read(_reader, prim.m_obb);
group.m_prims.push_back(prim);
}
m_groups.push_back(group);
group.reset();
}
break;
default:
DBG("%08x at %d", chunk, bx::skip(_reader, 0) );
break;
}
}
}
void unload()
{
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
{
const Group& group = *it;
bgfx::destroyVertexBuffer(group.m_vbh);
if (bgfx::isValid(group.m_ibh) )
{
bgfx::destroyIndexBuffer(group.m_ibh);
}
}
m_groups.clear();
}
void submit(uint8_t _id, bgfx::ProgramHandle _program, float* _mtx)
{
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
{
const Group& group = *it;
// Set model matrix for rendering.
bgfx::setTransform(_mtx);
bgfx::setProgram(_program);
bgfx::setIndexBuffer(group.m_ibh);
bgfx::setVertexBuffer(group.m_vbh);
// Set render states.
bgfx::setState(0
| BGFX_STATE_RGB_WRITE
| BGFX_STATE_ALPHA_WRITE
| BGFX_STATE_DEPTH_WRITE
| BGFX_STATE_DEPTH_TEST_LESS
| BGFX_STATE_CULL_CCW
| BGFX_STATE_MSAA
);
// Submit primitive for rendering to view 0.
bgfx::submit(_id);
}
}
bgfx::VertexDecl m_decl;
typedef std::vector<Group> GroupArray;
GroupArray m_groups;
};
Mesh* meshLoad(bx::ReaderSeekerI* _reader)
{
Mesh* mesh = new Mesh;
mesh->load(_reader);
return mesh;
}
Mesh* meshLoad(const char* _filePath)
{
bx::FileReaderI* reader = entry::getFileReader();
bx::open(reader, _filePath);
Mesh* mesh = meshLoad(reader);
bx::close(reader);
return mesh;
}
void meshUnload(Mesh* _mesh)
{
_mesh->unload();
delete _mesh;
}
void meshSubmit(Mesh* _mesh, uint8_t _id, bgfx::ProgramHandle _program, float* _mtx)
{
_mesh->submit(_id, _program, _mtx);
}

Просмотреть файл

@ -0,0 +1,21 @@
/*
* Copyright 2011-2014 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#ifndef BGFX_UTILS_H_HEADER_GUARD
#define BGFX_UTILS_H_HEADER_GUARD
#include <bgfx.h>
void* load(const char* _filePath);
bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName);
bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags = BGFX_TEXTURE_NONE, uint8_t _skip = 0, bgfx::TextureInfo* _info = NULL);
void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices);
struct Mesh;
Mesh* meshLoad(const char* _filePath);
void meshUnload(Mesh* _mesh);
void meshSubmit(Mesh* _mesh, uint8_t _id, bgfx::ProgramHandle _program, float* _mtx);
#endif // BGFX_UTILS_H_HEADER_GUARD

Просмотреть файл

@ -3,4 +3,7 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include <bx/timer.h>
#include "entry/entry.h"
#include "fpumath.h"

Просмотреть файл

@ -5,6 +5,7 @@
#include <bgfx.h>
#include <bx/string.h>
#include <bx/readerwriter.h>
#include <time.h>
@ -19,6 +20,8 @@ namespace entry
static uint32_t s_debug = BGFX_DEBUG_NONE;
static uint32_t s_reset = BGFX_RESET_NONE;
static bool s_exit = false;
static bx::FileReaderI* s_fileReader = NULL;
static bx::FileWriterI* s_fileWriter = NULL;
bool setOrToggle(uint32_t& _flags, const char* _name, uint32_t _bit, int _first, int _argc, char const* const* _argv)
{
@ -120,6 +123,11 @@ namespace entry
{
//DBG(BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME);
#if BX_CONFIG_CRT_FILE_READER_WRITER
s_fileReader = new bx::CrtFileReader;
s_fileWriter = new bx::CrtFileWriter;
#endif // BX_CONFIG_CRT_FILE_READER_WRITER
cmdAdd("mouselock", cmdMouseLock);
cmdAdd("graphics", cmdGraphics );
cmdAdd("exit", cmdExit );
@ -127,6 +135,15 @@ namespace entry
inputAddBindings("bindings", s_bindings);
int32_t result = ::_main_(_argc, _argv);
#if BX_CONFIG_CRT_FILE_READER_WRITER
delete s_fileReader;
s_fileReader = NULL;
delete s_fileWriter;
s_fileWriter = NULL;
#endif // BX_CONFIG_CRT_FILE_READER_WRITER
return result;
}
@ -216,4 +233,14 @@ namespace entry
return s_exit;
}
bx::FileReaderI* getFileReader()
{
return s_fileReader;
}
bx::FileWriterI* getFileWriter()
{
return s_fileWriter;
}
} // namespace entry

Просмотреть файл

@ -10,6 +10,8 @@
#include <bx/bx.h>
namespace bx { struct FileReaderI; struct FileWriterI; }
namespace entry
{
struct MouseButton
@ -142,6 +144,9 @@ namespace entry
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL);
bx::FileReaderI* getFileReader();
bx::FileWriterI* getFileWriter();
} // namespace entry
#endif // ENTRY_H_HEADER_GUARD

Просмотреть файл

@ -5,10 +5,11 @@
#define USE_EDTAA3 0
#include <freetype/freetype.h>
#include "../common.h"
#include <bgfx.h>
#include <freetype/freetype.h>
#include <math.h>
#if USE_EDTAA3

Просмотреть файл

@ -160,7 +160,7 @@ struct Imgui
m_textureProgram.idx = bgfx::invalidHandle;
}
bool create(const void* _data, uint32_t /*_size*/)
bool create(const void* _data)
{
for (int32_t ii = 0; ii < NUM_CIRCLE_VERTS; ++ii)
{
@ -1423,9 +1423,9 @@ struct Imgui
static Imgui s_imgui;
bool imguiCreate(const void* _data, uint32_t _size)
bool imguiCreate(const void* _data)
{
return s_imgui.create(_data, _size);
return s_imgui.create(_data);
}
void imguiDestroy()

Просмотреть файл

@ -49,7 +49,7 @@ inline uint32_t imguiRGBA(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255)
;
}
bool imguiCreate(const void* _data, uint32_t _size);
bool imguiCreate(const void* _data);
void imguiDestroy();
void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint8_t _view = 31);