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

Joined: 27 Oct 2016
Posts: 12

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


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


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;

   //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->setTextureAttributeAndModes(controlSetIDs[itrcontrolSet], tbo.get());


And here's the shader 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!

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 DirectX Texture Stage Sets to OSG sbrkopac General 2 Tue Dec 04, 2018 8:47 pm View latest post
No new posts reflection on mesh texture nonnenmacher General 2 Tue Nov 06, 2018 7:58 pm View latest post
No new posts Mapping texture coordinates to a port... ijwolf8 General 0 Thu Oct 25, 2018 8:11 pm View latest post
No new posts [Help] OSG + ArKit: Problem convertin... Brayner General 4 Mon Oct 08, 2018 7:07 pm View latest post
No new posts Rend to Texture Once GuiYe General 1 Sun Aug 26, 2018 7:31 am 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