mirror of https://github.com/bjornbytes/lovr.git
parent
a81cd0d731
commit
1e7749a58a
|
@ -171,7 +171,7 @@ int _luax_checkenum(lua_State* L, int index, const StringEntry* map, const char*
|
|||
size_t length;
|
||||
const char* string = fallback ? luaL_optlstring(L, index, fallback, &length) : luaL_checklstring(L, index, &length);
|
||||
|
||||
for (size_t i = 0; map[i].length; i++) {
|
||||
for (int i = 0; map[i].length; i++) {
|
||||
if (map[i].length == length && !memcmp(map[i].string, string, length)) {
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -1452,19 +1452,19 @@ static const char* luax_readshadersource(lua_State* L, int index, int *outLength
|
|||
|
||||
Blob* blob = luax_totype(L, index, Blob);
|
||||
if (blob) {
|
||||
*outLength = blob->size;
|
||||
*outLength = (int) blob->size;
|
||||
return blob->data;
|
||||
}
|
||||
|
||||
size_t length;
|
||||
const char* source = luaL_checklstring(L, index, &length);
|
||||
if (memchr(source, '\n', MIN(1024, length))) {
|
||||
*outLength = length;
|
||||
*outLength = (int) length;
|
||||
return source;
|
||||
} else {
|
||||
void* contents = luax_readfile(source, &length);
|
||||
lovrAssert(contents, "Could not read shader from file '%s'", source);
|
||||
*outLength = length;
|
||||
*outLength = (int) length;
|
||||
return contents;
|
||||
}
|
||||
}
|
||||
|
@ -1551,9 +1551,7 @@ static int l_lovrGraphicsNewShader(lua_State* L) {
|
|||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
shader = lovrShaderCreateGraphics(
|
||||
vertexSource, vertexSourceLength, fragmentSource, fragmentSourceLength,
|
||||
flags, flagCount, multiview);
|
||||
shader = lovrShaderCreateGraphics(vertexSource, vertexSourceLength, fragmentSource, fragmentSourceLength, flags, flagCount, multiview);
|
||||
}
|
||||
|
||||
luax_pushtype(L, Shader, shader);
|
||||
|
|
|
@ -296,7 +296,7 @@ static int l_lovrMeshSetVertices(lua_State* L) {
|
|||
|
||||
Blob* blob = luax_totype(L, 2, Blob);
|
||||
if (blob) {
|
||||
count = MIN(count, blob->size / stride);
|
||||
count = MIN(count, (uint32_t) (blob->size / stride));
|
||||
lovrAssert(start + count <= capacity, "Overflow in Mesh:setVertices: Mesh can only hold %d vertices", capacity);
|
||||
void* data = lovrBufferMap(buffer, start * stride, false);
|
||||
memcpy(data, blob->data, count * stride);
|
||||
|
|
|
@ -24,7 +24,7 @@ static int threadRunner(void* data) {
|
|||
lua_pop(L, 2);
|
||||
|
||||
if (!luaL_loadbuffer(L, thread->body->data, thread->body->size, "thread")) {
|
||||
for (size_t i = 0; i < thread->argumentCount; i++) {
|
||||
for (uint32_t i = 0; i < thread->argumentCount; i++) {
|
||||
luax_pushvariant(L, &thread->arguments[i]);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
static int l_lovrThreadStart(lua_State* L) {
|
||||
Thread* thread = luax_checktype(L, 1, Thread);
|
||||
Variant arguments[MAX_THREAD_ARGUMENTS];
|
||||
size_t argumentCount = MIN(MAX_THREAD_ARGUMENTS, lua_gettop(L) - 1);
|
||||
for (size_t i = 0; i < argumentCount; i++) {
|
||||
uint32_t argumentCount = MIN(MAX_THREAD_ARGUMENTS, lua_gettop(L) - 1);
|
||||
for (uint32_t i = 0; i < argumentCount; i++) {
|
||||
luax_checkvariant(L, 2 + i, &arguments[i]);
|
||||
}
|
||||
lovrThreadStart(thread, arguments, argumentCount);
|
||||
|
|
|
@ -73,7 +73,7 @@ void* png_encode(uint8_t* pixels, uint32_t w, uint32_t h, int32_t stride, size_t
|
|||
data += 8 + sizeof(header) + 4;
|
||||
|
||||
// IDAT
|
||||
memcpy(data, (uint8_t[4]) { idatSize >> 24, idatSize >> 16, idatSize >> 8, idatSize >> 0 }, 4);
|
||||
memcpy(data, (uint8_t[4]) { idatSize >> 24 & 0xff, idatSize >> 16 & 0xff, idatSize >> 8 & 0xff, idatSize >> 0 & 0xff }, 4);
|
||||
memcpy(data + 4, "IDAT", 4);
|
||||
|
||||
{
|
||||
|
@ -93,8 +93,8 @@ void* png_encode(uint8_t* pixels, uint32_t w, uint32_t h, int32_t stride, size_t
|
|||
*p++ = (length == rowSize);
|
||||
|
||||
// Write length and negated length
|
||||
memcpy(p + 0, &(uint16_t) {blockSize}, 2);
|
||||
memcpy(p + 2, &(uint16_t) {~blockSize}, 2);
|
||||
memcpy(p + 0, &(uint16_t) { blockSize & 0xffff }, 2);
|
||||
memcpy(p + 2, &(uint16_t) { ~blockSize & 0xffff }, 2);
|
||||
p += 4;
|
||||
|
||||
// Write the filter method (0) and the row data
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#define MAX(a, b) (a > b ? a : b)
|
||||
#define MIN(a, b) (a < b ? a : b)
|
||||
#define CLAMP(x, min, max) MAX(min, MIN(max, x))
|
||||
#define ALIGN(p, n) (((uintptr_t) (p) + (n - 1)) & -n)
|
||||
#define ALIGN(p, n) (((uintptr_t) (p) + (n - 1)) & ~(n - 1))
|
||||
#define CHECK_SIZEOF(T) int(*_o)[sizeof(T)]=1
|
||||
|
||||
typedef struct Color { float r, g, b, a; } Color;
|
||||
|
|
|
@ -202,7 +202,7 @@ ModelData* lovrModelDataInitObj(ModelData* model, Blob* source, ModelDataIO* io)
|
|||
}
|
||||
|
||||
float empty[3] = { 0.f };
|
||||
arr_push(&indexBlob, vertexBlob.length / 8);
|
||||
arr_push(&indexBlob, (int) vertexBlob.length / 8);
|
||||
map_set(&vertexMap, hash, vertexBlob.length / 8);
|
||||
arr_append(&vertexBlob, positions.data + 3 * (v - 1), 3);
|
||||
arr_append(&vertexBlob, vn > 0 ? (normals.data + 3 * (vn - 1)) : empty, 3);
|
||||
|
|
|
@ -2612,14 +2612,14 @@ Shader* lovrShaderCreateGraphics(const char* vertexSource, int vertexSourceLengt
|
|||
vertexSource = vertexSource == NULL ? lovrUnlitVertexShader : vertexSource;
|
||||
const char* vertexSources[] = { version, singlepass[0], flagSource ? flagSource : "", lovrShaderVertexPrefix, vertexSource, lovrShaderVertexSuffix };
|
||||
int vertexSourceLengths[] = { -1, -1, -1, -1, vertexSourceLength, -1 };
|
||||
size_t vertexSourceCount = sizeof(vertexSources) / sizeof(vertexSources[0]);
|
||||
int vertexSourceCount = sizeof(vertexSources) / sizeof(vertexSources[0]);
|
||||
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexSources, vertexSourceLengths, vertexSourceCount);
|
||||
|
||||
// Fragment
|
||||
fragmentSource = fragmentSource == NULL ? lovrUnlitFragmentShader : fragmentSource;
|
||||
const char* fragmentSources[] = { version, singlepass[1], flagSource ? flagSource : "", lovrShaderFragmentPrefix, fragmentSource, lovrShaderFragmentSuffix };
|
||||
int fragmentSourceLengths[] = { -1, -1, -1, -1, fragmentSourceLength, -1 };
|
||||
size_t fragmentSourceCount = sizeof(fragmentSources) / sizeof(fragmentSources[0]);
|
||||
int fragmentSourceCount = sizeof(fragmentSources) / sizeof(fragmentSources[0]);
|
||||
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentSources, fragmentSourceLengths, fragmentSourceCount);
|
||||
|
||||
free(flagSource);
|
||||
|
@ -2695,7 +2695,7 @@ Shader* lovrShaderCreateCompute(const char* source, int length, ShaderFlag* flag
|
|||
char* flagSource = lovrShaderGetFlagCode(flags, flagCount);
|
||||
const char* sources[] = { lovrShaderComputePrefix, flagSource ? flagSource : "", source, lovrShaderComputeSuffix };
|
||||
int lengths[] = { -1, -1, length, -1 };
|
||||
size_t count = sizeof(sources) / sizeof(sources[0]);
|
||||
int count = sizeof(sources) / sizeof(sources[0]);
|
||||
GLuint computeShader = compileShader(GL_COMPUTE_SHADER, sources, lengths, count);
|
||||
free(flagSource);
|
||||
GLuint program = glCreateProgram();
|
||||
|
@ -2842,7 +2842,7 @@ size_t lovrShaderComputeUniformLayout(arr_uniform_t* uniforms) {
|
|||
ShaderBlock* lovrShaderBlockCreate(BlockType type, Buffer* buffer, arr_uniform_t* uniforms) {
|
||||
ShaderBlock* block = lovrAlloc(ShaderBlock);
|
||||
arr_init(&block->uniforms);
|
||||
map_init(&block->uniformMap, uniforms->length);
|
||||
map_init(&block->uniformMap, (uint32_t) uniforms->length);
|
||||
|
||||
arr_append(&block->uniforms, uniforms->data, uniforms->length);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ void lovrThreadDestroy(void* ref) {
|
|||
free(thread->error);
|
||||
}
|
||||
|
||||
void lovrThreadStart(Thread* thread, Variant* arguments, size_t argumentCount) {
|
||||
void lovrThreadStart(Thread* thread, Variant* arguments, uint32_t argumentCount) {
|
||||
bool running = lovrThreadIsRunning(thread);
|
||||
|
||||
if (running) {
|
||||
|
|
|
@ -18,7 +18,7 @@ typedef struct Thread {
|
|||
mtx_t lock;
|
||||
Blob* body;
|
||||
Variant arguments[MAX_THREAD_ARGUMENTS];
|
||||
size_t argumentCount;
|
||||
uint32_t argumentCount;
|
||||
int (*runner)(void*);
|
||||
char* error;
|
||||
bool running;
|
||||
|
@ -32,7 +32,7 @@ void lovrThreadRemoveChannel(uint64_t hash);
|
|||
Thread* lovrThreadInit(Thread* thread, int (*runner)(void*), Blob* body);
|
||||
#define lovrThreadCreate(...) lovrThreadInit(lovrAlloc(Thread), __VA_ARGS__)
|
||||
void lovrThreadDestroy(void* ref);
|
||||
void lovrThreadStart(Thread* thread, Variant* arguments, size_t argumentCount);
|
||||
void lovrThreadStart(Thread* thread, Variant* arguments, uint32_t argumentCount);
|
||||
void lovrThreadWait(Thread* thread);
|
||||
const char* lovrThreadGetError(Thread* thread);
|
||||
bool lovrThreadIsRunning(Thread* thread);
|
||||
|
|
Loading…
Reference in New Issue