fixed texture loading
This commit is contained in:
@@ -109,14 +109,16 @@ namespace Game
|
||||
GameInst = &instance;
|
||||
}
|
||||
|
||||
void* AllocateScratch(size_t byteCount, size_t align = 16)
|
||||
void* AllocateScratch(size_t byteCount, size_t align)
|
||||
{
|
||||
size_t offset = GetInstance().UsedScratchAmount;
|
||||
uint8_t* base = static_cast<uint8_t*>(GetShared().Game.TransientStorage);
|
||||
uint8_t* current = base + offset;
|
||||
uintptr_t ptrAligned = ((reinterpret_cast<uintptr_t>(current) + align - 1) / align) * align;
|
||||
uintptr_t newOffset = ptrAligned - reinterpret_cast<uintptr_t>(base) + byteCount;
|
||||
size_t offsetAligned = ((offset + align - 1) / align) * align;
|
||||
uint8_t* ptrAligned = base + offsetAligned;
|
||||
size_t newOffset = offsetAligned + byteCount;
|
||||
if (newOffset > GetShared().Game.TransientStorageSize) return nullptr;
|
||||
GetInstance().UsedScratchAmount = newOffset;
|
||||
return reinterpret_cast<void*>(ptrAligned);
|
||||
}
|
||||
} // namespace Game
|
||||
|
||||
@@ -76,5 +76,5 @@ namespace Game
|
||||
void SetShared(SharedData& instance);
|
||||
GameInstance& GetInstance();
|
||||
void SetInstance(GameInstance& instance);
|
||||
void* AllocateScratch(size_t byteCount);
|
||||
void* AllocateScratch(size_t byteCount, size_t align = 16);
|
||||
} // namespace Game
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Game
|
||||
{
|
||||
bool IsInitialized = false;
|
||||
uint64_t Size = sizeof(GameInstance);
|
||||
uint8_t UsedScratchAmount = 0;
|
||||
uint64_t UsedScratchAmount = 0;
|
||||
Time Time;
|
||||
PlayerData Player;
|
||||
Level GameLevel;
|
||||
|
||||
@@ -141,8 +141,8 @@ namespace Game
|
||||
|
||||
void TestEntity::Update()
|
||||
{
|
||||
EData.TestColor[0] = 0.6f;
|
||||
EData.TestColor[1] = 0.9f;
|
||||
EData.TestColor[2] = 0.5f;
|
||||
EData.TestColor[0] = 0.0f;
|
||||
// EData.TestColor[1] = 0.9f;
|
||||
// EData.TestColor[2] = 0.5f;
|
||||
}
|
||||
} // namespace Game
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -37,7 +37,8 @@ namespace Game
|
||||
long fileSize = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
const bgfx::Memory* mem = bgfx::alloc(fileSize + 1);
|
||||
void* rawMem = AllocateScratch(fileSize + 1);
|
||||
const bgfx::Memory* mem = bgfx::makeRef(rawMem, fileSize + 1);
|
||||
fread(mem->data, 1, fileSize, file);
|
||||
if (appendZero)
|
||||
{
|
||||
@@ -126,7 +127,9 @@ namespace Game
|
||||
*_orientation = imageContainer.m_orientation;
|
||||
}
|
||||
|
||||
const bgfx::Memory* mem = bgfx::makeRef(imageContainer.m_data, imageContainer.m_size);
|
||||
const bgfx::Memory* mem =
|
||||
bgfx::makeRef(data->data + imageContainer.m_offset, data->size - imageContainer.m_offset);
|
||||
// const bgfx::Memory* mem = bgfx::makeRef(imageContainer.m_data, imageContainer.m_size);
|
||||
|
||||
if (NULL != _info)
|
||||
{
|
||||
|
||||
@@ -24,6 +24,11 @@ float calcBrightness(vec3 lightPos, vec3 vertPos, vec3 normal)
|
||||
return diffuse * clamp(1.0 - distance(lightPos, vertPos) * 0.01, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float calcBrightnessDirectional(vec3 sunDir, vec3 normal)
|
||||
{
|
||||
return max(0.0, dot(sunDir, normal));
|
||||
}
|
||||
|
||||
float circles(vec2 uv, float level, float subLevel, float brightness)
|
||||
{
|
||||
vec2 offsetUv = uv + 0.5;
|
||||
@@ -57,7 +62,9 @@ void main()
|
||||
float testSpeed = 1.0;
|
||||
vec3 testOffset = vec3(0.0, 0.0, 50.0);
|
||||
float3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius);
|
||||
float brightness = calcBrightness(lightPos, v_wpos, v_normal);
|
||||
// float brightness = calcBrightness(lightPos, v_wpos, v_normal);
|
||||
float brightness = calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal);
|
||||
// brightness = 1.0;
|
||||
// brightness = 0.1 + brightness * 0.9;
|
||||
|
||||
float baseScale = 2.0;
|
||||
@@ -80,12 +87,15 @@ void main()
|
||||
|
||||
vec2 uv = v_uv0 * exp2(patternScaleLevel);
|
||||
float dither = circles(uv, patternScaleLevel, patternFractional, brightness);
|
||||
vec3 color = desaturate(u_testColor.xyz) * 0.01 + dither * u_testColor.xyz * 0.95;
|
||||
vec3 texColor = u_testColor.x > 0.1 ? u_testColor.xyz : texture2D(s_texColor, v_uv0).xyz;
|
||||
vec3 color = desaturate(texColor) * 0.01 + dither * texColor * 0.95;
|
||||
vec3 smoothColor = brightness * u_testColor.xyz;
|
||||
vec3 mixedColor = 0.1 * smoothColor + 0.9 * color;
|
||||
gl_FragColor = vec4(mixedColor, 1.0);
|
||||
// gl_FragColor = vec4(mixedColor, 1.0);
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
// gl_FragColor = brightness;
|
||||
// gl_FragColor = dither;
|
||||
// gl_FragColor = u_testColor;
|
||||
gl_FragColor = texture2D(s_texColor, v_uv0);
|
||||
// gl_FragColor = texture2D(s_texColor, v_uv0);
|
||||
// gl_FragColor = vec4(v_normal, 1.0);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,5 @@ void main()
|
||||
v_color0 = a_color0;
|
||||
v_uv0 = a_texcoord0;
|
||||
v_wpos = mul(u_model[0], vec4(a_position, 1.0)).xyz;
|
||||
|
||||
v_normal = normalize(mul(mat3(u_model[0]), a_normal));
|
||||
v_normal = normalize(mul(u_model[0], a_normal));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user