ewooycom
ewooycom

Reputation: 2721

OpenGL - Buffer, shader

Every time I search on Google about OpenGL programming I found articles but it seems that all are mentioning shaders and buffers. What are those? Can you explain some of them:

I heard for few of them but couldn't find whole list. What are shaders in OpenGL, and what are buffers? Can somebody provide examples when we are using them?

Upvotes: 2

Views: 420

Answers (2)

Damon
Damon

Reputation: 70206

A color buffer is some piece of internal memory with a specified memory layout, but otherwise more or less opaque to you that represents an image. It holds information about the color of each pixel in the image. You draw/render into color buffers. There can be more than a single color buffer with recent versions of OpenGL on recent hardware, which you can use to make some special rendering techniques more efficient.

Depth and stencil buffers are the same as color buffers, except they hold (as the name implies) depth and stencil information rather than color. Depth and stencil are often combined into one buffer (but need not be), and you can never have more than one depth/stencil buffer at a time.
The depth buffer is normally used to resolve overdrawing ambiguity when rendering several objects in no particular order. Only the one fragment closest to "your eye" survives. The stencil buffer can be used for special effects, e.g. to mask out regions of a buffer.

A framebuffer is something you attach color buffers to and draw/render into and which is optionally visible on the screen. There is always at least one framebuffer, this is what you see on your screen, but there may be any number of them. This is managed by the framebuffer extension which is core functionality since version 3.0. A framebuffer usually has separate "front" and "back" buffers too. One will be shown to you while you render to the other. At appropriate times, the buffers are flipped, so you do not see flickering.

A shader, most generally, is a "program" that OpenGL executes on your behalf inside its pipeline at well-defined times on well-defined data to generate some desired effect. It most often runs on the graphics card, but it may also be executed partially or wholly on the CPU.
Pixel shaders, the first shaders historically available (and namegivers) are run once for every fragment. They take some defined inputs (e.g. light position, normals) and produce a single output that later goes through the depth test, and is finally is written to or blended with the color buffer.
Vertex, geometry, or tesselation shaders do not really "shade" anything (they transform and/or generate vertices and primitives, which are later turned into fragments), but they inherit the name.

Upvotes: 4

Mattias Isegran Bergander
Mattias Isegran Bergander

Reputation: 11909

Type in opengl shaders in google and you get the answer for shaders actually.

The first search result: http://en.wikipedia.org/wiki/GLSL

And for more direct listing of each shader, follow the link there too: http://en.wikipedia.org/wiki/Shader#Types_of_shaders

For OpenGL you use GLSL for programming shaders and HLSL for Direct3D.

That should serve as a general introduction.

Some quick notes on the other (may be simplifications):

Depth buffer, also known as z-buffer, is used to solve the problem of what is behind what when rendering.

Frame buffer is simply the memory where the current frame (screen/pixels) is stored.

Stencil buffer is a bit more complicated and be used in a few different ways.

For introduction purposes, googles first hits on each (wikipedia) serves you quite well regarding these:

http://en.wikipedia.org/wiki/Framebuffer

http://en.wikipedia.org/wiki/Stencil_buffer

http://en.wikipedia.org/wiki/Z-buffering

etc

Upvotes: 1

Related Questions