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
| 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 | } |
nothing calls this directly
no test coverage detected