Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (800)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (867)
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  
  [Solved] Wasted space a big deal in GLSL Shaders?  (Read 3219 times)
0 Members and 1 Guest are viewing this topic.
Offline thedanisaur

JGO Knight


Medals: 59



« Posted 2015-04-23 06:44:28 »

I'm writing a 3D object batcher, 256 objects per batch, so I'll have 256 modelview, projection, normal matrices, etc. The arrays won't always be full, should I be concerned about the wasted space?


Edit: not really solved, just can't pass enough uniforms for it to matter.


Every village needs an idiot Cool
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2015-04-23 18:00:06 »

I'm writing a 3D object batcher, 256 objects per batch, so I'll have 256 modelview, projection, normal matrices, etc. The arrays won't always be full, should I be concerned about the wasted space?


Edit: not really solved, just can't pass enough uniforms for it to matter.


Texture Buffer Objects to the rescue Pointing

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline theagentd
« Reply #2 - Posted 2015-04-24 09:32:30 »

Texture buffer objects work really well for this.

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #3 - Posted 2015-04-24 18:44:36 »

Yeah after Riven posted I looked into it and it's exactly what I want. Thanks guys!

Edit: I just realized I posted this on the wrong board, sorry about that

Every village needs an idiot Cool
Offline KaiHH

JGO Kernel


Medals: 783



« Reply #4 - Posted 2015-04-24 20:52:35 »

Just one note:
You might want to also have a look at Uniform Buffer Object.
Those could be more up to the task when it comes to feeding structured data to your shader, since they allow for aggregate data types, such as vec4 and mat4 directly in them and you therefore do not need a custom texture lookup function to build matrices from texel samples.
You also do not need a backing texture and sampler, just a Buffer Object.

UBOs however need a defined static (max.) size in the shader.
So if you know you are going to have at max 256 objects, you can use the following:

1  
2  
3  
4  
5  
6  
7  
8  
9  
#define MAX_OBJECTS 256
struct Object {
  mat4 modelviewMatrix;
  mat4 projectionMatrix;
  mat4 normalMatrix;
}
layout (std140) uniform Objects {
  Object objects[MAX_OBJECTS];
}


The layout with std140 in memory (in the Buffer Object) on your Java side in this particular case is column-major, tight packing without any padding.
And to retrieve the modelview matrix (for example), you can just use:
1  
objects[theIndex].modelviewMatrix


MAX_OBJECTS is also just an upper bound on the maximum number of objects that can be contained in the UBO. You can always glBufferData just a subset of the data to the Buffer Object and access that subset in the shader.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (351 views)
2019-09-04 15:33:17

hadezbladez (5154 views)
2018-11-16 13:46:03

hadezbladez (2038 views)
2018-11-16 13:41:33

hadezbladez (5405 views)
2018-11-16 13:35:35

hadezbladez (1124 views)
2018-11-16 13:32:03

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

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

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

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

nelsongames (4555 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org 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‑gaming.org
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!