OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Texture Buffer Object Initialization Problem


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
EonStrife
Newbie


Joined: 27 Oct 2016
Posts: 12

PostPosted: Tue Feb 27, 2018 7:53 am    Post subject:
Texture Buffer Object Initialization Problem
Reply with quote

Hi,

I am trying to attach additional per-vertex information to each vertex. For each vertex, there are 3 sets of RGBA values I want to attach (each called controlSetA, controlSetB, controlSetC) to. The controlSet values are from an additional file in JSON format, and it is not embedded in the original 3D model. So, my plan here is that I will load those controlSet values and keep each controlSet in a Texture Buffer Object, and I will sample them in GLSL vertex shader.

However I encounter an problem :

Just say my 3D model is a sphere consists of 382 vertices. So the JSON file has 1528 values ( 382 x 4 channels = 1528) for each Control Set. In total : 1528 x 3 sets = 4584 values). So, in "tboImage->allocateImage", I request a texture with dimension 382 x 1 x 1 with RGBA float texels. During the runtime in this initialization function, I see from Visual Studio watch that it has correct 382 x 1 x 1 dimension. However, when I check it using codeXL, the texture's dimension is only 47 x 1 x 1 (if I am not wrong). Moreover, if I try to visualize the value in rendering, I can see that the sphere is painted with the value until about one quarter of the surface (from bottom) only.

I am using OpenSceneGraph version 3.5.6, 64-bit, Visual Studio 2013

The following is the relevant code

Code:


std::vector<std::string> controlSetNames = { "controlSetA", "controlSetB", "controlSetC" };
std::vector<int> controlSetIDs = { 3, 4, 6 };

...

itrcontrolSet = 0
//for each control set
{
   int vertexCount = 0;
   std::vector<float> values;

   //just pseudocode here
   //for each vertex
   //{
   //   vertexCount++;
   //   for each channel
   //   {
   //      values.push_back(channel->GetFloat());
   //   }
   //}

   //create the texture image
   osg::ref_ptr<osg::Image> tboImage = new osg::Image;
   tboImage->allocateImage(vertexCount, 1, 1, GL_RGBA, GL_FLOAT);
   float *dataF = (float*)tboImage->data();

   //copy the json data to it
   //memcpy(dataF, texels, sizeof(GL_FLOAT) * values.size());
   for (int i = 0; i < values.size(); i++)
      *(dataF++) = values[i];

   //create texture buffer object
   osg::ref_ptr<osg::TextureBuffer> tbo = new osg::TextureBuffer;
   tbo->setImage(tboImage.get());
   tbo->setInternalFormat(GL_RGBA32F_ARB);
   tbo->setTextureWidth(vertexCount);
   tbo->dirtyTextureParameters();

   //attach to the TBO
   osg::ref_ptr<osg::StateSet> stateset = foundNode->getOrCreateStateSet();
   osg::Uniform* texControlSet = new osg::Uniform(controlSetNames[itrcontrolSet].c_str(), controlSetIDs[itrcontrolSet]);
   stateset->addUniform(texControlSet);
   stateset->setTextureAttributeAndModes(controlSetIDs[itrcontrolSet], tbo.get());

   itrcontrolSet++;
}


And here's the shader code
Code:

#version 330 compatibility
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_explicit_uniform_location : enable

layout( location = 3) uniform samplerBuffer controlSetA;
layout( location = 4) uniform samplerBuffer controlSetB;
layout( location = 6) uniform samplerBuffer controlSetC;

...

layout( location = 0 ) out vec4 out_vColor0;
layout( location = 1 ) out vec4 out_vColor1;
layout( location = 2 ) out vec4 out_vColor2;
layout( location = 3 ) out vec4 out_vColor3;

..

void main()
{

...
   vec4 in_vColor0      = gl_Color;

   out_vColor0 = saturate(in_vColor0);
   out_vColor1 = texelFetch(controlSetA, gl_VertexID);
   out_vColor2 = texelFetch(controlSetB, gl_VertexID);
   out_vColor3 = texelFetch(controlSetC, gl_VertexID);

...

}



Thank you!

Cheers,
Eon
[/code]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts problem with picking/intersecting in ... mue General 0 Sat Jun 09, 2018 11:18 am View latest post
No new posts Positioning a Camera relative to anot... Takarashy General 0 Thu May 24, 2018 8:27 am View latest post
No new posts Positioning an object based on the Vi... Takarashy General 0 Wed May 23, 2018 3:14 pm View latest post
No new posts osgText: problem with SCREEN_COORDS mode gwaldron General 9 Thu May 17, 2018 3:56 pm View latest post
No new posts DXT texture compression urbanchaos General [forum] 14 Tue May 08, 2018 12:13 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP