Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Non-square and non-power-of-two textures?  (Read 634 times)
0 Members and 1 Guest are viewing this topic.
Offline Varkas
« Posted 2013-12-06 16:33:11 »

Now and then I read about problems with non-square and non-power-of-two textures with OpenGL. I know that old OpenGL implementations had such restrictions, but I want to ask, is this still the case?

I've tested fairly arbitrary texture sizes on three PCs (two desktop, one laptop, all Windows 7, was too lazy to remember the graphics hardware specs of each), and noticed no problems. Do I need to go through the extra hoops in adjusting my textures, or can I continue with my arbitrarily sized textures?

if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline Dxu1994
« Reply #1 - Posted 2013-12-06 16:54:26 »

NPOT textures have been standard in OpenGL ever since OpenGL 2, which was a long time ago (2004). The only question is how good performance is with NPOT textures by a given driver.

Although ever since shaders became commonplace any optimization based on the predictable patterns of fixed function texture memory access became sort of useless, so NPOT textures will work on the majority of hardware these days.


Offline theagentd
« Reply #2 - Posted 2013-12-06 22:36:51 »

Nope, it's not something to worry about. You may want to stick to resolutions that are multiples of 4 though or you'll have to mess with pixel unpack settings.

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

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #3 - Posted 2013-12-06 22:41:20 »

Think of it like this:

1  
int x = y << 2;
versus
1  
int x = y * 4;


There may be a slight difference, but not anything that will contribute to any noticable difference.

(EDIT: The reason I used that comparison is because the top one only works with powers of two)

Offline Varkas
« Reply #4 - Posted 2013-12-06 23:08:44 »

Thanks for the replies Smiley

Good to know that I can be lazy with the textures ...

if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline Mac70
« Reply #5 - Posted 2013-12-06 23:13:13 »

Having power of two textures help when you want to make sprite batch - some numbers cannot be presented in float/double format with 100% precision - this may lead to artifacts, using power of two textures there will never be any artifacts related to texture coordinates.

Check out my Devblog! Smiley
Offline theagentd
« Reply #6 - Posted 2013-12-07 00:58:44 »

Having power of two textures help when you want to make sprite batch - some numbers cannot be presented in float/double format with 100% precision - this may lead to artifacts, using power of two textures there will never be any artifacts related to texture coordinates.
I've suspected that this may be the culprit of a few unsolved texture bleeding problems out there, but I'm not sure if it's actually real. Let's say we have a texture containing three 20x20 sprites, making the texture 60x20 pixels large. If we want to draw the first sprite, the x texture coordinate would essentially go from 0 to 1.0/3.0. The second value would be rounded to 0.3333333432674408, which would potentially mean that the middle sprite could be sampled. How this rounding error would manifest itself would depend on how exactly the GPU interpolates texture coordinates for pixels, which probably varies between GPUs, vendors, drivers, etc.

This isn't a problem when both the sprite and the texture is a power of two thanks 1. to all edge values being exactly representable with floats and 2. the top-left fill convention OpenGL and DirectX uses.

Myomyomyo.
Offline Varkas
« Reply #7 - Posted 2013-12-11 16:21:25 »

I didn't think of the fractions and binary math. Good to know that the "power of 2" has more impact than just the optimization of some calculations for speed.

if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (22 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (54 views)
2014-07-16 00:42:17

Riven (54 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!