Normalized line endings.
This commit is contained in:
parent
bbfc599684
commit
8e0e21f40d
70 changed files with 4660 additions and 4660 deletions
3rdparty
edtaa3
forsyth-too
glext/gl
examples
00-helloworld
01-cubes
02-metaballs
03-raymarch
04-mesh
05-instancing
06-bump
07-callback
08-update
common
src
bgfx_shader.shcommon.shconfig.hdds.hfs_clear.scfs_debugfont.screnderer_d3d.hrenderer_d3d11.cpprenderer_d3d9.cpprenderer_gl.cppvarying.def.scvs_clear.scvs_debugfont.sc
tools
32
3rdparty/edtaa3/LICENSE.md
vendored
32
3rdparty/edtaa3/LICENSE.md
vendored
|
@ -1,16 +1,16 @@
|
||||||
Anti-aliased Euclidean distance transform
|
Anti-aliased Euclidean distance transform
|
||||||
http://webstaff.itn.liu.se/~stegu/edtaa/
|
http://webstaff.itn.liu.se/~stegu/edtaa/
|
||||||
|
|
||||||
Copyright (C) 2009 Stefan Gustavson (stefan.gustavson@gmail.com)
|
Copyright (C) 2009 Stefan Gustavson (stefan.gustavson@gmail.com)
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This program is free software; you can redistribute it and/or modify it
|
||||||
under the terms of the GNU General Public License as published by the
|
under the terms of the GNU General Public License as published by the
|
||||||
Free Software Foundation; either version 3 of the License, or (at your
|
Free Software Foundation; either version 3 of the License, or (at your
|
||||||
option) any later version.
|
option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
for more details.
|
for more details.
|
||||||
|
|
||||||
The GNU General Public License is available on <http://www.gnu.org/licenses/>.
|
The GNU General Public License is available on <http://www.gnu.org/licenses/>.
|
||||||
|
|
1128
3rdparty/edtaa3/edtaa3func.cpp
vendored
1128
3rdparty/edtaa3/edtaa3func.cpp
vendored
File diff suppressed because it is too large
Load diff
14
3rdparty/edtaa3/edtaa3func.h
vendored
14
3rdparty/edtaa3/edtaa3func.h
vendored
|
@ -1,7 +1,7 @@
|
||||||
#ifndef __EDTAA3_H__
|
#ifndef __EDTAA3_H__
|
||||||
#define __EDTAA3_H__
|
#define __EDTAA3_H__
|
||||||
|
|
||||||
extern void computegradient(double *img, int w, int h, double *gx, double *gy);
|
extern void computegradient(double *img, int w, int h, double *gx, double *gy);
|
||||||
extern void edtaa3(double *img, double *gx, double *gy, int w, int h, short *distx, short *disty, double *dist);
|
extern void edtaa3(double *img, double *gx, double *gy, int w, int h, short *distx, short *disty, double *dist);
|
||||||
|
|
||||||
#endif // __EDTAA3_H__
|
#endif // __EDTAA3_H__
|
||||||
|
|
26
3rdparty/forsyth-too/LICENSE.md
vendored
26
3rdparty/forsyth-too/LICENSE.md
vendored
|
@ -1,13 +1,13 @@
|
||||||
This is an implementation of Tom Forsyth's "Linear-Speed Vertex Cache
|
This is an implementation of Tom Forsyth's "Linear-Speed Vertex Cache
|
||||||
Optimization" algorithm as described here:
|
Optimization" algorithm as described here:
|
||||||
http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
|
http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
|
||||||
|
|
||||||
This code was authored and released into the public domain by
|
This code was authored and released into the public domain by
|
||||||
Adrian Stone (stone@gameangst.com).
|
Adrian Stone (stone@gameangst.com).
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
SHALL ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER
|
SHALL ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
|
@ -1,350 +1,350 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// This is an implementation of Tom Forsyth's "Linear-Speed Vertex Cache
|
// This is an implementation of Tom Forsyth's "Linear-Speed Vertex Cache
|
||||||
// Optimization" algorithm as described here:
|
// Optimization" algorithm as described here:
|
||||||
// http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
|
// http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
|
||||||
//
|
//
|
||||||
// This code was authored and released into the public domain by
|
// This code was authored and released into the public domain by
|
||||||
// Adrian Stone (stone@gameangst.com).
|
// Adrian Stone (stone@gameangst.com).
|
||||||
//
|
//
|
||||||
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER
|
// SHALL ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
// LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||||
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Forsyth
|
namespace Forsyth
|
||||||
{
|
{
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
typedef unsigned short uint16;
|
typedef unsigned short uint16;
|
||||||
typedef unsigned char byte;
|
typedef unsigned char byte;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// OptimizeFaces
|
// OptimizeFaces
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// indexList
|
// indexList
|
||||||
// input index list
|
// input index list
|
||||||
// indexCount
|
// indexCount
|
||||||
// the number of indices in the list
|
// the number of indices in the list
|
||||||
// vertexCount
|
// vertexCount
|
||||||
// the largest index value in indexList
|
// the largest index value in indexList
|
||||||
// newIndexList
|
// newIndexList
|
||||||
// a pointer to a preallocated buffer the same size as indexList to
|
// a pointer to a preallocated buffer the same size as indexList to
|
||||||
// hold the optimized index list
|
// hold the optimized index list
|
||||||
// lruCacheSize
|
// lruCacheSize
|
||||||
// the size of the simulated post-transform cache (max:64)
|
// the size of the simulated post-transform cache (max:64)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void OptimizeFaces(const uint16* indexList, uint indexCount, uint vertexCount, uint16* newIndexList, uint16 lruCacheSize);
|
void OptimizeFaces(const uint16* indexList, uint indexCount, uint vertexCount, uint16* newIndexList, uint16 lruCacheSize);
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// code for computing vertex score was taken, as much as possible
|
// code for computing vertex score was taken, as much as possible
|
||||||
// directly from the original publication.
|
// directly from the original publication.
|
||||||
float ComputeVertexCacheScore(int cachePosition, int vertexCacheSize)
|
float ComputeVertexCacheScore(int cachePosition, int vertexCacheSize)
|
||||||
{
|
{
|
||||||
const float FindVertexScore_CacheDecayPower = 1.5f;
|
const float FindVertexScore_CacheDecayPower = 1.5f;
|
||||||
const float FindVertexScore_LastTriScore = 0.75f;
|
const float FindVertexScore_LastTriScore = 0.75f;
|
||||||
|
|
||||||
float score = 0.0f;
|
float score = 0.0f;
|
||||||
if ( cachePosition < 0 )
|
if ( cachePosition < 0 )
|
||||||
{
|
{
|
||||||
// Vertex is not in FIFO cache - no score.
|
// Vertex is not in FIFO cache - no score.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( cachePosition < 3 )
|
if ( cachePosition < 3 )
|
||||||
{
|
{
|
||||||
// This vertex was used in the last triangle,
|
// This vertex was used in the last triangle,
|
||||||
// so it has a fixed score, whichever of the three
|
// so it has a fixed score, whichever of the three
|
||||||
// it's in. Otherwise, you can get very different
|
// it's in. Otherwise, you can get very different
|
||||||
// answers depending on whether you add
|
// answers depending on whether you add
|
||||||
// the triangle 1,2,3 or 3,1,2 - which is silly.
|
// the triangle 1,2,3 or 3,1,2 - which is silly.
|
||||||
score = FindVertexScore_LastTriScore;
|
score = FindVertexScore_LastTriScore;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert ( cachePosition < vertexCacheSize );
|
assert ( cachePosition < vertexCacheSize );
|
||||||
// Points for being high in the cache.
|
// Points for being high in the cache.
|
||||||
const float scaler = 1.0f / ( vertexCacheSize - 3 );
|
const float scaler = 1.0f / ( vertexCacheSize - 3 );
|
||||||
score = 1.0f - ( cachePosition - 3 ) * scaler;
|
score = 1.0f - ( cachePosition - 3 ) * scaler;
|
||||||
score = powf ( score, FindVertexScore_CacheDecayPower );
|
score = powf ( score, FindVertexScore_CacheDecayPower );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ComputeVertexValenceScore(uint numActiveFaces)
|
float ComputeVertexValenceScore(uint numActiveFaces)
|
||||||
{
|
{
|
||||||
const float FindVertexScore_ValenceBoostScale = 2.0f;
|
const float FindVertexScore_ValenceBoostScale = 2.0f;
|
||||||
const float FindVertexScore_ValenceBoostPower = 0.5f;
|
const float FindVertexScore_ValenceBoostPower = 0.5f;
|
||||||
|
|
||||||
float score = 0.f;
|
float score = 0.f;
|
||||||
|
|
||||||
// Bonus points for having a low number of tris still to
|
// Bonus points for having a low number of tris still to
|
||||||
// use the vert, so we get rid of lone verts quickly.
|
// use the vert, so we get rid of lone verts quickly.
|
||||||
float valenceBoost = powf ( static_cast<float>(numActiveFaces),
|
float valenceBoost = powf ( static_cast<float>(numActiveFaces),
|
||||||
-FindVertexScore_ValenceBoostPower );
|
-FindVertexScore_ValenceBoostPower );
|
||||||
score += FindVertexScore_ValenceBoostScale * valenceBoost;
|
score += FindVertexScore_ValenceBoostScale * valenceBoost;
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const int kMaxVertexCacheSize = 64;
|
const int kMaxVertexCacheSize = 64;
|
||||||
const uint kMaxPrecomputedVertexValenceScores = 64;
|
const uint kMaxPrecomputedVertexValenceScores = 64;
|
||||||
float s_vertexCacheScores[kMaxVertexCacheSize+1][kMaxVertexCacheSize];
|
float s_vertexCacheScores[kMaxVertexCacheSize+1][kMaxVertexCacheSize];
|
||||||
float s_vertexValenceScores[kMaxPrecomputedVertexValenceScores];
|
float s_vertexValenceScores[kMaxPrecomputedVertexValenceScores];
|
||||||
|
|
||||||
bool ComputeVertexScores()
|
bool ComputeVertexScores()
|
||||||
{
|
{
|
||||||
for (int cacheSize=0; cacheSize<=kMaxVertexCacheSize; ++cacheSize)
|
for (int cacheSize=0; cacheSize<=kMaxVertexCacheSize; ++cacheSize)
|
||||||
{
|
{
|
||||||
for (int cachePos=0; cachePos<cacheSize; ++cachePos)
|
for (int cachePos=0; cachePos<cacheSize; ++cachePos)
|
||||||
{
|
{
|
||||||
s_vertexCacheScores[cacheSize][cachePos] = ComputeVertexCacheScore(cachePos, cacheSize);
|
s_vertexCacheScores[cacheSize][cachePos] = ComputeVertexCacheScore(cachePos, cacheSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint valence=0; valence<kMaxPrecomputedVertexValenceScores; ++valence)
|
for (uint valence=0; valence<kMaxPrecomputedVertexValenceScores; ++valence)
|
||||||
{
|
{
|
||||||
s_vertexValenceScores[valence] = ComputeVertexValenceScore(valence);
|
s_vertexValenceScores[valence] = ComputeVertexValenceScore(valence);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool s_vertexScoresComputed = ComputeVertexScores();
|
bool s_vertexScoresComputed = ComputeVertexScores();
|
||||||
|
|
||||||
inline float FindVertexCacheScore(uint cachePosition, uint maxSizeVertexCache)
|
inline float FindVertexCacheScore(uint cachePosition, uint maxSizeVertexCache)
|
||||||
{
|
{
|
||||||
return s_vertexCacheScores[maxSizeVertexCache][cachePosition];
|
return s_vertexCacheScores[maxSizeVertexCache][cachePosition];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float FindVertexValenceScore(uint numActiveTris)
|
inline float FindVertexValenceScore(uint numActiveTris)
|
||||||
{
|
{
|
||||||
return s_vertexValenceScores[numActiveTris];
|
return s_vertexValenceScores[numActiveTris];
|
||||||
}
|
}
|
||||||
|
|
||||||
float FindVertexScore(uint numActiveFaces, uint cachePosition, uint vertexCacheSize)
|
float FindVertexScore(uint numActiveFaces, uint cachePosition, uint vertexCacheSize)
|
||||||
{
|
{
|
||||||
assert(s_vertexScoresComputed);
|
assert(s_vertexScoresComputed);
|
||||||
|
|
||||||
if ( numActiveFaces == 0 )
|
if ( numActiveFaces == 0 )
|
||||||
{
|
{
|
||||||
// No tri needs this vertex!
|
// No tri needs this vertex!
|
||||||
return -1.0f;
|
return -1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float score = 0.f;
|
float score = 0.f;
|
||||||
if (cachePosition < vertexCacheSize)
|
if (cachePosition < vertexCacheSize)
|
||||||
{
|
{
|
||||||
score += s_vertexCacheScores[vertexCacheSize][cachePosition];
|
score += s_vertexCacheScores[vertexCacheSize][cachePosition];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numActiveFaces < kMaxPrecomputedVertexValenceScores)
|
if (numActiveFaces < kMaxPrecomputedVertexValenceScores)
|
||||||
{
|
{
|
||||||
score += s_vertexValenceScores[numActiveFaces];
|
score += s_vertexValenceScores[numActiveFaces];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
score += ComputeVertexValenceScore(numActiveFaces);
|
score += ComputeVertexValenceScore(numActiveFaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OptimizeVertexData
|
struct OptimizeVertexData
|
||||||
{
|
{
|
||||||
float score;
|
float score;
|
||||||
uint activeFaceListStart;
|
uint activeFaceListStart;
|
||||||
uint activeFaceListSize;
|
uint activeFaceListSize;
|
||||||
uint16 cachePos0;
|
uint16 cachePos0;
|
||||||
uint16 cachePos1;
|
uint16 cachePos1;
|
||||||
OptimizeVertexData() : score(0.f), activeFaceListStart(0), activeFaceListSize(0), cachePos0(0), cachePos1(0) { }
|
OptimizeVertexData() : score(0.f), activeFaceListStart(0), activeFaceListSize(0), cachePos0(0), cachePos1(0) { }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptimizeFaces(const uint16* indexList, uint indexCount, uint vertexCount, uint16* newIndexList, uint16 lruCacheSize)
|
void OptimizeFaces(const uint16* indexList, uint indexCount, uint vertexCount, uint16* newIndexList, uint16 lruCacheSize)
|
||||||
{
|
{
|
||||||
std::vector<OptimizeVertexData> vertexDataList;
|
std::vector<OptimizeVertexData> vertexDataList;
|
||||||
vertexDataList.resize(vertexCount);
|
vertexDataList.resize(vertexCount);
|
||||||
|
|
||||||
// compute face count per vertex
|
// compute face count per vertex
|
||||||
for (uint i=0; i<indexCount; ++i)
|
for (uint i=0; i<indexCount; ++i)
|
||||||
{
|
{
|
||||||
uint16 index = indexList[i];
|
uint16 index = indexList[i];
|
||||||
assert(index < vertexCount);
|
assert(index < vertexCount);
|
||||||
OptimizeVertexData& vertexData = vertexDataList[index];
|
OptimizeVertexData& vertexData = vertexDataList[index];
|
||||||
vertexData.activeFaceListSize++;
|
vertexData.activeFaceListSize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint> activeFaceList;
|
std::vector<uint> activeFaceList;
|
||||||
|
|
||||||
const uint16 kEvictedCacheIndex = std::numeric_limits<uint16>::max();
|
const uint16 kEvictedCacheIndex = std::numeric_limits<uint16>::max();
|
||||||
|
|
||||||
{
|
{
|
||||||
// allocate face list per vertex
|
// allocate face list per vertex
|
||||||
uint curActiveFaceListPos = 0;
|
uint curActiveFaceListPos = 0;
|
||||||
for (uint i=0; i<vertexCount; ++i)
|
for (uint i=0; i<vertexCount; ++i)
|
||||||
{
|
{
|
||||||
OptimizeVertexData& vertexData = vertexDataList[i];
|
OptimizeVertexData& vertexData = vertexDataList[i];
|
||||||
vertexData.cachePos0 = kEvictedCacheIndex;
|
vertexData.cachePos0 = kEvictedCacheIndex;
|
||||||
vertexData.cachePos1 = kEvictedCacheIndex;
|
vertexData.cachePos1 = kEvictedCacheIndex;
|
||||||
vertexData.activeFaceListStart = curActiveFaceListPos;
|
vertexData.activeFaceListStart = curActiveFaceListPos;
|
||||||
curActiveFaceListPos += vertexData.activeFaceListSize;
|
curActiveFaceListPos += vertexData.activeFaceListSize;
|
||||||
vertexData.score = FindVertexScore(vertexData.activeFaceListSize, vertexData.cachePos0, lruCacheSize);
|
vertexData.score = FindVertexScore(vertexData.activeFaceListSize, vertexData.cachePos0, lruCacheSize);
|
||||||
vertexData.activeFaceListSize = 0;
|
vertexData.activeFaceListSize = 0;
|
||||||
}
|
}
|
||||||
activeFaceList.resize(curActiveFaceListPos);
|
activeFaceList.resize(curActiveFaceListPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill out face list per vertex
|
// fill out face list per vertex
|
||||||
for (uint i=0; i<indexCount; i+=3)
|
for (uint i=0; i<indexCount; i+=3)
|
||||||
{
|
{
|
||||||
for (uint j=0; j<3; ++j)
|
for (uint j=0; j<3; ++j)
|
||||||
{
|
{
|
||||||
uint16 index = indexList[i+j];
|
uint16 index = indexList[i+j];
|
||||||
OptimizeVertexData& vertexData = vertexDataList[index];
|
OptimizeVertexData& vertexData = vertexDataList[index];
|
||||||
activeFaceList[vertexData.activeFaceListStart + vertexData.activeFaceListSize] = i;
|
activeFaceList[vertexData.activeFaceListStart + vertexData.activeFaceListSize] = i;
|
||||||
vertexData.activeFaceListSize++;
|
vertexData.activeFaceListSize++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<byte> processedFaceList;
|
std::vector<byte> processedFaceList;
|
||||||
processedFaceList.resize(indexCount);
|
processedFaceList.resize(indexCount);
|
||||||
|
|
||||||
uint16 vertexCacheBuffer[(kMaxVertexCacheSize+3)*2];
|
uint16 vertexCacheBuffer[(kMaxVertexCacheSize+3)*2];
|
||||||
uint16* cache0 = vertexCacheBuffer;
|
uint16* cache0 = vertexCacheBuffer;
|
||||||
uint16* cache1 = vertexCacheBuffer+(kMaxVertexCacheSize+3);
|
uint16* cache1 = vertexCacheBuffer+(kMaxVertexCacheSize+3);
|
||||||
uint16 entriesInCache0 = 0;
|
uint16 entriesInCache0 = 0;
|
||||||
|
|
||||||
uint bestFace = 0;
|
uint bestFace = 0;
|
||||||
float bestScore = -1.f;
|
float bestScore = -1.f;
|
||||||
|
|
||||||
const float maxValenceScore = FindVertexScore(1, kEvictedCacheIndex, lruCacheSize) * 3.f;
|
const float maxValenceScore = FindVertexScore(1, kEvictedCacheIndex, lruCacheSize) * 3.f;
|
||||||
|
|
||||||
for (uint i = 0; i < indexCount; i += 3)
|
for (uint i = 0; i < indexCount; i += 3)
|
||||||
{
|
{
|
||||||
if (bestScore < 0.f)
|
if (bestScore < 0.f)
|
||||||
{
|
{
|
||||||
// no verts in the cache are used by any unprocessed faces so
|
// no verts in the cache are used by any unprocessed faces so
|
||||||
// search all unprocessed faces for a new starting point
|
// search all unprocessed faces for a new starting point
|
||||||
for (uint j = 0; j < indexCount; j += 3)
|
for (uint j = 0; j < indexCount; j += 3)
|
||||||
{
|
{
|
||||||
if (processedFaceList[j] == 0)
|
if (processedFaceList[j] == 0)
|
||||||
{
|
{
|
||||||
uint face = j;
|
uint face = j;
|
||||||
float faceScore = 0.f;
|
float faceScore = 0.f;
|
||||||
for (uint k=0; k<3; ++k)
|
for (uint k=0; k<3; ++k)
|
||||||
{
|
{
|
||||||
uint16 index = indexList[face+k];
|
uint16 index = indexList[face+k];
|
||||||
OptimizeVertexData& vertexData = vertexDataList[index];
|
OptimizeVertexData& vertexData = vertexDataList[index];
|
||||||
assert(vertexData.activeFaceListSize > 0);
|
assert(vertexData.activeFaceListSize > 0);
|
||||||
assert(vertexData.cachePos0 >= lruCacheSize);
|
assert(vertexData.cachePos0 >= lruCacheSize);
|
||||||
faceScore += vertexData.score;
|
faceScore += vertexData.score;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (faceScore > bestScore)
|
if (faceScore > bestScore)
|
||||||
{
|
{
|
||||||
bestScore = faceScore;
|
bestScore = faceScore;
|
||||||
bestFace = face;
|
bestFace = face;
|
||||||
|
|
||||||
assert(bestScore <= maxValenceScore);
|
assert(bestScore <= maxValenceScore);
|
||||||
if (bestScore >= maxValenceScore)
|
if (bestScore >= maxValenceScore)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(bestScore >= 0.f);
|
assert(bestScore >= 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
processedFaceList[bestFace] = 1;
|
processedFaceList[bestFace] = 1;
|
||||||
uint16 entriesInCache1 = 0;
|
uint16 entriesInCache1 = 0;
|
||||||
|
|
||||||
// add bestFace to LRU cache and to newIndexList
|
// add bestFace to LRU cache and to newIndexList
|
||||||
for (uint v = 0; v < 3; ++v)
|
for (uint v = 0; v < 3; ++v)
|
||||||
{
|
{
|
||||||
uint16 index = indexList[bestFace+v];
|
uint16 index = indexList[bestFace+v];
|
||||||
newIndexList[i+v] = index;
|
newIndexList[i+v] = index;
|
||||||
|
|
||||||
OptimizeVertexData& vertexData = vertexDataList[index];
|
OptimizeVertexData& vertexData = vertexDataList[index];
|
||||||
|
|
||||||
if (vertexData.cachePos1 >= entriesInCache1)
|
if (vertexData.cachePos1 >= entriesInCache1)
|
||||||
{
|
{
|
||||||
vertexData.cachePos1 = entriesInCache1;
|
vertexData.cachePos1 = entriesInCache1;
|
||||||
cache1[entriesInCache1++] = index;
|
cache1[entriesInCache1++] = index;
|
||||||
|
|
||||||
if (vertexData.activeFaceListSize == 1)
|
if (vertexData.activeFaceListSize == 1)
|
||||||
{
|
{
|
||||||
--vertexData.activeFaceListSize;
|
--vertexData.activeFaceListSize;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(vertexData.activeFaceListSize > 0);
|
assert(vertexData.activeFaceListSize > 0);
|
||||||
uint* begin = &activeFaceList[vertexData.activeFaceListStart];
|
uint* begin = &activeFaceList[vertexData.activeFaceListStart];
|
||||||
uint* end = &activeFaceList[vertexData.activeFaceListStart + vertexData.activeFaceListSize];
|
uint* end = &activeFaceList[vertexData.activeFaceListStart + vertexData.activeFaceListSize];
|
||||||
uint* it = std::find(begin, end, bestFace);
|
uint* it = std::find(begin, end, bestFace);
|
||||||
assert(it != end);
|
assert(it != end);
|
||||||
std::swap(*it, *(end-1));
|
std::swap(*it, *(end-1));
|
||||||
--vertexData.activeFaceListSize;
|
--vertexData.activeFaceListSize;
|
||||||
vertexData.score = FindVertexScore(vertexData.activeFaceListSize, vertexData.cachePos1, lruCacheSize);
|
vertexData.score = FindVertexScore(vertexData.activeFaceListSize, vertexData.cachePos1, lruCacheSize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// move the rest of the old verts in the cache down and compute their new scores
|
// move the rest of the old verts in the cache down and compute their new scores
|
||||||
for (uint c0 = 0; c0 < entriesInCache0; ++c0)
|
for (uint c0 = 0; c0 < entriesInCache0; ++c0)
|
||||||
{
|
{
|
||||||
uint16 index = cache0[c0];
|
uint16 index = cache0[c0];
|
||||||
OptimizeVertexData& vertexData = vertexDataList[index];
|
OptimizeVertexData& vertexData = vertexDataList[index];
|
||||||
|
|
||||||
if (vertexData.cachePos1 >= entriesInCache1)
|
if (vertexData.cachePos1 >= entriesInCache1)
|
||||||
{
|
{
|
||||||
vertexData.cachePos1 = entriesInCache1;
|
vertexData.cachePos1 = entriesInCache1;
|
||||||
cache1[entriesInCache1++] = index;
|
cache1[entriesInCache1++] = index;
|
||||||
vertexData.score = FindVertexScore(vertexData.activeFaceListSize, vertexData.cachePos1, lruCacheSize);
|
vertexData.score = FindVertexScore(vertexData.activeFaceListSize, vertexData.cachePos1, lruCacheSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the best scoring triangle in the current cache (including up to 3 that were just evicted)
|
// find the best scoring triangle in the current cache (including up to 3 that were just evicted)
|
||||||
bestScore = -1.f;
|
bestScore = -1.f;
|
||||||
for (uint c1 = 0; c1 < entriesInCache1; ++c1)
|
for (uint c1 = 0; c1 < entriesInCache1; ++c1)
|
||||||
{
|
{
|
||||||
uint16 index = cache1[c1];
|
uint16 index = cache1[c1];
|
||||||
OptimizeVertexData& vertexData = vertexDataList[index];
|
OptimizeVertexData& vertexData = vertexDataList[index];
|
||||||
vertexData.cachePos0 = vertexData.cachePos1;
|
vertexData.cachePos0 = vertexData.cachePos1;
|
||||||
vertexData.cachePos1 = kEvictedCacheIndex;
|
vertexData.cachePos1 = kEvictedCacheIndex;
|
||||||
for (uint j=0; j<vertexData.activeFaceListSize; ++j)
|
for (uint j=0; j<vertexData.activeFaceListSize; ++j)
|
||||||
{
|
{
|
||||||
uint face = activeFaceList[vertexData.activeFaceListStart+j];
|
uint face = activeFaceList[vertexData.activeFaceListStart+j];
|
||||||
float faceScore = 0.f;
|
float faceScore = 0.f;
|
||||||
for (uint v=0; v<3; v++)
|
for (uint v=0; v<3; v++)
|
||||||
{
|
{
|
||||||
uint16 faceIndex = indexList[face+v];
|
uint16 faceIndex = indexList[face+v];
|
||||||
OptimizeVertexData& faceVertexData = vertexDataList[faceIndex];
|
OptimizeVertexData& faceVertexData = vertexDataList[faceIndex];
|
||||||
faceScore += faceVertexData.score;
|
faceScore += faceVertexData.score;
|
||||||
}
|
}
|
||||||
if (faceScore > bestScore)
|
if (faceScore > bestScore)
|
||||||
{
|
{
|
||||||
bestScore = faceScore;
|
bestScore = faceScore;
|
||||||
bestFace = face;
|
bestFace = face;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::swap(cache0, cache1);
|
std::swap(cache0, cache1);
|
||||||
entriesInCache0 = std::min(entriesInCache1, lruCacheSize);
|
entriesInCache0 = std::min(entriesInCache1, lruCacheSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Forsyth
|
} // namespace Forsyth
|
||||||
|
|
|
@ -1,44 +1,44 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// This is an implementation of Tom Forsyth's "Linear-Speed Vertex Cache
|
// This is an implementation of Tom Forsyth's "Linear-Speed Vertex Cache
|
||||||
// Optimization" algorithm as described here:
|
// Optimization" algorithm as described here:
|
||||||
// http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
|
// http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
|
||||||
//
|
//
|
||||||
// This code was authored and released into the public domain by
|
// This code was authored and released into the public domain by
|
||||||
// Adrian Stone (stone@gameangst.com).
|
// Adrian Stone (stone@gameangst.com).
|
||||||
//
|
//
|
||||||
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER
|
// SHALL ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
// LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||||
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef __FORSYTH_TRIANGLE_REORDER__
|
#ifndef __FORSYTH_TRIANGLE_REORDER__
|
||||||
#define __FORSYTH_TRIANGLE_REORDER__
|
#define __FORSYTH_TRIANGLE_REORDER__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace Forsyth
|
namespace Forsyth
|
||||||
{
|
{
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// OptimizeFaces
|
// OptimizeFaces
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// indexList
|
// indexList
|
||||||
// input index list
|
// input index list
|
||||||
// indexCount
|
// indexCount
|
||||||
// the number of indices in the list
|
// the number of indices in the list
|
||||||
// vertexCount
|
// vertexCount
|
||||||
// the largest index value in indexList
|
// the largest index value in indexList
|
||||||
// newIndexList
|
// newIndexList
|
||||||
// a pointer to a preallocated buffer the same size as indexList to
|
// a pointer to a preallocated buffer the same size as indexList to
|
||||||
// hold the optimized index list
|
// hold the optimized index list
|
||||||
// lruCacheSize
|
// lruCacheSize
|
||||||
// the size of the simulated post-transform cache (max:64)
|
// the size of the simulated post-transform cache (max:64)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void OptimizeFaces(const uint16_t* indexList, uint32_t indexCount, uint32_t vertexCount, uint16_t* newIndexList, uint16_t lruCacheSize);
|
void OptimizeFaces(const uint16_t* indexList, uint32_t indexCount, uint32_t vertexCount, uint16_t* newIndexList, uint16_t lruCacheSize);
|
||||||
|
|
||||||
} // namespace Forsyth
|
} // namespace Forsyth
|
||||||
|
|
||||||
#endif // __FORSYTH_TRIANGLE_REORDER__
|
#endif // __FORSYTH_TRIANGLE_REORDER__
|
||||||
|
|
134
3rdparty/glext/gl/GRemedyGLExtensions.h
vendored
134
3rdparty/glext/gl/GRemedyGLExtensions.h
vendored
|
@ -1,67 +1,67 @@
|
||||||
// ------------------------------ GRemdeyGLExtensions.h ------------------------------
|
// ------------------------------ GRemdeyGLExtensions.h ------------------------------
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
// © 2004 - 2012 Advanced Micro Devices, Inc. All rights reserved.
|
// © 2004 - 2012 Advanced Micro Devices, Inc. All rights reserved.
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef __GREMDEYGLEXTENSIONS
|
#ifndef __GREMDEYGLEXTENSIONS
|
||||||
#define __GREMDEYGLEXTENSIONS
|
#define __GREMDEYGLEXTENSIONS
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
|
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef APIENTRY
|
#ifndef APIENTRY
|
||||||
#define APIENTRY
|
#define APIENTRY
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef APIENTRYP
|
#ifndef APIENTRYP
|
||||||
#define APIENTRYP APIENTRY *
|
#define APIENTRYP APIENTRY *
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GLAPI
|
#ifndef GLAPI
|
||||||
#define GLAPI extern
|
#define GLAPI extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ----------------------- GL_GREMEDY_string_marker ----------------------- */
|
/* ----------------------- GL_GREMEDY_string_marker ----------------------- */
|
||||||
|
|
||||||
#ifndef GL_GREMEDY_string_marker
|
#ifndef GL_GREMEDY_string_marker
|
||||||
#define GL_GREMEDY_string_marker 1
|
#define GL_GREMEDY_string_marker 1
|
||||||
|
|
||||||
#ifdef GL_GLEXT_PROTOTYPES
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
GLAPI void APIENTRY glStringMarkerGREMEDY(GLsizei len, const GLvoid *string);
|
GLAPI void APIENTRY glStringMarkerGREMEDY(GLsizei len, const GLvoid *string);
|
||||||
#endif /* GL_GLEXT_PROTOTYPES */
|
#endif /* GL_GLEXT_PROTOTYPES */
|
||||||
|
|
||||||
typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC)(GLsizei len, const GLvoid *string);
|
typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC)(GLsizei len, const GLvoid *string);
|
||||||
|
|
||||||
#endif /* GL_GREMEDY_string_marker */
|
#endif /* GL_GREMEDY_string_marker */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------- GL_GREMEDY_frame_terminator ----------------------- */
|
/* ----------------------- GL_GREMEDY_frame_terminator ----------------------- */
|
||||||
|
|
||||||
#ifndef GL_GREMEDY_frame_terminator
|
#ifndef GL_GREMEDY_frame_terminator
|
||||||
#define GL_GREMEDY_frame_terminator 1
|
#define GL_GREMEDY_frame_terminator 1
|
||||||
|
|
||||||
#ifdef GL_GLEXT_PROTOTYPES
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
GLAPI void APIENTRY glFrameTerminatorGREMEDY(void);
|
GLAPI void APIENTRY glFrameTerminatorGREMEDY(void);
|
||||||
#endif /* GL_GLEXT_PROTOTYPES */
|
#endif /* GL_GLEXT_PROTOTYPES */
|
||||||
|
|
||||||
typedef void (APIENTRYP PFNGLFRAMETERMINATORGREMEDYPROC)(void);
|
typedef void (APIENTRYP PFNGLFRAMETERMINATORGREMEDYPROC)(void);
|
||||||
|
|
||||||
#endif /* GL_GREMEDY_frame_terminator */
|
#endif /* GL_GREMEDY_frame_terminator */
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* __GREMDEYGLEXTENSIONS */
|
#endif /* __GREMDEYGLEXTENSIONS */
|
||||||
|
|
602
README.md
602
README.md
|
@ -1,301 +1,301 @@
|
||||||
bgfx
|
bgfx
|
||||||
====
|
====
|
||||||
|
|
||||||
What is it?
|
What is it?
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
Cross-platform rendering library.
|
Cross-platform rendering library.
|
||||||
|
|
||||||
Supported rendering backends:
|
Supported rendering backends:
|
||||||
|
|
||||||
* OpenGL 2.1
|
* OpenGL 2.1
|
||||||
* OpenGL ES 2
|
* OpenGL ES 2
|
||||||
* OpenGL ES 3
|
* OpenGL ES 3
|
||||||
* Direct3D 9
|
* Direct3D 9
|
||||||
* Direct3D 11
|
* Direct3D 11
|
||||||
|
|
||||||
Platforms:
|
Platforms:
|
||||||
|
|
||||||
* Windows
|
* Windows
|
||||||
* Linux
|
* Linux
|
||||||
* Android
|
* Android
|
||||||
* Native Client
|
* Native Client
|
||||||
* JavaScript (via Emscripten)
|
* JavaScript (via Emscripten)
|
||||||
* OSX
|
* OSX
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
------------
|
------------
|
||||||
|
|
||||||
[https://github.com/bkaradzic/bx](https://github.com/bkaradzic/bx)
|
[https://github.com/bkaradzic/bx](https://github.com/bkaradzic/bx)
|
||||||
|
|
||||||
Optional:
|
Optional:
|
||||||
[https://github.com/mendsley/tinystl](https://github.com/mendsley/tinystl)
|
[https://github.com/mendsley/tinystl](https://github.com/mendsley/tinystl)
|
||||||
|
|
||||||
Building
|
Building
|
||||||
--------
|
--------
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
Premake 4.4 beta4
|
Premake 4.4 beta4
|
||||||
[http://industriousone.com/premake/download](http://industriousone.com/premake/download)
|
[http://industriousone.com/premake/download](http://industriousone.com/premake/download)
|
||||||
|
|
||||||
GNU make
|
GNU make
|
||||||
Windows users download GNU make utility from:
|
Windows users download GNU make utility from:
|
||||||
[http://gnuwin32.sourceforge.net/packages/make.htm](http://gnuwin32.sourceforge.net/packages/make.htm)
|
[http://gnuwin32.sourceforge.net/packages/make.htm](http://gnuwin32.sourceforge.net/packages/make.htm)
|
||||||
|
|
||||||
### Getting source
|
### Getting source
|
||||||
|
|
||||||
git clone git://github.com/bkaradzic/bx.git
|
git clone git://github.com/bkaradzic/bx.git
|
||||||
git clone git://github.com/bkaradzic/bgfx.git
|
git clone git://github.com/bkaradzic/bgfx.git
|
||||||
cd bgfx
|
cd bgfx
|
||||||
make
|
make
|
||||||
|
|
||||||
After calling make, .build/projects/* directory will be generated. All
|
After calling make, .build/projects/* directory will be generated. All
|
||||||
intermediate files generated by compiler will be inside .build directory
|
intermediate files generated by compiler will be inside .build directory
|
||||||
structure. Deleting .build directory at any time is safe.
|
structure. Deleting .build directory at any time is safe.
|
||||||
|
|
||||||
### Prerequisites for Linux
|
### Prerequisites for Linux
|
||||||
|
|
||||||
sudo apt-get install libgl1-mesa-dev
|
sudo apt-get install libgl1-mesa-dev
|
||||||
|
|
||||||
### Prerequisites for Windows
|
### Prerequisites for Windows
|
||||||
|
|
||||||
When building on Windows, you have to set DXSDK_DIR environment variable to
|
When building on Windows, you have to set DXSDK_DIR environment variable to
|
||||||
point to DirectX SDK directory.
|
point to DirectX SDK directory.
|
||||||
|
|
||||||
setx DXSDK_DIR <path to DirectX SDK directory>
|
setx DXSDK_DIR <path to DirectX SDK directory>
|
||||||
|
|
||||||
If you're building with Visual Studio 2008, you'll need TR1 support from:
|
If you're building with Visual Studio 2008, you'll need TR1 support from:
|
||||||
[Visual C++ 2008 Feature Pack Release](https://www.microsoft.com/en-us/download/details.aspx?id=6922)
|
[Visual C++ 2008 Feature Pack Release](https://www.microsoft.com/en-us/download/details.aspx?id=6922)
|
||||||
|
|
||||||
If you're building with MinGW/TDM compiler on Windows make DirectX SDK
|
If you're building with MinGW/TDM compiler on Windows make DirectX SDK
|
||||||
directory link to directory without spaces in the path.
|
directory link to directory without spaces in the path.
|
||||||
|
|
||||||
mklink /D <path to DirectX SDK directory> c:\dxsdk
|
mklink /D <path to DirectX SDK directory> c:\dxsdk
|
||||||
setx DXSDK_DIR c:\dxsdk
|
setx DXSDK_DIR c:\dxsdk
|
||||||
|
|
||||||
### Prerequisites for Native Client (Pepper 22) on Windows
|
### Prerequisites for Native Client (Pepper 22) on Windows
|
||||||
|
|
||||||
Download Native Client SDK from:
|
Download Native Client SDK from:
|
||||||
[https://developers.google.com/native-client/sdk/download](https://developers.google.com/native-client/sdk/download)
|
[https://developers.google.com/native-client/sdk/download](https://developers.google.com/native-client/sdk/download)
|
||||||
|
|
||||||
setx NACL <path to Native Client SDK directory>\toolchain\win_x86_newlib
|
setx NACL <path to Native Client SDK directory>\toolchain\win_x86_newlib
|
||||||
|
|
||||||
### Building
|
### Building
|
||||||
|
|
||||||
Visual Studio 2008 command line:
|
Visual Studio 2008 command line:
|
||||||
|
|
||||||
make vs2008-release64
|
make vs2008-release64
|
||||||
|
|
||||||
Visual Studio 2008 IDE:
|
Visual Studio 2008 IDE:
|
||||||
|
|
||||||
start .build/projects/vs2008/bgfx.sln
|
start .build/projects/vs2008/bgfx.sln
|
||||||
|
|
||||||
Linux 64-bit:
|
Linux 64-bit:
|
||||||
|
|
||||||
make linux-release64
|
make linux-release64
|
||||||
|
|
||||||
Other platforms:
|
Other platforms:
|
||||||
|
|
||||||
make <configuration>
|
make <configuration>
|
||||||
|
|
||||||
Configuration is `<platform>-<debug/release><32/64>`. For example:
|
Configuration is `<platform>-<debug/release><32/64>`. For example:
|
||||||
|
|
||||||
linux-release32, nacl-debug64, android-release32, etc.
|
linux-release32, nacl-debug64, android-release32, etc.
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
|
|
||||||
### 00-helloworld
|
### 00-helloworld
|
||||||
Initialization and debug text.
|
Initialization and debug text.
|
||||||
|
|
||||||
### 01-cubes
|
### 01-cubes
|
||||||
Rendering simple static mesh.
|
Rendering simple static mesh.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 02-metaballs
|
### 02-metaballs
|
||||||
Rendering with transient buffers.
|
Rendering with transient buffers.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 03-raymarch
|
### 03-raymarch
|
||||||
Updating shader uniforms.
|
Updating shader uniforms.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 04-mesh
|
### 04-mesh
|
||||||
Loading meshes.
|
Loading meshes.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 05-instancing
|
### 05-instancing
|
||||||
Geometry instancing.
|
Geometry instancing.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 06-bump
|
### 06-bump
|
||||||
Loading textures.
|
Loading textures.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 07-callback
|
### 07-callback
|
||||||
Implementing application specific callbacks for taking screen shots, caching
|
Implementing application specific callbacks for taking screen shots, caching
|
||||||
OpenGL binary shaders, and video capture.
|
OpenGL binary shaders, and video capture.
|
||||||
|
|
||||||
### 08-update
|
### 08-update
|
||||||
Updating textures.
|
Updating textures.
|
||||||
|
|
||||||
Internals
|
Internals
|
||||||
---------
|
---------
|
||||||
|
|
||||||
bgfx is using sort-based draw call bucketing. This means that submition order
|
bgfx is using sort-based draw call bucketing. This means that submition order
|
||||||
doesn't necessarily matches the rendering order, but on the low-level they
|
doesn't necessarily matches the rendering order, but on the low-level they
|
||||||
will be sorted and ordered correctly. On the high level this allows
|
will be sorted and ordered correctly. On the high level this allows
|
||||||
more optimal way of submitting draw calls for all passes at one place, and on
|
more optimal way of submitting draw calls for all passes at one place, and on
|
||||||
the low-level this allows better optimization of rendering order. This sometimes
|
the low-level this allows better optimization of rendering order. This sometimes
|
||||||
creates undesired results usually for GUI rendering, where draw order should
|
creates undesired results usually for GUI rendering, where draw order should
|
||||||
usually match submit order. bgfx provides way to enable sequential rendering for
|
usually match submit order. bgfx provides way to enable sequential rendering for
|
||||||
these cases (see `bgfx::setViewSeq`).
|
these cases (see `bgfx::setViewSeq`).
|
||||||
|
|
||||||
Internally all low-level rendering draw calls are issued inside single function
|
Internally all low-level rendering draw calls are issued inside single function
|
||||||
`Context::rendererSubmit`. This function exist inside each renderer backend
|
`Context::rendererSubmit`. This function exist inside each renderer backend
|
||||||
implementation.
|
implementation.
|
||||||
|
|
||||||
More detailed description of sort-based draw call bucketing can be found at:
|
More detailed description of sort-based draw call bucketing can be found at:
|
||||||
[Order your graphics draw calls around!](http://realtimecollisiondetection.net/blog/?p=86)
|
[Order your graphics draw calls around!](http://realtimecollisiondetection.net/blog/?p=86)
|
||||||
|
|
||||||
Customization
|
Customization
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
By default each platform has sane default values. For example on Windows default
|
By default each platform has sane default values. For example on Windows default
|
||||||
renderer is DirectX9, and on Linux it is OpenGL 2.1. On Windows platform all
|
renderer is DirectX9, and on Linux it is OpenGL 2.1. On Windows platform all
|
||||||
rendering backends are available. For OpenGL ES on desktop you can find more
|
rendering backends are available. For OpenGL ES on desktop you can find more
|
||||||
information at:-
|
information at:-
|
||||||
[OpenGL ES 2.0 and EGL on desktop](http://www.g-truc.net/post-0457.html)
|
[OpenGL ES 2.0 and EGL on desktop](http://www.g-truc.net/post-0457.html)
|
||||||
|
|
||||||
If you're targeting specific mobile hardware, you can find GLES support in their
|
If you're targeting specific mobile hardware, you can find GLES support in their
|
||||||
official SDKs:
|
official SDKs:
|
||||||
[Adreno SDK](http://developer.qualcomm.com/mobile-development/mobile-technologies/gaming-graphics-optimization-adreno/tools-and-resources),
|
[Adreno SDK](http://developer.qualcomm.com/mobile-development/mobile-technologies/gaming-graphics-optimization-adreno/tools-and-resources),
|
||||||
[Mali SDK](http://www.malideveloper.com/),
|
[Mali SDK](http://www.malideveloper.com/),
|
||||||
[PowerVR SDK](http://www.imgtec.com/powervr/insider/sdkdownloads/).
|
[PowerVR SDK](http://www.imgtec.com/powervr/insider/sdkdownloads/).
|
||||||
|
|
||||||
All configuration settings are located inside [src/config.h](https://github.com/bkaradzic/bgfx/blob/master/src/config.h).
|
All configuration settings are located inside [src/config.h](https://github.com/bkaradzic/bgfx/blob/master/src/config.h).
|
||||||
|
|
||||||
Every `BGFX_CONFIG_*` setting can be changed by passing defines thru compiler
|
Every `BGFX_CONFIG_*` setting can be changed by passing defines thru compiler
|
||||||
switches. For example setting preprocessor define `BGFX_CONFIG_RENDERER_OPENGL=1`
|
switches. For example setting preprocessor define `BGFX_CONFIG_RENDERER_OPENGL=1`
|
||||||
on Windows will change backend renderer to OpenGL 2.1. on Windows. Since
|
on Windows will change backend renderer to OpenGL 2.1. on Windows. Since
|
||||||
rendering APIs are platform specific, this obviously won't work nor make sense
|
rendering APIs are platform specific, this obviously won't work nor make sense
|
||||||
in all cases. Certain platforms have only single choice, for example the Native
|
in all cases. Certain platforms have only single choice, for example the Native
|
||||||
Client works only with OpenGL ES 2.0 renderer, using anything other than that
|
Client works only with OpenGL ES 2.0 renderer, using anything other than that
|
||||||
will result in build errors.
|
will result in build errors.
|
||||||
|
|
||||||
Tools
|
Tools
|
||||||
-----
|
-----
|
||||||
|
|
||||||
### Shader Compiler (shaderc)
|
### Shader Compiler (shaderc)
|
||||||
|
|
||||||
bgfx cross-platform shader language is based on GLSL syntax. It's uses ANSI C
|
bgfx cross-platform shader language is based on GLSL syntax. It's uses ANSI C
|
||||||
preprocessor to transform GLSL like language syntax into HLSL. This technique
|
preprocessor to transform GLSL like language syntax into HLSL. This technique
|
||||||
has certain drawbacks, but overall it's simple and allows quick authoring of
|
has certain drawbacks, but overall it's simple and allows quick authoring of
|
||||||
cross-platform shaders.
|
cross-platform shaders.
|
||||||
|
|
||||||
### Texture Compiler (texturec)
|
### Texture Compiler (texturec)
|
||||||
|
|
||||||
This tool doesn't currently exist. Use nvdxt, or any other tool that produces
|
This tool doesn't currently exist. Use nvdxt, or any other tool that produces
|
||||||
DDS textures for now.
|
DDS textures for now.
|
||||||
|
|
||||||
### Geometry Compiler (geometryc)
|
### Geometry Compiler (geometryc)
|
||||||
|
|
||||||
Converts Wavefront .obj mesh file to format optimal for using with bgfx.
|
Converts Wavefront .obj mesh file to format optimal for using with bgfx.
|
||||||
|
|
||||||
Todo
|
Todo
|
||||||
----
|
----
|
||||||
|
|
||||||
- Multiple render targets.
|
- Multiple render targets.
|
||||||
- BlendFuncSeparate and BlendEquationSeparate.
|
- BlendFuncSeparate and BlendEquationSeparate.
|
||||||
- Blit between textures.
|
- Blit between textures.
|
||||||
- Occlusion queries.
|
- Occlusion queries.
|
||||||
- iOS platforms.
|
- iOS platforms.
|
||||||
- DX11: MSAA.
|
- DX11: MSAA.
|
||||||
- GL: MSAA.
|
- GL: MSAA.
|
||||||
- Fullscreen mode.
|
- Fullscreen mode.
|
||||||
|
|
||||||
Notice
|
Notice
|
||||||
------
|
------
|
||||||
|
|
||||||
This is alpha software, and it lacks documentation and examples. If you're
|
This is alpha software, and it lacks documentation and examples. If you're
|
||||||
interested to use it in your project, please let me know.
|
interested to use it in your project, please let me know.
|
||||||
|
|
||||||
Contact
|
Contact
|
||||||
-------
|
-------
|
||||||
|
|
||||||
[@bkaradzic](https://twitter.com/bkaradzic)
|
[@bkaradzic](https://twitter.com/bkaradzic)
|
||||||
http://www.stuckingeometry.com
|
http://www.stuckingeometry.com
|
||||||
|
|
||||||
Project page
|
Project page
|
||||||
https://github.com/bkaradzic/bgfx
|
https://github.com/bkaradzic/bgfx
|
||||||
|
|
||||||
3rd Party Libraries
|
3rd Party Libraries
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
All required 3rd party libraries are included in bgfx repository in [3rdparty/](https://github.com/bkaradzic/bgfx/tree/master/3rdparty)
|
All required 3rd party libraries are included in bgfx repository in [3rdparty/](https://github.com/bkaradzic/bgfx/tree/master/3rdparty)
|
||||||
directory.
|
directory.
|
||||||
|
|
||||||
### edtaa3 (MIT)
|
### edtaa3 (MIT)
|
||||||
|
|
||||||
Contour Rendering by Distance Fields
|
Contour Rendering by Distance Fields
|
||||||
|
|
||||||
https://github.com/OpenGLInsights/OpenGLInsightsCode/tree/master/Chapter%2012%202D%20Shape%20Rendering%20by%20Distance%20Fields
|
https://github.com/OpenGLInsights/OpenGLInsightsCode/tree/master/Chapter%2012%202D%20Shape%20Rendering%20by%20Distance%20Fields
|
||||||
|
|
||||||
### fcpp (BSD)
|
### fcpp (BSD)
|
||||||
|
|
||||||
Frexx C preprocessor
|
Frexx C preprocessor
|
||||||
|
|
||||||
https://github.com/bagder/fcpp
|
https://github.com/bagder/fcpp
|
||||||
|
|
||||||
### Forsyth Triangle Order Optimizer (Public Domain)
|
### Forsyth Triangle Order Optimizer (Public Domain)
|
||||||
|
|
||||||
http://gameangst.com/?p=9
|
http://gameangst.com/?p=9
|
||||||
|
|
||||||
### glsl-optimizer (MIT)
|
### glsl-optimizer (MIT)
|
||||||
|
|
||||||
GLSL optimizer based on Mesa's GLSL compiler. Used in Unity for mobile shader
|
GLSL optimizer based on Mesa's GLSL compiler. Used in Unity for mobile shader
|
||||||
optimization.
|
optimization.
|
||||||
|
|
||||||
https://github.com/aras-p/glsl-optimizer
|
https://github.com/aras-p/glsl-optimizer
|
||||||
|
|
||||||
### stb_image (Public Domain)
|
### stb_image (Public Domain)
|
||||||
|
|
||||||
http://nothings.org/stb_image.c
|
http://nothings.org/stb_image.c
|
||||||
|
|
||||||
Contributors
|
Contributors
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Garett Bass ([@gtbass](https://github.com/gtbass)) - OSX port.
|
Garett Bass ([@gtbass](https://github.com/gtbass)) - OSX port.
|
||||||
|
|
||||||
License (BSD 2-clause)
|
License (BSD 2-clause)
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
Copyright 2010-2013 Branimir Karadzic. All rights reserved.
|
Copyright 2010-2013 Branimir Karadzic. All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice,
|
1. Redistributions of source code must retain the above copyright notice,
|
||||||
this list of conditions and the following disclaimer.
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR
|
THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR
|
||||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <bgfx.h>
|
#include <bgfx.h>
|
||||||
#include <bx/bx.h>
|
#include <bx/bx.h>
|
||||||
#include "../common/entry.h"
|
#include "../common/entry.h"
|
||||||
#include "../common/dbg.h"
|
#include "../common/dbg.h"
|
||||||
#include "../common/processevents.h"
|
#include "../common/processevents.h"
|
||||||
|
|
||||||
int _main_(int _argc, char** _argv)
|
int _main_(int _argc, char** _argv)
|
||||||
{
|
{
|
||||||
uint32_t width = 1280;
|
uint32_t width = 1280;
|
||||||
uint32_t height = 720;
|
uint32_t height = 720;
|
||||||
uint32_t debug = BGFX_DEBUG_TEXT;
|
uint32_t debug = BGFX_DEBUG_TEXT;
|
||||||
|
@ -20,36 +20,36 @@ int _main_(int _argc, char** _argv)
|
||||||
|
|
||||||
// Enable debug text.
|
// Enable debug text.
|
||||||
bgfx::setDebug(debug);
|
bgfx::setDebug(debug);
|
||||||
|
|
||||||
// Set view 0 clear state.
|
// Set view 0 clear state.
|
||||||
bgfx::setViewClear(0
|
bgfx::setViewClear(0
|
||||||
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
||||||
, 0x303030ff
|
, 0x303030ff
|
||||||
, 1.0f
|
, 1.0f
|
||||||
, 0
|
, 0
|
||||||
);
|
);
|
||||||
|
|
||||||
while (!processEvents(width, height, debug) )
|
while (!processEvents(width, height, debug) )
|
||||||
{
|
{
|
||||||
// Set view 0 default viewport.
|
// Set view 0 default viewport.
|
||||||
bgfx::setViewRect(0, 0, 0, width, height);
|
bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
|
||||||
// This dummy draw call is here to make sure that view 0 is cleared
|
// This dummy draw call is here to make sure that view 0 is cleared
|
||||||
// if no other draw calls are submitted to view 0.
|
// if no other draw calls are submitted to view 0.
|
||||||
bgfx::submit(0);
|
bgfx::submit(0);
|
||||||
|
|
||||||
// Use debug font to print information about this example.
|
// Use debug font to print information about this example.
|
||||||
bgfx::dbgTextClear();
|
bgfx::dbgTextClear();
|
||||||
bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/00-helloworld");
|
bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/00-helloworld");
|
||||||
bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Initialization and debug text.");
|
bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Initialization and debug text.");
|
||||||
|
|
||||||
// Advance to next frame. Rendering thread will be kicked to
|
// Advance to next frame. Rendering thread will be kicked to
|
||||||
// process submitted rendering primitives.
|
// process submitted rendering primitives.
|
||||||
bgfx::frame();
|
bgfx::frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown bgfx.
|
// Shutdown bgfx.
|
||||||
bgfx::shutdown();
|
bgfx::shutdown();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,16 +96,16 @@ static const bgfx::Memory* loadShader(const char* _name)
|
||||||
|
|
||||||
int _main_(int _argc, char** _argv)
|
int _main_(int _argc, char** _argv)
|
||||||
{
|
{
|
||||||
uint32_t width = 1280;
|
uint32_t width = 1280;
|
||||||
uint32_t height = 720;
|
uint32_t height = 720;
|
||||||
uint32_t debug = BGFX_DEBUG_TEXT;
|
uint32_t debug = BGFX_DEBUG_TEXT;
|
||||||
|
|
||||||
bgfx::init();
|
bgfx::init();
|
||||||
bgfx::reset(width, height);
|
bgfx::reset(width, height);
|
||||||
|
|
||||||
// Enable debug text.
|
// Enable debug text.
|
||||||
bgfx::setDebug(debug);
|
bgfx::setDebug(debug);
|
||||||
|
|
||||||
// Set view 0 clear state.
|
// Set view 0 clear state.
|
||||||
bgfx::setViewClear(0
|
bgfx::setViewClear(0
|
||||||
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
||||||
|
@ -171,11 +171,11 @@ int _main_(int _argc, char** _argv)
|
||||||
bgfx::destroyVertexShader(vsh);
|
bgfx::destroyVertexShader(vsh);
|
||||||
bgfx::destroyFragmentShader(fsh);
|
bgfx::destroyFragmentShader(fsh);
|
||||||
|
|
||||||
while (!processEvents(width, height, debug) )
|
while (!processEvents(width, height, debug) )
|
||||||
{
|
{
|
||||||
// Set view 0 default viewport.
|
// Set view 0 default viewport.
|
||||||
bgfx::setViewRect(0, 0, 0, width, height);
|
bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
|
||||||
// This dummy draw call is here to make sure that view 0 is cleared
|
// This dummy draw call is here to make sure that view 0 is cleared
|
||||||
// if no other draw calls are submitted to view 0.
|
// if no other draw calls are submitted to view 0.
|
||||||
bgfx::submit(0);
|
bgfx::submit(0);
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
$input v_color0
|
$input v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_FragColor = v_color0;
|
gl_FragColor = v_color0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
vec3 a_position : POSITION;
|
vec3 a_position : POSITION;
|
||||||
vec4 a_color0 : COLOR0;
|
vec4 a_color0 : COLOR0;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
$input a_position, a_color0
|
$input a_position, a_color0
|
||||||
$output v_color0
|
$output v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||||
v_color0 = a_color0;
|
v_color0 = a_color0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
$input v_normal, v_color0
|
$input v_normal, v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 lightDir = vec3(0.0, 0.0, -1.0);
|
vec3 lightDir = vec3(0.0, 0.0, -1.0);
|
||||||
float ndotl = max(dot(normalize(v_normal), lightDir), 0.0);
|
float ndotl = max(dot(normalize(v_normal), lightDir), 0.0);
|
||||||
float spec = pow(ndotl, 30.0);
|
float spec = pow(ndotl, 30.0);
|
||||||
gl_FragColor = pow(pow(v_color0, vec4_splat(2.2) ) * ndotl + spec, vec4_splat(1.0/2.2) );
|
gl_FragColor = pow(pow(v_color0, vec4_splat(2.2) ) * ndotl + spec, vec4_splat(1.0/2.2) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -571,11 +571,11 @@ int _main_(int _argc, char** _argv)
|
||||||
const uint32_t zpitch = DIMS*DIMS;
|
const uint32_t zpitch = DIMS*DIMS;
|
||||||
const float invdim = 1.0f/float(DIMS-1);
|
const float invdim = 1.0f/float(DIMS-1);
|
||||||
|
|
||||||
while (!processEvents(width, height, debug) )
|
while (!processEvents(width, height, debug) )
|
||||||
{
|
{
|
||||||
// Set view 0 default viewport.
|
// Set view 0 default viewport.
|
||||||
bgfx::setViewRect(0, 0, 0, width, height);
|
bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
|
||||||
// This dummy draw call is here to make sure that view 0 is cleared
|
// This dummy draw call is here to make sure that view 0 is cleared
|
||||||
// if no other draw calls are submitted to view 0.
|
// if no other draw calls are submitted to view 0.
|
||||||
bgfx::submit(0);
|
bgfx::submit(0);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
vec3 v_normal : TEXCOORD1 = vec3(0.0, 0.0, 1.0);
|
vec3 v_normal : TEXCOORD1 = vec3(0.0, 0.0, 1.0);
|
||||||
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
vec3 a_position : POSITION;
|
vec3 a_position : POSITION;
|
||||||
vec3 a_normal : NORMAL;
|
vec3 a_normal : NORMAL;
|
||||||
vec4 a_color0 : COLOR0;
|
vec4 a_color0 : COLOR0;
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
$input a_position, a_normal, a_color0
|
$input a_position, a_normal, a_color0
|
||||||
$output v_normal, v_color0
|
$output v_normal, v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||||
v_normal = mul(u_model, vec4(a_normal, 0.0) ).xyz;
|
v_normal = mul(u_model, vec4(a_normal, 0.0) ).xyz;
|
||||||
v_color0 = a_color0;
|
v_color0 = a_color0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,131 +1,131 @@
|
||||||
$input v_color0, v_texcoord0
|
$input v_color0, v_texcoord0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// References:
|
// References:
|
||||||
// Sphere tracing: a geometric method for the antialiased ray tracing of implicit surfaces - John C. Hart
|
// Sphere tracing: a geometric method for the antialiased ray tracing of implicit surfaces - John C. Hart
|
||||||
// http://web.archive.org/web/20110331200546/http://graphics.cs.uiuc.edu/~jch/papers/zeno.pdf
|
// http://web.archive.org/web/20110331200546/http://graphics.cs.uiuc.edu/~jch/papers/zeno.pdf
|
||||||
//
|
//
|
||||||
// Modeling with distance functions
|
// Modeling with distance functions
|
||||||
// http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
// http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
#include "iq_sdf.sh"
|
#include "iq_sdf.sh"
|
||||||
|
|
||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
uniform mat4 u_mtx;
|
uniform mat4 u_mtx;
|
||||||
uniform vec3 u_lightDir;
|
uniform vec3 u_lightDir;
|
||||||
|
|
||||||
float sceneDist(vec3 _pos)
|
float sceneDist(vec3 _pos)
|
||||||
{
|
{
|
||||||
float d1 = udRoundBox(_pos, vec3(2.5, 2.5, 2.5), 0.5);
|
float d1 = udRoundBox(_pos, vec3(2.5, 2.5, 2.5), 0.5);
|
||||||
float d2 = sdSphere(_pos + vec3( 4.0, 0.0, 0.0), 1.0);
|
float d2 = sdSphere(_pos + vec3( 4.0, 0.0, 0.0), 1.0);
|
||||||
float d3 = sdSphere(_pos + vec3(-4.0, 0.0, 0.0), 1.0);
|
float d3 = sdSphere(_pos + vec3(-4.0, 0.0, 0.0), 1.0);
|
||||||
float d4 = sdSphere(_pos + vec3( 0.0, 4.0, 0.0), 1.0);
|
float d4 = sdSphere(_pos + vec3( 0.0, 4.0, 0.0), 1.0);
|
||||||
float d5 = sdSphere(_pos + vec3( 0.0,-4.0, 0.0), 1.0);
|
float d5 = sdSphere(_pos + vec3( 0.0,-4.0, 0.0), 1.0);
|
||||||
float d6 = sdSphere(_pos + vec3( 0.0, 0.0, 4.0), 1.0);
|
float d6 = sdSphere(_pos + vec3( 0.0, 0.0, 4.0), 1.0);
|
||||||
float d7 = sdSphere(_pos + vec3( 0.0, 0.0,-4.0), 1.0);
|
float d7 = sdSphere(_pos + vec3( 0.0, 0.0,-4.0), 1.0);
|
||||||
float dist = min(min(min(min(min(min(d1, d2), d3), d4), d5), d6), d7);
|
float dist = min(min(min(min(min(min(d1, d2), d3), d4), d5), d6), d7);
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 calcNormal(vec3 _pos)
|
vec3 calcNormal(vec3 _pos)
|
||||||
{
|
{
|
||||||
const vec2 delta = vec2(0.002, 0.0);
|
const vec2 delta = vec2(0.002, 0.0);
|
||||||
float nx = sceneDist(_pos + delta.xyy) - sceneDist(_pos - delta.xyy);
|
float nx = sceneDist(_pos + delta.xyy) - sceneDist(_pos - delta.xyy);
|
||||||
float ny = sceneDist(_pos + delta.yxy) - sceneDist(_pos - delta.yxy);
|
float ny = sceneDist(_pos + delta.yxy) - sceneDist(_pos - delta.yxy);
|
||||||
float nz = sceneDist(_pos + delta.yyx) - sceneDist(_pos - delta.yyx);
|
float nz = sceneDist(_pos + delta.yyx) - sceneDist(_pos - delta.yyx);
|
||||||
return normalize(vec3(nx, ny, nz) );
|
return normalize(vec3(nx, ny, nz) );
|
||||||
}
|
}
|
||||||
|
|
||||||
float calcAmbOcc(vec3 _pos, vec3 _normal)
|
float calcAmbOcc(vec3 _pos, vec3 _normal)
|
||||||
{
|
{
|
||||||
float occ = 0.0;
|
float occ = 0.0;
|
||||||
float aostep = 0.2;
|
float aostep = 0.2;
|
||||||
for (int ii = 1; ii < 4; ii++)
|
for (int ii = 1; ii < 4; ii++)
|
||||||
{
|
{
|
||||||
float fi = float(ii);
|
float fi = float(ii);
|
||||||
float dist = sceneDist(_pos + _normal * fi * aostep);
|
float dist = sceneDist(_pos + _normal * fi * aostep);
|
||||||
occ += (fi * aostep - dist) / pow(2.0, fi);
|
occ += (fi * aostep - dist) / pow(2.0, fi);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1.0 - occ;
|
return 1.0 - occ;
|
||||||
}
|
}
|
||||||
|
|
||||||
float trace(vec3 _ray, vec3 _dir, float _maxd)
|
float trace(vec3 _ray, vec3 _dir, float _maxd)
|
||||||
{
|
{
|
||||||
float tt = 0.0;
|
float tt = 0.0;
|
||||||
float epsilon = 0.001;
|
float epsilon = 0.001;
|
||||||
|
|
||||||
for (int ii = 0; ii < 64; ii++)
|
for (int ii = 0; ii < 64; ii++)
|
||||||
{
|
{
|
||||||
float dist = sceneDist(_ray + _dir*tt);
|
float dist = sceneDist(_ray + _dir*tt);
|
||||||
if (dist > epsilon)
|
if (dist > epsilon)
|
||||||
{
|
{
|
||||||
tt += dist;
|
tt += dist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tt < _maxd ? tt : 0.0;
|
return tt < _maxd ? tt : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
|
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
|
||||||
{
|
{
|
||||||
float ndotl = dot(_normal, _lightDir);
|
float ndotl = dot(_normal, _lightDir);
|
||||||
vec3 reflected = _lightDir - 2.0*ndotl*_normal; // reflect(_lightDir, _normal);
|
vec3 reflected = _lightDir - 2.0*ndotl*_normal; // reflect(_lightDir, _normal);
|
||||||
float rdotv = dot(reflected, _viewDir);
|
float rdotv = dot(reflected, _viewDir);
|
||||||
return vec2(ndotl, rdotv);
|
return vec2(ndotl, rdotv);
|
||||||
}
|
}
|
||||||
|
|
||||||
float fresnel(float _ndotl, float _bias, float _pow)
|
float fresnel(float _ndotl, float _bias, float _pow)
|
||||||
{
|
{
|
||||||
float facing = (1.0 - _ndotl);
|
float facing = (1.0 - _ndotl);
|
||||||
return max(_bias + (1.0 - _bias) * pow(facing, _pow), 0.0);
|
return max(_bias + (1.0 - _bias) * pow(facing, _pow), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 lit(float _ndotl, float _rdotv, float _m)
|
vec4 lit(float _ndotl, float _rdotv, float _m)
|
||||||
{
|
{
|
||||||
float diff = max(0.0, _ndotl);
|
float diff = max(0.0, _ndotl);
|
||||||
float spec = step(0.0, _ndotl) * max(0.0, _rdotv * _m);
|
float spec = step(0.0, _ndotl) * max(0.0, _rdotv * _m);
|
||||||
return vec4(1.0, diff, spec, 1.0);
|
return vec4(1.0, diff, spec, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 tmp;
|
vec4 tmp;
|
||||||
tmp = mul(u_mtx, vec4(v_texcoord0.x, v_texcoord0.y, 0.0, 1.0) );
|
tmp = mul(u_mtx, vec4(v_texcoord0.x, v_texcoord0.y, 0.0, 1.0) );
|
||||||
vec3 eye = tmp.xyz/tmp.w;
|
vec3 eye = tmp.xyz/tmp.w;
|
||||||
|
|
||||||
tmp = mul(u_mtx, vec4(v_texcoord0.x, v_texcoord0.y, 1.0, 1.0) );
|
tmp = mul(u_mtx, vec4(v_texcoord0.x, v_texcoord0.y, 1.0, 1.0) );
|
||||||
vec3 at = tmp.xyz/tmp.w;
|
vec3 at = tmp.xyz/tmp.w;
|
||||||
|
|
||||||
float maxd = length(at - eye);
|
float maxd = length(at - eye);
|
||||||
vec3 dir = normalize(at - eye);
|
vec3 dir = normalize(at - eye);
|
||||||
|
|
||||||
float dist = trace(eye, dir, maxd);
|
float dist = trace(eye, dir, maxd);
|
||||||
|
|
||||||
if (dist > 0.5)
|
if (dist > 0.5)
|
||||||
{
|
{
|
||||||
vec3 pos = eye + dir*dist;
|
vec3 pos = eye + dir*dist;
|
||||||
vec3 normal = calcNormal(pos);
|
vec3 normal = calcNormal(pos);
|
||||||
|
|
||||||
vec2 bln = blinn(u_lightDir, normal, dir);
|
vec2 bln = blinn(u_lightDir, normal, dir);
|
||||||
vec4 lc = lit(bln.x, bln.y, 1.0);
|
vec4 lc = lit(bln.x, bln.y, 1.0);
|
||||||
float fres = fresnel(bln.x, 0.2, 5.0);
|
float fres = fresnel(bln.x, 0.2, 5.0);
|
||||||
|
|
||||||
float val = 0.9*lc.y + pow(lc.z, 128.0)*fres;
|
float val = 0.9*lc.y + pow(lc.z, 128.0)*fres;
|
||||||
val *= calcAmbOcc(pos, normal);
|
val *= calcAmbOcc(pos, normal);
|
||||||
val = pow(val, 1.0/2.2);
|
val = pow(val, 1.0/2.2);
|
||||||
|
|
||||||
gl_FragColor = vec4(val, val, val, 1.0);
|
gl_FragColor = vec4(val, val, val, 1.0);
|
||||||
gl_FragDepth = dist/maxd;
|
gl_FragDepth = dist/maxd;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gl_FragColor = v_color0;
|
gl_FragColor = v_color0;
|
||||||
gl_FragDepth = 1.0;
|
gl_FragDepth = 1.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,82 +1,82 @@
|
||||||
//
|
//
|
||||||
// References:
|
// References:
|
||||||
// Modeling with distance functions
|
// Modeling with distance functions
|
||||||
// http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
// http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||||
//
|
//
|
||||||
|
|
||||||
// primitives
|
// primitives
|
||||||
|
|
||||||
float sdSphere(vec3 _pos, float _radius)
|
float sdSphere(vec3 _pos, float _radius)
|
||||||
{
|
{
|
||||||
return length(_pos) - _radius;
|
return length(_pos) - _radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
float udBox(vec3 _pos, vec3 _extents)
|
float udBox(vec3 _pos, vec3 _extents)
|
||||||
{
|
{
|
||||||
return length(max(abs(_pos) - _extents, 0.0) );
|
return length(max(abs(_pos) - _extents, 0.0) );
|
||||||
}
|
}
|
||||||
|
|
||||||
float udRoundBox(vec3 _pos, vec3 _extents, float r)
|
float udRoundBox(vec3 _pos, vec3 _extents, float r)
|
||||||
{
|
{
|
||||||
return length(max(abs(_pos) - _extents, 0.0) ) - r;
|
return length(max(abs(_pos) - _extents, 0.0) ) - r;
|
||||||
}
|
}
|
||||||
|
|
||||||
float sdBox(vec3 _pos, vec3 _extents)
|
float sdBox(vec3 _pos, vec3 _extents)
|
||||||
{
|
{
|
||||||
vec3 d = abs(_pos) - _extents;
|
vec3 d = abs(_pos) - _extents;
|
||||||
return min(max(d.x, max(d.y, d.z) ), 0.0) +
|
return min(max(d.x, max(d.y, d.z) ), 0.0) +
|
||||||
length(max(d, 0.0) );
|
length(max(d, 0.0) );
|
||||||
}
|
}
|
||||||
|
|
||||||
float sdTorus(vec3 _pos, vec2 t)
|
float sdTorus(vec3 _pos, vec2 t)
|
||||||
{
|
{
|
||||||
vec2 q = vec2(length(_pos.xz) - t.x, _pos.y);
|
vec2 q = vec2(length(_pos.xz) - t.x, _pos.y);
|
||||||
return length(q) - t.y;
|
return length(q) - t.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
float sdCylinder(vec3 _pos, vec3 c)
|
float sdCylinder(vec3 _pos, vec3 c)
|
||||||
{
|
{
|
||||||
return length(_pos.xz - c.xy) - c.z;
|
return length(_pos.xz - c.xy) - c.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
float sdCone(vec3 _pos, vec2 c)
|
float sdCone(vec3 _pos, vec2 c)
|
||||||
{
|
{
|
||||||
// c must be normalized
|
// c must be normalized
|
||||||
float q = length(_pos.xy);
|
float q = length(_pos.xy);
|
||||||
return dot(c, vec2(q, _pos.z) );
|
return dot(c, vec2(q, _pos.z) );
|
||||||
}
|
}
|
||||||
|
|
||||||
float sdPlane(vec3 _pos, vec4 n)
|
float sdPlane(vec3 _pos, vec4 n)
|
||||||
{
|
{
|
||||||
// n must be normalized
|
// n must be normalized
|
||||||
return dot(_pos, n.xyz) + n.w;
|
return dot(_pos, n.xyz) + n.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
float sdHexPrism(vec3 _pos, vec2 h)
|
float sdHexPrism(vec3 _pos, vec2 h)
|
||||||
{
|
{
|
||||||
vec3 q = abs(_pos);
|
vec3 q = abs(_pos);
|
||||||
return max(q.z - h.y, max(q.x + q.y * 0.57735, q.y * 1.1547) - h.x);
|
return max(q.z - h.y, max(q.x + q.y * 0.57735, q.y * 1.1547) - h.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
float sdTriPrism(vec3 _pos, vec2 h)
|
float sdTriPrism(vec3 _pos, vec2 h)
|
||||||
{
|
{
|
||||||
vec3 q = abs(_pos);
|
vec3 q = abs(_pos);
|
||||||
return max(q.z - h.y, max(q.x * 0.866025 + _pos.y * 0.5, -_pos.y) - h.x * 0.5);
|
return max(q.z - h.y, max(q.x * 0.866025 + _pos.y * 0.5, -_pos.y) - h.x * 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
// domain operations
|
// domain operations
|
||||||
|
|
||||||
float opUnion(float d1, float d2)
|
float opUnion(float d1, float d2)
|
||||||
{
|
{
|
||||||
return min(d1, d2);
|
return min(d1, d2);
|
||||||
}
|
}
|
||||||
|
|
||||||
float opSubtract(float d1, float d2)
|
float opSubtract(float d1, float d2)
|
||||||
{
|
{
|
||||||
return max(-d1, d2);
|
return max(-d1, d2);
|
||||||
}
|
}
|
||||||
|
|
||||||
float opIntersect(float d1, float d2)
|
float opIntersect(float d1, float d2)
|
||||||
{
|
{
|
||||||
return max(d1, d2);
|
return max(d1, d2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,16 +175,16 @@ void renderScreenSpaceQuad(uint32_t _view, bgfx::ProgramHandle _program, float _
|
||||||
|
|
||||||
int _main_(int _argc, char** _argv)
|
int _main_(int _argc, char** _argv)
|
||||||
{
|
{
|
||||||
uint32_t width = 1280;
|
uint32_t width = 1280;
|
||||||
uint32_t height = 720;
|
uint32_t height = 720;
|
||||||
uint32_t debug = BGFX_DEBUG_TEXT;
|
uint32_t debug = BGFX_DEBUG_TEXT;
|
||||||
|
|
||||||
bgfx::init();
|
bgfx::init();
|
||||||
bgfx::reset(width, height);
|
bgfx::reset(width, height);
|
||||||
|
|
||||||
// Enable debug text.
|
// Enable debug text.
|
||||||
bgfx::setDebug(debug);
|
bgfx::setDebug(debug);
|
||||||
|
|
||||||
// Set view 0 clear state.
|
// Set view 0 clear state.
|
||||||
bgfx::setViewClear(0
|
bgfx::setViewClear(0
|
||||||
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
||||||
|
@ -231,14 +231,14 @@ int _main_(int _argc, char** _argv)
|
||||||
|
|
||||||
bgfx::ProgramHandle raymarching = loadProgram("vs_raymarching", "fs_raymarching");
|
bgfx::ProgramHandle raymarching = loadProgram("vs_raymarching", "fs_raymarching");
|
||||||
|
|
||||||
while (!processEvents(width, height, debug) )
|
while (!processEvents(width, height, debug) )
|
||||||
{
|
{
|
||||||
// Set view 0 default viewport.
|
// Set view 0 default viewport.
|
||||||
bgfx::setViewRect(0, 0, 0, width, height);
|
bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
|
||||||
// Set view 1 default viewport.
|
// Set view 1 default viewport.
|
||||||
bgfx::setViewRect(1, 0, 0, width, height);
|
bgfx::setViewRect(1, 0, 0, width, height);
|
||||||
|
|
||||||
// This dummy draw call is here to make sure that view 0 is cleared
|
// This dummy draw call is here to make sure that view 0 is cleared
|
||||||
// if no other draw calls are submitted to viewZ 0.
|
// if no other draw calls are submitted to viewZ 0.
|
||||||
bgfx::submit(0);
|
bgfx::submit(0);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
||||||
|
|
||||||
vec3 a_position : POSITION;
|
vec3 a_position : POSITION;
|
||||||
vec4 a_color0 : COLOR0;
|
vec4 a_color0 : COLOR0;
|
||||||
vec2 a_texcoord0 : TEXCOORD0;
|
vec2 a_texcoord0 : TEXCOORD0;
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
$input a_position, a_color0, a_texcoord0
|
$input a_position, a_color0, a_texcoord0
|
||||||
$output v_color0, v_texcoord0
|
$output v_color0, v_texcoord0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||||
v_color0 = a_color0;
|
v_color0 = a_color0;
|
||||||
v_texcoord0 = a_texcoord0;
|
v_texcoord0 = a_texcoord0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +1,54 @@
|
||||||
$input v_pos, v_view, v_normal, v_color0
|
$input v_pos, v_view, v_normal, v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
|
|
||||||
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
|
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
|
||||||
{
|
{
|
||||||
float ndotl = dot(_normal, _lightDir);
|
float ndotl = dot(_normal, _lightDir);
|
||||||
vec3 reflected = _lightDir - 2.0*ndotl*_normal; // reflect(_lightDir, _normal);
|
vec3 reflected = _lightDir - 2.0*ndotl*_normal; // reflect(_lightDir, _normal);
|
||||||
float rdotv = dot(reflected, _viewDir);
|
float rdotv = dot(reflected, _viewDir);
|
||||||
return vec2(ndotl, rdotv);
|
return vec2(ndotl, rdotv);
|
||||||
}
|
}
|
||||||
|
|
||||||
float fresnel(float _ndotl, float _bias, float _pow)
|
float fresnel(float _ndotl, float _bias, float _pow)
|
||||||
{
|
{
|
||||||
float facing = (1.0 - _ndotl);
|
float facing = (1.0 - _ndotl);
|
||||||
return max(_bias + (1.0 - _bias) * pow(facing, _pow), 0.0);
|
return max(_bias + (1.0 - _bias) * pow(facing, _pow), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 lit(float _ndotl, float _rdotv, float _m)
|
vec4 lit(float _ndotl, float _rdotv, float _m)
|
||||||
{
|
{
|
||||||
float diff = max(0.0, _ndotl);
|
float diff = max(0.0, _ndotl);
|
||||||
float spec = step(0.0, _ndotl) * max(0.0, _rdotv * _m);
|
float spec = step(0.0, _ndotl) * max(0.0, _rdotv * _m);
|
||||||
return vec4(1.0, diff, spec, 1.0);
|
return vec4(1.0, diff, spec, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 lightDir = vec3(0.0, 0.0, -1.0);
|
vec3 lightDir = vec3(0.0, 0.0, -1.0);
|
||||||
vec3 normal = normalize(v_normal);
|
vec3 normal = normalize(v_normal);
|
||||||
vec3 view = normalize(v_view);
|
vec3 view = normalize(v_view);
|
||||||
vec2 bln = blinn(lightDir, normal, view);
|
vec2 bln = blinn(lightDir, normal, view);
|
||||||
vec4 lc = lit(bln.x, bln.y, 1.0);
|
vec4 lc = lit(bln.x, bln.y, 1.0);
|
||||||
float fres = fresnel(bln.x, 0.2, 5.0);
|
float fres = fresnel(bln.x, 0.2, 5.0);
|
||||||
|
|
||||||
float index = ( (sin(v_pos.x*3.0+u_time)*0.3+0.7)
|
float index = ( (sin(v_pos.x*3.0+u_time)*0.3+0.7)
|
||||||
+ ( cos(v_pos.y*3.0+u_time)*0.4+0.6)
|
+ ( cos(v_pos.y*3.0+u_time)*0.4+0.6)
|
||||||
+ ( cos(v_pos.z*3.0+u_time)*0.2+0.8)
|
+ ( cos(v_pos.z*3.0+u_time)*0.2+0.8)
|
||||||
)*M_PI;
|
)*M_PI;
|
||||||
|
|
||||||
vec3 color = vec3(sin(index*8.0)*0.4 + 0.6
|
vec3 color = vec3(sin(index*8.0)*0.4 + 0.6
|
||||||
, sin(index*4.0)*0.4 + 0.6
|
, sin(index*4.0)*0.4 + 0.6
|
||||||
, sin(index*2.0)*0.4 + 0.6
|
, sin(index*2.0)*0.4 + 0.6
|
||||||
) * v_color0.xyz;
|
) * v_color0.xyz;
|
||||||
|
|
||||||
gl_FragColor.xyz = pow(vec3(0.07, 0.06, 0.08) + color*lc.y + fres*pow(lc.z, 128.0), vec3_splat(1.0/2.2) );
|
gl_FragColor.xyz = pow(vec3(0.07, 0.06, 0.08) + color*lc.y + fres*pow(lc.z, 128.0), vec3_splat(1.0/2.2) );
|
||||||
gl_FragColor.w = 1.0;
|
gl_FragColor.w = 1.0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
vec3 v_normal : NORMAL = vec3(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 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
||||||
vec3 v_pos : TEXCOORD1 = vec3(0.0, 0.0, 0.0);
|
vec3 v_pos : TEXCOORD1 = vec3(0.0, 0.0, 0.0);
|
||||||
vec3 v_view : TEXCOORD2 = vec3(0.0, 0.0, 0.0);
|
vec3 v_view : TEXCOORD2 = vec3(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
vec3 a_position : POSITION;
|
vec3 a_position : POSITION;
|
||||||
vec4 a_color0 : COLOR0;
|
vec4 a_color0 : COLOR0;
|
||||||
vec2 a_texcoord0 : TEXCOORD0;
|
vec2 a_texcoord0 : TEXCOORD0;
|
||||||
vec3 a_normal : NORMAL;
|
vec3 a_normal : NORMAL;
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
$input a_position, a_normal
|
$input a_position, a_normal
|
||||||
$output v_pos, v_view, v_normal, v_color0
|
$output v_pos, v_view, v_normal, v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 pos = a_position;
|
vec3 pos = a_position;
|
||||||
|
|
||||||
float sx = sin(pos.x*32.0+u_time*4.0)*0.5+0.5;
|
float sx = sin(pos.x*32.0+u_time*4.0)*0.5+0.5;
|
||||||
float cy = cos(pos.y*32.0+u_time*4.0)*0.5+0.5;
|
float cy = cos(pos.y*32.0+u_time*4.0)*0.5+0.5;
|
||||||
vec3 displacement = vec3(sx, cy, sx*cy);
|
vec3 displacement = vec3(sx, cy, sx*cy);
|
||||||
vec3 normal = a_normal.xyz*2.0 - 1.0;
|
vec3 normal = a_normal.xyz*2.0 - 1.0;
|
||||||
|
|
||||||
pos = pos + normal*displacement*vec3(0.06, 0.06, 0.06);
|
pos = pos + normal*displacement*vec3(0.06, 0.06, 0.06);
|
||||||
|
|
||||||
gl_Position = mul(u_modelViewProj, vec4(pos, 1.0) );
|
gl_Position = mul(u_modelViewProj, vec4(pos, 1.0) );
|
||||||
v_pos = gl_Position.xyz;
|
v_pos = gl_Position.xyz;
|
||||||
v_view = mul(u_modelView, vec4(pos, 1.0) ).xyz;
|
v_view = mul(u_modelView, vec4(pos, 1.0) ).xyz;
|
||||||
|
|
||||||
v_normal = mul(u_modelView, vec4(normal, 0.0) ).xyz;
|
v_normal = mul(u_modelView, vec4(normal, 0.0) ).xyz;
|
||||||
|
|
||||||
float len = length(displacement)*0.4+0.6;
|
float len = length(displacement)*0.4+0.6;
|
||||||
v_color0 = vec4(len, len, len, 1.0);
|
v_color0 = vec4(len, len, len, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
$input v_color0
|
$input v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_FragColor = v_color0;
|
gl_FragColor = v_color0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,16 +96,16 @@ static const bgfx::Memory* loadShader(const char* _name)
|
||||||
|
|
||||||
int _main_(int _argc, char** _argv)
|
int _main_(int _argc, char** _argv)
|
||||||
{
|
{
|
||||||
uint32_t width = 1280;
|
uint32_t width = 1280;
|
||||||
uint32_t height = 720;
|
uint32_t height = 720;
|
||||||
uint32_t debug = BGFX_DEBUG_TEXT;
|
uint32_t debug = BGFX_DEBUG_TEXT;
|
||||||
|
|
||||||
bgfx::init();
|
bgfx::init();
|
||||||
bgfx::reset(width, height);
|
bgfx::reset(width, height);
|
||||||
|
|
||||||
// Enable debug text.
|
// Enable debug text.
|
||||||
bgfx::setDebug(debug);
|
bgfx::setDebug(debug);
|
||||||
|
|
||||||
// Set view 0 clear state.
|
// Set view 0 clear state.
|
||||||
bgfx::setViewClear(0
|
bgfx::setViewClear(0
|
||||||
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
||||||
|
@ -171,11 +171,11 @@ int _main_(int _argc, char** _argv)
|
||||||
bgfx::destroyVertexShader(vsh);
|
bgfx::destroyVertexShader(vsh);
|
||||||
bgfx::destroyFragmentShader(fsh);
|
bgfx::destroyFragmentShader(fsh);
|
||||||
|
|
||||||
while (!processEvents(width, height, debug) )
|
while (!processEvents(width, height, debug) )
|
||||||
{
|
{
|
||||||
// Set view 0 default viewport.
|
// Set view 0 default viewport.
|
||||||
bgfx::setViewRect(0, 0, 0, width, height);
|
bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
|
||||||
// This dummy draw call is here to make sure that view 0 is cleared
|
// This dummy draw call is here to make sure that view 0 is cleared
|
||||||
// if no other draw calls are submitted to view 0.
|
// if no other draw calls are submitted to view 0.
|
||||||
bgfx::submit(0);
|
bgfx::submit(0);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
vec3 a_position : POSITION;
|
vec3 a_position : POSITION;
|
||||||
vec4 a_color0 : COLOR0;
|
vec4 a_color0 : COLOR0;
|
||||||
vec4 i_data0 : TEXCOORD3;
|
vec4 i_data0 : TEXCOORD3;
|
||||||
vec4 i_data1 : TEXCOORD4;
|
vec4 i_data1 : TEXCOORD4;
|
||||||
vec4 i_data2 : TEXCOORD5;
|
vec4 i_data2 : TEXCOORD5;
|
||||||
vec4 i_data3 : TEXCOORD6;
|
vec4 i_data3 : TEXCOORD6;
|
||||||
vec4 i_data4 : TEXCOORD7;
|
vec4 i_data4 : TEXCOORD7;
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
$input a_position, a_color0, i_data0, i_data1, i_data2, i_data3, i_data4
|
$input a_position, a_color0, i_data0, i_data1, i_data2, i_data3, i_data4
|
||||||
$output v_color0
|
$output v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
mat4 model;
|
mat4 model;
|
||||||
model[0] = i_data0;
|
model[0] = i_data0;
|
||||||
model[1] = i_data1;
|
model[1] = i_data1;
|
||||||
model[2] = i_data2;
|
model[2] = i_data2;
|
||||||
model[3] = i_data3;
|
model[3] = i_data3;
|
||||||
|
|
||||||
vec4 worldPos = instMul(model, vec4(a_position, 1.0) );
|
vec4 worldPos = instMul(model, vec4(a_position, 1.0) );
|
||||||
gl_Position = mul(u_viewProj, worldPos);
|
gl_Position = mul(u_viewProj, worldPos);
|
||||||
v_color0 = a_color0*i_data4;
|
v_color0 = a_color0*i_data4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,17 +151,17 @@ static const bgfx::Memory* loadTexture(const char* _name)
|
||||||
|
|
||||||
void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices)
|
void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices)
|
||||||
{
|
{
|
||||||
struct PosTexcoord
|
struct PosTexcoord
|
||||||
{
|
{
|
||||||
float m_x;
|
float m_x;
|
||||||
float m_y;
|
float m_y;
|
||||||
float m_z;
|
float m_z;
|
||||||
float m_pad0;
|
float m_pad0;
|
||||||
float m_u;
|
float m_u;
|
||||||
float m_v;
|
float m_v;
|
||||||
float m_pad1;
|
float m_pad1;
|
||||||
float m_pad2;
|
float m_pad2;
|
||||||
};
|
};
|
||||||
|
|
||||||
float* tangents = new float[6*_numVertices];
|
float* tangents = new float[6*_numVertices];
|
||||||
memset(tangents, 0, 6*_numVertices*sizeof(float) );
|
memset(tangents, 0, 6*_numVertices*sizeof(float) );
|
||||||
|
@ -252,16 +252,16 @@ void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl
|
||||||
|
|
||||||
int _main_(int _argc, char** _argv)
|
int _main_(int _argc, char** _argv)
|
||||||
{
|
{
|
||||||
uint32_t width = 1280;
|
uint32_t width = 1280;
|
||||||
uint32_t height = 720;
|
uint32_t height = 720;
|
||||||
uint32_t debug = BGFX_DEBUG_TEXT;
|
uint32_t debug = BGFX_DEBUG_TEXT;
|
||||||
|
|
||||||
bgfx::init();
|
bgfx::init();
|
||||||
bgfx::reset(width, height);
|
bgfx::reset(width, height);
|
||||||
|
|
||||||
// Enable debug text.
|
// Enable debug text.
|
||||||
bgfx::setDebug(debug);
|
bgfx::setDebug(debug);
|
||||||
|
|
||||||
// Set view 0 clear state.
|
// Set view 0 clear state.
|
||||||
bgfx::setViewClear(0
|
bgfx::setViewClear(0
|
||||||
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
||||||
|
@ -347,11 +347,11 @@ int _main_(int _argc, char** _argv)
|
||||||
mem = loadTexture("fieldstone-n.dds");
|
mem = loadTexture("fieldstone-n.dds");
|
||||||
bgfx::TextureHandle textureNormal = bgfx::createTexture(mem);
|
bgfx::TextureHandle textureNormal = bgfx::createTexture(mem);
|
||||||
|
|
||||||
while (!processEvents(width, height, debug) )
|
while (!processEvents(width, height, debug) )
|
||||||
{
|
{
|
||||||
// Set view 0 default viewport.
|
// Set view 0 default viewport.
|
||||||
bgfx::setViewRect(0, 0, 0, width, height);
|
bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
|
||||||
// This dummy draw call is here to make sure that view 0 is cleared
|
// This dummy draw call is here to make sure that view 0 is cleared
|
||||||
// if no other draw calls are submitted to view 0.
|
// if no other draw calls are submitted to view 0.
|
||||||
bgfx::submit(0);
|
bgfx::submit(0);
|
||||||
|
|
|
@ -1,79 +1,79 @@
|
||||||
$input v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0
|
$input v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
SAMPLER2D(u_texColor, 0);
|
SAMPLER2D(u_texColor, 0);
|
||||||
SAMPLER2D(u_texNormal, 1);
|
SAMPLER2D(u_texNormal, 1);
|
||||||
uniform vec4 u_lightPosRadius[4];
|
uniform vec4 u_lightPosRadius[4];
|
||||||
uniform vec4 u_lightRgbInnerR[4];
|
uniform vec4 u_lightRgbInnerR[4];
|
||||||
|
|
||||||
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
|
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
|
||||||
{
|
{
|
||||||
float ndotl = dot(_normal, _lightDir);
|
float ndotl = dot(_normal, _lightDir);
|
||||||
vec3 reflected = _lightDir - 2.0*ndotl*_normal; // reflect(_lightDir, _normal);
|
vec3 reflected = _lightDir - 2.0*ndotl*_normal; // reflect(_lightDir, _normal);
|
||||||
float rdotv = dot(reflected, _viewDir);
|
float rdotv = dot(reflected, _viewDir);
|
||||||
return vec2(ndotl, rdotv);
|
return vec2(ndotl, rdotv);
|
||||||
}
|
}
|
||||||
|
|
||||||
float fresnel(float _ndotl, float _bias, float _pow)
|
float fresnel(float _ndotl, float _bias, float _pow)
|
||||||
{
|
{
|
||||||
float facing = (1.0 - _ndotl);
|
float facing = (1.0 - _ndotl);
|
||||||
return max(_bias + (1.0 - _bias) * pow(facing, _pow), 0.0);
|
return max(_bias + (1.0 - _bias) * pow(facing, _pow), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 lit(float _ndotl, float _rdotv, float _m)
|
vec4 lit(float _ndotl, float _rdotv, float _m)
|
||||||
{
|
{
|
||||||
float diff = max(0.0, _ndotl);
|
float diff = max(0.0, _ndotl);
|
||||||
float spec = step(0.0, _ndotl) * max(0.0, _rdotv * _m);
|
float spec = step(0.0, _ndotl) * max(0.0, _rdotv * _m);
|
||||||
return vec4(1.0, diff, spec, 1.0);
|
return vec4(1.0, diff, spec, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 powRgba(vec4 _rgba, float _pow)
|
vec4 powRgba(vec4 _rgba, float _pow)
|
||||||
{
|
{
|
||||||
vec4 result;
|
vec4 result;
|
||||||
result.xyz = pow(_rgba.xyz, vec3_splat(_pow) );
|
result.xyz = pow(_rgba.xyz, vec3_splat(_pow) );
|
||||||
result.w = _rgba.w;
|
result.w = _rgba.w;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 calcLight(int _idx, mat3 _tbn, vec3 _wpos, vec3 _normal, vec3 _view)
|
vec3 calcLight(int _idx, mat3 _tbn, vec3 _wpos, vec3 _normal, vec3 _view)
|
||||||
{
|
{
|
||||||
vec3 lp = u_lightPosRadius[_idx].xyz - _wpos;
|
vec3 lp = u_lightPosRadius[_idx].xyz - _wpos;
|
||||||
float attn = 1.0 - smoothstep(u_lightRgbInnerR[_idx].w, 1.0, length(lp) / u_lightPosRadius[_idx].w);
|
float attn = 1.0 - smoothstep(u_lightRgbInnerR[_idx].w, 1.0, length(lp) / u_lightPosRadius[_idx].w);
|
||||||
vec3 lightDir = mul(_tbn, normalize(lp) );
|
vec3 lightDir = mul(_tbn, normalize(lp) );
|
||||||
vec2 bln = blinn(lightDir, _normal, _view);
|
vec2 bln = blinn(lightDir, _normal, _view);
|
||||||
vec4 lc = lit(bln.x, bln.y, 1.0);
|
vec4 lc = lit(bln.x, bln.y, 1.0);
|
||||||
vec3 rgb = u_lightRgbInnerR[_idx].xyz*max(0.0, saturate(lc.y) ) * attn;
|
vec3 rgb = u_lightRgbInnerR[_idx].xyz*max(0.0, saturate(lc.y) ) * attn;
|
||||||
return rgb;
|
return rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
mat3 tbn = mat3(
|
mat3 tbn = mat3(
|
||||||
normalize(v_tangent),
|
normalize(v_tangent),
|
||||||
normalize(v_bitangent),
|
normalize(v_bitangent),
|
||||||
normalize(v_normal)
|
normalize(v_normal)
|
||||||
);
|
);
|
||||||
|
|
||||||
vec3 normal;
|
vec3 normal;
|
||||||
normal.xy = texture2D(u_texNormal, v_texcoord0).xy * 2.0 - 1.0;
|
normal.xy = texture2D(u_texNormal, v_texcoord0).xy * 2.0 - 1.0;
|
||||||
normal.z = sqrt(1.0 - dot(normal.xy, normal.xy) );
|
normal.z = sqrt(1.0 - dot(normal.xy, normal.xy) );
|
||||||
vec3 view = -normalize(v_view);
|
vec3 view = -normalize(v_view);
|
||||||
|
|
||||||
vec3 lightColor;
|
vec3 lightColor;
|
||||||
lightColor = calcLight(0, tbn, v_wpos, normal, view);
|
lightColor = calcLight(0, tbn, v_wpos, normal, view);
|
||||||
lightColor += calcLight(1, tbn, v_wpos, normal, view);
|
lightColor += calcLight(1, tbn, v_wpos, normal, view);
|
||||||
lightColor += calcLight(2, tbn, v_wpos, normal, view);
|
lightColor += calcLight(2, tbn, v_wpos, normal, view);
|
||||||
lightColor += calcLight(3, tbn, v_wpos, normal, view);
|
lightColor += calcLight(3, tbn, v_wpos, normal, view);
|
||||||
|
|
||||||
vec4 color = toLinear(texture2D(u_texColor, v_texcoord0) );
|
vec4 color = toLinear(texture2D(u_texColor, v_texcoord0) );
|
||||||
|
|
||||||
gl_FragColor.xyz = max(vec3_splat(0.05), lightColor.xyz)*color.xyz;
|
gl_FragColor.xyz = max(vec3_splat(0.05), lightColor.xyz)*color.xyz;
|
||||||
gl_FragColor.w = 1.0;
|
gl_FragColor.w = 1.0;
|
||||||
gl_FragColor = toGamma(gl_FragColor);
|
gl_FragColor = toGamma(gl_FragColor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
||||||
vec3 v_wpos : TEXCOORD1 = vec3(0.0, 0.0, 0.0);
|
vec3 v_wpos : TEXCOORD1 = vec3(0.0, 0.0, 0.0);
|
||||||
vec3 v_view : TEXCOORD2 = vec3(0.0, 0.0, 0.0);
|
vec3 v_view : TEXCOORD2 = vec3(0.0, 0.0, 0.0);
|
||||||
vec3 v_normal : NORMAL = vec3(0.0, 0.0, 1.0);
|
vec3 v_normal : NORMAL = vec3(0.0, 0.0, 1.0);
|
||||||
vec3 v_tangent : TANGENT = vec3(1.0, 0.0, 0.0);
|
vec3 v_tangent : TANGENT = vec3(1.0, 0.0, 0.0);
|
||||||
vec3 v_bitangent : BINORMAL = vec3(0.0, 1.0, 0.0);
|
vec3 v_bitangent : BINORMAL = vec3(0.0, 1.0, 0.0);
|
||||||
|
|
||||||
vec3 a_position : POSITION;
|
vec3 a_position : POSITION;
|
||||||
vec4 a_normal : NORMAL;
|
vec4 a_normal : NORMAL;
|
||||||
vec4 a_tangent : TANGENT;
|
vec4 a_tangent : TANGENT;
|
||||||
vec2 a_texcoord0 : TEXCOORD0;
|
vec2 a_texcoord0 : TEXCOORD0;
|
||||||
vec4 i_data0 : TEXCOORD4;
|
vec4 i_data0 : TEXCOORD4;
|
||||||
vec4 i_data1 : TEXCOORD5;
|
vec4 i_data1 : TEXCOORD5;
|
||||||
vec4 i_data2 : TEXCOORD6;
|
vec4 i_data2 : TEXCOORD6;
|
||||||
vec4 i_data3 : TEXCOORD7;
|
vec4 i_data3 : TEXCOORD7;
|
||||||
|
|
|
@ -1,43 +1,43 @@
|
||||||
$input a_position, a_normal, a_tangent, a_texcoord0, i_data0, i_data1, i_data2, i_data3
|
$input a_position, a_normal, a_tangent, a_texcoord0, i_data0, i_data1, i_data2, i_data3
|
||||||
$output v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0
|
$output v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
mat4 model;
|
mat4 model;
|
||||||
model[0] = i_data0;
|
model[0] = i_data0;
|
||||||
model[1] = i_data1;
|
model[1] = i_data1;
|
||||||
model[2] = i_data2;
|
model[2] = i_data2;
|
||||||
model[3] = i_data3;
|
model[3] = i_data3;
|
||||||
|
|
||||||
vec3 wpos = instMul(model, vec4(a_position, 1.0) ).xyz;
|
vec3 wpos = instMul(model, vec4(a_position, 1.0) ).xyz;
|
||||||
gl_Position = mul(u_viewProj, vec4(wpos, 1.0) );
|
gl_Position = mul(u_viewProj, vec4(wpos, 1.0) );
|
||||||
|
|
||||||
vec4 normal = a_normal * 2.0f - 1.0f;
|
vec4 normal = a_normal * 2.0f - 1.0f;
|
||||||
vec3 wnormal = instMul(model, vec4(normal.xyz, 0.0) ).xyz;
|
vec3 wnormal = instMul(model, vec4(normal.xyz, 0.0) ).xyz;
|
||||||
|
|
||||||
vec4 tangent = a_tangent * 2.0f - 1.0f;
|
vec4 tangent = a_tangent * 2.0f - 1.0f;
|
||||||
vec3 wtangent = instMul(model, vec4(tangent.xyz, 0.0) ).xyz;
|
vec3 wtangent = instMul(model, vec4(tangent.xyz, 0.0) ).xyz;
|
||||||
|
|
||||||
vec3 viewNormal = normalize(mul(u_view, vec4(wnormal, 0.0) ).xyz);
|
vec3 viewNormal = normalize(mul(u_view, vec4(wnormal, 0.0) ).xyz);
|
||||||
vec3 viewTangent = normalize(mul(u_view, vec4(wtangent, 0.0) ).xyz);
|
vec3 viewTangent = normalize(mul(u_view, vec4(wtangent, 0.0) ).xyz);
|
||||||
vec3 viewBitangent = cross(viewNormal, viewTangent) * tangent.w;
|
vec3 viewBitangent = cross(viewNormal, viewTangent) * tangent.w;
|
||||||
mat3 tbn = mat3(viewTangent, viewBitangent, viewNormal);
|
mat3 tbn = mat3(viewTangent, viewBitangent, viewNormal);
|
||||||
|
|
||||||
v_wpos = wpos;
|
v_wpos = wpos;
|
||||||
|
|
||||||
vec3 view = mul(u_view, vec4(wpos, 0.0) ).xyz;
|
vec3 view = mul(u_view, vec4(wpos, 0.0) ).xyz;
|
||||||
v_view = instMul(view, tbn);
|
v_view = instMul(view, tbn);
|
||||||
|
|
||||||
v_normal = viewNormal;
|
v_normal = viewNormal;
|
||||||
v_tangent = viewTangent;
|
v_tangent = viewTangent;
|
||||||
v_bitangent = viewBitangent;
|
v_bitangent = viewBitangent;
|
||||||
|
|
||||||
v_texcoord0 = a_texcoord0;
|
v_texcoord0 = a_texcoord0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
$input v_world, v_color0
|
$input v_world, v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 normal = normalize(cross(dFdx(v_world), dFdy(v_world) ) );
|
vec3 normal = normalize(cross(dFdx(v_world), dFdy(v_world) ) );
|
||||||
vec3 lightDir = vec3(0.0, 0.0, 1.0);
|
vec3 lightDir = vec3(0.0, 0.0, 1.0);
|
||||||
float ndotl = max(dot(normal, lightDir), 0.0);
|
float ndotl = max(dot(normal, lightDir), 0.0);
|
||||||
float spec = pow(ndotl, 30.0);
|
float spec = pow(ndotl, 30.0);
|
||||||
gl_FragColor = pow(pow(v_color0, vec4_splat(2.2) ) * ndotl + spec, vec4_splat(1.0/2.2) );
|
gl_FragColor = pow(pow(v_color0, vec4_splat(2.2) ) * ndotl + spec, vec4_splat(1.0/2.2) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
vec3 v_world : TEXCOORD0 = vec3(0.0, 0.0, 0.0);
|
vec3 v_world : TEXCOORD0 = vec3(0.0, 0.0, 0.0);
|
||||||
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
vec3 a_position : POSITION;
|
vec3 a_position : POSITION;
|
||||||
vec4 a_color0 : COLOR0;
|
vec4 a_color0 : COLOR0;
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
$input a_position, a_color0
|
$input a_position, a_color0
|
||||||
$output v_world, v_color0
|
$output v_world, v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||||
v_world = mul(u_model, vec4(a_position, 1.0) ).xyz;
|
v_world = mul(u_model, vec4(a_position, 1.0) ).xyz;
|
||||||
v_color0 = a_color0;
|
v_color0 = a_color0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
$input v_texcoord0
|
$input v_texcoord0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
SAMPLERCUBE(u_texCube, 0);
|
SAMPLERCUBE(u_texCube, 0);
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_FragColor = textureCube(u_texCube, v_texcoord0);
|
gl_FragColor = textureCube(u_texCube, v_texcoord0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,16 +125,16 @@ static const bgfx::Memory* loadShader(const char* _name)
|
||||||
|
|
||||||
int _main_(int _argc, char** _argv)
|
int _main_(int _argc, char** _argv)
|
||||||
{
|
{
|
||||||
uint32_t width = 1280;
|
uint32_t width = 1280;
|
||||||
uint32_t height = 720;
|
uint32_t height = 720;
|
||||||
uint32_t debug = BGFX_DEBUG_TEXT;
|
uint32_t debug = BGFX_DEBUG_TEXT;
|
||||||
|
|
||||||
bgfx::init();
|
bgfx::init();
|
||||||
bgfx::reset(width, height);
|
bgfx::reset(width, height);
|
||||||
|
|
||||||
// Enable debug text.
|
// Enable debug text.
|
||||||
bgfx::setDebug(debug);
|
bgfx::setDebug(debug);
|
||||||
|
|
||||||
// Set view 0 clear state.
|
// Set view 0 clear state.
|
||||||
bgfx::setViewClear(0
|
bgfx::setViewClear(0
|
||||||
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
|
||||||
|
@ -227,11 +227,11 @@ int _main_(int _argc, char** _argv)
|
||||||
|
|
||||||
int64_t updateTime = 0;
|
int64_t updateTime = 0;
|
||||||
|
|
||||||
while (!processEvents(width, height, debug) )
|
while (!processEvents(width, height, debug) )
|
||||||
{
|
{
|
||||||
// Set view 0 default viewport.
|
// Set view 0 default viewport.
|
||||||
bgfx::setViewRect(0, 0, 0, width, height);
|
bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
|
||||||
// This dummy draw call is here to make sure that view 0 is cleared
|
// This dummy draw call is here to make sure that view 0 is cleared
|
||||||
// if no other draw calls are submitted to view 0.
|
// if no other draw calls are submitted to view 0.
|
||||||
bgfx::submit(0);
|
bgfx::submit(0);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
vec3 v_texcoord0 : TEXCOORD0 = vec3(9.0, 0.0, 0.0);
|
vec3 v_texcoord0 : TEXCOORD0 = vec3(9.0, 0.0, 0.0);
|
||||||
|
|
||||||
vec3 a_position : POSITION;
|
vec3 a_position : POSITION;
|
||||||
vec3 a_texcoord0 : TEXCOORD0;
|
vec3 a_texcoord0 : TEXCOORD0;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
$input a_position, a_texcoord0
|
$input a_position, a_texcoord0
|
||||||
$output v_texcoord0
|
$output v_texcoord0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common/common.sh"
|
#include "../common/common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||||
v_texcoord0 = a_texcoord0;
|
v_texcoord0 = a_texcoord0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,229 +1,229 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __AVIWRITER_H__
|
#ifndef __AVIWRITER_H__
|
||||||
#define __AVIWRITER_H__
|
#define __AVIWRITER_H__
|
||||||
|
|
||||||
#include <bx/readerwriter.h>
|
#include <bx/readerwriter.h>
|
||||||
|
|
||||||
// Simple AVI writer. VideoLAN and VirtualDub can decode it.
|
// Simple AVI writer. VideoLAN and VirtualDub can decode it.
|
||||||
// Needs some bits to get jiggled to work with other players. But it's good
|
// Needs some bits to get jiggled to work with other players. But it's good
|
||||||
// enough for an example.
|
// enough for an example.
|
||||||
struct AviWriter
|
struct AviWriter
|
||||||
{
|
{
|
||||||
AviWriter()
|
AviWriter()
|
||||||
: m_frame(NULL)
|
: m_frame(NULL)
|
||||||
, m_frameSize(0)
|
, m_frameSize(0)
|
||||||
, m_numFrames(0)
|
, m_numFrames(0)
|
||||||
, m_width(0)
|
, m_width(0)
|
||||||
, m_height(0)
|
, m_height(0)
|
||||||
, m_yflip(false)
|
, m_yflip(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool open(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _fps, bool _yflip)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_frameSize = _width * _height * 3;
|
m_frameSize = _width * _height * 3;
|
||||||
m_frame = new uint8_t[m_frameSize + 8];
|
m_frame = new uint8_t[m_frameSize + 8];
|
||||||
m_numFrames = 0;
|
m_numFrames = 0;
|
||||||
m_width = _width;
|
m_width = _width;
|
||||||
m_height = _height;
|
m_height = _height;
|
||||||
|
|
||||||
// Bgfx returns _yflip true for OpenGL since bottom left corner is 0, 0. In D3D top left corner
|
// Bgfx returns _yflip true for OpenGL since bottom left corner is 0, 0. In D3D top left corner
|
||||||
// is 0, 0. DIB expect OpenGL style coordinates, so this is inverted logic for AVI writer.
|
// is 0, 0. DIB expect OpenGL style coordinates, so this is inverted logic for AVI writer.
|
||||||
m_yflip = !_yflip;
|
m_yflip = !_yflip;
|
||||||
|
|
||||||
bx::StaticMemoryBlockWriter mem(m_frame, 8);
|
bx::StaticMemoryBlockWriter mem(m_frame, 8);
|
||||||
// Stream Data (LIST 'movi' Chunk) http://msdn.microsoft.com/en-us/library/ms899496.aspx
|
// Stream Data (LIST 'movi' Chunk) http://msdn.microsoft.com/en-us/library/ms899496.aspx
|
||||||
bx::write(&mem, BX_MAKEFOURCC('0', '0', 'd', 'b') );
|
bx::write(&mem, BX_MAKEFOURCC('0', '0', 'd', 'b') );
|
||||||
bx::write(&mem, m_frameSize);
|
bx::write(&mem, m_frameSize);
|
||||||
|
|
||||||
bx::write(&m_writer, BX_MAKEFOURCC('R', 'I', 'F', 'F') );
|
bx::write(&m_writer, BX_MAKEFOURCC('R', 'I', 'F', 'F') );
|
||||||
m_riffSizeOffset = m_writer.seek();
|
m_riffSizeOffset = m_writer.seek();
|
||||||
bx::write(&m_writer, UINT32_C(0) );
|
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
|
// 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, BX_MAKEFOURCC('L', 'I', 'S', 'T') );
|
||||||
bx::write(&m_writer, UINT32_C(192) );
|
bx::write(&m_writer, UINT32_C(192) );
|
||||||
bx::write(&m_writer, BX_MAKEFOURCC('h', 'd', 'r', 'l') );
|
bx::write(&m_writer, BX_MAKEFOURCC('h', 'd', 'r', 'l') );
|
||||||
|
|
||||||
// AVI Main Header http://msdn.microsoft.com/en-us/library/ms779632.aspx
|
// 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, BX_MAKEFOURCC('a', 'v', 'i', 'h') );
|
||||||
bx::write(&m_writer, UINT32_C(56) );
|
bx::write(&m_writer, UINT32_C(56) );
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwMicroSecPerFrame
|
bx::write(&m_writer, UINT32_C(0) ); // dwMicroSecPerFrame
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwMaxBytesPerSec
|
bx::write(&m_writer, UINT32_C(0) ); // dwMaxBytesPerSec
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwPaddingGranularity
|
bx::write(&m_writer, UINT32_C(0) ); // dwPaddingGranularity
|
||||||
bx::write(&m_writer, UINT32_C(0x101) ); // dwFlags
|
bx::write(&m_writer, UINT32_C(0x101) ); // dwFlags
|
||||||
|
|
||||||
m_totalFramesOffset = m_writer.seek();
|
m_totalFramesOffset = m_writer.seek();
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwTotalFrames
|
bx::write(&m_writer, UINT32_C(0) ); // dwTotalFrames
|
||||||
|
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwInitialFrames
|
bx::write(&m_writer, UINT32_C(0) ); // dwInitialFrames
|
||||||
bx::write(&m_writer, UINT32_C(1) ); // dwStreams
|
bx::write(&m_writer, UINT32_C(1) ); // dwStreams
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwSuggestedBufferSize
|
bx::write(&m_writer, UINT32_C(0) ); // dwSuggestedBufferSize
|
||||||
bx::write(&m_writer, _width); // dwWidth
|
bx::write(&m_writer, _width); // dwWidth
|
||||||
bx::write(&m_writer, _height); // dwHeight
|
bx::write(&m_writer, _height); // dwHeight
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwReserved0
|
bx::write(&m_writer, UINT32_C(0) ); // dwReserved0
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwReserved1
|
bx::write(&m_writer, UINT32_C(0) ); // dwReserved1
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwReserved2
|
bx::write(&m_writer, UINT32_C(0) ); // dwReserved2
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwReserved3
|
bx::write(&m_writer, UINT32_C(0) ); // dwReserved3
|
||||||
|
|
||||||
bx::write(&m_writer, BX_MAKEFOURCC('L', 'I', 'S', 'T') );
|
bx::write(&m_writer, BX_MAKEFOURCC('L', 'I', 'S', 'T') );
|
||||||
bx::write(&m_writer, UINT32_C(116) );
|
bx::write(&m_writer, UINT32_C(116) );
|
||||||
bx::write(&m_writer, BX_MAKEFOURCC('s', 't', 'r', 'l') );
|
bx::write(&m_writer, BX_MAKEFOURCC('s', 't', 'r', 'l') );
|
||||||
|
|
||||||
// AVISTREAMHEADER Structure http://msdn.microsoft.com/en-us/library/ms779638.aspx
|
// 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, BX_MAKEFOURCC('s', 't', 'r', 'h') );
|
||||||
bx::write(&m_writer, UINT32_C(56) );
|
bx::write(&m_writer, UINT32_C(56) );
|
||||||
// AVI Stream Headers http://msdn.microsoft.com/en-us/library/ms899423.aspx
|
// 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('v', 'i', 'd', 's') ); // fccType
|
||||||
bx::write(&m_writer, BX_MAKEFOURCC('D', 'I', 'B', ' ') ); // fccHandler
|
bx::write(&m_writer, BX_MAKEFOURCC('D', 'I', 'B', ' ') ); // fccHandler
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwFlags
|
bx::write(&m_writer, UINT32_C(0) ); // dwFlags
|
||||||
bx::write(&m_writer, UINT16_C(0) ); // wPriority
|
bx::write(&m_writer, UINT16_C(0) ); // wPriority
|
||||||
bx::write(&m_writer, UINT16_C(0) ); // wLanguage
|
bx::write(&m_writer, UINT16_C(0) ); // wLanguage
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwInitialFrames
|
bx::write(&m_writer, UINT32_C(0) ); // dwInitialFrames
|
||||||
bx::write(&m_writer, UINT32_C(1) ); // dwScale
|
bx::write(&m_writer, UINT32_C(1) ); // dwScale
|
||||||
bx::write(&m_writer, _fps); // dwRate
|
bx::write(&m_writer, _fps); // dwRate
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwStart
|
bx::write(&m_writer, UINT32_C(0) ); // dwStart
|
||||||
|
|
||||||
m_lengthOffset = m_writer.seek();
|
m_lengthOffset = m_writer.seek();
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwLength
|
bx::write(&m_writer, UINT32_C(0) ); // dwLength
|
||||||
|
|
||||||
bx::write(&m_writer, m_frameSize); // dwSuggestedBufferSize
|
bx::write(&m_writer, m_frameSize); // dwSuggestedBufferSize
|
||||||
bx::write(&m_writer, UINT32_MAX); // dwQuality
|
bx::write(&m_writer, UINT32_MAX); // dwQuality
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // dwSampleSize
|
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.left
|
||||||
bx::write(&m_writer, INT16_C(0) ); // rcFrame.top
|
bx::write(&m_writer, INT16_C(0) ); // rcFrame.top
|
||||||
bx::write(&m_writer, uint16_t(_width) ); // rcFrame.right
|
bx::write(&m_writer, uint16_t(_width) ); // rcFrame.right
|
||||||
bx::write(&m_writer, uint16_t(_height) );// rcFrame.bottom
|
bx::write(&m_writer, uint16_t(_height) );// rcFrame.bottom
|
||||||
|
|
||||||
bx::write(&m_writer, BX_MAKEFOURCC('s', 't', 'r', 'f') );
|
bx::write(&m_writer, BX_MAKEFOURCC('s', 't', 'r', 'f') );
|
||||||
bx::write(&m_writer, UINT32_C(40) );
|
bx::write(&m_writer, UINT32_C(40) );
|
||||||
|
|
||||||
// BITMAPINFOHEADER structure http://msdn.microsoft.com/en-us/library/windows/desktop/dd318229%28v=vs.85%29.aspx
|
// 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, UINT32_C(40) ); // biSize
|
||||||
bx::write(&m_writer, _width); // biWidth
|
bx::write(&m_writer, _width); // biWidth
|
||||||
bx::write(&m_writer, _height); // biHeight
|
bx::write(&m_writer, _height); // biHeight
|
||||||
bx::write(&m_writer, UINT16_C(1) ); // biPlanes
|
bx::write(&m_writer, UINT16_C(1) ); // biPlanes
|
||||||
bx::write(&m_writer, UINT16_C(24) ); // biBitCount
|
bx::write(&m_writer, UINT16_C(24) ); // biBitCount
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // biCompression
|
bx::write(&m_writer, UINT32_C(0) ); // biCompression
|
||||||
bx::write(&m_writer, m_frameSize); // biSizeImage
|
bx::write(&m_writer, m_frameSize); // biSizeImage
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // biXPelsPerMeter
|
bx::write(&m_writer, UINT32_C(0) ); // biXPelsPerMeter
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // biYPelsPerMeter
|
bx::write(&m_writer, UINT32_C(0) ); // biYPelsPerMeter
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // biClrUsed
|
bx::write(&m_writer, UINT32_C(0) ); // biClrUsed
|
||||||
bx::write(&m_writer, UINT32_C(0) ); // biClrImportant
|
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();
|
m_moviListOffset = m_writer.seek();
|
||||||
bx::write(&m_writer, UINT32_C(0) );
|
bx::write(&m_writer, UINT32_C(0) );
|
||||||
bx::write(&m_writer, BX_MAKEFOURCC('m', 'o', 'v', 'i') );
|
bx::write(&m_writer, BX_MAKEFOURCC('m', 'o', 'v', 'i') );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void close()
|
void close()
|
||||||
{
|
{
|
||||||
if (NULL != m_frame)
|
if (NULL != m_frame)
|
||||||
{
|
{
|
||||||
int64_t pos = m_writer.seek();
|
int64_t pos = m_writer.seek();
|
||||||
m_writer.seek(m_moviListOffset, bx::Whence::Begin);
|
m_writer.seek(m_moviListOffset, bx::Whence::Begin);
|
||||||
bx::write(&m_writer, uint32_t(pos-m_moviListOffset-4) );
|
bx::write(&m_writer, uint32_t(pos-m_moviListOffset-4) );
|
||||||
m_writer.seek(pos, bx::Whence::Begin);
|
m_writer.seek(pos, bx::Whence::Begin);
|
||||||
|
|
||||||
bx::write(&m_writer, BX_MAKEFOURCC('i', 'd', 'x', '1') );
|
bx::write(&m_writer, BX_MAKEFOURCC('i', 'd', 'x', '1') );
|
||||||
bx::write(&m_writer, m_numFrames*16);
|
bx::write(&m_writer, m_numFrames*16);
|
||||||
|
|
||||||
for (uint32_t ii = 0, offset = 4; ii < m_numFrames; ++ii)
|
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, BX_MAKEFOURCC('0', '0', 'd', 'b') );
|
||||||
bx::write(&m_writer, UINT32_C(16) );
|
bx::write(&m_writer, UINT32_C(16) );
|
||||||
bx::write(&m_writer, offset);
|
bx::write(&m_writer, offset);
|
||||||
bx::write(&m_writer, m_frameSize);
|
bx::write(&m_writer, m_frameSize);
|
||||||
offset += m_frameSize + 8;
|
offset += m_frameSize + 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = m_writer.seek();
|
pos = m_writer.seek();
|
||||||
m_writer.seek(m_riffSizeOffset, bx::Whence::Begin);
|
m_writer.seek(m_riffSizeOffset, bx::Whence::Begin);
|
||||||
bx::write(&m_writer, uint32_t(pos-m_riffSizeOffset-4) );
|
bx::write(&m_writer, uint32_t(pos-m_riffSizeOffset-4) );
|
||||||
|
|
||||||
m_writer.seek(m_totalFramesOffset, bx::Whence::Begin);
|
m_writer.seek(m_totalFramesOffset, bx::Whence::Begin);
|
||||||
bx::write(&m_writer, m_numFrames);
|
bx::write(&m_writer, m_numFrames);
|
||||||
|
|
||||||
m_writer.seek(m_lengthOffset, bx::Whence::Begin);
|
m_writer.seek(m_lengthOffset, bx::Whence::Begin);
|
||||||
bx::write(&m_writer, m_numFrames);
|
bx::write(&m_writer, m_numFrames);
|
||||||
|
|
||||||
m_writer.close();
|
m_writer.close();
|
||||||
|
|
||||||
delete [] m_frame;
|
delete [] m_frame;
|
||||||
m_frame = NULL;
|
m_frame = NULL;
|
||||||
m_frameSize = 0;
|
m_frameSize = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void frame(const void* _data)
|
void frame(const void* _data)
|
||||||
{
|
{
|
||||||
if (NULL != m_frame)
|
if (NULL != m_frame)
|
||||||
{
|
{
|
||||||
++m_numFrames;
|
++m_numFrames;
|
||||||
uint32_t width = m_width;
|
uint32_t width = m_width;
|
||||||
uint32_t height = m_height;
|
uint32_t height = m_height;
|
||||||
|
|
||||||
uint8_t* bgr = &m_frame[8];
|
uint8_t* bgr = &m_frame[8];
|
||||||
|
|
||||||
if (m_yflip)
|
if (m_yflip)
|
||||||
{
|
{
|
||||||
for (uint32_t yy = 0; yy < height; ++yy)
|
for (uint32_t yy = 0; yy < height; ++yy)
|
||||||
{
|
{
|
||||||
const uint8_t* bgra = (const uint8_t*)_data + (height-1-yy)*width*4;
|
const uint8_t* bgra = (const uint8_t*)_data + (height-1-yy)*width*4;
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < width; ++ii)
|
for (uint32_t ii = 0; ii < width; ++ii)
|
||||||
{
|
{
|
||||||
bgr[0] = bgra[0];
|
bgr[0] = bgra[0];
|
||||||
bgr[1] = bgra[1];
|
bgr[1] = bgra[1];
|
||||||
bgr[2] = bgra[2];
|
bgr[2] = bgra[2];
|
||||||
bgr += 3;
|
bgr += 3;
|
||||||
bgra += 4;
|
bgra += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const uint8_t* bgra = (const uint8_t*)_data;
|
const uint8_t* bgra = (const uint8_t*)_data;
|
||||||
for (uint32_t ii = 0, num = m_frameSize/3; ii < num; ++ii)
|
for (uint32_t ii = 0, num = m_frameSize/3; ii < num; ++ii)
|
||||||
{
|
{
|
||||||
bgr[0] = bgra[0];
|
bgr[0] = bgra[0];
|
||||||
bgr[1] = bgra[1];
|
bgr[1] = bgra[1];
|
||||||
bgr[2] = bgra[2];
|
bgr[2] = bgra[2];
|
||||||
bgr += 3;
|
bgr += 3;
|
||||||
bgra += 4;
|
bgra += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bx::write(&m_writer, m_frame, m_frameSize+8);
|
bx::write(&m_writer, m_frame, m_frameSize+8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bx::CrtFileWriter m_writer;
|
bx::CrtFileWriter m_writer;
|
||||||
int64_t m_riffSizeOffset;
|
int64_t m_riffSizeOffset;
|
||||||
int64_t m_totalFramesOffset;
|
int64_t m_totalFramesOffset;
|
||||||
int64_t m_lengthOffset;
|
int64_t m_lengthOffset;
|
||||||
int64_t m_moviListOffset;
|
int64_t m_moviListOffset;
|
||||||
uint8_t* m_frame;
|
uint8_t* m_frame;
|
||||||
uint32_t m_frameSize;
|
uint32_t m_frameSize;
|
||||||
uint32_t m_numFrames;
|
uint32_t m_numFrames;
|
||||||
uint32_t m_width;
|
uint32_t m_width;
|
||||||
uint32_t m_height;
|
uint32_t m_height;
|
||||||
bool m_yflip;
|
bool m_yflip;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __AVIWRITER_H__
|
#endif // __AVIWRITER_H__
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../../src/common.sh"
|
#include "../../src/common.sh"
|
||||||
#include "shaderlib.sh"
|
#include "shaderlib.sh"
|
||||||
|
|
|
@ -1,109 +1,109 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <bx/bx.h>
|
#include <bx/bx.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <ctype.h> // isprint
|
#include <ctype.h> // isprint
|
||||||
|
|
||||||
#include "dbg.h"
|
#include "dbg.h"
|
||||||
#include <bx/string.h>
|
#include <bx/string.h>
|
||||||
|
|
||||||
#if BX_COMPILER_MSVC
|
#if BX_COMPILER_MSVC
|
||||||
# define snprintf _snprintf
|
# define snprintf _snprintf
|
||||||
#endif // BX_COMPILER_MSVC
|
#endif // BX_COMPILER_MSVC
|
||||||
|
|
||||||
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
|
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
__declspec(dllimport) void __stdcall OutputDebugStringA(const char* _str);
|
__declspec(dllimport) void __stdcall OutputDebugStringA(const char* _str);
|
||||||
}
|
}
|
||||||
#endif // BX_PLATFORM_WINDOWS
|
#endif // BX_PLATFORM_WINDOWS
|
||||||
|
|
||||||
void dbgOutput(const char* _out)
|
void dbgOutput(const char* _out)
|
||||||
{
|
{
|
||||||
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
|
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
|
||||||
OutputDebugStringA(_out);
|
OutputDebugStringA(_out);
|
||||||
#elif BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_OSX
|
#elif BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_OSX
|
||||||
fputs(_out, stderr);
|
fputs(_out, stderr);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
#endif // BX_PLATFORM_
|
#endif // BX_PLATFORM_
|
||||||
}
|
}
|
||||||
|
|
||||||
void dbgPrintfVargs(const char* _format, va_list _argList)
|
void dbgPrintfVargs(const char* _format, va_list _argList)
|
||||||
{
|
{
|
||||||
char temp[8192];
|
char temp[8192];
|
||||||
char* out = temp;
|
char* out = temp;
|
||||||
int32_t len = bx::vsnprintf(out, sizeof(temp), _format, _argList);
|
int32_t len = bx::vsnprintf(out, sizeof(temp), _format, _argList);
|
||||||
if ( (int32_t)sizeof(temp) < len)
|
if ( (int32_t)sizeof(temp) < len)
|
||||||
{
|
{
|
||||||
out = (char*)alloca(len+1);
|
out = (char*)alloca(len+1);
|
||||||
len = bx::vsnprintf(out, len, _format, _argList);
|
len = bx::vsnprintf(out, len, _format, _argList);
|
||||||
}
|
}
|
||||||
out[len] = '\0';
|
out[len] = '\0';
|
||||||
dbgOutput(out);
|
dbgOutput(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dbgPrintf(const char* _format, ...)
|
void dbgPrintf(const char* _format, ...)
|
||||||
{
|
{
|
||||||
va_list argList;
|
va_list argList;
|
||||||
va_start(argList, _format);
|
va_start(argList, _format);
|
||||||
dbgPrintfVargs(_format, argList);
|
dbgPrintfVargs(_format, argList);
|
||||||
va_end(argList);
|
va_end(argList);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DBG_ADDRESS "%" PRIxPTR
|
#define DBG_ADDRESS "%" PRIxPTR
|
||||||
|
|
||||||
void dbgPrintfData(const void* _data, uint32_t _size, const char* _format, ...)
|
void dbgPrintfData(const void* _data, uint32_t _size, const char* _format, ...)
|
||||||
{
|
{
|
||||||
#define HEX_DUMP_WIDTH 16
|
#define HEX_DUMP_WIDTH 16
|
||||||
#define HEX_DUMP_SPACE_WIDTH 48
|
#define HEX_DUMP_SPACE_WIDTH 48
|
||||||
#define HEX_DUMP_FORMAT "%-" DBG_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "." DBG_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "s"
|
#define HEX_DUMP_FORMAT "%-" DBG_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "." DBG_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "s"
|
||||||
|
|
||||||
va_list argList;
|
va_list argList;
|
||||||
va_start(argList, _format);
|
va_start(argList, _format);
|
||||||
dbgPrintfVargs(_format, argList);
|
dbgPrintfVargs(_format, argList);
|
||||||
va_end(argList);
|
va_end(argList);
|
||||||
|
|
||||||
dbgPrintf("\ndata: " DBG_ADDRESS ", size: %d\n", _data, _size);
|
dbgPrintf("\ndata: " DBG_ADDRESS ", size: %d\n", _data, _size);
|
||||||
|
|
||||||
if (NULL != _data)
|
if (NULL != _data)
|
||||||
{
|
{
|
||||||
const uint8_t* data = reinterpret_cast<const uint8_t*>(_data);
|
const uint8_t* data = reinterpret_cast<const uint8_t*>(_data);
|
||||||
char hex[HEX_DUMP_WIDTH*3+1];
|
char hex[HEX_DUMP_WIDTH*3+1];
|
||||||
char ascii[HEX_DUMP_WIDTH+1];
|
char ascii[HEX_DUMP_WIDTH+1];
|
||||||
uint32_t hexPos = 0;
|
uint32_t hexPos = 0;
|
||||||
uint32_t asciiPos = 0;
|
uint32_t asciiPos = 0;
|
||||||
for (uint32_t ii = 0; ii < _size; ++ii)
|
for (uint32_t ii = 0; ii < _size; ++ii)
|
||||||
{
|
{
|
||||||
snprintf(&hex[hexPos], sizeof(hex)-hexPos, "%02x ", data[asciiPos]);
|
snprintf(&hex[hexPos], sizeof(hex)-hexPos, "%02x ", data[asciiPos]);
|
||||||
hexPos += 3;
|
hexPos += 3;
|
||||||
|
|
||||||
ascii[asciiPos] = isprint(data[asciiPos]) ? data[asciiPos] : '.';
|
ascii[asciiPos] = isprint(data[asciiPos]) ? data[asciiPos] : '.';
|
||||||
asciiPos++;
|
asciiPos++;
|
||||||
|
|
||||||
if (HEX_DUMP_WIDTH == asciiPos)
|
if (HEX_DUMP_WIDTH == asciiPos)
|
||||||
{
|
{
|
||||||
ascii[asciiPos] = '\0';
|
ascii[asciiPos] = '\0';
|
||||||
dbgPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
|
dbgPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
|
||||||
data += asciiPos;
|
data += asciiPos;
|
||||||
hexPos = 0;
|
hexPos = 0;
|
||||||
asciiPos = 0;
|
asciiPos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != asciiPos)
|
if (0 != asciiPos)
|
||||||
{
|
{
|
||||||
ascii[asciiPos] = '\0';
|
ascii[asciiPos] = '\0';
|
||||||
dbgPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
|
dbgPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef HEX_DUMP_WIDTH
|
#undef HEX_DUMP_WIDTH
|
||||||
#undef HEX_DUMP_SPACE_WIDTH
|
#undef HEX_DUMP_SPACE_WIDTH
|
||||||
#undef HEX_DUMP_FORMAT
|
#undef HEX_DUMP_FORMAT
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __DBG_H__
|
#ifndef __DBG_H__
|
||||||
#define __DBG_H__
|
#define __DBG_H__
|
||||||
|
|
||||||
#include <stdarg.h> // va_list
|
#include <stdarg.h> // va_list
|
||||||
|
|
||||||
#define DBG_STRINGIZE(_x) DBG_STRINGIZE_(_x)
|
#define DBG_STRINGIZE(_x) DBG_STRINGIZE_(_x)
|
||||||
#define DBG_STRINGIZE_(_x) #_x
|
#define DBG_STRINGIZE_(_x) #_x
|
||||||
#define DBG_FILE_LINE_LITERAL "" __FILE__ "(" DBG_STRINGIZE(__LINE__) "): "
|
#define DBG_FILE_LINE_LITERAL "" __FILE__ "(" DBG_STRINGIZE(__LINE__) "): "
|
||||||
#define DBG(_format, ...) dbgPrintf(DBG_FILE_LINE_LITERAL "" _format "\n", ##__VA_ARGS__)
|
#define DBG(_format, ...) dbgPrintf(DBG_FILE_LINE_LITERAL "" _format "\n", ##__VA_ARGS__)
|
||||||
|
|
||||||
extern void dbgOutput(const char* _out);
|
extern void dbgOutput(const char* _out);
|
||||||
extern void dbgPrintfVargs(const char* _format, va_list _argList);
|
extern void dbgPrintfVargs(const char* _format, va_list _argList);
|
||||||
extern void dbgPrintf(const char* _format, ...);
|
extern void dbgPrintf(const char* _format, ...);
|
||||||
extern void dbgPrintfData(const void* _data, uint32_t _size, const char* _format, ...);
|
extern void dbgPrintfData(const void* _data, uint32_t _size, const char* _format, ...);
|
||||||
|
|
||||||
#endif // __DBG_H__
|
#endif // __DBG_H__
|
||||||
|
|
|
@ -1,166 +1,166 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __ENTRY_H__
|
#ifndef __ENTRY_H__
|
||||||
#define __ENTRY_H__
|
#define __ENTRY_H__
|
||||||
|
|
||||||
namespace entry
|
namespace entry
|
||||||
{
|
{
|
||||||
struct MouseButton
|
struct MouseButton
|
||||||
{
|
{
|
||||||
enum Enum
|
enum Enum
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Left,
|
Left,
|
||||||
Middle,
|
Middle,
|
||||||
Right,
|
Right,
|
||||||
|
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Modifier
|
struct Modifier
|
||||||
{
|
{
|
||||||
enum Enum
|
enum Enum
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
LeftAlt = 0x01,
|
LeftAlt = 0x01,
|
||||||
RightAlt = 0x02,
|
RightAlt = 0x02,
|
||||||
LeftCtrl = 0x04,
|
LeftCtrl = 0x04,
|
||||||
RightCtrl = 0x08,
|
RightCtrl = 0x08,
|
||||||
LeftShift = 0x10,
|
LeftShift = 0x10,
|
||||||
RightShift = 0x20,
|
RightShift = 0x20,
|
||||||
LeftMeta = 0x40,
|
LeftMeta = 0x40,
|
||||||
RightMeta = 0x80,
|
RightMeta = 0x80,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Key
|
struct Key
|
||||||
{
|
{
|
||||||
enum Enum
|
enum Enum
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
Esc,
|
Esc,
|
||||||
Return,
|
Return,
|
||||||
Tab,
|
Tab,
|
||||||
Space,
|
Space,
|
||||||
Backspace,
|
Backspace,
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Right,
|
||||||
PageUp,
|
PageUp,
|
||||||
PageDown,
|
PageDown,
|
||||||
Home,
|
Home,
|
||||||
End,
|
End,
|
||||||
Print,
|
Print,
|
||||||
Plus,
|
Plus,
|
||||||
Minus,
|
Minus,
|
||||||
F1,
|
F1,
|
||||||
F2,
|
F2,
|
||||||
F3,
|
F3,
|
||||||
F4,
|
F4,
|
||||||
F5,
|
F5,
|
||||||
F6,
|
F6,
|
||||||
F7,
|
F7,
|
||||||
F8,
|
F8,
|
||||||
F9,
|
F9,
|
||||||
F10,
|
F10,
|
||||||
F11,
|
F11,
|
||||||
F12,
|
F12,
|
||||||
NumPad0,
|
NumPad0,
|
||||||
NumPad1,
|
NumPad1,
|
||||||
NumPad2,
|
NumPad2,
|
||||||
NumPad3,
|
NumPad3,
|
||||||
NumPad4,
|
NumPad4,
|
||||||
NumPad5,
|
NumPad5,
|
||||||
NumPad6,
|
NumPad6,
|
||||||
NumPad7,
|
NumPad7,
|
||||||
NumPad8,
|
NumPad8,
|
||||||
NumPad9,
|
NumPad9,
|
||||||
Key0,
|
Key0,
|
||||||
Key1,
|
Key1,
|
||||||
Key2,
|
Key2,
|
||||||
Key3,
|
Key3,
|
||||||
Key4,
|
Key4,
|
||||||
Key5,
|
Key5,
|
||||||
Key6,
|
Key6,
|
||||||
Key7,
|
Key7,
|
||||||
Key8,
|
Key8,
|
||||||
Key9,
|
Key9,
|
||||||
KeyA,
|
KeyA,
|
||||||
KeyB,
|
KeyB,
|
||||||
KeyC,
|
KeyC,
|
||||||
KeyD,
|
KeyD,
|
||||||
KeyE,
|
KeyE,
|
||||||
KeyF,
|
KeyF,
|
||||||
KeyG,
|
KeyG,
|
||||||
KeyH,
|
KeyH,
|
||||||
KeyI,
|
KeyI,
|
||||||
KeyJ,
|
KeyJ,
|
||||||
KeyK,
|
KeyK,
|
||||||
KeyL,
|
KeyL,
|
||||||
KeyM,
|
KeyM,
|
||||||
KeyN,
|
KeyN,
|
||||||
KeyO,
|
KeyO,
|
||||||
KeyP,
|
KeyP,
|
||||||
KeyQ,
|
KeyQ,
|
||||||
KeyR,
|
KeyR,
|
||||||
KeyS,
|
KeyS,
|
||||||
KeyT,
|
KeyT,
|
||||||
KeyU,
|
KeyU,
|
||||||
KeyV,
|
KeyV,
|
||||||
KeyW,
|
KeyW,
|
||||||
KeyX,
|
KeyX,
|
||||||
KeyY,
|
KeyY,
|
||||||
KeyZ,
|
KeyZ,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Event
|
struct Event
|
||||||
{
|
{
|
||||||
enum Enum
|
enum Enum
|
||||||
{
|
{
|
||||||
Exit,
|
Exit,
|
||||||
Key,
|
Key,
|
||||||
Mouse,
|
Mouse,
|
||||||
Size,
|
Size,
|
||||||
};
|
};
|
||||||
|
|
||||||
Event::Enum m_type;
|
Event::Enum m_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct KeyEvent : public Event
|
struct KeyEvent : public Event
|
||||||
{
|
{
|
||||||
Key::Enum m_key;
|
Key::Enum m_key;
|
||||||
uint8_t m_modifiers;
|
uint8_t m_modifiers;
|
||||||
bool m_down;
|
bool m_down;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MouseEvent : public Event
|
struct MouseEvent : public Event
|
||||||
{
|
{
|
||||||
int32_t m_mx;
|
int32_t m_mx;
|
||||||
int32_t m_my;
|
int32_t m_my;
|
||||||
MouseButton::Enum m_button;
|
MouseButton::Enum m_button;
|
||||||
bool m_down;
|
bool m_down;
|
||||||
bool m_move;
|
bool m_move;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SizeEvent : public Event
|
struct SizeEvent : public Event
|
||||||
{
|
{
|
||||||
uint32_t m_width;
|
uint32_t m_width;
|
||||||
uint32_t m_height;
|
uint32_t m_height;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Event* poll();
|
const Event* poll();
|
||||||
void release(const Event* _event);
|
void release(const Event* _event);
|
||||||
|
|
||||||
void setWindowSize(uint32_t _width, uint32_t _height);
|
void setWindowSize(uint32_t _width, uint32_t _height);
|
||||||
void toggleWindowFrame();
|
void toggleWindowFrame();
|
||||||
void setMouseLock(bool _lock);
|
void setMouseLock(bool _lock);
|
||||||
|
|
||||||
} // namespace entry
|
} // namespace entry
|
||||||
|
|
||||||
#endif // __ENTRY_H__
|
#endif // __ENTRY_H__
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <bx/bx.h>
|
#include <bx/bx.h>
|
||||||
|
|
||||||
#if BX_PLATFORM_EMSCRIPTEN
|
#if BX_PLATFORM_EMSCRIPTEN
|
||||||
|
|
||||||
#include <emscripten/emscripten.h>
|
#include <emscripten/emscripten.h>
|
||||||
#include <alloca.h>
|
#include <alloca.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
#include "entry.h"
|
#include "entry.h"
|
||||||
|
|
||||||
namespace entry
|
namespace entry
|
||||||
{
|
{
|
||||||
const Event* poll()
|
const Event* poll()
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -24,50 +24,50 @@ namespace entry
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWindowSize(uint32_t _width, uint32_t _height)
|
void setWindowSize(uint32_t _width, uint32_t _height)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleWindowFrame()
|
void toggleWindowFrame()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMouseLock(bool _lock)
|
void setMouseLock(bool _lock)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace entry
|
} // namespace entry
|
||||||
|
|
||||||
extern int _main_(int _argc, char** _argv);
|
extern int _main_(int _argc, char** _argv);
|
||||||
|
|
||||||
static jmp_buf s_main;
|
static jmp_buf s_main;
|
||||||
static jmp_buf s_loop;
|
static jmp_buf s_loop;
|
||||||
|
|
||||||
void emscripten_yield()
|
void emscripten_yield()
|
||||||
{
|
{
|
||||||
if (!setjmp(s_main) )
|
if (!setjmp(s_main) )
|
||||||
{
|
{
|
||||||
longjmp(s_loop, 1);
|
longjmp(s_loop, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if (!setjmp(s_loop) )
|
if (!setjmp(s_loop) )
|
||||||
{
|
{
|
||||||
longjmp(s_main, 1);
|
longjmp(s_main, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int _argc, char** _argv)
|
int main(int _argc, char** _argv)
|
||||||
{
|
{
|
||||||
if (!setjmp(s_loop) )
|
if (!setjmp(s_loop) )
|
||||||
{
|
{
|
||||||
alloca(16<<10);
|
alloca(16<<10);
|
||||||
_main_(_argc, _argv);
|
_main_(_argc, _argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
emscripten_set_main_loop(loop, 10, true);
|
emscripten_set_main_loop(loop, 10, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // BX_PLATFORM_EMSCRIPTEN
|
#endif // BX_PLATFORM_EMSCRIPTEN
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <bx/bx.h>
|
#include <bx/bx.h>
|
||||||
|
|
||||||
#if BX_PLATFORM_NACL
|
#if BX_PLATFORM_NACL
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <ppapi/c/pp_errors.h>
|
#include <ppapi/c/pp_errors.h>
|
||||||
#include <ppapi/c/pp_module.h>
|
#include <ppapi/c/pp_module.h>
|
||||||
#include <ppapi/c/ppb.h>
|
#include <ppapi/c/ppb.h>
|
||||||
#include <ppapi/c/ppb_graphics_3d.h>
|
#include <ppapi/c/ppb_graphics_3d.h>
|
||||||
#include <ppapi/c/ppb_instance.h>
|
#include <ppapi/c/ppb_instance.h>
|
||||||
#include <ppapi/c/ppp.h>
|
#include <ppapi/c/ppp.h>
|
||||||
#include <ppapi/c/ppp_instance.h>
|
#include <ppapi/c/ppp_instance.h>
|
||||||
#include <ppapi/gles2/gl2ext_ppapi.h>
|
#include <ppapi/gles2/gl2ext_ppapi.h>
|
||||||
|
|
||||||
#include <bgfxplatform.h>
|
#include <bgfxplatform.h>
|
||||||
#include "dbg.h"
|
#include "dbg.h"
|
||||||
|
|
||||||
#include "entry.h"
|
#include "entry.h"
|
||||||
|
|
||||||
namespace entry
|
namespace entry
|
||||||
{
|
{
|
||||||
const Event* poll()
|
const Event* poll()
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -36,117 +36,117 @@ namespace entry
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWindowSize(uint32_t _width, uint32_t _height)
|
void setWindowSize(uint32_t _width, uint32_t _height)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleWindowFrame()
|
void toggleWindowFrame()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMouseLock(bool _lock)
|
void setMouseLock(bool _lock)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace entry
|
} // namespace entry
|
||||||
|
|
||||||
extern int _main_(int _argc, char** _argv);
|
extern int _main_(int _argc, char** _argv);
|
||||||
|
|
||||||
static void* _entry_(void*)
|
static void* _entry_(void*)
|
||||||
{
|
{
|
||||||
const char* argv[1] = { "nacl.nexe" };
|
const char* argv[1] = { "nacl.nexe" };
|
||||||
_main_(1, const_cast<char**>(argv) );
|
_main_(1, const_cast<char**>(argv) );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NaclContext
|
struct NaclContext
|
||||||
{
|
{
|
||||||
NaclContext()
|
NaclContext()
|
||||||
: m_thread(0)
|
: m_thread(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const PPB_Instance* m_instInterface;
|
const PPB_Instance* m_instInterface;
|
||||||
const PPB_Graphics3D* m_graphicsInterface;
|
const PPB_Graphics3D* m_graphicsInterface;
|
||||||
|
|
||||||
pthread_t m_thread;
|
pthread_t m_thread;
|
||||||
PP_Module m_module;
|
PP_Module m_module;
|
||||||
PP_Instance m_instance;
|
PP_Instance m_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
static NaclContext s_ctx;
|
static NaclContext s_ctx;
|
||||||
|
|
||||||
static PP_Bool naclInstanceDidCreate(PP_Instance _instance, uint32_t _argc, const char* _argn[], const char* _argv[])
|
static PP_Bool naclInstanceDidCreate(PP_Instance _instance, uint32_t _argc, const char* _argn[], const char* _argv[])
|
||||||
{
|
{
|
||||||
s_ctx.m_instance = _instance;
|
s_ctx.m_instance = _instance;
|
||||||
|
|
||||||
bgfx::naclSetIntefraces(s_ctx.m_instance, s_ctx.m_instInterface, s_ctx.m_graphicsInterface, NULL);
|
bgfx::naclSetIntefraces(s_ctx.m_instance, s_ctx.m_instInterface, s_ctx.m_graphicsInterface, NULL);
|
||||||
pthread_create(&s_ctx.m_thread, NULL, _entry_, NULL);
|
pthread_create(&s_ctx.m_thread, NULL, _entry_, NULL);
|
||||||
|
|
||||||
return PP_TRUE;
|
return PP_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void naclInstanceDidDestroy(PP_Instance _instance)
|
static void naclInstanceDidDestroy(PP_Instance _instance)
|
||||||
{
|
{
|
||||||
if (s_ctx.m_thread)
|
if (s_ctx.m_thread)
|
||||||
{
|
{
|
||||||
pthread_join(s_ctx.m_thread, NULL);
|
pthread_join(s_ctx.m_thread, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void naclInstanceDidChangeView(PP_Instance _instance, PP_Resource _view)
|
static void naclInstanceDidChangeView(PP_Instance _instance, PP_Resource _view)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void naclInstanceDidChangeFocus(PP_Instance _instance, PP_Bool _focus)
|
static void naclInstanceDidChangeFocus(PP_Instance _instance, PP_Bool _focus)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static PP_Bool naclInstanceHandleDocumentLoad(PP_Instance _instance, PP_Resource _urlLoader)
|
static PP_Bool naclInstanceHandleDocumentLoad(PP_Instance _instance, PP_Resource _urlLoader)
|
||||||
{
|
{
|
||||||
return PP_FALSE;
|
return PP_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
PP_EXPORT const void* PPP_GetInterface(const char* _name)
|
PP_EXPORT const void* PPP_GetInterface(const char* _name)
|
||||||
{
|
{
|
||||||
if (0 == strcmp(_name, PPP_INSTANCE_INTERFACE) )
|
if (0 == strcmp(_name, PPP_INSTANCE_INTERFACE) )
|
||||||
{
|
{
|
||||||
static PPP_Instance instanceInterface =
|
static PPP_Instance instanceInterface =
|
||||||
{
|
{
|
||||||
&naclInstanceDidCreate,
|
&naclInstanceDidCreate,
|
||||||
&naclInstanceDidDestroy,
|
&naclInstanceDidDestroy,
|
||||||
&naclInstanceDidChangeView,
|
&naclInstanceDidChangeView,
|
||||||
&naclInstanceDidChangeFocus,
|
&naclInstanceDidChangeFocus,
|
||||||
&naclInstanceHandleDocumentLoad,
|
&naclInstanceHandleDocumentLoad,
|
||||||
};
|
};
|
||||||
|
|
||||||
return &instanceInterface;
|
return &instanceInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
bool initializeInterface(const Type*& _result, PPB_GetInterface _interface, const char* _name)
|
bool initializeInterface(const Type*& _result, PPB_GetInterface _interface, const char* _name)
|
||||||
{
|
{
|
||||||
_result = reinterpret_cast<const Type*>(_interface(_name) );
|
_result = reinterpret_cast<const Type*>(_interface(_name) );
|
||||||
return NULL != _result;
|
return NULL != _result;
|
||||||
}
|
}
|
||||||
|
|
||||||
PP_EXPORT int32_t PPP_InitializeModule(PP_Module _module, PPB_GetInterface _interface)
|
PP_EXPORT int32_t PPP_InitializeModule(PP_Module _module, PPB_GetInterface _interface)
|
||||||
{
|
{
|
||||||
s_ctx.m_module = _module;
|
s_ctx.m_module = _module;
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
result &= initializeInterface(s_ctx.m_instInterface, _interface, PPB_INSTANCE_INTERFACE);
|
result &= initializeInterface(s_ctx.m_instInterface, _interface, PPB_INSTANCE_INTERFACE);
|
||||||
result &= initializeInterface(s_ctx.m_graphicsInterface, _interface, PPB_GRAPHICS_3D_INTERFACE);
|
result &= initializeInterface(s_ctx.m_graphicsInterface, _interface, PPB_GRAPHICS_3D_INTERFACE);
|
||||||
result &= glInitializePPAPI(_interface);
|
result &= glInitializePPAPI(_interface);
|
||||||
|
|
||||||
return result ? PP_OK : PP_ERROR_NOINTERFACE;
|
return result ? PP_OK : PP_ERROR_NOINTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
PP_EXPORT void PPP_ShutdownModule()
|
PP_EXPORT void PPP_ShutdownModule()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // BX_PLATFROM_NACL
|
#endif // BX_PLATFROM_NACL
|
||||||
|
|
|
@ -602,14 +602,14 @@ namespace entry
|
||||||
s_ctx.m_eventQueue.release(_event);
|
s_ctx.m_eventQueue.release(_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWindowSize(uint32_t _width, uint32_t _height)
|
void setWindowSize(uint32_t _width, uint32_t _height)
|
||||||
{
|
{
|
||||||
PostMessage(s_ctx.m_hwnd, WM_USER_SET_WINDOW_SIZE, 0, (_height<<16) | (_width&0xffff) );
|
PostMessage(s_ctx.m_hwnd, WM_USER_SET_WINDOW_SIZE, 0, (_height<<16) | (_width&0xffff) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleWindowFrame()
|
void toggleWindowFrame()
|
||||||
{
|
{
|
||||||
PostMessage(s_ctx.m_hwnd, WM_USER_TOGGLE_WINDOW_FRAME, 0, 0);
|
PostMessage(s_ctx.m_hwnd, WM_USER_TOGGLE_WINDOW_FRAME, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMouseLock(bool _lock)
|
void setMouseLock(bool _lock)
|
||||||
|
|
|
@ -1,258 +1,258 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __SHADERLIB_SH__
|
#ifndef __SHADERLIB_SH__
|
||||||
#define __SHADERLIB_SH__
|
#define __SHADERLIB_SH__
|
||||||
|
|
||||||
vec4 encodeRE8(float _r)
|
vec4 encodeRE8(float _r)
|
||||||
{
|
{
|
||||||
float exponent = ceil(log2(_r) );
|
float exponent = ceil(log2(_r) );
|
||||||
return vec4(_r / exp2(exponent)
|
return vec4(_r / exp2(exponent)
|
||||||
, 0.0
|
, 0.0
|
||||||
, 0.0
|
, 0.0
|
||||||
, (exponent + 128.0) / 255.0
|
, (exponent + 128.0) / 255.0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
float decodeRE8(vec4 _re8)
|
float decodeRE8(vec4 _re8)
|
||||||
{
|
{
|
||||||
float exponent = _re8.w * 255.0 - 128.0;
|
float exponent = _re8.w * 255.0 - 128.0;
|
||||||
return _re8.x * exp2(exponent);
|
return _re8.x * exp2(exponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 encodeRGBE8(vec3 _rgb)
|
vec4 encodeRGBE8(vec3 _rgb)
|
||||||
{
|
{
|
||||||
vec4 rgbe8;
|
vec4 rgbe8;
|
||||||
float maxComponent = max(max(_rgb.x, _rgb.y), _rgb.z);
|
float maxComponent = max(max(_rgb.x, _rgb.y), _rgb.z);
|
||||||
float exponent = ceil(log2(maxComponent) );
|
float exponent = ceil(log2(maxComponent) );
|
||||||
rgbe8.xyz = _rgb / exp2(exponent);
|
rgbe8.xyz = _rgb / exp2(exponent);
|
||||||
rgbe8.w = (exponent + 128.0) / 255.0;
|
rgbe8.w = (exponent + 128.0) / 255.0;
|
||||||
return rgbe8;
|
return rgbe8;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 decodeRGBE8(vec4 _rgbe8)
|
vec3 decodeRGBE8(vec4 _rgbe8)
|
||||||
{
|
{
|
||||||
float exponent = _rgbe8.w * 255.0 - 128.0;
|
float exponent = _rgbe8.w * 255.0 - 128.0;
|
||||||
vec3 rgb = _rgbe8.xyz * exp2(exponent);
|
vec3 rgb = _rgbe8.xyz * exp2(exponent);
|
||||||
return rgb;
|
return rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reference:
|
// Reference:
|
||||||
// RGB/XYZ Matrices
|
// RGB/XYZ Matrices
|
||||||
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
|
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
|
||||||
vec3 convertRGB2XYZ(vec3 _rgb)
|
vec3 convertRGB2XYZ(vec3 _rgb)
|
||||||
{
|
{
|
||||||
vec3 xyz;
|
vec3 xyz;
|
||||||
xyz.x = dot(vec3(0.4124564, 0.3575761, 0.1804375), _rgb);
|
xyz.x = dot(vec3(0.4124564, 0.3575761, 0.1804375), _rgb);
|
||||||
xyz.y = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb);
|
xyz.y = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb);
|
||||||
xyz.z = dot(vec3(0.0193339, 0.1191920, 0.9503041), _rgb);
|
xyz.z = dot(vec3(0.0193339, 0.1191920, 0.9503041), _rgb);
|
||||||
return xyz;
|
return xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 convertXYZ2RGB(vec3 _xyz)
|
vec3 convertXYZ2RGB(vec3 _xyz)
|
||||||
{
|
{
|
||||||
vec3 rgb;
|
vec3 rgb;
|
||||||
rgb.x = dot(vec3( 3.2404542, -1.5371385, -0.4985314), _xyz);
|
rgb.x = dot(vec3( 3.2404542, -1.5371385, -0.4985314), _xyz);
|
||||||
rgb.y = dot(vec3(-0.9692660, 1.8760108, 0.0415560), _xyz);
|
rgb.y = dot(vec3(-0.9692660, 1.8760108, 0.0415560), _xyz);
|
||||||
rgb.z = dot(vec3( 0.0556434, -0.2040259, 1.0572252), _xyz);
|
rgb.z = dot(vec3( 0.0556434, -0.2040259, 1.0572252), _xyz);
|
||||||
return rgb;
|
return rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 convertXYZ2Yxy(vec3 _xyz)
|
vec3 convertXYZ2Yxy(vec3 _xyz)
|
||||||
{
|
{
|
||||||
// Reference:
|
// Reference:
|
||||||
// http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_xyY.html
|
// http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_xyY.html
|
||||||
float inv = 1.0/dot(_xyz, vec3(1.0, 1.0, 1.0) );
|
float inv = 1.0/dot(_xyz, vec3(1.0, 1.0, 1.0) );
|
||||||
return vec3(_xyz.y, _xyz.x*inv, _xyz.y*inv);
|
return vec3(_xyz.y, _xyz.x*inv, _xyz.y*inv);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 convertYxy2XYZ(vec3 _Yxy)
|
vec3 convertYxy2XYZ(vec3 _Yxy)
|
||||||
{
|
{
|
||||||
// Reference:
|
// Reference:
|
||||||
// http://www.brucelindbloom.com/index.html?Eqn_xyY_to_XYZ.html
|
// http://www.brucelindbloom.com/index.html?Eqn_xyY_to_XYZ.html
|
||||||
vec3 xyz;
|
vec3 xyz;
|
||||||
xyz.x = _Yxy.x*_Yxy.y/_Yxy.z;
|
xyz.x = _Yxy.x*_Yxy.y/_Yxy.z;
|
||||||
xyz.y = _Yxy.x;
|
xyz.y = _Yxy.x;
|
||||||
xyz.z = _Yxy.x*(1.0 - _Yxy.y - _Yxy.z)/_Yxy.z;
|
xyz.z = _Yxy.x*(1.0 - _Yxy.y - _Yxy.z)/_Yxy.z;
|
||||||
return xyz;
|
return xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 convertRGB2Yxy(vec3 _rgb)
|
vec3 convertRGB2Yxy(vec3 _rgb)
|
||||||
{
|
{
|
||||||
return convertXYZ2Yxy(convertRGB2XYZ(_rgb) );
|
return convertXYZ2Yxy(convertRGB2XYZ(_rgb) );
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 convertYxy2RGB(vec3 _Yxy)
|
vec3 convertYxy2RGB(vec3 _Yxy)
|
||||||
{
|
{
|
||||||
return convertXYZ2RGB(convertYxy2XYZ(_Yxy) );
|
return convertXYZ2RGB(convertYxy2XYZ(_Yxy) );
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 convertRGB2Yuv(vec3 _rgb)
|
vec3 convertRGB2Yuv(vec3 _rgb)
|
||||||
{
|
{
|
||||||
vec3 yuv;
|
vec3 yuv;
|
||||||
yuv.x = dot(_rgb, vec3(0.299, 0.587, 0.114) );
|
yuv.x = dot(_rgb, vec3(0.299, 0.587, 0.114) );
|
||||||
yuv.y = (_rgb.x - yuv.x)*0.713 + 0.5;
|
yuv.y = (_rgb.x - yuv.x)*0.713 + 0.5;
|
||||||
yuv.z = (_rgb.z - yuv.x)*0.564 + 0.5;
|
yuv.z = (_rgb.z - yuv.x)*0.564 + 0.5;
|
||||||
return yuv;
|
return yuv;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 convertYuv2RGB(vec3 _yuv)
|
vec3 convertYuv2RGB(vec3 _yuv)
|
||||||
{
|
{
|
||||||
vec3 rgb;
|
vec3 rgb;
|
||||||
rgb.x = _yuv.x + 1.403*(_yuv.y-0.5);
|
rgb.x = _yuv.x + 1.403*(_yuv.y-0.5);
|
||||||
rgb.y = _yuv.x - 0.344*(_yuv.y-0.5) - 0.714*(_yuv.z-0.5);
|
rgb.y = _yuv.x - 0.344*(_yuv.y-0.5) - 0.714*(_yuv.z-0.5);
|
||||||
rgb.z = _yuv.x + 1.773*(_yuv.z-0.5);
|
rgb.z = _yuv.x + 1.773*(_yuv.z-0.5);
|
||||||
return rgb;
|
return rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 convertRGB2YIQ(vec3 _rgb)
|
vec3 convertRGB2YIQ(vec3 _rgb)
|
||||||
{
|
{
|
||||||
vec3 yiq;
|
vec3 yiq;
|
||||||
yiq.x = dot(vec3(0.299, 0.587, 0.114 ), _rgb);
|
yiq.x = dot(vec3(0.299, 0.587, 0.114 ), _rgb);
|
||||||
yiq.y = dot(vec3(0.595716, -0.274453, -0.321263), _rgb);
|
yiq.y = dot(vec3(0.595716, -0.274453, -0.321263), _rgb);
|
||||||
yiq.z = dot(vec3(0.211456, -0.522591, 0.311135), _rgb);
|
yiq.z = dot(vec3(0.211456, -0.522591, 0.311135), _rgb);
|
||||||
return yiq;
|
return yiq;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 convertYIQ2RGB(vec3 _yiq)
|
vec3 convertYIQ2RGB(vec3 _yiq)
|
||||||
{
|
{
|
||||||
vec3 rgb;
|
vec3 rgb;
|
||||||
rgb.x = dot(vec3(1.0, 0.9563, 0.6210), _yiq);
|
rgb.x = dot(vec3(1.0, 0.9563, 0.6210), _yiq);
|
||||||
rgb.y = dot(vec3(1.0, -0.2721, -0.6474), _yiq);
|
rgb.y = dot(vec3(1.0, -0.2721, -0.6474), _yiq);
|
||||||
rgb.z = dot(vec3(1.0, -1.1070, 1.7046), _yiq);
|
rgb.z = dot(vec3(1.0, -1.1070, 1.7046), _yiq);
|
||||||
return rgb;
|
return rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 toLinear(vec3 _rgb)
|
vec3 toLinear(vec3 _rgb)
|
||||||
{
|
{
|
||||||
return pow(_rgb, vec3_splat(2.2) );
|
return pow(_rgb, vec3_splat(2.2) );
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 toLinear(vec4 _rgba)
|
vec4 toLinear(vec4 _rgba)
|
||||||
{
|
{
|
||||||
return vec4(toLinear(_rgba.xyz), _rgba.w);
|
return vec4(toLinear(_rgba.xyz), _rgba.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 toGamma(vec3 _rgb)
|
vec3 toGamma(vec3 _rgb)
|
||||||
{
|
{
|
||||||
return pow(_rgb, vec3_splat(1.0/2.2) );
|
return pow(_rgb, vec3_splat(1.0/2.2) );
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 toGamma(vec4 _rgba)
|
vec4 toGamma(vec4 _rgba)
|
||||||
{
|
{
|
||||||
return vec4(toGamma(_rgba.xyz), _rgba.w);
|
return vec4(toGamma(_rgba.xyz), _rgba.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 toReinhard(vec3 _rgb)
|
vec3 toReinhard(vec3 _rgb)
|
||||||
{
|
{
|
||||||
return toGamma(_rgb/(_rgb+vec3_splat(1.0) ) );
|
return toGamma(_rgb/(_rgb+vec3_splat(1.0) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 toReinhard(vec4 _rgba)
|
vec4 toReinhard(vec4 _rgba)
|
||||||
{
|
{
|
||||||
return vec4(toReinhard(_rgba.xyz), _rgba.w);
|
return vec4(toReinhard(_rgba.xyz), _rgba.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 toFilmic(vec3 _rgb)
|
vec3 toFilmic(vec3 _rgb)
|
||||||
{
|
{
|
||||||
_rgb = max(vec3_splat(0.0), _rgb - 0.004);
|
_rgb = max(vec3_splat(0.0), _rgb - 0.004);
|
||||||
_rgb = (_rgb*(6.2*_rgb + 0.5) ) / (_rgb*(6.2*_rgb + 1.7) + 0.06);
|
_rgb = (_rgb*(6.2*_rgb + 0.5) ) / (_rgb*(6.2*_rgb + 1.7) + 0.06);
|
||||||
return _rgb;
|
return _rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 toFilmic(vec4 _rgba)
|
vec4 toFilmic(vec4 _rgba)
|
||||||
{
|
{
|
||||||
return vec4(toFilmic(_rgba.xyz), _rgba.w);
|
return vec4(toFilmic(_rgba.xyz), _rgba.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 luma(vec3 _rgb)
|
vec3 luma(vec3 _rgb)
|
||||||
{
|
{
|
||||||
float yy = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb);
|
float yy = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb);
|
||||||
return vec3_splat(yy);
|
return vec3_splat(yy);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 luma(vec4 _rgba)
|
vec4 luma(vec4 _rgba)
|
||||||
{
|
{
|
||||||
return vec4(luma(_rgba.xyz), _rgba.w);
|
return vec4(luma(_rgba.xyz), _rgba.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 conSatBri(vec3 _rgb, vec3 _csb)
|
vec3 conSatBri(vec3 _rgb, vec3 _csb)
|
||||||
{
|
{
|
||||||
vec3 rgb = _rgb * _csb.z;
|
vec3 rgb = _rgb * _csb.z;
|
||||||
rgb = lerp(luma(rgb), rgb, _csb.y);
|
rgb = lerp(luma(rgb), rgb, _csb.y);
|
||||||
rgb = lerp(vec3_splat(0.5), rgb, _csb.x);
|
rgb = lerp(vec3_splat(0.5), rgb, _csb.x);
|
||||||
return rgb;
|
return rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 conSatBri(vec4 _rgba, vec3 _csb)
|
vec4 conSatBri(vec4 _rgba, vec3 _csb)
|
||||||
{
|
{
|
||||||
return vec4(conSatBri(_rgba.xyz, _csb), _rgba.w);
|
return vec4(conSatBri(_rgba.xyz, _csb), _rgba.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 posterize(vec3 _rgb, float _numColors)
|
vec3 posterize(vec3 _rgb, float _numColors)
|
||||||
{
|
{
|
||||||
return floor(_rgb*_numColors) / _numColors;
|
return floor(_rgb*_numColors) / _numColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 posterize(vec4 _rgba, float _numColors)
|
vec4 posterize(vec4 _rgba, float _numColors)
|
||||||
{
|
{
|
||||||
return vec4(posterize(_rgba.xyz, _numColors), _rgba.w);
|
return vec4(posterize(_rgba.xyz, _numColors), _rgba.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 sepia(vec3 _rgb)
|
vec3 sepia(vec3 _rgb)
|
||||||
{
|
{
|
||||||
vec3 color;
|
vec3 color;
|
||||||
color.x = dot(_rgb, vec3(0.393, 0.769, 0.189) );
|
color.x = dot(_rgb, vec3(0.393, 0.769, 0.189) );
|
||||||
color.y = dot(_rgb, vec3(0.349, 0.686, 0.168) );
|
color.y = dot(_rgb, vec3(0.349, 0.686, 0.168) );
|
||||||
color.z = dot(_rgb, vec3(0.272, 0.534, 0.131) );
|
color.z = dot(_rgb, vec3(0.272, 0.534, 0.131) );
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 sepia(vec4 _rgba)
|
vec4 sepia(vec4 _rgba)
|
||||||
{
|
{
|
||||||
return vec4(sepia(_rgba.xyz), _rgba.w);
|
return vec4(sepia(_rgba.xyz), _rgba.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 blendOverlay(vec3 _base, vec3 _blend)
|
vec3 blendOverlay(vec3 _base, vec3 _blend)
|
||||||
{
|
{
|
||||||
vec3 lt = 2.0 * _base * _blend;
|
vec3 lt = 2.0 * _base * _blend;
|
||||||
vec3 gte = 1.0 - 2.0 * (1.0 - _base) * (1.0 - _blend);
|
vec3 gte = 1.0 - 2.0 * (1.0 - _base) * (1.0 - _blend);
|
||||||
return lerp(lt, gte, step(vec3_splat(0.5), _base) );
|
return lerp(lt, gte, step(vec3_splat(0.5), _base) );
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 blendOverlay(vec4 _base, vec4 _blend)
|
vec4 blendOverlay(vec4 _base, vec4 _blend)
|
||||||
{
|
{
|
||||||
return vec4(blendOverlay(_base.xyz, _blend.xyz), _base.w);
|
return vec4(blendOverlay(_base.xyz, _blend.xyz), _base.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 adjustHue(vec3 _rgb, float _hue)
|
vec3 adjustHue(vec3 _rgb, float _hue)
|
||||||
{
|
{
|
||||||
vec3 yiq = convertRGB2YIQ(_rgb);
|
vec3 yiq = convertRGB2YIQ(_rgb);
|
||||||
float angle = _hue + atan2(yiq.z, yiq.y);
|
float angle = _hue + atan2(yiq.z, yiq.y);
|
||||||
float len = length(yiq.yz);
|
float len = length(yiq.yz);
|
||||||
return convertYIQ2RGB(vec3(yiq.x, len*cos(angle), len*sin(angle) ) );
|
return convertYIQ2RGB(vec3(yiq.x, len*cos(angle), len*sin(angle) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 packFloatToRgba(float _value)
|
vec4 packFloatToRgba(float _value)
|
||||||
{
|
{
|
||||||
const vec4 shift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);
|
const vec4 shift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);
|
||||||
const vec4 mask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
|
const vec4 mask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
|
||||||
vec4 comp = frac(_value * shift);
|
vec4 comp = frac(_value * shift);
|
||||||
comp -= comp.xxyz * mask;
|
comp -= comp.xxyz * mask;
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
float unpackRgbaToFloat(vec4 _rgba)
|
float unpackRgbaToFloat(vec4 _rgba)
|
||||||
{
|
{
|
||||||
const vec4 shift = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
|
const vec4 shift = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
|
||||||
return dot(_rgba, shift);
|
return dot(_rgba, shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
float random(vec2 _uv)
|
float random(vec2 _uv)
|
||||||
{
|
{
|
||||||
return frac(sin(dot(_uv.xy, vec2(12.9898, 78.233) ) ) * 43758.5453);
|
return frac(sin(dot(_uv.xy, vec2(12.9898, 78.233) ) ) * 43758.5453);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __SHADERLIB_SH__
|
#endif // __SHADERLIB_SH__
|
||||||
|
|
|
@ -1,161 +1,161 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __BGFX_SHADER_H__
|
#ifndef __BGFX_SHADER_H__
|
||||||
#define __BGFX_SHADER_H__
|
#define __BGFX_SHADER_H__
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
|
|
||||||
#if BGFX_SHADER_LANGUAGE_HLSL
|
#if BGFX_SHADER_LANGUAGE_HLSL
|
||||||
# define dFdx(_x) ddx(_x)
|
# define dFdx(_x) ddx(_x)
|
||||||
# define dFdy(_y) ddy(-_y)
|
# define dFdy(_y) ddy(-_y)
|
||||||
|
|
||||||
# if BGFX_SHADER_LANGUAGE_HLSL > 3
|
# if BGFX_SHADER_LANGUAGE_HLSL > 3
|
||||||
struct BgfxSampler2D
|
struct BgfxSampler2D
|
||||||
{
|
{
|
||||||
SamplerState m_sampler;
|
SamplerState m_sampler;
|
||||||
Texture2D m_texture;
|
Texture2D m_texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
vec4 bgfxTexture2D(BgfxSampler2D _sampler, vec2 _coord)
|
vec4 bgfxTexture2D(BgfxSampler2D _sampler, vec2 _coord)
|
||||||
{
|
{
|
||||||
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
|
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 bgfxTexture2DLod(BgfxSampler2D _sampler, vec2 _coord, float _level)
|
vec4 bgfxTexture2DLod(BgfxSampler2D _sampler, vec2 _coord, float _level)
|
||||||
{
|
{
|
||||||
return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
|
return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BgfxSampler3D
|
struct BgfxSampler3D
|
||||||
{
|
{
|
||||||
SamplerState m_sampler;
|
SamplerState m_sampler;
|
||||||
Texture3D m_texture;
|
Texture3D m_texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord)
|
vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord)
|
||||||
{
|
{
|
||||||
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
|
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 bgfxTexture3DLod(BgfxSampler3D _sampler, vec3 _coord, float _level)
|
vec4 bgfxTexture3DLod(BgfxSampler3D _sampler, vec3 _coord, float _level)
|
||||||
{
|
{
|
||||||
return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
|
return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BgfxSamplerCube
|
struct BgfxSamplerCube
|
||||||
{
|
{
|
||||||
SamplerState m_sampler;
|
SamplerState m_sampler;
|
||||||
TextureCube m_texture;
|
TextureCube m_texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
vec4 bgfxTextureCube(BgfxSamplerCube _sampler, vec3 _coord)
|
vec4 bgfxTextureCube(BgfxSamplerCube _sampler, vec3 _coord)
|
||||||
{
|
{
|
||||||
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
|
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 bgfxTextureCubeLod(BgfxSamplerCube _sampler, vec3 _coord, float _level)
|
vec4 bgfxTextureCubeLod(BgfxSamplerCube _sampler, vec3 _coord, float _level)
|
||||||
{
|
{
|
||||||
return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
|
return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
|
||||||
}
|
}
|
||||||
|
|
||||||
# define SAMPLER2D(_name, _reg) \
|
# define SAMPLER2D(_name, _reg) \
|
||||||
uniform SamplerState _name ## Sampler : register(s[_reg]); \
|
uniform SamplerState _name ## Sampler : register(s[_reg]); \
|
||||||
uniform Texture2D _name ## Texture : register(t[_reg]); \
|
uniform Texture2D _name ## Texture : register(t[_reg]); \
|
||||||
static BgfxSampler2D _name = { _name ## Sampler, _name ## Texture }
|
static BgfxSampler2D _name = { _name ## Sampler, _name ## Texture }
|
||||||
# define sampler2D BgfxSampler2D
|
# define sampler2D BgfxSampler2D
|
||||||
# define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord)
|
# define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord)
|
||||||
# define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level)
|
# define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level)
|
||||||
|
|
||||||
# define SAMPLER3D(_name, _reg) \
|
# define SAMPLER3D(_name, _reg) \
|
||||||
uniform SamplerState _name ## Sampler : register(s[_reg]); \
|
uniform SamplerState _name ## Sampler : register(s[_reg]); \
|
||||||
uniform Texture3D _name ## Texture : register(t[_reg]); \
|
uniform Texture3D _name ## Texture : register(t[_reg]); \
|
||||||
static BgfxSampler3D _name = { _name ## Sampler, _name ## Texture }
|
static BgfxSampler3D _name = { _name ## Sampler, _name ## Texture }
|
||||||
# define sampler3D BgfxSampler3D
|
# define sampler3D BgfxSampler3D
|
||||||
# define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord)
|
# define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord)
|
||||||
# define texture3DLod(_sampler, _coord, _level) bgfxTexture3DLod(_sampler, _coord, _level)
|
# define texture3DLod(_sampler, _coord, _level) bgfxTexture3DLod(_sampler, _coord, _level)
|
||||||
|
|
||||||
# define SAMPLERCUBE(_name, _reg) \
|
# define SAMPLERCUBE(_name, _reg) \
|
||||||
uniform SamplerState _name ## Sampler : register(s[_reg]); \
|
uniform SamplerState _name ## Sampler : register(s[_reg]); \
|
||||||
uniform TextureCube _name ## Texture : register(t[_reg]); \
|
uniform TextureCube _name ## Texture : register(t[_reg]); \
|
||||||
static BgfxSamplerCube _name = { _name ## Sampler, _name ## Texture }
|
static BgfxSamplerCube _name = { _name ## Sampler, _name ## Texture }
|
||||||
# define samplerCube BgfxSamplerCube
|
# define samplerCube BgfxSamplerCube
|
||||||
# define textureCube(_sampler, _coord) bgfxTextureCube(_sampler, _coord)
|
# define textureCube(_sampler, _coord) bgfxTextureCube(_sampler, _coord)
|
||||||
# define textureCubeLod(_sampler, _coord, _level) bgfxTextureCubeLod(_sampler, _coord, _level)
|
# define textureCubeLod(_sampler, _coord, _level) bgfxTextureCubeLod(_sampler, _coord, _level)
|
||||||
# else
|
# else
|
||||||
# define SAMPLER2D(_name, _reg) uniform sampler2D _name : register(s ## _reg)
|
# define SAMPLER2D(_name, _reg) uniform sampler2D _name : register(s ## _reg)
|
||||||
# define texture2D(_sampler, _coord) tex2D(_sampler, _coord)
|
# define texture2D(_sampler, _coord) tex2D(_sampler, _coord)
|
||||||
# define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec3( (_coord).xy, _level) )
|
# define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec3( (_coord).xy, _level) )
|
||||||
# define SAMPLER3D(_name, _reg) uniform sampler3D _name : register(s ## _reg)
|
# define SAMPLER3D(_name, _reg) uniform sampler3D _name : register(s ## _reg)
|
||||||
# define texture3D(_sampler, _coord) tex3D(_sampler, _coord)
|
# define texture3D(_sampler, _coord) tex3D(_sampler, _coord)
|
||||||
# define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) )
|
# define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) )
|
||||||
# define SAMPLERCUBE(_name, _reg) uniform samplerCUBE _name : register(s[_reg])
|
# define SAMPLERCUBE(_name, _reg) uniform samplerCUBE _name : register(s[_reg])
|
||||||
# define textureCube(_sampler, _coord) texCUBE(_sampler, _coord)
|
# define textureCube(_sampler, _coord) texCUBE(_sampler, _coord)
|
||||||
# define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) )
|
# define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) )
|
||||||
# endif //
|
# endif //
|
||||||
|
|
||||||
# define vec2_splat(_x) float2(_x, _x)
|
# define vec2_splat(_x) float2(_x, _x)
|
||||||
# define vec3_splat(_x) float3(_x, _x, _x)
|
# define vec3_splat(_x) float3(_x, _x, _x)
|
||||||
# define vec4_splat(_x) float4(_x, _x, _x, _x)
|
# define vec4_splat(_x) float4(_x, _x, _x, _x)
|
||||||
|
|
||||||
# define bvec2 bool2
|
# define bvec2 bool2
|
||||||
# define bvec3 bool3
|
# define bvec3 bool3
|
||||||
# define bvec4 bool4
|
# define bvec4 bool4
|
||||||
|
|
||||||
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); }
|
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); }
|
||||||
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); }
|
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); }
|
||||||
vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_mtx, _vec); }
|
vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_mtx, _vec); }
|
||||||
vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_vec, _mtx); }
|
vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_vec, _mtx); }
|
||||||
|
|
||||||
bvec2 lessThan(vec2 _a, vec2 _b) { return _a < _b; }
|
bvec2 lessThan(vec2 _a, vec2 _b) { return _a < _b; }
|
||||||
bvec3 lessThan(vec3 _a, vec3 _b) { return _a < _b; }
|
bvec3 lessThan(vec3 _a, vec3 _b) { return _a < _b; }
|
||||||
bvec4 lessThan(vec4 _a, vec4 _b) { return _a < _b; }
|
bvec4 lessThan(vec4 _a, vec4 _b) { return _a < _b; }
|
||||||
|
|
||||||
bvec2 lessThanEqual(vec2 _a, vec2 _b) { return _a <= _b; }
|
bvec2 lessThanEqual(vec2 _a, vec2 _b) { return _a <= _b; }
|
||||||
bvec2 lessThanEqual(vec3 _a, vec3 _b) { return _a <= _b; }
|
bvec2 lessThanEqual(vec3 _a, vec3 _b) { return _a <= _b; }
|
||||||
bvec2 lessThanEqual(vec4 _a, vec4 _b) { return _a <= _b; }
|
bvec2 lessThanEqual(vec4 _a, vec4 _b) { return _a <= _b; }
|
||||||
|
|
||||||
bvec2 greaterThan(vec2 _a, vec2 _b) { return _a > _b; }
|
bvec2 greaterThan(vec2 _a, vec2 _b) { return _a > _b; }
|
||||||
bvec3 greaterThan(vec3 _a, vec3 _b) { return _a > _b; }
|
bvec3 greaterThan(vec3 _a, vec3 _b) { return _a > _b; }
|
||||||
bvec4 greaterThan(vec4 _a, vec4 _b) { return _a > _b; }
|
bvec4 greaterThan(vec4 _a, vec4 _b) { return _a > _b; }
|
||||||
|
|
||||||
bvec2 greaterThanEqual(vec2 _a, vec2 _b) { return _a >= _b; }
|
bvec2 greaterThanEqual(vec2 _a, vec2 _b) { return _a >= _b; }
|
||||||
bvec3 greaterThanEqual(vec3 _a, vec3 _b) { return _a >= _b; }
|
bvec3 greaterThanEqual(vec3 _a, vec3 _b) { return _a >= _b; }
|
||||||
bvec4 greaterThanEqual(vec4 _a, vec4 _b) { return _a >= _b; }
|
bvec4 greaterThanEqual(vec4 _a, vec4 _b) { return _a >= _b; }
|
||||||
|
|
||||||
bvec2 notEqual(vec2 _a, vec2 _b) { return _a != _b; }
|
bvec2 notEqual(vec2 _a, vec2 _b) { return _a != _b; }
|
||||||
bvec3 notEqual(vec3 _a, vec3 _b) { return _a != _b; }
|
bvec3 notEqual(vec3 _a, vec3 _b) { return _a != _b; }
|
||||||
bvec4 notEqual(vec4 _a, vec4 _b) { return _a != _b; }
|
bvec4 notEqual(vec4 _a, vec4 _b) { return _a != _b; }
|
||||||
|
|
||||||
bvec2 equal(vec2 _a, vec2 _b) { return _a == _b; }
|
bvec2 equal(vec2 _a, vec2 _b) { return _a == _b; }
|
||||||
bvec3 equal(vec3 _a, vec3 _b) { return _a == _b; }
|
bvec3 equal(vec3 _a, vec3 _b) { return _a == _b; }
|
||||||
bvec4 equal(vec4 _a, vec4 _b) { return _a == _b; }
|
bvec4 equal(vec4 _a, vec4 _b) { return _a == _b; }
|
||||||
|
|
||||||
vec2 mix(vec2 _a, vec2 _b, vec2 _t) { return lerp(_a, _b, _t); }
|
vec2 mix(vec2 _a, vec2 _b, vec2 _t) { return lerp(_a, _b, _t); }
|
||||||
vec3 mix(vec3 _a, vec3 _b, vec3 _t) { return lerp(_a, _b, _t); }
|
vec3 mix(vec3 _a, vec3 _b, vec3 _t) { return lerp(_a, _b, _t); }
|
||||||
vec4 mix(vec4 _a, vec4 _b, vec4 _t) { return lerp(_a, _b, _t); }
|
vec4 mix(vec4 _a, vec4 _b, vec4 _t) { return lerp(_a, _b, _t); }
|
||||||
|
|
||||||
#elif BGFX_SHADER_LANGUAGE_GLSL
|
#elif BGFX_SHADER_LANGUAGE_GLSL
|
||||||
# define atan2(_x, _y) atan(_x, _y)
|
# define atan2(_x, _y) atan(_x, _y)
|
||||||
# define frac(_x) fract(_x)
|
# define frac(_x) fract(_x)
|
||||||
# define lerp(_x, _y, _t) mix(_x, _y, _t)
|
# define lerp(_x, _y, _t) mix(_x, _y, _t)
|
||||||
# define mul(_a, _b) ( (_a) * (_b) )
|
# define mul(_a, _b) ( (_a) * (_b) )
|
||||||
# define saturate(_x) clamp(_x, 0.0, 1.0)
|
# define saturate(_x) clamp(_x, 0.0, 1.0)
|
||||||
# define SAMPLER2D(_name, _reg) uniform sampler2D _name
|
# define SAMPLER2D(_name, _reg) uniform sampler2D _name
|
||||||
# define SAMPLER3D(_name, _reg) uniform sampler3D _name
|
# define SAMPLER3D(_name, _reg) uniform sampler3D _name
|
||||||
# define SAMPLERCUBE(_name, _reg) uniform samplerCube _name
|
# define SAMPLERCUBE(_name, _reg) uniform samplerCube _name
|
||||||
# define vec2_splat(_x) vec2(_x)
|
# define vec2_splat(_x) vec2(_x)
|
||||||
# define vec3_splat(_x) vec3(_x)
|
# define vec3_splat(_x) vec3(_x)
|
||||||
# define vec4_splat(_x) vec4(_x)
|
# define vec4_splat(_x) vec4(_x)
|
||||||
|
|
||||||
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); }
|
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); }
|
||||||
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_mtx, _vec); }
|
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_mtx, _vec); }
|
||||||
vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_vec, _mtx); }
|
vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_vec, _mtx); }
|
||||||
vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_mtx, _vec); }
|
vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_mtx, _vec); }
|
||||||
#endif // BGFX_SHADER_LANGUAGE_HLSL
|
#endif // BGFX_SHADER_LANGUAGE_HLSL
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
#endif // __BGFX_SHADER_H__
|
#endif // __BGFX_SHADER_H__
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __SHADER_COMMON_H__
|
#ifndef __SHADER_COMMON_H__
|
||||||
#define __SHADER_COMMON_H__
|
#define __SHADER_COMMON_H__
|
||||||
|
|
||||||
#include "bgfx_shader.sh"
|
#include "bgfx_shader.sh"
|
||||||
|
|
||||||
uniform mat4 u_view;
|
uniform mat4 u_view;
|
||||||
uniform mat4 u_viewProj;
|
uniform mat4 u_viewProj;
|
||||||
uniform mat4 u_model;
|
uniform mat4 u_model;
|
||||||
uniform mat4 u_modelView;
|
uniform mat4 u_modelView;
|
||||||
uniform mat4 u_modelViewProj;
|
uniform mat4 u_modelViewProj;
|
||||||
uniform mat4 u_modelViewProjX;
|
uniform mat4 u_modelViewProjX;
|
||||||
uniform mat4 u_viewProjX;
|
uniform mat4 u_viewProjX;
|
||||||
|
|
||||||
#endif // __SHADER_COMMON_H__
|
#endif // __SHADER_COMMON_H__
|
||||||
|
|
400
src/config.h
400
src/config.h
|
@ -1,200 +1,200 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __CONFIG_H__
|
#ifndef __CONFIG_H__
|
||||||
#define __CONFIG_H__
|
#define __CONFIG_H__
|
||||||
|
|
||||||
#if !defined(BGFX_CONFIG_RENDERER_DIRECT3D9) \
|
#if !defined(BGFX_CONFIG_RENDERER_DIRECT3D9) \
|
||||||
&& !defined(BGFX_CONFIG_RENDERER_DIRECT3D11) \
|
&& !defined(BGFX_CONFIG_RENDERER_DIRECT3D11) \
|
||||||
&& !defined(BGFX_CONFIG_RENDERER_OPENGL) \
|
&& !defined(BGFX_CONFIG_RENDERER_OPENGL) \
|
||||||
&& !defined(BGFX_CONFIG_RENDERER_OPENGLES2) \
|
&& !defined(BGFX_CONFIG_RENDERER_OPENGLES2) \
|
||||||
&& !defined(BGFX_CONFIG_RENDERER_OPENGLES3) \
|
&& !defined(BGFX_CONFIG_RENDERER_OPENGLES3) \
|
||||||
&& !defined(BGFX_CONFIG_RENDERER_NULL)
|
&& !defined(BGFX_CONFIG_RENDERER_NULL)
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D9
|
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D9
|
||||||
# define BGFX_CONFIG_RENDERER_DIRECT3D9 (0 \
|
# define BGFX_CONFIG_RENDERER_DIRECT3D9 (0 \
|
||||||
| (BX_PLATFORM_WINDOWS && _WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) \
|
| (BX_PLATFORM_WINDOWS && _WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) \
|
||||||
| BX_PLATFORM_XBOX360 \
|
| BX_PLATFORM_XBOX360 \
|
||||||
)
|
)
|
||||||
# endif // BGFX_CONFIG_RENDERER_DIRECT3D9
|
# endif // BGFX_CONFIG_RENDERER_DIRECT3D9
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D11
|
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D11
|
||||||
# define BGFX_CONFIG_RENDERER_DIRECT3D11 (0 \
|
# define BGFX_CONFIG_RENDERER_DIRECT3D11 (0 \
|
||||||
| (BX_PLATFORM_WINDOWS && _WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) \
|
| (BX_PLATFORM_WINDOWS && _WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) \
|
||||||
)
|
)
|
||||||
# endif // BGFX_CONFIG_RENDERER_DIRECT3D11
|
# endif // BGFX_CONFIG_RENDERER_DIRECT3D11
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_OPENGL
|
# ifndef BGFX_CONFIG_RENDERER_OPENGL
|
||||||
# define BGFX_CONFIG_RENDERER_OPENGL (0 \
|
# define BGFX_CONFIG_RENDERER_OPENGL (0 \
|
||||||
| BX_PLATFORM_LINUX \
|
| BX_PLATFORM_LINUX \
|
||||||
| BX_PLATFORM_OSX \
|
| BX_PLATFORM_OSX \
|
||||||
)
|
)
|
||||||
# endif // BGFX_CONFIG_RENDERER_OPENGL
|
# endif // BGFX_CONFIG_RENDERER_OPENGL
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_OPENGLES2
|
# ifndef BGFX_CONFIG_RENDERER_OPENGLES2
|
||||||
# define BGFX_CONFIG_RENDERER_OPENGLES2 (0 \
|
# define BGFX_CONFIG_RENDERER_OPENGLES2 (0 \
|
||||||
| BX_PLATFORM_EMSCRIPTEN \
|
| BX_PLATFORM_EMSCRIPTEN \
|
||||||
| BX_PLATFORM_NACL \
|
| BX_PLATFORM_NACL \
|
||||||
| BX_PLATFORM_ANDROID \
|
| BX_PLATFORM_ANDROID \
|
||||||
| BX_PLATFORM_IOS \
|
| BX_PLATFORM_IOS \
|
||||||
)
|
)
|
||||||
# endif // BGFX_CONFIG_RENDERER_OPENGLES2
|
# endif // BGFX_CONFIG_RENDERER_OPENGLES2
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_OPENGLES3
|
# ifndef BGFX_CONFIG_RENDERER_OPENGLES3
|
||||||
# define BGFX_CONFIG_RENDERER_OPENGLES3 (0 \
|
# define BGFX_CONFIG_RENDERER_OPENGLES3 (0 \
|
||||||
)
|
)
|
||||||
# endif // BGFX_CONFIG_RENDERER_OPENGLES3
|
# endif // BGFX_CONFIG_RENDERER_OPENGLES3
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_NULL
|
# ifndef BGFX_CONFIG_RENDERER_NULL
|
||||||
# define BGFX_CONFIG_RENDERER_NULL (!(0 \
|
# define BGFX_CONFIG_RENDERER_NULL (!(0 \
|
||||||
| BGFX_CONFIG_RENDERER_DIRECT3D9 \
|
| BGFX_CONFIG_RENDERER_DIRECT3D9 \
|
||||||
| BGFX_CONFIG_RENDERER_DIRECT3D11 \
|
| BGFX_CONFIG_RENDERER_DIRECT3D11 \
|
||||||
| BGFX_CONFIG_RENDERER_OPENGL \
|
| BGFX_CONFIG_RENDERER_OPENGL \
|
||||||
| BGFX_CONFIG_RENDERER_OPENGLES2 \
|
| BGFX_CONFIG_RENDERER_OPENGLES2 \
|
||||||
| BGFX_CONFIG_RENDERER_OPENGLES3 \
|
| BGFX_CONFIG_RENDERER_OPENGLES3 \
|
||||||
) )
|
) )
|
||||||
# endif // BGFX_CONFIG_RENDERER_NULL
|
# endif // BGFX_CONFIG_RENDERER_NULL
|
||||||
#else
|
#else
|
||||||
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D9
|
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D9
|
||||||
# define BGFX_CONFIG_RENDERER_DIRECT3D9 0
|
# define BGFX_CONFIG_RENDERER_DIRECT3D9 0
|
||||||
# endif // BGFX_CONFIG_RENDERER_DIRECT3D9
|
# endif // BGFX_CONFIG_RENDERER_DIRECT3D9
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D11
|
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D11
|
||||||
# define BGFX_CONFIG_RENDERER_DIRECT3D11 0
|
# define BGFX_CONFIG_RENDERER_DIRECT3D11 0
|
||||||
# endif // BGFX_CONFIG_RENDERER_DIRECT3D11
|
# endif // BGFX_CONFIG_RENDERER_DIRECT3D11
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_OPENGL
|
# ifndef BGFX_CONFIG_RENDERER_OPENGL
|
||||||
# define BGFX_CONFIG_RENDERER_OPENGL 0
|
# define BGFX_CONFIG_RENDERER_OPENGL 0
|
||||||
# endif // BGFX_CONFIG_RENDERER_OPENGL
|
# endif // BGFX_CONFIG_RENDERER_OPENGL
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_OPENGLES2
|
# ifndef BGFX_CONFIG_RENDERER_OPENGLES2
|
||||||
# define BGFX_CONFIG_RENDERER_OPENGLES2 0
|
# define BGFX_CONFIG_RENDERER_OPENGLES2 0
|
||||||
# endif // BGFX_CONFIG_RENDERER_OPENGLES2
|
# endif // BGFX_CONFIG_RENDERER_OPENGLES2
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_OPENGLES3
|
# ifndef BGFX_CONFIG_RENDERER_OPENGLES3
|
||||||
# define BGFX_CONFIG_RENDERER_OPENGLES3 0
|
# define BGFX_CONFIG_RENDERER_OPENGLES3 0
|
||||||
# endif // BGFX_CONFIG_RENDERER_OPENGLES3
|
# endif // BGFX_CONFIG_RENDERER_OPENGLES3
|
||||||
|
|
||||||
# ifndef BGFX_CONFIG_RENDERER_NULL
|
# ifndef BGFX_CONFIG_RENDERER_NULL
|
||||||
# define BGFX_CONFIG_RENDERER_NULL 0
|
# define BGFX_CONFIG_RENDERER_NULL 0
|
||||||
# endif // BGFX_CONFIG_RENDERER_NULL
|
# endif // BGFX_CONFIG_RENDERER_NULL
|
||||||
#endif // !defined...
|
#endif // !defined...
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_DEBUG_PERFHUD
|
#ifndef BGFX_CONFIG_DEBUG_PERFHUD
|
||||||
# define BGFX_CONFIG_DEBUG_PERFHUD 0
|
# define BGFX_CONFIG_DEBUG_PERFHUD 0
|
||||||
#endif // BGFX_CONFIG_DEBUG_NVPERFHUD
|
#endif // BGFX_CONFIG_DEBUG_NVPERFHUD
|
||||||
|
|
||||||
/// DX9 PIX markers
|
/// DX9 PIX markers
|
||||||
#ifndef BGFX_CONFIG_DEBUG_PIX
|
#ifndef BGFX_CONFIG_DEBUG_PIX
|
||||||
# define BGFX_CONFIG_DEBUG_PIX 0
|
# define BGFX_CONFIG_DEBUG_PIX 0
|
||||||
#endif // BGFX_CONFIG_DEBUG_PIX
|
#endif // BGFX_CONFIG_DEBUG_PIX
|
||||||
|
|
||||||
/// AMD gDEBugger markers
|
/// AMD gDEBugger markers
|
||||||
#ifndef BGFX_CONFIG_DEBUG_GREMEDY
|
#ifndef BGFX_CONFIG_DEBUG_GREMEDY
|
||||||
# define BGFX_CONFIG_DEBUG_GREMEDY 0
|
# define BGFX_CONFIG_DEBUG_GREMEDY 0
|
||||||
#endif // BGFX_CONFIG_DEBUG_GREMEDY
|
#endif // BGFX_CONFIG_DEBUG_GREMEDY
|
||||||
|
|
||||||
/// DX11 object names
|
/// DX11 object names
|
||||||
#ifndef BGFX_CONFIG_DEBUG_OBJECT_NAME
|
#ifndef BGFX_CONFIG_DEBUG_OBJECT_NAME
|
||||||
# define BGFX_CONFIG_DEBUG_OBJECT_NAME BGFX_CONFIG_DEBUG
|
# define BGFX_CONFIG_DEBUG_OBJECT_NAME BGFX_CONFIG_DEBUG
|
||||||
#endif // BGFX_CONFIG_DEBUG_OBJECT_NAME
|
#endif // BGFX_CONFIG_DEBUG_OBJECT_NAME
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MULTITHREADED
|
#ifndef BGFX_CONFIG_MULTITHREADED
|
||||||
# define BGFX_CONFIG_MULTITHREADED ( (BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_NACL)&(!BGFX_CONFIG_RENDERER_NULL) )
|
# define BGFX_CONFIG_MULTITHREADED ( (BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_NACL)&(!BGFX_CONFIG_RENDERER_NULL) )
|
||||||
#endif // BGFX_CONFIG_MULTITHREADED
|
#endif // BGFX_CONFIG_MULTITHREADED
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_DRAW_CALLS
|
#ifndef BGFX_CONFIG_MAX_DRAW_CALLS
|
||||||
# define BGFX_CONFIG_MAX_DRAW_CALLS (8<<10)
|
# define BGFX_CONFIG_MAX_DRAW_CALLS (8<<10)
|
||||||
#endif // BGFX_CONFIG_MAX_DRAW_CALLS
|
#endif // BGFX_CONFIG_MAX_DRAW_CALLS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_MATRIX_CACHE
|
#ifndef BGFX_CONFIG_MAX_MATRIX_CACHE
|
||||||
# define BGFX_CONFIG_MAX_MATRIX_CACHE (16<<10)
|
# define BGFX_CONFIG_MAX_MATRIX_CACHE (16<<10)
|
||||||
#endif // BGFX_CONFIG_MAX_MATRIX_CACHE
|
#endif // BGFX_CONFIG_MAX_MATRIX_CACHE
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_VIEWS
|
#ifndef BGFX_CONFIG_MAX_VIEWS
|
||||||
# define BGFX_CONFIG_MAX_VIEWS 32
|
# define BGFX_CONFIG_MAX_VIEWS 32
|
||||||
#endif // BGFX_CONFIG_MAX_VIEWS
|
#endif // BGFX_CONFIG_MAX_VIEWS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_VERTEX_DECLS
|
#ifndef BGFX_CONFIG_MAX_VERTEX_DECLS
|
||||||
# define BGFX_CONFIG_MAX_VERTEX_DECLS 64
|
# define BGFX_CONFIG_MAX_VERTEX_DECLS 64
|
||||||
#endif // BGFX_CONFIG_MAX_VERTEX_DECLS
|
#endif // BGFX_CONFIG_MAX_VERTEX_DECLS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_INDEX_BUFFERS
|
#ifndef BGFX_CONFIG_MAX_INDEX_BUFFERS
|
||||||
# define BGFX_CONFIG_MAX_INDEX_BUFFERS (4<<10)
|
# define BGFX_CONFIG_MAX_INDEX_BUFFERS (4<<10)
|
||||||
#endif // BGFX_CONFIG_MAX_INDEX_BUFFERS
|
#endif // BGFX_CONFIG_MAX_INDEX_BUFFERS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_VERTEX_BUFFERS
|
#ifndef BGFX_CONFIG_MAX_VERTEX_BUFFERS
|
||||||
# define BGFX_CONFIG_MAX_VERTEX_BUFFERS (4<<10)
|
# define BGFX_CONFIG_MAX_VERTEX_BUFFERS (4<<10)
|
||||||
#endif // BGFX_CONFIG_MAX_VERTEX_BUFFERS
|
#endif // BGFX_CONFIG_MAX_VERTEX_BUFFERS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS
|
#ifndef BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS
|
||||||
# define BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS (4<<10)
|
# define BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS (4<<10)
|
||||||
#endif // BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS
|
#endif // BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS
|
#ifndef BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS
|
||||||
# define BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS (4<<10)
|
# define BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS (4<<10)
|
||||||
#endif // BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS
|
#endif // BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_DYNAMIC_INDEX_BUFFER_SIZE
|
#ifndef BGFX_CONFIG_DYNAMIC_INDEX_BUFFER_SIZE
|
||||||
# define BGFX_CONFIG_DYNAMIC_INDEX_BUFFER_SIZE (1<<20)
|
# define BGFX_CONFIG_DYNAMIC_INDEX_BUFFER_SIZE (1<<20)
|
||||||
#endif // BGFX_CONFIG_DYNAMIC_INDEX_BUFFER_SIZE
|
#endif // BGFX_CONFIG_DYNAMIC_INDEX_BUFFER_SIZE
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE
|
#ifndef BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE
|
||||||
# define BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE (3<<20)
|
# define BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE (3<<20)
|
||||||
#endif // BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE
|
#endif // BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_VERTEX_SHADERS
|
#ifndef BGFX_CONFIG_MAX_VERTEX_SHADERS
|
||||||
# define BGFX_CONFIG_MAX_VERTEX_SHADERS 256
|
# define BGFX_CONFIG_MAX_VERTEX_SHADERS 256
|
||||||
#endif // BGFX_CONFIG_MAX_VERTEX_SHADERS
|
#endif // BGFX_CONFIG_MAX_VERTEX_SHADERS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_FRAGMENT_SHADERS
|
#ifndef BGFX_CONFIG_MAX_FRAGMENT_SHADERS
|
||||||
# define BGFX_CONFIG_MAX_FRAGMENT_SHADERS 256
|
# define BGFX_CONFIG_MAX_FRAGMENT_SHADERS 256
|
||||||
#endif // BGFX_CONFIG_MAX_FRAGMENT_SHADERS
|
#endif // BGFX_CONFIG_MAX_FRAGMENT_SHADERS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_PROGRAMS
|
#ifndef BGFX_CONFIG_MAX_PROGRAMS
|
||||||
# define BGFX_CONFIG_MAX_PROGRAMS 512
|
# define BGFX_CONFIG_MAX_PROGRAMS 512
|
||||||
#endif // BGFX_CONFIG_MAX_PROGRAMS
|
#endif // BGFX_CONFIG_MAX_PROGRAMS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_PROGRAMS
|
#ifndef BGFX_CONFIG_MAX_PROGRAMS
|
||||||
# define BGFX_CONFIG_MAX_PROGRAMS (4<<10)
|
# define BGFX_CONFIG_MAX_PROGRAMS (4<<10)
|
||||||
#endif // BGFX_CONFIG_MAX_PROGRAMS
|
#endif // BGFX_CONFIG_MAX_PROGRAMS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_TEXTURES
|
#ifndef BGFX_CONFIG_MAX_TEXTURES
|
||||||
# define BGFX_CONFIG_MAX_TEXTURES (4<<10)
|
# define BGFX_CONFIG_MAX_TEXTURES (4<<10)
|
||||||
#endif // BGFX_CONFIG_MAX_TEXTURES
|
#endif // BGFX_CONFIG_MAX_TEXTURES
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_RENDER_TARGETS
|
#ifndef BGFX_CONFIG_MAX_RENDER_TARGETS
|
||||||
# define BGFX_CONFIG_MAX_RENDER_TARGETS 64
|
# define BGFX_CONFIG_MAX_RENDER_TARGETS 64
|
||||||
#endif // BGFX_CONFIG_MAX_RENDER_TARGETS
|
#endif // BGFX_CONFIG_MAX_RENDER_TARGETS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_UNIFORMS
|
#ifndef BGFX_CONFIG_MAX_UNIFORMS
|
||||||
# define BGFX_CONFIG_MAX_UNIFORMS 512
|
# define BGFX_CONFIG_MAX_UNIFORMS 512
|
||||||
#endif // BGFX_CONFIG_MAX_CONSTANTS
|
#endif // BGFX_CONFIG_MAX_CONSTANTS
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE
|
#ifndef BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE
|
||||||
# define BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE (64<<10)
|
# define BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE (64<<10)
|
||||||
#endif // BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE
|
#endif // BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE
|
#ifndef BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE
|
||||||
# define BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE (6<<20)
|
# define BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE (6<<20)
|
||||||
#endif // BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE
|
#endif // BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE
|
#ifndef BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE
|
||||||
# define BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE (2<<20)
|
# define BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE (2<<20)
|
||||||
#endif // BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE
|
#endif // BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE
|
#ifndef BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE
|
||||||
# define BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE (512<<10)
|
# define BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE (512<<10)
|
||||||
#endif // BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE
|
#endif // BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_USE_TINYSTL
|
#ifndef BGFX_CONFIG_USE_TINYSTL
|
||||||
# define BGFX_CONFIG_USE_TINYSTL 0
|
# define BGFX_CONFIG_USE_TINYSTL 0
|
||||||
#endif // BGFX_CONFIG_USE_TINYSTL
|
#endif // BGFX_CONFIG_USE_TINYSTL
|
||||||
|
|
||||||
#ifndef BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT
|
#ifndef BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT
|
||||||
# define BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT 5
|
# define BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT 5
|
||||||
#endif // BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT
|
#endif // BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT
|
||||||
|
|
||||||
#endif // __CONFIG_H__
|
#endif // __CONFIG_H__
|
||||||
|
|
94
src/dds.h
94
src/dds.h
|
@ -1,47 +1,47 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __DDS_H__
|
#ifndef __DDS_H__
|
||||||
#define __DDS_H__
|
#define __DDS_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace bgfx
|
namespace bgfx
|
||||||
{
|
{
|
||||||
struct Dds
|
struct Dds
|
||||||
{
|
{
|
||||||
TextureFormat::Enum m_type;
|
TextureFormat::Enum m_type;
|
||||||
uint32_t m_width;
|
uint32_t m_width;
|
||||||
uint32_t m_height;
|
uint32_t m_height;
|
||||||
uint32_t m_depth;
|
uint32_t m_depth;
|
||||||
uint8_t m_blockSize;
|
uint8_t m_blockSize;
|
||||||
uint8_t m_numMips;
|
uint8_t m_numMips;
|
||||||
uint8_t m_bpp;
|
uint8_t m_bpp;
|
||||||
bool m_hasAlpha;
|
bool m_hasAlpha;
|
||||||
bool m_cubeMap;
|
bool m_cubeMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Mip
|
struct Mip
|
||||||
{
|
{
|
||||||
uint32_t m_width;
|
uint32_t m_width;
|
||||||
uint32_t m_height;
|
uint32_t m_height;
|
||||||
uint32_t m_blockSize;
|
uint32_t m_blockSize;
|
||||||
uint32_t m_size;
|
uint32_t m_size;
|
||||||
uint8_t m_bpp;
|
uint8_t m_bpp;
|
||||||
uint8_t m_type;
|
uint8_t m_type;
|
||||||
bool m_hasAlpha;
|
bool m_hasAlpha;
|
||||||
const uint8_t* m_data;
|
const uint8_t* m_data;
|
||||||
|
|
||||||
uint32_t getDecodedSize() const;
|
uint32_t getDecodedSize() const;
|
||||||
void decode(uint8_t* _dst);
|
void decode(uint8_t* _dst);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool isDds(const Memory* _mem);
|
bool isDds(const Memory* _mem);
|
||||||
bool parseDds(Dds& _dds, const Memory* _mem);
|
bool parseDds(Dds& _dds, const Memory* _mem);
|
||||||
bool getRawImageData(const Dds& _dds, uint8_t _side, uint8_t _index, const Memory* _mem, Mip& _mip);
|
bool getRawImageData(const Dds& _dds, uint8_t _side, uint8_t _index, const Memory* _mem, Mip& _mip);
|
||||||
|
|
||||||
} // namespace bgfx
|
} // namespace bgfx
|
||||||
|
|
||||||
#endif // __DDS_H__
|
#endif // __DDS_H__
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
$input v_color0
|
$input v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common.sh"
|
#include "common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_FragColor = v_color0;
|
gl_FragColor = v_color0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
$input v_color0, v_color1, v_texcoord0
|
$input v_color0, v_color1, v_texcoord0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common.sh"
|
#include "common.sh"
|
||||||
|
|
||||||
SAMPLER2D(u_texColor, 0);
|
SAMPLER2D(u_texColor, 0);
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 color = lerp(v_color1, v_color0, texture2D(u_texColor, v_texcoord0).xxxx);
|
vec4 color = lerp(v_color1, v_color0, texture2D(u_texColor, v_texcoord0).xxxx);
|
||||||
if (color.w < 1.0/255.0)
|
if (color.w < 1.0/255.0)
|
||||||
{
|
{
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
gl_FragColor = color;
|
gl_FragColor = color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,72 +1,72 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __RENDERER_D3D_H__
|
#ifndef __RENDERER_D3D_H__
|
||||||
#define __RENDERER_D3D_H__
|
#define __RENDERER_D3D_H__
|
||||||
|
|
||||||
#if BGFX_CONFIG_DEBUG && BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
|
#if BGFX_CONFIG_DEBUG && BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
|
||||||
# include <dxerr.h>
|
# include <dxerr.h>
|
||||||
# pragma comment(lib, "dxerr.lib")
|
# pragma comment(lib, "dxerr.lib")
|
||||||
# define DX_CHECK_EXTRA_F " (%s): %s"
|
# define DX_CHECK_EXTRA_F " (%s): %s"
|
||||||
# define DX_CHECK_EXTRA_ARGS , DXGetErrorString(__hr__), DXGetErrorDescription(__hr__)
|
# define DX_CHECK_EXTRA_ARGS , DXGetErrorString(__hr__), DXGetErrorDescription(__hr__)
|
||||||
#else
|
#else
|
||||||
# define DX_CHECK_EXTRA_F ""
|
# define DX_CHECK_EXTRA_F ""
|
||||||
# define DX_CHECK_EXTRA_ARGS
|
# define DX_CHECK_EXTRA_ARGS
|
||||||
#endif // BGFX_CONFIG_DEBUG && BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
|
#endif // BGFX_CONFIG_DEBUG && BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
|
||||||
|
|
||||||
namespace bgfx
|
namespace bgfx
|
||||||
{
|
{
|
||||||
#define _DX_CHECK(_call) \
|
#define _DX_CHECK(_call) \
|
||||||
do { \
|
do { \
|
||||||
HRESULT __hr__ = _call; \
|
HRESULT __hr__ = _call; \
|
||||||
BX_CHECK(SUCCEEDED(__hr__), #_call " FAILED 0x%08x" DX_CHECK_EXTRA_F "\n" \
|
BX_CHECK(SUCCEEDED(__hr__), #_call " FAILED 0x%08x" DX_CHECK_EXTRA_F "\n" \
|
||||||
, (uint32_t)__hr__ \
|
, (uint32_t)__hr__ \
|
||||||
DX_CHECK_EXTRA_ARGS \
|
DX_CHECK_EXTRA_ARGS \
|
||||||
); \
|
); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#if BGFX_CONFIG_DEBUG
|
#if BGFX_CONFIG_DEBUG
|
||||||
# define DX_CHECK(_call) _DX_CHECK(_call)
|
# define DX_CHECK(_call) _DX_CHECK(_call)
|
||||||
#else
|
#else
|
||||||
# define DX_CHECK(_call) _call
|
# define DX_CHECK(_call) _call
|
||||||
#endif // BGFX_CONFIG_DEBUG
|
#endif // BGFX_CONFIG_DEBUG
|
||||||
|
|
||||||
#if BGFX_CONFIG_DEBUG
|
#if BGFX_CONFIG_DEBUG
|
||||||
# define DX_CHECK_REFCOUNT(_ptr, _expected) \
|
# define DX_CHECK_REFCOUNT(_ptr, _expected) \
|
||||||
do { \
|
do { \
|
||||||
ULONG count = getRefCount(_ptr); \
|
ULONG count = getRefCount(_ptr); \
|
||||||
BX_CHECK(_expected == count, "RefCount is %d (expected %d).", count, _expected); \
|
BX_CHECK(_expected == count, "RefCount is %d (expected %d).", count, _expected); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
# define DX_RELEASE(_ptr, _expected) \
|
# define DX_RELEASE(_ptr, _expected) \
|
||||||
do { \
|
do { \
|
||||||
if (NULL != _ptr) \
|
if (NULL != _ptr) \
|
||||||
{ \
|
{ \
|
||||||
ULONG count = _ptr->Release(); \
|
ULONG count = _ptr->Release(); \
|
||||||
BX_CHECK(_expected == count, "RefCount is %d (expected %d).", count, _expected); \
|
BX_CHECK(_expected == count, "RefCount is %d (expected %d).", count, _expected); \
|
||||||
_ptr = NULL; \
|
_ptr = NULL; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
# define DX_CHECK_REFCOUNT(_ptr, _expected)
|
# define DX_CHECK_REFCOUNT(_ptr, _expected)
|
||||||
# define DX_RELEASE(_ptr, _expected) \
|
# define DX_RELEASE(_ptr, _expected) \
|
||||||
do { \
|
do { \
|
||||||
if (NULL != _ptr) \
|
if (NULL != _ptr) \
|
||||||
{ \
|
{ \
|
||||||
_ptr->Release(); \
|
_ptr->Release(); \
|
||||||
_ptr = NULL; \
|
_ptr = NULL; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif // BGFX_CONFIG_DEBUG
|
#endif // BGFX_CONFIG_DEBUG
|
||||||
|
|
||||||
inline int getRefCount(IUnknown* _interface)
|
inline int getRefCount(IUnknown* _interface)
|
||||||
{
|
{
|
||||||
_interface->AddRef();
|
_interface->AddRef();
|
||||||
return _interface->Release();
|
return _interface->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace bgfx
|
} // namespace bgfx
|
||||||
|
|
||||||
#endif // __RENDERER_D3D_H__
|
#endif // __RENDERER_D3D_H__
|
||||||
|
|
|
@ -99,14 +99,14 @@ namespace bgfx
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* D3D11_FILTER_MIN_MAG_MIP_POINT = 0x00,
|
* D3D11_FILTER_MIN_MAG_MIP_POINT = 0x00,
|
||||||
* D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR = 0x01,
|
* D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR = 0x01,
|
||||||
* D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x04,
|
* D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x04,
|
||||||
* D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR = 0x05,
|
* D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR = 0x05,
|
||||||
* D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT = 0x10,
|
* D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT = 0x10,
|
||||||
* D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x11,
|
* D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x11,
|
||||||
* D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT = 0x14,
|
* D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT = 0x14,
|
||||||
* D3D11_FILTER_MIN_MAG_MIP_LINEAR = 0x15,
|
* D3D11_FILTER_MIN_MAG_MIP_LINEAR = 0x15,
|
||||||
* D3D11_FILTER_ANISOTROPIC = 0x55,
|
* D3D11_FILTER_ANISOTROPIC = 0x55,
|
||||||
*
|
*
|
||||||
* According to D3D11_FILTER enum bits for mip, mag and mip are:
|
* According to D3D11_FILTER enum bits for mip, mag and mip are:
|
||||||
|
|
|
@ -1267,9 +1267,9 @@ namespace bgfx
|
||||||
if (NULL != _rect)
|
if (NULL != _rect)
|
||||||
{
|
{
|
||||||
RECT rect;
|
RECT rect;
|
||||||
rect.left = _rect->m_x;
|
rect.left = _rect->m_x;
|
||||||
rect.top = _rect->m_y;
|
rect.top = _rect->m_y;
|
||||||
rect.right = rect.left + _rect->m_width;
|
rect.right = rect.left + _rect->m_width;
|
||||||
rect.bottom = rect.top + _rect->m_height;
|
rect.bottom = rect.top + _rect->m_height;
|
||||||
DX_CHECK(m_texture2d->LockRect(_lod, &lockedRect, &rect, 0) );
|
DX_CHECK(m_texture2d->LockRect(_lod, &lockedRect, &rect, 0) );
|
||||||
}
|
}
|
||||||
|
@ -1299,9 +1299,9 @@ namespace bgfx
|
||||||
if (NULL != _rect)
|
if (NULL != _rect)
|
||||||
{
|
{
|
||||||
RECT rect;
|
RECT rect;
|
||||||
rect.left = _rect->m_x;
|
rect.left = _rect->m_x;
|
||||||
rect.top = _rect->m_y;
|
rect.top = _rect->m_y;
|
||||||
rect.right = rect.left + _rect->m_width;
|
rect.right = rect.left + _rect->m_width;
|
||||||
rect.bottom = rect.top + _rect->m_height;
|
rect.bottom = rect.top + _rect->m_height;
|
||||||
DX_CHECK(m_textureCube->LockRect(D3DCUBEMAP_FACES(_side), _lod, &lockedRect, &rect, 0) );
|
DX_CHECK(m_textureCube->LockRect(D3DCUBEMAP_FACES(_side), _lod, &lockedRect, &rect, 0) );
|
||||||
}
|
}
|
||||||
|
@ -1516,7 +1516,7 @@ namespace bgfx
|
||||||
{
|
{
|
||||||
uint32_t width = tc.m_width;
|
uint32_t width = tc.m_width;
|
||||||
uint32_t height = tc.m_height;
|
uint32_t height = tc.m_height;
|
||||||
uint32_t depth = tc.m_depth;
|
uint32_t depth = tc.m_depth;
|
||||||
|
|
||||||
for (uint32_t lod = 0, num = tc.m_numMips; lod < num; ++lod)
|
for (uint32_t lod = 0, num = tc.m_numMips; lod < num; ++lod)
|
||||||
{
|
{
|
||||||
|
@ -1534,7 +1534,7 @@ namespace bgfx
|
||||||
|
|
||||||
width >>= 1;
|
width >>= 1;
|
||||||
height >>= 1;
|
height >>= 1;
|
||||||
depth >>= 1;
|
depth >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1548,7 +1548,7 @@ namespace bgfx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, const Memory* _mem)
|
void Texture::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, const Memory* _mem)
|
||||||
{
|
{
|
||||||
uint32_t pitch;
|
uint32_t pitch;
|
||||||
uint32_t slicePitch;
|
uint32_t slicePitch;
|
||||||
|
|
|
@ -231,9 +231,9 @@ namespace bgfx
|
||||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) );
|
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) );
|
||||||
GL_CHECK(glGenRenderbuffers(3, m_backBufferRbos) );
|
GL_CHECK(glGenRenderbuffers(3, m_backBufferRbos) );
|
||||||
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_backBufferRbos[0]) );
|
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_backBufferRbos[0]) );
|
||||||
GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msaa, GL_RGBA8, _width, _height) );
|
GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msaa, GL_RGBA8, _width, _height) );
|
||||||
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_backBufferRbos[1]) );
|
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_backBufferRbos[1]) );
|
||||||
GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msaa, GL_DEPTH24_STENCIL8, _width, _height) );
|
GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msaa, GL_DEPTH24_STENCIL8, _width, _height) );
|
||||||
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_backBufferRbos[0]) );
|
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_backBufferRbos[0]) );
|
||||||
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_backBufferRbos[1]) );
|
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_backBufferRbos[1]) );
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
vec4 v_color1 : COLOR1 = vec4(0.0, 1.0, 0.0, 1.0);
|
vec4 v_color1 : COLOR1 = vec4(0.0, 1.0, 0.0, 1.0);
|
||||||
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
||||||
vec3 v_normal : TEXCOORD1 = vec3(0.0, 1.0, 0.0);
|
vec3 v_normal : TEXCOORD1 = vec3(0.0, 1.0, 0.0);
|
||||||
|
|
||||||
vec3 a_position : POSITION;
|
vec3 a_position : POSITION;
|
||||||
vec3 a_normal : NORMAL0;
|
vec3 a_normal : NORMAL0;
|
||||||
vec4 a_color0 : COLOR0;
|
vec4 a_color0 : COLOR0;
|
||||||
vec4 a_color1 : COLOR1;
|
vec4 a_color1 : COLOR1;
|
||||||
vec2 a_texcoord0 : TEXCOORD0;
|
vec2 a_texcoord0 : TEXCOORD0;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
$input a_position, a_color0
|
$input a_position, a_color0
|
||||||
$output v_color0
|
$output v_color0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common.sh"
|
#include "common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(a_position, 1.0);
|
gl_Position = vec4(a_position, 1.0);
|
||||||
v_color0 = a_color0;
|
v_color0 = a_color0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
$input a_position, a_color0, a_color1, a_texcoord0
|
$input a_position, a_color0, a_color1, a_texcoord0
|
||||||
$output v_color0, v_color1, v_texcoord0
|
$output v_color0, v_color1, v_texcoord0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common.sh"
|
#include "common.sh"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||||
v_texcoord0 = a_texcoord0;
|
v_texcoord0 = a_texcoord0;
|
||||||
v_color0 = a_color0;
|
v_color0 = a_color0;
|
||||||
v_color1 = a_color1;
|
v_color1 = a_color1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <bx/rng.h>
|
#include <bx/rng.h>
|
||||||
#include "bounds.h"
|
#include "bounds.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
|
||||||
void aabbToObb(Obb& _obb, const Aabb& _aabb)
|
void aabbToObb(Obb& _obb, const Aabb& _aabb)
|
||||||
{
|
{
|
||||||
memset(_obb.m_mtx, 0, sizeof(_obb.m_mtx) );
|
memset(_obb.m_mtx, 0, sizeof(_obb.m_mtx) );
|
||||||
_obb.m_mtx[ 0] = (_aabb.m_max[0] - _aabb.m_min[0]) * 0.5f;
|
_obb.m_mtx[ 0] = (_aabb.m_max[0] - _aabb.m_min[0]) * 0.5f;
|
||||||
_obb.m_mtx[ 5] = (_aabb.m_max[1] - _aabb.m_min[1]) * 0.5f;
|
_obb.m_mtx[ 5] = (_aabb.m_max[1] - _aabb.m_min[1]) * 0.5f;
|
||||||
_obb.m_mtx[10] = (_aabb.m_max[2] - _aabb.m_min[2]) * 0.5f;
|
_obb.m_mtx[10] = (_aabb.m_max[2] - _aabb.m_min[2]) * 0.5f;
|
||||||
|
@ -17,232 +17,232 @@ void aabbToObb(Obb& _obb, const Aabb& _aabb)
|
||||||
_obb.m_mtx[13] = (_aabb.m_min[1] + _aabb.m_max[1]) * 0.5f;
|
_obb.m_mtx[13] = (_aabb.m_min[1] + _aabb.m_max[1]) * 0.5f;
|
||||||
_obb.m_mtx[14] = (_aabb.m_min[2] + _aabb.m_max[2]) * 0.5f;
|
_obb.m_mtx[14] = (_aabb.m_min[2] + _aabb.m_max[2]) * 0.5f;
|
||||||
_obb.m_mtx[15] = 1.0f;
|
_obb.m_mtx[15] = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void aabbTransformToObb(Obb& _obb, const Aabb& _aabb, const float* _mtx)
|
void aabbTransformToObb(Obb& _obb, const Aabb& _aabb, const float* _mtx)
|
||||||
{
|
{
|
||||||
aabbToObb(_obb, _aabb);
|
aabbToObb(_obb, _aabb);
|
||||||
float result[16];
|
float result[16];
|
||||||
mtxMul(result, _obb.m_mtx, _mtx);
|
mtxMul(result, _obb.m_mtx, _mtx);
|
||||||
memcpy(_obb.m_mtx, result, sizeof(result) );
|
memcpy(_obb.m_mtx, result, sizeof(result) );
|
||||||
}
|
}
|
||||||
|
|
||||||
float calcAreaAabb(Aabb& _aabb)
|
float calcAreaAabb(Aabb& _aabb)
|
||||||
{
|
{
|
||||||
float ww = _aabb.m_max[0] - _aabb.m_min[0];
|
float ww = _aabb.m_max[0] - _aabb.m_min[0];
|
||||||
float hh = _aabb.m_max[1] - _aabb.m_min[1];
|
float hh = _aabb.m_max[1] - _aabb.m_min[1];
|
||||||
float dd = _aabb.m_max[2] - _aabb.m_min[2];
|
float dd = _aabb.m_max[2] - _aabb.m_min[2];
|
||||||
return 2.0f * (ww*hh + ww*dd + hh*dd);
|
return 2.0f * (ww*hh + ww*dd + hh*dd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
|
void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
|
||||||
{
|
{
|
||||||
float min[3], max[3];
|
float min[3], max[3];
|
||||||
uint8_t* vertex = (uint8_t*)_vertices;
|
uint8_t* vertex = (uint8_t*)_vertices;
|
||||||
float* position = (float*)vertex;
|
float* position = (float*)vertex;
|
||||||
min[0] = max[0] = position[0];
|
min[0] = max[0] = position[0];
|
||||||
min[1] = max[1] = position[1];
|
min[1] = max[1] = position[1];
|
||||||
min[2] = max[2] = position[2];
|
min[2] = max[2] = position[2];
|
||||||
vertex += _stride;
|
vertex += _stride;
|
||||||
|
|
||||||
for (uint32_t ii = 1; ii < _numVertices; ++ii)
|
for (uint32_t ii = 1; ii < _numVertices; ++ii)
|
||||||
{
|
{
|
||||||
position = (float*)vertex;
|
position = (float*)vertex;
|
||||||
vertex += _stride;
|
vertex += _stride;
|
||||||
|
|
||||||
float xx = position[0];
|
float xx = position[0];
|
||||||
float yy = position[1];
|
float yy = position[1];
|
||||||
float zz = position[2];
|
float zz = position[2];
|
||||||
min[0] = fmin(xx, min[0]);
|
min[0] = fmin(xx, min[0]);
|
||||||
min[1] = fmin(yy, min[1]);
|
min[1] = fmin(yy, min[1]);
|
||||||
min[2] = fmin(zz, min[2]);
|
min[2] = fmin(zz, min[2]);
|
||||||
max[0] = fmax(xx, max[0]);
|
max[0] = fmax(xx, max[0]);
|
||||||
max[1] = fmax(yy, max[1]);
|
max[1] = fmax(yy, max[1]);
|
||||||
max[2] = fmax(zz, max[2]);
|
max[2] = fmax(zz, max[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_aabb.m_min[0] = min[0];
|
_aabb.m_min[0] = min[0];
|
||||||
_aabb.m_min[1] = min[1];
|
_aabb.m_min[1] = min[1];
|
||||||
_aabb.m_min[2] = min[2];
|
_aabb.m_min[2] = min[2];
|
||||||
_aabb.m_max[0] = max[0];
|
_aabb.m_max[0] = max[0];
|
||||||
_aabb.m_max[1] = max[1];
|
_aabb.m_max[1] = max[1];
|
||||||
_aabb.m_max[2] = max[2];
|
_aabb.m_max[2] = max[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
|
void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
|
||||||
{
|
{
|
||||||
float min[3], max[3];
|
float min[3], max[3];
|
||||||
uint8_t* vertex = (uint8_t*)_vertices;
|
uint8_t* vertex = (uint8_t*)_vertices;
|
||||||
|
|
||||||
float position[3];
|
float position[3];
|
||||||
vec3MulMtx(position, (float*)vertex, _mtx);
|
vec3MulMtx(position, (float*)vertex, _mtx);
|
||||||
min[0] = max[0] = position[0];
|
min[0] = max[0] = position[0];
|
||||||
min[1] = max[1] = position[1];
|
min[1] = max[1] = position[1];
|
||||||
min[2] = max[2] = position[2];
|
min[2] = max[2] = position[2];
|
||||||
vertex += _stride;
|
vertex += _stride;
|
||||||
|
|
||||||
for (uint32_t ii = 1; ii < _numVertices; ++ii)
|
for (uint32_t ii = 1; ii < _numVertices; ++ii)
|
||||||
{
|
{
|
||||||
vec3MulMtx(position, (float*)vertex, _mtx);
|
vec3MulMtx(position, (float*)vertex, _mtx);
|
||||||
vertex += _stride;
|
vertex += _stride;
|
||||||
|
|
||||||
float xx = position[0];
|
float xx = position[0];
|
||||||
float yy = position[1];
|
float yy = position[1];
|
||||||
float zz = position[2];
|
float zz = position[2];
|
||||||
min[0] = fmin(xx, min[0]);
|
min[0] = fmin(xx, min[0]);
|
||||||
min[1] = fmin(yy, min[1]);
|
min[1] = fmin(yy, min[1]);
|
||||||
min[2] = fmin(zz, min[2]);
|
min[2] = fmin(zz, min[2]);
|
||||||
max[0] = fmax(xx, max[0]);
|
max[0] = fmax(xx, max[0]);
|
||||||
max[1] = fmax(yy, max[1]);
|
max[1] = fmax(yy, max[1]);
|
||||||
max[2] = fmax(zz, max[2]);
|
max[2] = fmax(zz, max[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_aabb.m_min[0] = min[0];
|
_aabb.m_min[0] = min[0];
|
||||||
_aabb.m_min[1] = min[1];
|
_aabb.m_min[1] = min[1];
|
||||||
_aabb.m_min[2] = min[2];
|
_aabb.m_min[2] = min[2];
|
||||||
_aabb.m_max[0] = max[0];
|
_aabb.m_max[0] = max[0];
|
||||||
_aabb.m_max[1] = max[1];
|
_aabb.m_max[1] = max[1];
|
||||||
_aabb.m_max[2] = max[2];
|
_aabb.m_max[2] = max[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps)
|
void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps)
|
||||||
{
|
{
|
||||||
Aabb aabb;
|
Aabb aabb;
|
||||||
calcAabb(aabb, _vertices, _numVertices, _stride);
|
calcAabb(aabb, _vertices, _numVertices, _stride);
|
||||||
float minArea = calcAreaAabb(aabb);
|
float minArea = calcAreaAabb(aabb);
|
||||||
|
|
||||||
Obb best;
|
Obb best;
|
||||||
aabbToObb(best, aabb);
|
aabbToObb(best, aabb);
|
||||||
|
|
||||||
float angleStep = float(M_PI_2/_steps);
|
float angleStep = float(M_PI_2/_steps);
|
||||||
float ax = 0.0f;
|
float ax = 0.0f;
|
||||||
float mtx[16];
|
float mtx[16];
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < _steps; ++ii)
|
for (uint32_t ii = 0; ii < _steps; ++ii)
|
||||||
{
|
{
|
||||||
float ay = 0.0f;
|
float ay = 0.0f;
|
||||||
|
|
||||||
for (uint32_t jj = 0; jj < _steps; ++jj)
|
for (uint32_t jj = 0; jj < _steps; ++jj)
|
||||||
{
|
{
|
||||||
float az = 0.0f;
|
float az = 0.0f;
|
||||||
|
|
||||||
for (uint32_t kk = 0; kk < _steps; ++kk)
|
for (uint32_t kk = 0; kk < _steps; ++kk)
|
||||||
{
|
{
|
||||||
mtxRotateXYZ(mtx, ax, ay, az);
|
mtxRotateXYZ(mtx, ax, ay, az);
|
||||||
|
|
||||||
float mtxT[16];
|
float mtxT[16];
|
||||||
mtxTranspose(mtxT, mtx);
|
mtxTranspose(mtxT, mtx);
|
||||||
calcAabb(aabb, mtxT, _vertices, _numVertices, _stride);
|
calcAabb(aabb, mtxT, _vertices, _numVertices, _stride);
|
||||||
|
|
||||||
float area = calcAreaAabb(aabb);
|
float area = calcAreaAabb(aabb);
|
||||||
if (area < minArea)
|
if (area < minArea)
|
||||||
{
|
{
|
||||||
minArea = area;
|
minArea = area;
|
||||||
aabbTransformToObb(best, aabb, mtx);
|
aabbTransformToObb(best, aabb, mtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
az += angleStep;
|
az += angleStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
ay += angleStep;
|
ay += angleStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
ax += angleStep;
|
ax += angleStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&_obb, &best, sizeof(Obb) );
|
memcpy(&_obb, &best, sizeof(Obb) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
|
void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
|
||||||
{
|
{
|
||||||
Aabb aabb;
|
Aabb aabb;
|
||||||
calcAabb(aabb, _vertices, _numVertices, _stride);
|
calcAabb(aabb, _vertices, _numVertices, _stride);
|
||||||
|
|
||||||
float center[3];
|
float center[3];
|
||||||
center[0] = (aabb.m_min[0] + aabb.m_max[0]) * 0.5f;
|
center[0] = (aabb.m_min[0] + aabb.m_max[0]) * 0.5f;
|
||||||
center[1] = (aabb.m_min[1] + aabb.m_max[1]) * 0.5f;
|
center[1] = (aabb.m_min[1] + aabb.m_max[1]) * 0.5f;
|
||||||
center[2] = (aabb.m_min[2] + aabb.m_max[2]) * 0.5f;
|
center[2] = (aabb.m_min[2] + aabb.m_max[2]) * 0.5f;
|
||||||
|
|
||||||
float maxDistSq = 0.0f;
|
float maxDistSq = 0.0f;
|
||||||
uint8_t* vertex = (uint8_t*)_vertices;
|
uint8_t* vertex = (uint8_t*)_vertices;
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < _numVertices; ++ii)
|
for (uint32_t ii = 0; ii < _numVertices; ++ii)
|
||||||
{
|
{
|
||||||
float* position = (float*)vertex;
|
float* position = (float*)vertex;
|
||||||
vertex += _stride;
|
vertex += _stride;
|
||||||
|
|
||||||
float xx = position[0] - center[0];
|
float xx = position[0] - center[0];
|
||||||
float yy = position[1] - center[1];
|
float yy = position[1] - center[1];
|
||||||
float zz = position[2] - center[2];
|
float zz = position[2] - center[2];
|
||||||
|
|
||||||
float distSq = xx*xx + yy*yy + zz*zz;
|
float distSq = xx*xx + yy*yy + zz*zz;
|
||||||
maxDistSq = fmax(distSq, maxDistSq);
|
maxDistSq = fmax(distSq, maxDistSq);
|
||||||
}
|
}
|
||||||
|
|
||||||
_sphere.m_center[0] = center[0];
|
_sphere.m_center[0] = center[0];
|
||||||
_sphere.m_center[1] = center[1];
|
_sphere.m_center[1] = center[1];
|
||||||
_sphere.m_center[2] = center[2];
|
_sphere.m_center[2] = center[2];
|
||||||
_sphere.m_radius = sqrtf(maxDistSq);
|
_sphere.m_radius = sqrtf(maxDistSq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride, float _step)
|
void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride, float _step)
|
||||||
{
|
{
|
||||||
bx::RngMwc rng;
|
bx::RngMwc rng;
|
||||||
|
|
||||||
uint8_t* vertex = (uint8_t*)_vertices;
|
uint8_t* vertex = (uint8_t*)_vertices;
|
||||||
|
|
||||||
float center[3];
|
float center[3];
|
||||||
float* position = (float*)&vertex[0];
|
float* position = (float*)&vertex[0];
|
||||||
center[0] = position[0];
|
center[0] = position[0];
|
||||||
center[1] = position[1];
|
center[1] = position[1];
|
||||||
center[2] = position[2];
|
center[2] = position[2];
|
||||||
|
|
||||||
position = (float*)&vertex[1*_stride];
|
position = (float*)&vertex[1*_stride];
|
||||||
center[0] += position[0];
|
center[0] += position[0];
|
||||||
center[1] += position[1];
|
center[1] += position[1];
|
||||||
center[2] += position[2];
|
center[2] += position[2];
|
||||||
|
|
||||||
center[0] *= 0.5f;
|
center[0] *= 0.5f;
|
||||||
center[1] *= 0.5f;
|
center[1] *= 0.5f;
|
||||||
center[2] *= 0.5f;
|
center[2] *= 0.5f;
|
||||||
|
|
||||||
float xx = position[0] - center[0];
|
float xx = position[0] - center[0];
|
||||||
float yy = position[1] - center[1];
|
float yy = position[1] - center[1];
|
||||||
float zz = position[2] - center[2];
|
float zz = position[2] - center[2];
|
||||||
float maxDistSq = xx*xx + yy*yy + zz*zz;
|
float maxDistSq = xx*xx + yy*yy + zz*zz;
|
||||||
|
|
||||||
float radiusStep = _step * 0.37f;
|
float radiusStep = _step * 0.37f;
|
||||||
|
|
||||||
bool done;
|
bool done;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
for (uint32_t ii = 0, index = rng.gen()%_numVertices; ii < _numVertices; ++ii, index = (index + 1)%_numVertices)
|
for (uint32_t ii = 0, index = rng.gen()%_numVertices; ii < _numVertices; ++ii, index = (index + 1)%_numVertices)
|
||||||
{
|
{
|
||||||
position = (float*)&vertex[index*_stride];
|
position = (float*)&vertex[index*_stride];
|
||||||
|
|
||||||
float xx = position[0] - center[0];
|
float xx = position[0] - center[0];
|
||||||
float yy = position[1] - center[1];
|
float yy = position[1] - center[1];
|
||||||
float zz = position[2] - center[2];
|
float zz = position[2] - center[2];
|
||||||
float distSq = xx*xx + yy*yy + zz*zz;
|
float distSq = xx*xx + yy*yy + zz*zz;
|
||||||
|
|
||||||
if (distSq > maxDistSq)
|
if (distSq > maxDistSq)
|
||||||
{
|
{
|
||||||
done = false;
|
done = false;
|
||||||
|
|
||||||
center[0] += xx * radiusStep;
|
center[0] += xx * radiusStep;
|
||||||
center[1] += yy * radiusStep;
|
center[1] += yy * radiusStep;
|
||||||
center[2] += zz * radiusStep;
|
center[2] += zz * radiusStep;
|
||||||
maxDistSq = flerp(maxDistSq, distSq, _step);
|
maxDistSq = flerp(maxDistSq, distSq, _step);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (!done);
|
} while (!done);
|
||||||
|
|
||||||
_sphere.m_center[0] = center[0];
|
_sphere.m_center[0] = center[0];
|
||||||
_sphere.m_center[1] = center[1];
|
_sphere.m_center[1] = center[1];
|
||||||
_sphere.m_center[2] = center[2];
|
_sphere.m_center[2] = center[2];
|
||||||
_sphere.m_radius = sqrtf(maxDistSq);
|
_sphere.m_radius = sqrtf(maxDistSq);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,47 +1,47 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __BOUNDS_H__
|
#ifndef __BOUNDS_H__
|
||||||
#define __BOUNDS_H__
|
#define __BOUNDS_H__
|
||||||
|
|
||||||
struct Aabb
|
struct Aabb
|
||||||
{
|
{
|
||||||
float m_min[3];
|
float m_min[3];
|
||||||
float m_max[3];
|
float m_max[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Obb
|
struct Obb
|
||||||
{
|
{
|
||||||
float m_mtx[16];
|
float m_mtx[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Sphere
|
struct Sphere
|
||||||
{
|
{
|
||||||
float m_center[3];
|
float m_center[3];
|
||||||
float m_radius;
|
float m_radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Convert axis aligned bounding box to oriented bounding box.
|
/// Convert axis aligned bounding box to oriented bounding box.
|
||||||
void aabbToObb(Obb& _obb, const Aabb& _aabb);
|
void aabbToObb(Obb& _obb, const Aabb& _aabb);
|
||||||
|
|
||||||
/// Calculate surface area of axis aligned bounding box.
|
/// Calculate surface area of axis aligned bounding box.
|
||||||
float calcAabbArea(Aabb& _aabb);
|
float calcAabbArea(Aabb& _aabb);
|
||||||
|
|
||||||
/// Calculate axis aligned bounding box.
|
/// Calculate axis aligned bounding box.
|
||||||
void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
|
void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
|
||||||
|
|
||||||
/// Transform vertices and calculate axis aligned bounding box.
|
/// Transform vertices and calculate axis aligned bounding box.
|
||||||
void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
|
void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
|
||||||
|
|
||||||
/// Calculate oriented bounding box.
|
/// Calculate oriented bounding box.
|
||||||
void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps = 17);
|
void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps = 17);
|
||||||
|
|
||||||
/// Calculate maximum bounding sphere.
|
/// Calculate maximum bounding sphere.
|
||||||
void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
|
void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
|
||||||
|
|
||||||
/// Calculate minimum bounding sphere.
|
/// Calculate minimum bounding sphere.
|
||||||
void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride, float _step = 0.01f);
|
void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride, float _step = 0.01f);
|
||||||
|
|
||||||
#endif // __BOUNDS_H__
|
#endif // __BOUNDS_H__
|
||||||
|
|
|
@ -12,21 +12,21 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
inline float fmin(float _a, float _b)
|
inline float fmin(float _a, float _b)
|
||||||
{
|
{
|
||||||
return _a < _b ? _a : _b;
|
return _a < _b ? _a : _b;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float fmax(float _a, float _b)
|
inline float fmax(float _a, float _b)
|
||||||
{
|
{
|
||||||
return _a > _b ? _a : _b;
|
return _a > _b ? _a : _b;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float flerp(float _a, float _b, float _t)
|
inline float flerp(float _a, float _b, float _t)
|
||||||
{
|
{
|
||||||
return _a + (_b - _a) * _t;
|
return _a + (_b - _a) * _t;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void vec3Add(float* __restrict _result, const float* __restrict _a, const float* __restrict _b)
|
inline void vec3Add(float* __restrict _result, const float* __restrict _a, const float* __restrict _b)
|
||||||
{
|
{
|
||||||
_result[0] = _a[0] + _b[0];
|
_result[0] = _a[0] + _b[0];
|
||||||
|
@ -224,13 +224,13 @@ inline void mtxRotateXYZ(float* _result, float _ax, float _ay, float _az)
|
||||||
_result[ 0] = cy*cz;
|
_result[ 0] = cy*cz;
|
||||||
_result[ 1] = -cy*sz;
|
_result[ 1] = -cy*sz;
|
||||||
_result[ 2] = sy;
|
_result[ 2] = sy;
|
||||||
_result[ 4] = cz*sx*sy + cx*sz;
|
_result[ 4] = cz*sx*sy + cx*sz;
|
||||||
_result[ 5] = cx*cz - sx*sy*sz;
|
_result[ 5] = cx*cz - sx*sy*sz;
|
||||||
_result[ 6] = -cy*sx;
|
_result[ 6] = -cy*sx;
|
||||||
_result[ 8] = -cx*cz*sy + sx*sz;
|
_result[ 8] = -cx*cz*sy + sx*sz;
|
||||||
_result[ 9] = cz*sx + cx*sy*sz;
|
_result[ 9] = cz*sx + cx*sy*sz;
|
||||||
_result[10] = cx*cy;
|
_result[10] = cx*cy;
|
||||||
_result[15] = 1.0f;
|
_result[15] = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void mtxRotateZYX(float* _result, float _ax, float _ay, float _az)
|
inline void mtxRotateZYX(float* _result, float _ax, float _ay, float _az)
|
||||||
|
@ -243,16 +243,16 @@ inline void mtxRotateZYX(float* _result, float _ax, float _ay, float _az)
|
||||||
float cz = cosf(_az);
|
float cz = cosf(_az);
|
||||||
|
|
||||||
memset(_result, 0, sizeof(float)*16);
|
memset(_result, 0, sizeof(float)*16);
|
||||||
_result[ 0] = cy*cz;
|
_result[ 0] = cy*cz;
|
||||||
_result[ 1] = cz*sx*sy-cx*sz;
|
_result[ 1] = cz*sx*sy-cx*sz;
|
||||||
_result[ 2] = cx*cz*sy+sx*sz;
|
_result[ 2] = cx*cz*sy+sx*sz;
|
||||||
_result[ 4] = cy*sz;
|
_result[ 4] = cy*sz;
|
||||||
_result[ 5] = cx*cz + sx*sy*sz;
|
_result[ 5] = cx*cz + sx*sy*sz;
|
||||||
_result[ 6] = -cz*sx + cx*sy*sz;
|
_result[ 6] = -cz*sx + cx*sy*sz;
|
||||||
_result[ 8] = -sy;
|
_result[ 8] = -sy;
|
||||||
_result[ 9] = cy*sx;
|
_result[ 9] = cy*sx;
|
||||||
_result[10] = cx*cy;
|
_result[10] = cx*cy;
|
||||||
_result[15] = 1.0f;
|
_result[15] = 1.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void vec3MulMtx(float* __restrict _result, const float* __restrict _vec, const float* __restrict _mat)
|
inline void vec3MulMtx(float* __restrict _result, const float* __restrict _vec, const float* __restrict _mat)
|
||||||
|
|
|
@ -1,201 +1,201 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012 Branimir Karadzic. All rights reserved.
|
* Copyright 2012 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "tokenizecmd.h"
|
#include "tokenizecmd.h"
|
||||||
|
|
||||||
// Reference:
|
// Reference:
|
||||||
// http://msdn.microsoft.com/en-us/library/a1y7w461.aspx
|
// http://msdn.microsoft.com/en-us/library/a1y7w461.aspx
|
||||||
const char* tokenizeCommandLine(const char* _commandLine, char* _buffer, uint32_t& _bufferSize, int& _argc, char* _argv[], int _maxArgvs, char _term)
|
const char* tokenizeCommandLine(const char* _commandLine, char* _buffer, uint32_t& _bufferSize, int& _argc, char* _argv[], int _maxArgvs, char _term)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
const char* curr = _commandLine;
|
const char* curr = _commandLine;
|
||||||
char* currOut = _buffer;
|
char* currOut = _buffer;
|
||||||
char term = ' ';
|
char term = ' ';
|
||||||
bool sub = false;
|
bool sub = false;
|
||||||
|
|
||||||
enum ParserState
|
enum ParserState
|
||||||
{
|
{
|
||||||
SkipWhitespace,
|
SkipWhitespace,
|
||||||
SetTerm,
|
SetTerm,
|
||||||
Copy,
|
Copy,
|
||||||
Escape,
|
Escape,
|
||||||
End,
|
End,
|
||||||
};
|
};
|
||||||
|
|
||||||
ParserState state = SkipWhitespace;
|
ParserState state = SkipWhitespace;
|
||||||
|
|
||||||
while ('\0' != *curr
|
while ('\0' != *curr
|
||||||
&& _term != *curr
|
&& _term != *curr
|
||||||
&& argc < _maxArgvs)
|
&& argc < _maxArgvs)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case SkipWhitespace:
|
case SkipWhitespace:
|
||||||
for (; isspace(*curr); ++curr); // skip whitespace
|
for (; isspace(*curr); ++curr); // skip whitespace
|
||||||
state = SetTerm;
|
state = SetTerm;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SetTerm:
|
case SetTerm:
|
||||||
if ('"' == *curr)
|
if ('"' == *curr)
|
||||||
{
|
{
|
||||||
term = '"';
|
term = '"';
|
||||||
++curr; // skip begining quote
|
++curr; // skip begining quote
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
term = ' ';
|
term = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
_argv[argc] = currOut;
|
_argv[argc] = currOut;
|
||||||
++argc;
|
++argc;
|
||||||
|
|
||||||
state = Copy;
|
state = Copy;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Copy:
|
case Copy:
|
||||||
if ('\\' == *curr)
|
if ('\\' == *curr)
|
||||||
{
|
{
|
||||||
state = Escape;
|
state = Escape;
|
||||||
}
|
}
|
||||||
else if ('"' == *curr
|
else if ('"' == *curr
|
||||||
&& '"' != term)
|
&& '"' != term)
|
||||||
{
|
{
|
||||||
sub = !sub;
|
sub = !sub;
|
||||||
}
|
}
|
||||||
else if (isspace(*curr) && !sub)
|
else if (isspace(*curr) && !sub)
|
||||||
{
|
{
|
||||||
state = End;
|
state = End;
|
||||||
}
|
}
|
||||||
else if (term != *curr || sub)
|
else if (term != *curr || sub)
|
||||||
{
|
{
|
||||||
*currOut = *curr;
|
*currOut = *curr;
|
||||||
++currOut;
|
++currOut;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
state = End;
|
state = End;
|
||||||
}
|
}
|
||||||
++curr;
|
++curr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Escape:
|
case Escape:
|
||||||
{
|
{
|
||||||
const char* start = --curr;
|
const char* start = --curr;
|
||||||
for (; '\\' == *curr; ++curr);
|
for (; '\\' == *curr; ++curr);
|
||||||
|
|
||||||
if ('"' != *curr)
|
if ('"' != *curr)
|
||||||
{
|
{
|
||||||
int count = (int)(curr-start);
|
int count = (int)(curr-start);
|
||||||
|
|
||||||
curr = start;
|
curr = start;
|
||||||
for (int ii = 0; ii < count; ++ii)
|
for (int ii = 0; ii < count; ++ii)
|
||||||
{
|
{
|
||||||
*currOut = *curr;
|
*currOut = *curr;
|
||||||
++currOut;
|
++currOut;
|
||||||
++curr;
|
++curr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
curr = start+1;
|
curr = start+1;
|
||||||
*currOut = *curr;
|
*currOut = *curr;
|
||||||
++currOut;
|
++currOut;
|
||||||
++curr;
|
++curr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state = Copy;
|
state = Copy;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case End:
|
case End:
|
||||||
*currOut = '\0';
|
*currOut = '\0';
|
||||||
++currOut;
|
++currOut;
|
||||||
state = SkipWhitespace;
|
state = SkipWhitespace;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*currOut = '\0';
|
*currOut = '\0';
|
||||||
if (0 < argc
|
if (0 < argc
|
||||||
&& '\0' == _argv[argc-1][0])
|
&& '\0' == _argv[argc-1][0])
|
||||||
{
|
{
|
||||||
--argc;
|
--argc;
|
||||||
}
|
}
|
||||||
|
|
||||||
_bufferSize = (uint32_t)(currOut - _buffer);
|
_bufferSize = (uint32_t)(currOut - _buffer);
|
||||||
_argc = argc;
|
_argc = argc;
|
||||||
|
|
||||||
if ('\0' != *curr)
|
if ('\0' != *curr)
|
||||||
{
|
{
|
||||||
++curr;
|
++curr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return curr;
|
return curr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main(int _argc, const char** _argv)
|
int main(int _argc, const char** _argv)
|
||||||
{
|
{
|
||||||
const char* input[7] =
|
const char* input[7] =
|
||||||
{
|
{
|
||||||
" ",
|
" ",
|
||||||
"\\",
|
"\\",
|
||||||
"\"a b c\" d e",
|
"\"a b c\" d e",
|
||||||
"\"ab\\\"c\" \"\\\\\" d",
|
"\"ab\\\"c\" \"\\\\\" d",
|
||||||
"a\\\\\\b d\"e f\"g h",
|
"a\\\\\\b d\"e f\"g h",
|
||||||
"a\\\\\\\"b c d",
|
"a\\\\\\\"b c d",
|
||||||
"a\\\\\\\\\"b c\" d e",
|
"a\\\\\\\\\"b c\" d e",
|
||||||
};
|
};
|
||||||
|
|
||||||
const int expected_argc[7] =
|
const int expected_argc[7] =
|
||||||
{
|
{
|
||||||
0, 0, 3, 3, 3, 3, 3
|
0, 0, 3, 3, 3, 3, 3
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* expected_results[] =
|
const char* expected_results[] =
|
||||||
{
|
{
|
||||||
"a b c", "d", "e",
|
"a b c", "d", "e",
|
||||||
"ab\"c", "\\", "d",
|
"ab\"c", "\\", "d",
|
||||||
"a\\\\\\b", "de fg", "h",
|
"a\\\\\\b", "de fg", "h",
|
||||||
"a\\\"b", "c", "d",
|
"a\\\"b", "c", "d",
|
||||||
"a\\\\b c", "d", "e",
|
"a\\\\b c", "d", "e",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char** expected_argv[7] =
|
const char** expected_argv[7] =
|
||||||
{
|
{
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
&expected_results[0],
|
&expected_results[0],
|
||||||
&expected_results[3],
|
&expected_results[3],
|
||||||
&expected_results[6],
|
&expected_results[6],
|
||||||
&expected_results[9],
|
&expected_results[9],
|
||||||
&expected_results[12],
|
&expected_results[12],
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int ii = 0; ii < 7; ++ii)
|
for (int ii = 0; ii < 7; ++ii)
|
||||||
{
|
{
|
||||||
char commandLine[1024];
|
char commandLine[1024];
|
||||||
unsigned int size = 1023;
|
unsigned int size = 1023;
|
||||||
char* argv[50];
|
char* argv[50];
|
||||||
int argc = tokenizeCommandLine(input[ii], commandLine, size, argv, 50);
|
int argc = tokenizeCommandLine(input[ii], commandLine, size, argv, 50);
|
||||||
printf("\n%d (%d): %s %s\n", ii, argc, input[ii], expected_argc[ii]==argc?"":"FAILED!");
|
printf("\n%d (%d): %s %s\n", ii, argc, input[ii], expected_argc[ii]==argc?"":"FAILED!");
|
||||||
for (int jj = 0; jj < argc; ++jj)
|
for (int jj = 0; jj < argc; ++jj)
|
||||||
{
|
{
|
||||||
printf("\t%d: {%s} %s\n"
|
printf("\t%d: {%s} %s\n"
|
||||||
, jj
|
, jj
|
||||||
, argv[jj]
|
, argv[jj]
|
||||||
, jj<argc?(0==strcmp(argv[jj], expected_argv[ii][jj])?"":"FAILED!"):"FAILED!"
|
, jj<argc?(0==strcmp(argv[jj], expected_argv[ii][jj])?"":"FAILED!"):"FAILED!"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012 Branimir Karadzic. All rights reserved.
|
* Copyright 2012 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TOKENIZE_CMD_H__
|
#ifndef __TOKENIZE_CMD_H__
|
||||||
#define __TOKENIZE_CMD_H__
|
#define __TOKENIZE_CMD_H__
|
||||||
|
|
||||||
const char* tokenizeCommandLine(const char* _commandLine, char* _buffer, uint32_t& _bufferSize, int& _argc, char* _argv[], int _maxArgvs, char _term = '\0');
|
const char* tokenizeCommandLine(const char* _commandLine, char* _buffer, uint32_t& _bufferSize, int& _argc, char* _argv[], int _maxArgvs, char _term = '\0');
|
||||||
|
|
||||||
#endif // __TOKENIZE_CMD_H__
|
#endif // __TOKENIZE_CMD_H__
|
||||||
|
|
|
@ -1,193 +1,193 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <edtaa3func.h>
|
#include <edtaa3func.h>
|
||||||
#include <stb_image.c>
|
#include <stb_image.c>
|
||||||
|
|
||||||
#define BX_NAMESPACE 1
|
#define BX_NAMESPACE 1
|
||||||
#include <bx/bx.h>
|
#include <bx/bx.h>
|
||||||
#include <bx/commandline.h>
|
#include <bx/commandline.h>
|
||||||
#include <bx/uint32_t.h>
|
#include <bx/uint32_t.h>
|
||||||
|
|
||||||
long int fsize(FILE* _file)
|
long int fsize(FILE* _file)
|
||||||
{
|
{
|
||||||
long int pos = ftell(_file);
|
long int pos = ftell(_file);
|
||||||
fseek(_file, 0L, SEEK_END);
|
fseek(_file, 0L, SEEK_END);
|
||||||
long int size = ftell(_file);
|
long int size = ftell(_file);
|
||||||
fseek(_file, pos, SEEK_SET);
|
fseek(_file, pos, SEEK_SET);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void edtaa3(double* _img, uint16_t _width, uint16_t _height, double* _out)
|
void edtaa3(double* _img, uint16_t _width, uint16_t _height, double* _out)
|
||||||
{
|
{
|
||||||
uint32_t size = _width*_height;
|
uint32_t size = _width*_height;
|
||||||
|
|
||||||
short* xdist = (short*)malloc(size*sizeof(short) );
|
short* xdist = (short*)malloc(size*sizeof(short) );
|
||||||
short* ydist = (short*)malloc(size*sizeof(short) );
|
short* ydist = (short*)malloc(size*sizeof(short) );
|
||||||
double* gx = (double*)malloc(size*sizeof(double) );
|
double* gx = (double*)malloc(size*sizeof(double) );
|
||||||
double* gy = (double*)malloc(size*sizeof(double) );
|
double* gy = (double*)malloc(size*sizeof(double) );
|
||||||
|
|
||||||
computegradient(_img, _width, _height, gx, gy);
|
computegradient(_img, _width, _height, gx, gy);
|
||||||
edtaa3(_img, gx, gy, _width, _height, xdist, ydist, _out);
|
edtaa3(_img, gx, gy, _width, _height, xdist, ydist, _out);
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < size; ++ii)
|
for (uint32_t ii = 0; ii < size; ++ii)
|
||||||
{
|
{
|
||||||
if (_out[ii] < 0.0)
|
if (_out[ii] < 0.0)
|
||||||
{
|
{
|
||||||
_out[ii] = 0.0;
|
_out[ii] = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(xdist);
|
free(xdist);
|
||||||
free(ydist);
|
free(ydist);
|
||||||
free(gx);
|
free(gx);
|
||||||
free(gy);
|
free(gy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, bool _grayscale, const void* _data)
|
void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, bool _grayscale, const void* _data)
|
||||||
{
|
{
|
||||||
FILE* file = fopen(_filePath, "wb");
|
FILE* file = fopen(_filePath, "wb");
|
||||||
if ( NULL != file )
|
if ( NULL != file )
|
||||||
{
|
{
|
||||||
uint8_t type = _grayscale ? 3 : 2;
|
uint8_t type = _grayscale ? 3 : 2;
|
||||||
uint8_t bpp = _grayscale ? 8 : 32;
|
uint8_t bpp = _grayscale ? 8 : 32;
|
||||||
uint8_t xorig = 0;
|
uint8_t xorig = 0;
|
||||||
uint8_t yorig = 0;
|
uint8_t yorig = 0;
|
||||||
|
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(type, file);
|
putc(type, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(xorig, file);
|
putc(xorig, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(yorig, file);
|
putc(yorig, file);
|
||||||
putc(_width&0xff, file);
|
putc(_width&0xff, file);
|
||||||
putc( (_width>>8)&0xff, file);
|
putc( (_width>>8)&0xff, file);
|
||||||
putc(_height&0xff, file);
|
putc(_height&0xff, file);
|
||||||
putc( (_height>>8)&0xff, file);
|
putc( (_height>>8)&0xff, file);
|
||||||
putc(bpp, file);
|
putc(bpp, file);
|
||||||
putc(32, file);
|
putc(32, file);
|
||||||
|
|
||||||
uint32_t width = _width * bpp / 8;
|
uint32_t width = _width * bpp / 8;
|
||||||
uint8_t* data = (uint8_t*)_data;
|
uint8_t* data = (uint8_t*)_data;
|
||||||
for (uint32_t yy = 0; yy < _height; ++yy)
|
for (uint32_t yy = 0; yy < _height; ++yy)
|
||||||
{
|
{
|
||||||
fwrite(data, width, 1, file);
|
fwrite(data, width, 1, file);
|
||||||
data += _pitch;
|
data += _pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double min(double _a, double _b)
|
inline double min(double _a, double _b)
|
||||||
{
|
{
|
||||||
return _a > _b ? _b : _a;
|
return _a > _b ? _b : _a;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double max(double _a, double _b)
|
inline double max(double _a, double _b)
|
||||||
{
|
{
|
||||||
return _a > _b ? _a : _b;
|
return _a > _b ? _a : _b;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double clamp(double _val, double _min, double _max)
|
inline double clamp(double _val, double _min, double _max)
|
||||||
{
|
{
|
||||||
return max(min(_val, _max), _min);
|
return max(min(_val, _max), _min);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double saturate(double _val)
|
inline double saturate(double _val)
|
||||||
{
|
{
|
||||||
return clamp(_val, 0.0, 1.0);
|
return clamp(_val, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int _argc, const char* _argv[])
|
int main(int _argc, const char* _argv[])
|
||||||
{
|
{
|
||||||
CommandLine cmdLine(_argc, _argv);
|
CommandLine cmdLine(_argc, _argv);
|
||||||
|
|
||||||
const char* inFilePath = cmdLine.findOption('i');
|
const char* inFilePath = cmdLine.findOption('i');
|
||||||
if (NULL == inFilePath)
|
if (NULL == inFilePath)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Input file name must be specified.\n");
|
fprintf(stderr, "Input file name must be specified.\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* outFilePath = cmdLine.findOption('o');
|
const char* outFilePath = cmdLine.findOption('o');
|
||||||
if (NULL == outFilePath)
|
if (NULL == outFilePath)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Output file name must be specified.\n");
|
fprintf(stderr, "Output file name must be specified.\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
double edge = 16.0;
|
double edge = 16.0;
|
||||||
const char* edgeOpt = cmdLine.findOption('e');
|
const char* edgeOpt = cmdLine.findOption('e');
|
||||||
if (NULL != edgeOpt)
|
if (NULL != edgeOpt)
|
||||||
{
|
{
|
||||||
edge = atof(edgeOpt);
|
edge = atof(edgeOpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int comp;
|
int comp;
|
||||||
|
|
||||||
stbi_uc* img = stbi_load(inFilePath, &width, &height, &comp, 1);
|
stbi_uc* img = stbi_load(inFilePath, &width, &height, &comp, 1);
|
||||||
|
|
||||||
if (NULL == img)
|
if (NULL == img)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to load %s.\n", inFilePath);
|
fprintf(stderr, "Failed to load %s.\n", inFilePath);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size = width*height;
|
uint32_t size = width*height;
|
||||||
|
|
||||||
double* imgIn = (double*)malloc(size*sizeof(double) );
|
double* imgIn = (double*)malloc(size*sizeof(double) );
|
||||||
double* outside = (double*)malloc(size*sizeof(double) );
|
double* outside = (double*)malloc(size*sizeof(double) );
|
||||||
double* inside = (double*)malloc(size*sizeof(double) );
|
double* inside = (double*)malloc(size*sizeof(double) );
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < size; ++ii)
|
for (uint32_t ii = 0; ii < size; ++ii)
|
||||||
{
|
{
|
||||||
imgIn[ii] = double(img[ii])/255.0;
|
imgIn[ii] = double(img[ii])/255.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
edtaa3(imgIn, width, height, outside);
|
edtaa3(imgIn, width, height, outside);
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < size; ++ii)
|
for (uint32_t ii = 0; ii < size; ++ii)
|
||||||
{
|
{
|
||||||
imgIn[ii] = 1.0 - imgIn[ii];
|
imgIn[ii] = 1.0 - imgIn[ii];
|
||||||
}
|
}
|
||||||
|
|
||||||
edtaa3(imgIn, width, height, inside);
|
edtaa3(imgIn, width, height, inside);
|
||||||
|
|
||||||
free(imgIn);
|
free(imgIn);
|
||||||
|
|
||||||
uint8_t* grayscale = (uint8_t*)malloc(size);
|
uint8_t* grayscale = (uint8_t*)malloc(size);
|
||||||
|
|
||||||
double edgeOffset = edge*0.5;
|
double edgeOffset = edge*0.5;
|
||||||
double invEdge = 1.0/edge;
|
double invEdge = 1.0/edge;
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < size; ++ii)
|
for (uint32_t ii = 0; ii < size; ++ii)
|
||||||
{
|
{
|
||||||
double dist = saturate( ( (outside[ii] - inside[ii])+edgeOffset) * invEdge);
|
double dist = saturate( ( (outside[ii] - inside[ii])+edgeOffset) * invEdge);
|
||||||
grayscale[ii] = 255-uint8_t(dist * 255.0);
|
grayscale[ii] = 255-uint8_t(dist * 255.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(inside);
|
free(inside);
|
||||||
free(outside);
|
free(outside);
|
||||||
|
|
||||||
saveTga(outFilePath, width, height, width, true, grayscale);
|
saveTga(outFilePath, width, height, width, true, grayscale);
|
||||||
|
|
||||||
free(grayscale);
|
free(grayscale);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ extern "C"
|
||||||
# define BX_TRACE(_format, ...) fprintf(stderr, "" _format "\n", ##__VA_ARGS__)
|
# define BX_TRACE(_format, ...) fprintf(stderr, "" _format "\n", ##__VA_ARGS__)
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
#define BGFX_CHUNK_MAGIC_VSH BX_MAKEFOURCC('V', 'S', 'H', 0x1)
|
#define BGFX_CHUNK_MAGIC_VSH BX_MAKEFOURCC('V', 'S', 'H', 0x1)
|
||||||
#define BGFX_CHUNK_MAGIC_FSH BX_MAKEFOURCC('F', 'S', 'H', 0x1)
|
#define BGFX_CHUNK_MAGIC_FSH BX_MAKEFOURCC('F', 'S', 'H', 0x1)
|
||||||
|
|
||||||
#include <bx/bx.h>
|
#include <bx/bx.h>
|
||||||
|
|
||||||
|
@ -1247,11 +1247,11 @@ void help(const char* _error = NULL)
|
||||||
" --bin2c <file path> Generate C header file.\n"
|
" --bin2c <file path> Generate C header file.\n"
|
||||||
" --depends <file path> Generate makefile style depends file.\n"
|
" --depends <file path> Generate makefile style depends file.\n"
|
||||||
" --platform <platform> Target platform.\n"
|
" --platform <platform> Target platform.\n"
|
||||||
" android\n"
|
" android\n"
|
||||||
" ios\n"
|
" ios\n"
|
||||||
" linux\n"
|
" linux\n"
|
||||||
" nacl\n"
|
" nacl\n"
|
||||||
" osx\n"
|
" osx\n"
|
||||||
" windows\n"
|
" windows\n"
|
||||||
" --type <type> Shader type (vertex, fragment)\n"
|
" --type <type> Shader type (vertex, fragment)\n"
|
||||||
" --varyingdef <file path> Path to varying.def.sc file.\n"
|
" --varyingdef <file path> Path to varying.def.sc file.\n"
|
||||||
|
@ -1483,23 +1483,23 @@ int main(int _argc, const char* _argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t padding = 16;
|
const size_t padding = 16;
|
||||||
uint32_t size = (uint32_t)fsize(file);
|
uint32_t size = (uint32_t)fsize(file);
|
||||||
char* data = new char[size+padding+1];
|
char* data = new char[size+padding+1];
|
||||||
size = (uint32_t)fread(data, 1, size, file);
|
size = (uint32_t)fread(data, 1, size, file);
|
||||||
// Compiler generates "error X3000: syntax error: unexpected end of file"
|
// Compiler generates "error X3000: syntax error: unexpected end of file"
|
||||||
// if input doesn't have empty line at EOF.
|
// if input doesn't have empty line at EOF.
|
||||||
data[size] = '\n';
|
data[size] = '\n';
|
||||||
memset(&data[size+1], 0, padding);
|
memset(&data[size+1], 0, padding);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
char* entry = strstr(data, "void main()");
|
char* entry = strstr(data, "void main()");
|
||||||
if (NULL == entry)
|
if (NULL == entry)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Shader entry point 'void main()' is not found.\n");
|
fprintf(stderr, "Shader entry point 'void main()' is not found.\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
InOut shaderInputs;
|
InOut shaderInputs;
|
||||||
InOut shaderOutputs;
|
InOut shaderOutputs;
|
||||||
uint32_t inputHash = 0;
|
uint32_t inputHash = 0;
|
||||||
|
|
|
@ -1,188 +1,188 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// Just hacking DDS loading code in here.
|
// Just hacking DDS loading code in here.
|
||||||
#include "bgfx_p.h"
|
#include "bgfx_p.h"
|
||||||
using namespace bgfx;
|
using namespace bgfx;
|
||||||
|
|
||||||
#include "dds.h"
|
#include "dds.h"
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
# define BX_TRACE(_format, ...) fprintf(stderr, "" _format "\n", ##__VA_ARGS__)
|
# define BX_TRACE(_format, ...) fprintf(stderr, "" _format "\n", ##__VA_ARGS__)
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
#include <bx/bx.h>
|
#include <bx/bx.h>
|
||||||
#include <bx/commandline.h>
|
#include <bx/commandline.h>
|
||||||
#include <bx/uint32_t.h>
|
#include <bx/uint32_t.h>
|
||||||
|
|
||||||
namespace bgfx
|
namespace bgfx
|
||||||
{
|
{
|
||||||
const Memory* alloc(uint32_t _size)
|
const Memory* alloc(uint32_t _size)
|
||||||
{
|
{
|
||||||
Memory* mem = (Memory*)::realloc(NULL, sizeof(Memory) + _size);
|
Memory* mem = (Memory*)::realloc(NULL, sizeof(Memory) + _size);
|
||||||
mem->size = _size;
|
mem->size = _size;
|
||||||
mem->data = (uint8_t*)mem + sizeof(Memory);
|
mem->data = (uint8_t*)mem + sizeof(Memory);
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src, bool _grayscale, bool _yflip)
|
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");
|
FILE* file = fopen(_filePath, "wb");
|
||||||
if ( NULL != file )
|
if ( NULL != file )
|
||||||
{
|
{
|
||||||
uint8_t type = _grayscale ? 3 : 2;
|
uint8_t type = _grayscale ? 3 : 2;
|
||||||
uint8_t bpp = _grayscale ? 8 : 32;
|
uint8_t bpp = _grayscale ? 8 : 32;
|
||||||
|
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(type, file);
|
putc(type, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(0, file);
|
putc(0, file);
|
||||||
putc(_width&0xff, file);
|
putc(_width&0xff, file);
|
||||||
putc( (_width>>8)&0xff, file);
|
putc( (_width>>8)&0xff, file);
|
||||||
putc(_height&0xff, file);
|
putc(_height&0xff, file);
|
||||||
putc( (_height>>8)&0xff, file);
|
putc( (_height>>8)&0xff, file);
|
||||||
putc(bpp, file);
|
putc(bpp, file);
|
||||||
putc(32, file);
|
putc(32, file);
|
||||||
|
|
||||||
uint32_t dstPitch = _width*bpp/8;
|
uint32_t dstPitch = _width*bpp/8;
|
||||||
if (_yflip)
|
if (_yflip)
|
||||||
{
|
{
|
||||||
uint8_t* data = (uint8_t*)_src + dstPitch*_height - _srcPitch;
|
uint8_t* data = (uint8_t*)_src + dstPitch*_height - _srcPitch;
|
||||||
for (uint32_t yy = 0; yy < _height; ++yy)
|
for (uint32_t yy = 0; yy < _height; ++yy)
|
||||||
{
|
{
|
||||||
fwrite(data, dstPitch, 1, file);
|
fwrite(data, dstPitch, 1, file);
|
||||||
data -= _srcPitch;
|
data -= _srcPitch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t* data = (uint8_t*)_src;
|
uint8_t* data = (uint8_t*)_src;
|
||||||
for (uint32_t yy = 0; yy < _height; ++yy)
|
for (uint32_t yy = 0; yy < _height; ++yy)
|
||||||
{
|
{
|
||||||
fwrite(data, dstPitch, 1, file);
|
fwrite(data, dstPitch, 1, file);
|
||||||
data += _srcPitch;
|
data += _srcPitch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long int fsize(FILE* _file)
|
long int fsize(FILE* _file)
|
||||||
{
|
{
|
||||||
long int pos = ftell(_file);
|
long int pos = ftell(_file);
|
||||||
fseek(_file, 0L, SEEK_END);
|
fseek(_file, 0L, SEEK_END);
|
||||||
long int size = ftell(_file);
|
long int size = ftell(_file);
|
||||||
fseek(_file, pos, SEEK_SET);
|
fseek(_file, pos, SEEK_SET);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int _argc, const char* _argv[])
|
int main(int _argc, const char* _argv[])
|
||||||
{
|
{
|
||||||
bx::CommandLine cmdLine(_argc, _argv);
|
bx::CommandLine cmdLine(_argc, _argv);
|
||||||
|
|
||||||
FILE* file = fopen(_argv[1], "rb");
|
FILE* file = fopen(_argv[1], "rb");
|
||||||
uint32_t size = fsize(file);
|
uint32_t size = fsize(file);
|
||||||
const Memory* mem = alloc(size);
|
const Memory* mem = alloc(size);
|
||||||
size_t readSize = fread(mem->data, 1, size, file);
|
size_t readSize = fread(mem->data, 1, size, file);
|
||||||
BX_UNUSED(readSize);
|
BX_UNUSED(readSize);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
Dds dds;
|
Dds dds;
|
||||||
|
|
||||||
if (parseDds(dds, mem) )
|
if (parseDds(dds, mem) )
|
||||||
{
|
{
|
||||||
bool decompress = cmdLine.hasArg('d');
|
bool decompress = cmdLine.hasArg('d');
|
||||||
|
|
||||||
if (decompress
|
if (decompress
|
||||||
|| 0 == dds.m_type)
|
|| 0 == dds.m_type)
|
||||||
{
|
{
|
||||||
for (uint8_t side = 0, numSides = dds.m_cubeMap ? 6 : 1; side < numSides; ++side)
|
for (uint8_t side = 0, numSides = dds.m_cubeMap ? 6 : 1; side < numSides; ++side)
|
||||||
{
|
{
|
||||||
uint32_t width = dds.m_width;
|
uint32_t width = dds.m_width;
|
||||||
uint32_t height = dds.m_height;
|
uint32_t height = dds.m_height;
|
||||||
|
|
||||||
for (uint32_t lod = 0, num = dds.m_numMips; lod < num; ++lod)
|
for (uint32_t lod = 0, num = dds.m_numMips; lod < num; ++lod)
|
||||||
{
|
{
|
||||||
width = uint32_max(1, width);
|
width = uint32_max(1, width);
|
||||||
height = uint32_max(1, height);
|
height = uint32_max(1, height);
|
||||||
|
|
||||||
Mip mip;
|
Mip mip;
|
||||||
if (getRawImageData(dds, side, lod, mem, mip) )
|
if (getRawImageData(dds, side, lod, mem, mip) )
|
||||||
{
|
{
|
||||||
uint32_t dstpitch = width*4;
|
uint32_t dstpitch = width*4;
|
||||||
uint8_t* bits = (uint8_t*)malloc(dstpitch*height);
|
uint8_t* bits = (uint8_t*)malloc(dstpitch*height);
|
||||||
|
|
||||||
if (width != mip.m_width
|
if (width != mip.m_width
|
||||||
|| height != mip.m_height)
|
|| height != mip.m_height)
|
||||||
{
|
{
|
||||||
uint8_t* temp = (uint8_t*)realloc(NULL, mip.m_width*mip.m_height*4);
|
uint8_t* temp = (uint8_t*)realloc(NULL, mip.m_width*mip.m_height*4);
|
||||||
mip.decode(temp);
|
mip.decode(temp);
|
||||||
uint32_t srcpitch = mip.m_width*4;
|
uint32_t srcpitch = mip.m_width*4;
|
||||||
|
|
||||||
for (uint32_t yy = 0; yy < height; ++yy)
|
for (uint32_t yy = 0; yy < height; ++yy)
|
||||||
{
|
{
|
||||||
uint8_t* src = &temp[yy*srcpitch];
|
uint8_t* src = &temp[yy*srcpitch];
|
||||||
uint8_t* dst = &bits[yy*dstpitch];
|
uint8_t* dst = &bits[yy*dstpitch];
|
||||||
|
|
||||||
for (uint32_t xx = 0; xx < width; ++xx)
|
for (uint32_t xx = 0; xx < width; ++xx)
|
||||||
{
|
{
|
||||||
memcpy(dst, src, 4);
|
memcpy(dst, src, 4);
|
||||||
dst += 4;
|
dst += 4;
|
||||||
src += 4;
|
src += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mip.decode(bits);
|
mip.decode(bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
char filePath[256];
|
char filePath[256];
|
||||||
bx::snprintf(filePath, sizeof(filePath), "mip%d_%d.tga", side, lod);
|
bx::snprintf(filePath, sizeof(filePath), "mip%d_%d.tga", side, lod);
|
||||||
|
|
||||||
saveTga(filePath, width, height, dstpitch, bits);
|
saveTga(filePath, width, height, dstpitch, bits);
|
||||||
free(bits);
|
free(bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
width >>= 1;
|
width >>= 1;
|
||||||
height >>= 1;
|
height >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (uint32_t lod = 0, num = dds.m_numMips; lod < num; ++lod)
|
for (uint32_t lod = 0, num = dds.m_numMips; lod < num; ++lod)
|
||||||
{
|
{
|
||||||
Mip mip;
|
Mip mip;
|
||||||
if (getRawImageData(dds, 0, lod, mem, mip) )
|
if (getRawImageData(dds, 0, lod, mem, mip) )
|
||||||
{
|
{
|
||||||
char filePath[256];
|
char filePath[256];
|
||||||
bx::snprintf(filePath, sizeof(filePath), "mip%d.bin", lod);
|
bx::snprintf(filePath, sizeof(filePath), "mip%d.bin", lod);
|
||||||
file = fopen(filePath, "wb");
|
file = fopen(filePath, "wb");
|
||||||
fwrite(mip.m_data, 1, mip.m_size, file);
|
fwrite(mip.m_data, 1, mip.m_size, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue