c# - gDebugger doesn't show allocated textures with OpenTK -


i'm using opentk warpper c#, shaders weren't running correctly (i want generate vertex displacement shader using textures), pretend use gpu debugger see happening.

the application quite simple. creates game window, load shaders, textures , render textured cubes (so it's working fine, discovered problem trying use vertex displacement).

i used gdebugger , amd codexl same results. debugger detects shaders, vbos, etc never see allocated textures. have non-sense because when i'm running application see textured cube spinning around screen , debugger render object on back/front buffer.

for reference, here texture-loading function:

 int loadimage(bitmap image,int tex)         {                                                        int texid = gl.gentexture();             gl.bindtexture(texturetarget.texture2d, texid);             system.drawing.imaging.bitmapdata data = image.lockbits(new system.drawing.rectangle(0, 0, image.width, image.height),                 system.drawing.imaging.imagelockmode.readonly, system.drawing.imaging.pixelformat.format32bppargb);               gl.teximage2d(texturetarget.texture2d, 0, pixelinternalformat.rgba, data.width, data.height, 0,                 opentk.graphics.opengl.pixelformat.bgra, pixeltype.unsignedbyte, data.scan0);              image.unlockbits(data);                          return texid;         } 

i searching more information, couldn't find error, i'm not sure if problem in wrapper, in function or must have else considered

edit:

it seems problem in wrapper, opentk.bindtexture different native glbindtexture, profiler can't catch call , that's why textures not shown. next step way native gl calls using opentk.

proposed solution:

as said, functions of opentk wrapper different native glcalls, when use functions gl.bindtexture, gl.gentexture (i suppose there more functions, don't know yet), opentk uses overloaded calls not match original calls , profilers can't catch it.

it's easy check, use opentk.gentextures or gl.bindtextures adding breakpoints profiler functions , never break.

now, solution, thinking , conclussion replace opentk calls native gl.dll calls using getprocaddress function.

this gives me ideas: http://blogs.msdn.com/b/jonathanswift/archive/2006/10/03/dynamically-calling-an-unmanaged-dll-from-.net-_2800_c_23002900_.aspx

using opengl32.dll included in profiler, use same struct in previous link

static class nativemethods     {         [dllimport("kernel32.dll")]         public static extern intptr loadlibrary(string dlltoload);          [dllimport("kernel32.dll")]         public static extern intptr getprocaddress(intptr hmodule, string procedurename);           [dllimport("kernel32.dll")]         public static extern bool freelibrary(intptr hmodule);     } 

this added in gamewindow class:

 [unmanagedfunctionpointer(callingconvention.cdecl)]  private delegate void bindtexture(opentk.graphics.opengl.texturetarget target, int texid);   [unmanagedfunctionpointer(callingconvention.cdecl)]          private delegate void gentexture(int n, int[] arr_text);  

and here new bindtexture function:

 intptr pdll = nativemethods.loadlibrary(@"....\opengl32.dll");   intptr paddressoffunctiontocall = nativemethods.getprocaddress(pdll, "glbindtexture");                  bindtexture bindtexture = (bindtexture)marshal.getdelegateforfunctionpointer(paddressoffunctiontocall, typeof(bindtexture));   bindtexture(opentk.graphics.opengl.texturetarget.texture2d, arr_texture[0]); 

now if try again breakpoints in profiler, break glgentextures , glbindtextures, recognising allocated textures.

i hope helps.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -