Skip to content

Commit

Permalink
CNZSL: Use typedef instead of bool/float/double
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Apr 29, 2024
1 parent c2cd40a commit 333d4be
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 43 deletions.
4 changes: 4 additions & 0 deletions include/CNZSL/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@
#define CNZSL_API extern
#endif

typedef int nzslBool;
typedef float nzslFloat32;
typedef double nzslFloat64;

#endif /* CNZSL_CONFIG_H */
6 changes: 3 additions & 3 deletions include/CNZSL/GlslWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ typedef struct
{
unsigned int glMajorVersion;
unsigned int glMinorVersion;
int glES;
int flipYPosition;
int remapZPosition;
nzslBool glES;
nzslBool flipYPosition;
nzslBool remapZPosition;
int allowDrawParametersUniformsFallback;
} nzslGlslWriterEnvironment;

Expand Down
38 changes: 20 additions & 18 deletions include/CNZSL/WriterStates.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,33 @@ extern "C"
{
#endif

typedef uint32_t nzslOptionHash;

typedef struct nzslWriterStates nzslWriterStates;

CNZSL_API nzslWriterStates* nzslWriterStatesCreate(void);
CNZSL_API void nzslWriterStatesDestroy(nzslWriterStates* statesPtr);

CNZSL_API void nzslWriterStatesEnableOptimization(nzslWriterStates* statesPtr, int enable);
CNZSL_API void nzslWriterStatesEnableSanitization(nzslWriterStates* statesPtr, int enable);
CNZSL_API void nzslWriterStatesEnableOptimization(nzslWriterStates* statesPtr, nzslBool enable);
CNZSL_API void nzslWriterStatesEnableSanitization(nzslWriterStates* statesPtr, nzslBool enable);
CNZSL_API void nzslWriterStatesSetDebugLevel(nzslWriterStates* statesPtr, nzslDebugLevel debugLevel);

CNZSL_API void nzslWriterStatesSetOption_bool(nzslWriterStates* statesPtr, uint32_t optionHash, bool value);
CNZSL_API void nzslWriterStatesSetOption_f32(nzslWriterStates* statesPtr, uint32_t optionHash, float value);
CNZSL_API void nzslWriterStatesSetOption_i32(nzslWriterStates* statesPtr, uint32_t optionHash, int32_t value);
CNZSL_API void nzslWriterStatesSetOption_u32(nzslWriterStates* statesPtr, uint32_t optionHash, uint32_t value);
CNZSL_API void nzslWriterStatesSetOption_vec2bool(nzslWriterStates* statesPtr, uint32_t optionHash, const bool* values);
CNZSL_API void nzslWriterStatesSetOption_vec3bool(nzslWriterStates* statesPtr, uint32_t optionHash, const bool* values);
CNZSL_API void nzslWriterStatesSetOption_vec4bool(nzslWriterStates* statesPtr, uint32_t optionHash, const bool* values);
CNZSL_API void nzslWriterStatesSetOption_vec2f32(nzslWriterStates* statesPtr, uint32_t optionHash, const float* values);
CNZSL_API void nzslWriterStatesSetOption_vec3f32(nzslWriterStates* statesPtr, uint32_t optionHash, const float* values);
CNZSL_API void nzslWriterStatesSetOption_vec4f32(nzslWriterStates* statesPtr, uint32_t optionHash, const float* values);
CNZSL_API void nzslWriterStatesSetOption_vec2i32(nzslWriterStates* statesPtr, uint32_t optionHash, const int32_t* values);
CNZSL_API void nzslWriterStatesSetOption_vec3i32(nzslWriterStates* statesPtr, uint32_t optionHash, const int32_t* values);
CNZSL_API void nzslWriterStatesSetOption_vec4i32(nzslWriterStates* statesPtr, uint32_t optionHash, const int32_t* values);
CNZSL_API void nzslWriterStatesSetOption_vec2u32(nzslWriterStates* statesPtr, uint32_t optionHash, const uint32_t* values);
CNZSL_API void nzslWriterStatesSetOption_vec3u32(nzslWriterStates* statesPtr, uint32_t optionHash, const uint32_t* values);
CNZSL_API void nzslWriterStatesSetOption_vec4u32(nzslWriterStates* statesPtr, uint32_t optionHash, const uint32_t* values);
CNZSL_API void nzslWriterStatesSetOption_bool(nzslWriterStates* statesPtr, nzslOptionHash optionHash, nzslBool value);
CNZSL_API void nzslWriterStatesSetOption_f32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, nzslFloat32 value);
CNZSL_API void nzslWriterStatesSetOption_i32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, int32_t value);
CNZSL_API void nzslWriterStatesSetOption_u32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, uint32_t value);
CNZSL_API void nzslWriterStatesSetOption_vec2bool(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslBool* values);
CNZSL_API void nzslWriterStatesSetOption_vec3bool(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslBool* values);
CNZSL_API void nzslWriterStatesSetOption_vec4bool(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslBool* values);
CNZSL_API void nzslWriterStatesSetOption_vec2f32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslFloat32* values);
CNZSL_API void nzslWriterStatesSetOption_vec3f32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslFloat32* values);
CNZSL_API void nzslWriterStatesSetOption_vec4f32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslFloat32* values);
CNZSL_API void nzslWriterStatesSetOption_vec2i32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const int32_t* values);
CNZSL_API void nzslWriterStatesSetOption_vec3i32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const int32_t* values);
CNZSL_API void nzslWriterStatesSetOption_vec4i32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const int32_t* values);
CNZSL_API void nzslWriterStatesSetOption_vec2u32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const uint32_t* values);
CNZSL_API void nzslWriterStatesSetOption_vec3u32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const uint32_t* values);
CNZSL_API void nzslWriterStatesSetOption_vec4u32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const uint32_t* values);

#ifdef __cplusplus
}
Expand Down
45 changes: 23 additions & 22 deletions src/CNZSL/WriterStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <CNZSL/WriterStates.h>
#include <CNZSL/Structs/WriterStates.hpp>
#include <NZSL/Ast/Option.hpp>
#include <array>

extern "C"
Expand All @@ -18,12 +19,12 @@ extern "C"
delete statesPtr;
}

CNZSL_API void nzslWriterStatesEnableOptimization(nzslWriterStates* statesPtr, int enable)
CNZSL_API void nzslWriterStatesEnableOptimization(nzslWriterStates* statesPtr, nzslBool enable)
{
statesPtr->optimize = (enable != 0);
}

CNZSL_API void nzslWriterStatesEnableSanitization(nzslWriterStates* statesPtr, int enable)
CNZSL_API void nzslWriterStatesEnableSanitization(nzslWriterStates* statesPtr, nzslBool enable)
{
statesPtr->sanitized = (enable == 0);
}
Expand All @@ -40,82 +41,82 @@ extern "C"
statesPtr->debugLevel = s_debugLevels[debugLevel];
}

CNZSL_API void nzslWriterStatesSetOption_bool(nzslWriterStates* statesPtr, uint32_t optionHash, bool value)
CNZSL_API void nzslWriterStatesSetOption_bool(nzslWriterStates* statesPtr, nzslOptionHash optionHash, nzslBool value)
{
statesPtr->optionValues[optionHash] = value;
statesPtr->optionValues[optionHash] = (value != 0);
}

CNZSL_API void nzslWriterStatesSetOption_f32(nzslWriterStates* statesPtr, uint32_t optionHash, float value)
CNZSL_API void nzslWriterStatesSetOption_f32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, nzslFloat32 value)
{
statesPtr->optionValues[optionHash] = value;
}

CNZSL_API void nzslWriterStatesSetOption_i32(nzslWriterStates* statesPtr, uint32_t optionHash, int32_t value)
CNZSL_API void nzslWriterStatesSetOption_i32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, int32_t value)
{
statesPtr->optionValues[optionHash] = value;
}

CNZSL_API void nzslWriterStatesSetOption_u32(nzslWriterStates* statesPtr, uint32_t optionHash, uint32_t value)
CNZSL_API void nzslWriterStatesSetOption_u32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, uint32_t value)
{
statesPtr->optionValues[optionHash] = value;
}

CNZSL_API void nzslWriterStatesSetOption_vec2bool(nzslWriterStates* statesPtr, uint32_t optionHash, const bool* values)
CNZSL_API void nzslWriterStatesSetOption_vec2bool(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslBool* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector2<bool>(values[0], values[1]);
statesPtr->optionValues[optionHash] = nzsl::Vector2<bool>(values[0] != 0, values[1] != 0);
}

CNZSL_API void nzslWriterStatesSetOption_vec3bool(nzslWriterStates* statesPtr, uint32_t optionHash, const bool* values)
CNZSL_API void nzslWriterStatesSetOption_vec3bool(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslBool* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector3<bool>(values[0], values[1], values[2]);
statesPtr->optionValues[optionHash] = nzsl::Vector3<bool>(values[0] != 0, values[1] != 0, values[2] != 0);
}

CNZSL_API void nzslWriterStatesSetOption_vec4bool(nzslWriterStates* statesPtr, uint32_t optionHash, const bool* values)
CNZSL_API void nzslWriterStatesSetOption_vec4bool(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslBool* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector4<bool>(values[0], values[1], values[2], values[3]);
statesPtr->optionValues[optionHash] = nzsl::Vector4<bool>(values[0] != 0, values[1] != 0, values[2] != 0, values[3] != 0);
}

CNZSL_API void nzslWriterStatesSetOption_vec2f32(nzslWriterStates* statesPtr, uint32_t optionHash, const float* values)
CNZSL_API void nzslWriterStatesSetOption_vec2f32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslFloat32* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector2f32(values[0], values[1]);
}

CNZSL_API void nzslWriterStatesSetOption_vec3f32(nzslWriterStates* statesPtr, uint32_t optionHash, const float* values)
CNZSL_API void nzslWriterStatesSetOption_vec3f32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslFloat32* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector3f32(values[0], values[1], values[2]);
}

CNZSL_API void nzslWriterStatesSetOption_vec4f32(nzslWriterStates* statesPtr, uint32_t optionHash, const float* values)
CNZSL_API void nzslWriterStatesSetOption_vec4f32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const nzslFloat32* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector4f32(values[0], values[1], values[2], values[3]);
}

CNZSL_API void nzslWriterStatesSetOption_vec2i32(nzslWriterStates* statesPtr, uint32_t optionHash, const int32_t* values)
CNZSL_API void nzslWriterStatesSetOption_vec2i32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const int32_t* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector2i32(values[0], values[1]);
}

CNZSL_API void nzslWriterStatesSetOption_vec3i32(nzslWriterStates* statesPtr, uint32_t optionHash, const int32_t* values)
CNZSL_API void nzslWriterStatesSetOption_vec3i32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const int32_t* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector3i32(values[0], values[1], values[2]);
}

CNZSL_API void nzslWriterStatesSetOption_vec4i32(nzslWriterStates* statesPtr, uint32_t optionHash, const int32_t* values)
CNZSL_API void nzslWriterStatesSetOption_vec4i32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const int32_t* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector4i32(values[0], values[1], values[2], values[3]);
}

CNZSL_API void nzslWriterStatesSetOption_vec2u32(nzslWriterStates* statesPtr, uint32_t optionHash, const uint32_t* values)
CNZSL_API void nzslWriterStatesSetOption_vec2u32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const uint32_t* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector2u32(values[0], values[1]);
}

CNZSL_API void nzslWriterStatesSetOption_vec3u32(nzslWriterStates* statesPtr, uint32_t optionHash, const uint32_t* values)
CNZSL_API void nzslWriterStatesSetOption_vec3u32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const uint32_t* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector3u32(values[0], values[1], values[2]);
}

CNZSL_API void nzslWriterStatesSetOption_vec4u32(nzslWriterStates* statesPtr, uint32_t optionHash, const uint32_t* values)
CNZSL_API void nzslWriterStatesSetOption_vec4u32(nzslWriterStates* statesPtr, nzslOptionHash optionHash, const uint32_t* values)
{
statesPtr->optionValues[optionHash] = nzsl::Vector4u32(values[0], values[1], values[2], values[3]);
}
Expand Down

0 comments on commit 333d4be

Please sign in to comment.