Skip to content

Instantly share code, notes, and snippets.

@yorung
yorung / opengl_input_elements.cpp
Last active March 28, 2016 16:00
Share same vertex layout across multiple vertex shaders
struct InputElement {
const char* name;
ShaderFormat format;
int offset;
int inputSlot;
bool perInstance;
};
static InputElement elements[] = {
{"POSITION", SF_R32G32B32_FLOAT, 0, 0, false},
void Voice::Play(bool loop)
{
if (!IsReady()) {
return;
}
auto playback = [](SLAndroidSimpleBufferQueueItf q, void* context_) {
double now = GetTime();
if (now - systemMisc.GetLastUpdateTime() >= 0.5) {
return;
}
void Voice::Play(bool loop)
{
if (!IsReady()) {
return;
}
auto playback = [](SLAndroidSimpleBufferQueueItf q, void* context_) {
WaveContext* context = (WaveContext*)context_;
int totalSize;
const void* buf = RiffFindChunk(context->fileImg, "data", &totalSize);
SLCall(q, Enqueue, (char*)buf, totalSize);
struct WaveFormatEx {
uint16_t tag, channels;
uint32_t samplesPerSecond, averageBytesPerSecond;
uint16_t blockAlign, bitsPerSample;
};
struct WaveContext
{
SLObjectItf playerObject;
SLPlayItf playerPlay;
template <class T> void SafeDestroy(T& p)
{
if (p) {
(*p)->Destroy(p);
p = nullptr;
}
}
SLresult _slHandleError(const char* func, int line, const char* command, SLresult r)
{
class SL {
SLObjectItf engineObject = nullptr;
SLEngineItf engineEngine = nullptr;
SLObjectItf outputMixObject = nullptr;
public:
SL() {
SLHandleError(slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr));
SLCall(engineObject, Realize, SL_BOOLEAN_FALSE);
SLCall(engineObject, GetInterface, SL_IID_ENGINE, &engineEngine);
SLInterfaceID ids = SL_IID_ENVIRONMENTALREVERB;
function require(m)
package.loaded[m] = package.loaded[m] or dofile(m..".lua") or true
return package.loaded[m]
end
print("calling with dofile", dofile("random.lua"), dofile("random.lua"), dofile("random.lua"))
print("calling with require", require("random"), require("random"), require("random"))
assert(require("random") == package.loaded["random"])
@yorung
yorung / replace_require.lua
Created December 5, 2015 07:08
Write "require" in Lua
function require(m)
dofile(m..".lua")
end
@yorung
yorung / callee.lua
Created November 22, 2015 13:55
Return values of dofile
return "A message from callee!"