graphics

experiments with opengl3.2/ogles3.3 on linux and win7
git clone http://frotz.net/git/graphics.git
Log | Files | Refs

shared.h (1895B)


      1 /* Copyright 2013 Brian Swetland <swetland@frotz.net>
      2  *
      3  * Licensed under the Apache License, Version 2.0 (the "License");
      4  * you may not use this file except in compliance with the License.
      5  * You may obtain a copy of the License at
      6  *
      7  *     http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software
     10  * distributed under the License is distributed on an "AS IS" BASIS,
     11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12  * See the License for the specific language governing permissions and
     13  * limitations under the License.
     14  */
     15 
     16 #ifndef _SHARED_H_
     17 #define _SHARED_H_
     18 
     19 /* Constants that are shared with shader programs. */
     20 /* Ensure that the textual version below stays in sync. */
     21 
     22 #define A_POSITION	0
     23 #define A_NORMAL	1
     24 #define A_TEXCOORD	2
     25 
     26 #define U_SCENE		0
     27 #define U_OBJECT	1
     28 #define U_MATERIAL	2
     29 
     30 struct ubScene {
     31 	mat4 Ortho;		/* 1:1 2D mapping */
     32 	vec4 OrthoSize;		/* x,y = width,height */
     33 	ivec4 TextGrid;		/* cellwidth, cellheight, width, height */
     34 	vec4 LightColor;
     35 	vec4 LightPosition;
     36 };
     37 
     38 struct ubObject {
     39 	mat4 mvp;
     40 	mat4 mv;
     41 };
     42 
     43 struct ubMaterial {
     44 	vec4 Ambient;		/* ambient factor (of Color) */
     45 	vec4 Diffuse;		/* diffuse factor (of Color) */
     46 	vec4 Specular;		/* specular factor (of LightColor) */
     47 	vec4 Color;		/* used if non-textured */
     48 	float Shininess;
     49 };
     50 
     51 #if INCLUDE_SHADER_GLOBALS
     52 static const char *shader_globals = 
     53 "#define A_POSITION 0\n"
     54 "#define A_NORMAL 1\n"
     55 "#define A_TEXCOORD 2\n"
     56 "layout(std140) uniform block0 {\n"
     57 "	mat4 uOrtho;\n"
     58 "	vec4 uOrthoSize;\n"
     59 "	ivec4 uTextGrid;\n"
     60 "	vec4 uLightColor;\n"
     61 "	vec4 uLightPosition;\n"
     62 "};\n"
     63 "layout(std140) uniform block1 {\n"
     64 "	mat4 uMVP;\n"
     65 "	mat4 uMV;\n"
     66 "};\n"
     67 "layout(std140) uniform block2 {\n"
     68 "	vec4 uAmbient;\n"
     69 "	vec4 uDiffuse;\n"
     70 "	vec4 uSpecular;\n"
     71 "	vec4 uColor;\n"
     72 "	float uShininess;\n"
     73 "};\n"
     74 ;
     75 #endif
     76 
     77 #endif