<div dir="ltr">David,<div>This may or may not be helpful, but a while back I made a bindless version of osg::Texture2D here you can look at. It's mostly a experiment but you might be able to glean something front it:</div><div><br></div><div><a href="https://github.com/gwaldron/osgearth/blob/bindless/src/osgEarth/Texture">https://github.com/gwaldron/osgearth/blob/bindless/src/osgEarth/Texture</a><br></div><div><a href="https://github.com/gwaldron/osgearth/blob/bindless/src/osgEarth/Texture.cpp">https://github.com/gwaldron/osgearth/blob/bindless/src/osgEarth/Texture.cpp</a><br></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Glenn Waldron</div></div></div></div>
<br><div class="gmail_quote">On Fri, Jul 15, 2016 at 10:21 AM, David Heitbrink <span dir="ltr"><<a href="mailto:david-heitbrink@uiowa.edu" target="_blank">david-heitbrink@uiowa.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Has any one implemented bindless textures? I am trying to add this to my app to improve batching. I have a large scene, with lots of unique draw calls. We do use texture atlas's, the number of small objects is limited. I would like to further improve batching without having to redo textures. I do have LODs and occluder nodes as well.<br>
<br>
Conveniently most of my objects use triangle list, so merging those worked out pretty well. I am using a shader storage buffer object to upload the texture handles to the shader. I have confirmed the value for the handles that I have set are getting into the shader.<br>
<br>
Here is the segment of my shader where I get the texture:<br>
<br>
Code:<br>
<br>
<br>
layout (binding = 0, std140) coherent buffer TEXTURE_BLOCK<br>
{<br>
uint64_t tex[512];<br>
};<br>
uniform int textureIndex;<br>
void doTexture(inout vec4 color) {<br>
sampler2D s = sampler2D(tex[textureIndex]);<br>
vec4 texel = texture2D(s,TexCoord[0]);<br>
color.rgb = texel.rgb*color.rgb;<br>
}<br>
<br>
<br>
<br>
<br>
I have a draw call back that grabs the extensions:<br>
glGetTextureHandleARB<br>
glMakeTextureHandleResidentARB<br>
<br>
Also it grabs the texture handles, I have visitor go and grab references to all the relevant textures (when the scene is loaded and the objects are merged), and I do:<br>
<br>
Code:<br>
<br>
osg::UIntArray* array = static_cast<osg::UIntArray*>(m_ssbo->getBufferData(0));<br>
vector<GLuint> &rawData = array->asVector();<br>
GLuint64* raw64ptr = (GLuint64*)(rawData.data());<br>
<br>
<br>
if (!bindings)<br>
return false;<br>
for (auto itr = m_textureIdMap.begin(); itr != m_textureIdMap.end(); ++itr){<br>
osg::Texture* text= m_textureMap[itr->first];<br>
int id = itr->second;<br>
auto textObject = text->getTextureObject(rinfo.getContextID());<br>
if (!textObject){<br>
text->apply(*rinfo.getState());<br>
textObject = text->getTextureObject(rinfo.getContextID());<br>
if (!textObject) return false;<br>
}<br>
uint64 textId = glGetTextureHandleARB(textObject->_id);<br>
if (glIsTextureHandleResidentARB(textId)==GL_FALSE)<br>
glMakeTextureHandleResidentARB(textObject->_id);<br>
raw64ptr[id] = textId;<br>
}<br>
<br>
<br>
<br>
Right now I am getting black for my texture, I cycle through textureIndex from my first texture to my last, I plan on replacing this with an attribute later, but there is not much point right now if I cannot get any textures to show up. If I do get this to work I do plan on building an example app and submitting it.<br>
<br>
#version 430 compatibility<br>
#extension GL_NV_bindless_texture : require<br>
#extension GL_NV_shader_buffer_load : require<br>
#extension GL_NV_gpu_shader5 : require // uint64_t<br>
<br>
I am not sure doing a apply() to the texture and grabbing the id is the best idea.<br>
<br>
I am using OSG 3.4.0, I did make some modifications to support unsigned 64 bit uniforms, and to built OSG built-ins to after the last #extension. I have not checked to see if some has added this to the most recent development branch, if not I would gladly<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=68142#68142" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=68142#68142</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div><br></div>