Skip to main content
gamedev.net
🔒 Locked

OpenGL texture state rendering (HELP!)

Started by George of the jungle Jul 19, 2003 at 11:37 AM 5 replies 350+ views
Original Post
George of the jungle
George of the jungle
Hello, I have a question, I have a vector of 3D objects to render. They have references to a texture vector that contains information like: Some of the polygons are video color, rgb texture, blended textures and alpha mask textures. Do I render in a different OpenGL state each polygon? wouldn't it be slow? I have no clue how to organize this. Help! Win32Main ----> RenDerGL(with a reference to DataController.) | | DataController(add, del, get, set) | |____CTexture vector(uint id, filename, int type) | |____CObjModels vector(3d int vertexarray..) OpenGl #1 [edited by - George of the jungle on July 19, 2003 5:21:16 PM]
OpenGl #1
George of the jungle
George of the jungle
What about A Octree level with nodes that contains references to
faces with texture for:
-Normal
-Blended
-Alpha mask
-Mirror

After sorting, are you suppose to switch and render different states for the textures at each node or Render each node with a certain state at the time?

By the way ,I saw Wizard Duel 2, cool!


[edited by - George of the jungle on July 20, 2003 11:48:57 PM]
OpenGl #1
benjamin bunny
benjamin bunny
An octree would make it less clear-cut, particularly if you've got a lot of different textures. You would have to experiment in order to work out the best drawing order. You might want to, for example, traverse the octree multiple times, rendering one texture at a time. This would minimise binds, but you'd obviously have the added overhead from traversing the octree.

quote:
After sorting, are you suppose to switch and render different states for the textures at each node or Render each node with a certain state at the time?

The idea is that you render the nodes in order of their state attributes, from most expensive to least expensive.

With 4 attributes, you could store the state like this:
class State
{
BYTE texName;
BYTE alpha; //0 or 1

BYTE mirror;
BYTE blended;

unsigned int getScore()
{
return blended | //least expensive

alpha << 8 |
mirror << 16 |
texName << 24; //most expensive

}

public:
bool operator<(State &b) {return (getScore()<b.getScore()); }
bool operator>(State &b) {return (getScore()>b.getScore()); }
bool operator>=//... etc

}

You could then sort using the comparison operators. You could experiment and change the ordering just by modifying the getscore routine. A more efficient method would be only calculate the score once per state change, but you get the idea.

[edited by - benjamin bunny on July 21, 2003 10:12:49 AM]
George of the jungle
George of the jungle
Thank you for the reply.

Just a few questions to make sure I understood your code:

The class "State" is this a object attached to each node of the Octree?

In getScore, what is the numbers that are returned?

The state class is it use to sort only, and then we just render by texture state? Or we use it to know while rendering with the state object if we should even bother a rendering state?









[edited by - George of the jungle on July 21, 2003 12:47:58 PM]

[edited by - George of the jungle on July 21, 2003 12:50:30 PM]
OpenGl #1
benjamin bunny
benjamin bunny
quote:
The class "State" is this a object attached to each node of the Octree?
That's up to you, but yes, that would probably be the simplest way of doing it.

quote:
In getScore, what is the numbers that are returned?

The number returned is just a metric to compare states with for the purpose of sorting. The number is simply the 4 attribute bytes concatenated so that the most expensive attribute (I'm assuming it's texture name) is the most significant byte. To do this, I use the bitwise OR (|) and bitwise left shift (<<) operators.

quote:
The state class is it use to sort only, and then we just render by texture state? Or we use it to know while rendering with the state object if we should even bother a rendering state?

Each object would have its own state object. You would use it store the state information, and you could even use it to change the state if necessary, but the main purpose is that you can sort your objects using it before you render them. Once you've done this then you should only need to change state when the state changes so that the number of state changes is minimised.

For example, if you have a set of objects with the following states (sorted by state), here's are the state changes you'd need.

tex alpha blend mirror GL State changes
1 0 0 0 bind tex 1
1 0 0 1 enable mirror?
2 1 0 1 bind tex 2, enable alpha
2 0 1 0 disable alpha, enable blending, disable mirror


BTW, I've never actually bothered implementing this in my code, so I'm just trying to give you the general idea. You should experiment with it to find out what works best when you implement it.

[edited by - benjamin bunny on July 21, 2003 2:20:35 PM]

[edited by - benjamin bunny on July 21, 2003 3:52:03 PM]
George of the jungle
George of the jungle
Thank you very much for your help. I think I understand now.
Before I try this methods of sorting texture type per Octree Nodes, I just wanted to know if anybody else has a suggestion?
OpenGl #1

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.