MCPcopy Create free account
hub / github.com/defold/defold / RenderScript_EnableTexture

Function RenderScript_EnableTexture

engine/render/src/render/render_script.cpp:1362–1450  ·  view source on GitHub ↗

sets a texture to the render state * * Sets the specified texture handle for a render target attachment or a regular texture * that should be used for rendering. The texture can be bound to either a texture unit * or to a sampler name by a hash or a string. * A texture can be bound to multiple units and sampler names at the same time, * the actual binding will be appl

Source from the content-addressed store, hash-verified

1360 * ```
1361 */
1362 int RenderScript_EnableTexture(lua_State* L)
1363 {
1364 DM_LUA_STACK_CHECK(L, 0);
1365
1366 RenderScriptInstance* i = RenderScriptInstance_Check(L);
1367 dmhash_t sampler_hash = 0;
1368 uint32_t unit = 0;
1369
1370 if (lua_isnumber(L, 1))
1371 {
1372 unit = lua_tointeger(L, 1);
1373 }
1374 else
1375 {
1376 sampler_hash = dmScript::CheckHashOrString(L, 1);
1377 }
1378
1379 dmGraphics::HAssetHandle asset_handle;
1380 dmGraphics::AssetType asset_type;
1381
1382 if (lua_isnumber(L, 2))
1383 {
1384 asset_handle = (dmGraphics::HAssetHandle) lua_tonumber(L, 2);
1385 asset_type = dmGraphics::GetAssetType(asset_handle);
1386 }
1387 else if (dmScript::IsHash(L, 2) || lua_isstring(L, 2))
1388 {
1389 dmhash_t rt_id = dmScript::CheckHashOrString(L, 2);
1390 RenderResource* render_resource = i->m_RenderResources.Get(rt_id);
1391
1392 if (render_resource->m_Type != RENDER_RESOURCE_TYPE_RENDER_TARGET)
1393 {
1394 return DM_LUA_ERROR("Render resource is not a render target");
1395 }
1396
1397 asset_handle = (dmGraphics::HRenderTarget) render_resource->m_Resource;
1398 asset_type = dmGraphics::ASSET_TYPE_RENDER_TARGET;
1399 }
1400 else
1401 {
1402 return DM_LUA_ERROR("%s.enable_texture(unit, handle, buffer_type) for unit %d called with illegal parameters.", RENDER_SCRIPT_LIB_NAME, unit);
1403 }
1404
1405 if (!dmGraphics::IsAssetHandleValid(i->m_RenderContext->m_GraphicsContext, asset_handle))
1406 {
1407 char buf[128];
1408 return DM_LUA_ERROR("Texture handle '%s' is not valid.", AssetHandleToString(asset_handle, buf, sizeof(buf)));
1409 }
1410
1411 dmGraphics::HTexture texture = 0;
1412
1413 if (asset_type == dmGraphics::ASSET_TYPE_RENDER_TARGET)
1414 {
1415 dmGraphics::BufferType buffer_type = dmGraphics::BUFFER_TYPE_COLOR0_BIT;
1416 if (lua_isnumber(L, 3))
1417 {
1418 buffer_type = CheckBufferType(L, 3);
1419 }

Callers

nothing calls this directly

Calls 15

lua_isnumberFunction · 0.85
lua_tointegerFunction · 0.85
CheckHashOrStringFunction · 0.85
lua_tonumberFunction · 0.85
GetAssetTypeFunction · 0.85
IsHashFunction · 0.85
lua_isstringFunction · 0.85
IsAssetHandleValidFunction · 0.85
AssetHandleToStringFunction · 0.85
CheckBufferTypeFunction · 0.85
GetRenderTargetTextureFunction · 0.85

Tested by

no test coverage detected