Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (843)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Buffer offsets from Sys.getDirectBufferAddress();  (Read 3124 times)
0 Members and 1 Guest are viewing this topic.
Offline Spasi
« Posted 2002-12-11 11:57:27 »

Say I want to use the following method:

unProject(double winx, double winy, double winz, int modelMatrix, int projMatrix, int viewport, int objx, int objy, int objz);

The last 3 parameters and pointers to doubles. One way to use this method is to create 3 different one double long buffers, get their addresses and give them to unProject. Is there a way to use just one? For example, do something like this:

DoubleBuffer xyz = ByteBuffer.allocateDirect(3 * 8).order(ByteOrder.nativeOrder()).asDoubleBuffer();
int xyzP = Sys.getDirectBufferAddress(xyz);

and then:

unProject(winx, winy, winz, modelMatrix, projMatrix, viewport, xyzP, xyzP + 2, xyzP + 4);

where xyzP, the address of the first double
where xyzP + 2, the address of the second double
where xyzP + 4, the address of the third double

I have tested this and of course it didn't work. Actually, it run, but it didn't work correctly. Could something like this work, use one buffer's starting address to get offsets on the same buffer? Am I correct to assume that the second double is 2 addresses (2 * 32 bits = 64 bits) away from the first one? I'm asking this because I'm afraid of the overhead of many Buffers (should I?) and besides my code gets really ugly. It would be a lot easier and cleaner to use xyz.get(double_array[3]) than have three different buffers and use buffer.get() three times. It would be faster too. Any suggestions?
Offline Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

Monkey for a head

« Reply #1 - Posted 2002-12-11 12:23:55 »

Am I correct to assume that the second double is 2 addresses (2 * 32 bits = 64 bits)

Odds are I think that the addresses are going to be either byte or 16-bit word addressable, so your offsets of +2 and +4 should be doubled at least. I was using something similar for gluProject a little while ago, but i can't remember whether I got it working or not (or even if its cross-platform friendly..).

[ - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline princec

« JGO Spiffy Duke »

Medals: 1033
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #2 - Posted 2002-12-11 12:38:19 »

Yes, and it's a necessary evil to be sure. Offsets are in bytes so a double would need +8, +16 etc.

Cas Smiley

Pages: [1]
  ignore  |  Print  

EgonOlsen (42 views)
2018-06-10 19:43:48

EgonOlsen (22 views)
2018-06-10 19:43:44

EgonOlsen (43 views)
2018-06-10 19:43:20

DesertCoockie (197 views)
2018-05-13 18:23:11

nelsongames (124 views)
2018-04-24 18:15:36

nelsongames (123 views)
2018-04-24 18:14:32

ivj94 (863 views)
2018-03-24 14:47:39

ivj94 (124 views)
2018-03-24 14:46:31

ivj94 (768 views)
2018-03-24 14:43:53

Solater (140 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!