mirror of https://github.com/bjornbytes/lovr.git
Canvas:newTextureData;
This commit is contained in:
parent
74fec01e60
commit
e287cee1c9
|
@ -46,6 +46,18 @@ int l_lovrCanvasSetTexture(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrCanvasNewTextureData(lua_State* L) {
|
||||
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
||||
int index = luaL_optinteger(L, 2, 1) - 1;
|
||||
int count;
|
||||
lovrCanvasGetAttachments(canvas, &count);
|
||||
lovrAssert(index >= 0 && index < count, "Can not create a TextureData from Texture #%d of Canvas (it only has %d textures)", index, count);
|
||||
TextureData* textureData = lovrCanvasNewTextureData(canvas, index);
|
||||
luax_pushobject(L, textureData);
|
||||
lovrRelease(textureData);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrCanvasRenderTo(lua_State* L) {
|
||||
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
|
@ -60,6 +72,7 @@ int l_lovrCanvasRenderTo(lua_State* L) {
|
|||
const luaL_Reg lovrCanvas[] = {
|
||||
{ "getTexture", l_lovrCanvasGetTexture },
|
||||
{ "setTexture", l_lovrCanvasSetTexture },
|
||||
{ "newTextureData", l_lovrCanvasNewTextureData },
|
||||
{ "renderTo", l_lovrCanvasRenderTo },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -36,3 +36,4 @@ void lovrCanvasBlit(Canvas* canvas);
|
|||
bool lovrCanvasIsStereo(Canvas* canvas);
|
||||
uint32_t lovrCanvasGetWidth(Canvas* canvas);
|
||||
uint32_t lovrCanvasGetHeight(Canvas* canvas);
|
||||
TextureData* lovrCanvasNewTextureData(Canvas* canvas, int index);
|
||||
|
|
|
@ -1452,6 +1452,28 @@ uint32_t lovrCanvasGetHeight(Canvas* canvas) {
|
|||
return canvas->height;
|
||||
}
|
||||
|
||||
TextureData* lovrCanvasNewTextureData(Canvas* canvas, int index) {
|
||||
lovrCanvasBind(canvas);
|
||||
|
||||
Texture* texture = canvas->attachments[index].texture;
|
||||
if ((texture->incoherent >> BARRIER_TEXTURE) & 1) {
|
||||
lovrGpuWait(1 << BARRIER_TEXTURE);
|
||||
}
|
||||
|
||||
if (index != 0) {
|
||||
glReadBuffer(index);
|
||||
}
|
||||
|
||||
TextureData* textureData = lovrTextureDataCreate(canvas->width, canvas->height, 0x0, FORMAT_RGBA);
|
||||
glReadPixels(0, 0, canvas->width, canvas->height, GL_RGBA, GL_UNSIGNED_BYTE, textureData->blob.data);
|
||||
|
||||
if (index != 0) {
|
||||
glReadBuffer(0);
|
||||
}
|
||||
|
||||
return textureData;
|
||||
}
|
||||
|
||||
// Shader
|
||||
|
||||
static GLuint compileShader(GLenum type, const char** sources, int count) {
|
||||
|
|
Loading…
Reference in New Issue