Merge of in-progress Eval API test code to the mainline. Not much

here yet.
This commit is contained in:
Dirk Van Gelder 2013-02-04 09:35:43 -08:00
parent 687cedfb68
commit eed2d98a39
9 changed files with 2134 additions and 0 deletions

View File

@ -58,6 +58,7 @@
if( OPENGL_FOUND AND (GLEW_FOUND AND GLFW_FOUND) OR (APPLE AND GLFW_FOUND))
add_subdirectory(glViewer)
# add_subdirectory(simpleCpu)
# add_subdirectory(evalTest)
if(PTEX_FOUND)
add_subdirectory(ptexViewer)
endif()

View File

@ -0,0 +1,119 @@
#
# Copyright (C) Pixar. All rights reserved.
#
# This license governs use of the accompanying software. If you
# use the software, you accept this license. If you do not accept
# the license, do not use the software.
#
# 1. Definitions
# The terms "reproduce," "reproduction," "derivative works," and
# "distribution" have the same meaning here as under U.S.
# copyright law. A "contribution" is the original software, or
# any additions or changes to the software.
# A "contributor" is any person or entity that distributes its
# contribution under this license.
# "Licensed patents" are a contributor's patent claims that read
# directly on its contribution.
#
# 2. Grant of Rights
# (A) Copyright Grant- Subject to the terms of this license,
# including the license conditions and limitations in section 3,
# each contributor grants you a non-exclusive, worldwide,
# royalty-free copyright license to reproduce its contribution,
# prepare derivative works of its contribution, and distribute
# its contribution or any derivative works that you create.
# (B) Patent Grant- Subject to the terms of this license,
# including the license conditions and limitations in section 3,
# each contributor grants you a non-exclusive, worldwide,
# royalty-free license under its licensed patents to make, have
# made, use, sell, offer for sale, import, and/or otherwise
# dispose of its contribution in the software or derivative works
# of the contribution in the software.
#
# 3. Conditions and Limitations
# (A) No Trademark License- This license does not grant you
# rights to use any contributor's name, logo, or trademarks.
# (B) If you bring a patent claim against any contributor over
# patents that you claim are infringed by the software, your
# patent license from such contributor to the software ends
# automatically.
# (C) If you distribute any portion of the software, you must
# retain all copyright, patent, trademark, and attribution
# notices that are present in the software.
# (D) If you distribute any portion of the software in source
# code form, you may do so only under this license by including a
# complete copy of this license with your distribution. If you
# distribute any portion of the software in compiled or object
# code form, you may only do so under a license that complies
# with this license.
# (E) The software is licensed "as-is." You bear the risk of
# using it. The contributors give no express warranties,
# guarantees or conditions. You may have additional consumer
# rights under your local laws which this license cannot change.
# To the extent permitted under your local laws, the contributors
# exclude the implied warranties of merchantability, fitness for
# a particular purpose and non-infringement.
#
# *** evalTest ***
set(SHADER_FILES
shader.glsl
)
set(PLATFORM_LIBRARIES
${OSD_LINK_TARGET}
${OPENGL_LIBRARY}
${GLEW_LIBRARY}
${GLUT_LIBRARIES}
)
include_directories(
${PROJECT_SOURCE_DIR}/opensubdiv
${PROJECT_SOURCE_DIR}/regression
${GLEW_INCLUDE_DIR}
${GLUT_INCLUDE_DIR}
)
#-------------------------------------------------------------------------------
# Shader Stringification
# We want to use preprocessor include directives to include GLSL and OpenCL
# shader source files in cpp files, but since the sources contain newline
# characters we would need raw string literals from C++11 to do this directly.
# To avoid depending on C++11 we instead use a small tool called "line_quote"
# to generate source files that are suitable for direct inclusion.
foreach(shader_file ${SHADER_FILES})
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${shader_file})
string(REGEX REPLACE "(.*)[.].*" "\\1.inc" inc_file ${shader_file})
list(APPEND INC_FILES ${inc_file})
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
)
endforeach()
if(APPLE)
_add_glut_executable(evalTest
mainApple.mm
evalTest.cpp
${SHADER_FILES}
${INC_FILES}
)
else()
_add_glut_executable(evalTest
evalTest.cpp
mainGlut.cpp
${SHADER_FILES}
${INC_FILES}
)
endif()
target_link_libraries(evalTest
${PLATFORM_LIBRARIES}
)

210
examples/evalTest/algebra.h Normal file
View File

@ -0,0 +1,210 @@
#pragma once
#include <limits>
#include <cmath>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
//
// A few basic linear algebra operations
//
//
// Make the given matrix an identity matrix
//
inline void setIdentity(float* m)
{
m[0] = m[5] = m[10] = m[15] = 1.0f;
m[1] = m[2] = m[3] = m[4] = m[6] = m[7] = m[8] = m[9] = m[11] = m[12] = m[13] = m[14] = 0.0f;
}
//
// Multiply A * B and store the result in D
//
inline void
multMatrix(float *d, const float *a, const float *b)
{
for (int i=0; i<4; ++i)
{
for (int j=0; j<4; ++j)
{
d[i*4 + j] =
a[i*4 + 0] * b[0*4 + j] +
a[i*4 + 1] * b[1*4 + j] +
a[i*4 + 2] * b[2*4 + j] +
a[i*4 + 3] * b[3*4 + j];
}
}
}
//
// Create a perspective projection matrix
//
void setPersp( float fov, float aspect, float znear, float zfar, float* m )
{
float xymax = znear * tanf(fov * 3.141592653589793238462f / 360.f);
float ymin = -xymax;
float xmin = -xymax;
float width = xymax - xmin;
float height = xymax - ymin;
float depth = zfar - znear;
float q = -(zfar + znear) / depth;
float qn = -2 * (zfar * znear) / depth;
float w = 2 * znear / width;
w = w / aspect;
float h = 2 * znear / height;
m[0] = w;
m[1] = 0.f;
m[2] = 0.f;
m[3] = 0.f;
m[4] = 0.f;
m[5] = h;
m[6] = 0.f;
m[7] = 0.f;
m[8] = 0.f;
m[9] = 0.f;
m[10] = q;
m[11] = -1;
m[12] = 0.f;
m[13] = 0.f;
m[14] = qn;
m[15] = 0.f;
}
//
// Apply a translation to the given matrix m
//
void
translateMatrix(float x, float y, float z, float* m)
{
m[0] += m[3]*x; m[4] += m[7]*x; m[8] += m[11]*x; m[12] += m[15]*x;
m[1] += m[3]*y; m[5] += m[7]*y; m[9] += m[11]*y; m[13] += m[15]*y;
m[2] += m[3]*z; m[6] += m[7]*z; m[10]+= m[11]*z; m[14] += m[15]*z;
}
//
// Apply a rotation to the given matrix m
//
void
rotateMatrix(float angle, float x, float y, float z, float* m)
{
float rads = float((2*3.14159 / 360.) * angle);
float c = cosf(rads);
float s = sinf(rads);
float xx = x * x;
float xy = x * y;
float xz = x * z;
float yy = y * y;
float yz = y * z;
float zz = z * z;
float m2[16];
m2[0] = xx * (1 - c) + c;
m2[4] = xy * (1 - c) - z * s;
m2[8] = xz * (1 - c) + y * s;
m2[12] = 0;
m2[1] = xy * (1 - c) + z * s;
m2[5] = yy * (1 - c) + c;
m2[9] = yz * (1 - c) - x * s;
m2[13] = 0;
m2[2] = xz * (1 - c) - y * s;
m2[6] = yz * (1 - c) + x * s;
m2[10]= zz * (1 - c) + c;
m2[14]= 0;
m2[3]= 0;
m2[7]= 0;
m2[11]= 0;
m2[15]= 1;
float mOrig[16];
for (int i = 0; i < 16; i++)
mOrig[i] = m[i];
multMatrix(m, mOrig, m2);
}
//
// Print out the matrix (as usual, column-major order is assumed)
//
inline void printMatrix(float* m)
{
for (int r = 0; r < 4; r++) {
std::cout << " ";
for (int c = 0; c < 4; c++) {
std::cout << std::setprecision(3) << m[c*4 + r];
if (c != 3)
std::cout << ",";
else
std::cout << std::endl;
}
}
}
//
// Perform a cross-product of three points to calculate a face normal
//
inline void
cross(float *n, const float *p0, const float *p1, const float *p2)
{
float a[3] = { p1[0]-p0[0], p1[1]-p0[1], p1[2]-p0[2] };
float b[3] = { p2[0]-p0[0], p2[1]-p0[1], p2[2]-p0[2] };
n[0] = a[1]*b[2]-a[2]*b[1];
n[1] = a[2]*b[0]-a[0]*b[2];
n[2] = a[0]*b[1]-a[1]*b[0];
float rn = 1.0f/sqrtf(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);
n[0] *= rn;
n[1] *= rn;
n[2] *= rn;
}
//
// Normalize the given vector
//
inline void
normalize(float * p)
{
float dist = sqrtf( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] );
p[0]/=dist;
p[1]/=dist;
p[2]/=dist;
}
//
// Compute the center of the list of points and the size of the bound
//
inline void
computeCenterAndSize(const std::vector<float>& positions, float* center, float* size)
{
float fmax = std::numeric_limits<float>().max(),
fmin = std::numeric_limits<float>().min();
float min[3] = { fmax, fmax, fmax};
float max[3] = { fmin, fmin, fmin};
for (size_t i=0; i < positions.size()/3; ++i) {
for(int j=0; j<3; ++j) {
float v = positions[i*3+j];
min[j] = std::min(min[j], v);
max[j] = std::max(max[j], v);
}
}
for (int j=0; j<3; ++j) {
center[j] = (min[j] + max[j]) * 0.5f;
*size += (max[j]-min[j])*(max[j]-min[j]);
}
*size = sqrtf(*size);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,228 @@
//
// This file contains standard OpenGL API calls that are mostly uninteresting if
// you are purely trying to learn OSD. The following operations are implemented
// here:
//
// * First time OpenGL state initialization
// * Compile vertex and fragment shaders
// * Link shaders into a program
// * Per-frame drawing state setup
//
#pragma once
//
// ### OS Compatibility
// The following is to ensure the example runs on Linux, Windows and OS X
//
#if defined(__APPLE__)
#include <OpenGL/gl3.h>
#else
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>
#endif
#include "algebra.h"
#include <iostream>
#include <fstream>
#include <sstream>
//
// Microsoft uses a slightly different snprintf declaration, which we hide
// here by aliasing it as snprintf
//
#if _MSC_VER
#define snprintf _snprintf
#endif
#if defined(__APPLE__)
#define drawString(x, y, ...);
/* \
GLUT on OSX means gl 2.1, so forgoe the text drawing until we have a better solution
{ char line[1024]; \
snprintf(line, 1024, __VA_ARGS__); \
char *p = line; \
glWindowPos2f(x, y); \
while(*p) { glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *p++); } }
*/
#else
#define drawString(x, y, ...) \
{ char line[1024]; \
snprintf(line, 1024, __VA_ARGS__); \
char *p = line; \
glWindowPos2i(x, y); \
while(*p) { glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *p++); } }
#endif
//
// These are standard OpenGL shader program handles. One for wire frame and one
// for shaded rendering
//
GLuint g_quadLineProgram = 0;
GLuint g_quadFillProgram = 0;
//
// To avoid reading the shader source from a file, we include it here as a string
// see [shader.glsl](shader.html).
//
static const char *shaderSource =
#include "shader.inc"
;
GLfloat g_modelView[16], g_proj[16], g_mvp[16];
void
bindProgram(GLuint program)
{
glUseProgram(program);
// shader uniform setting
GLint position = glGetUniformLocation(program, "lightSource[0].position");
GLint ambient = glGetUniformLocation(program, "lightSource[0].ambient");
GLint diffuse = glGetUniformLocation(program, "lightSource[0].diffuse");
GLint specular = glGetUniformLocation(program, "lightSource[0].specular");
GLint position1 = glGetUniformLocation(program, "lightSource[1].position");
GLint ambient1 = glGetUniformLocation(program, "lightSource[1].ambient");
GLint diffuse1 = glGetUniformLocation(program, "lightSource[1].diffuse");
GLint specular1 = glGetUniformLocation(program, "lightSource[1].specular");
glUniform4f(position, 0.5, 0.2f, 1.0f, 0.0f);
glUniform4f(ambient, 0.1f, 0.1f, 0.1f, 1.0f);
glUniform4f(diffuse, 0.7f, 0.7f, 0.7f, 1.0f);
glUniform4f(specular, 0.8f, 0.8f, 0.8f, 1.0f);
glUniform4f(position1, -0.8f, 0.4f, -1.0f, 0.0f);
glUniform4f(ambient1, 0.0f, 0.0f, 0.0f, 1.0f);
glUniform4f(diffuse1, 0.5f, 0.5f, 0.5f, 1.0f);
glUniform4f(specular1, 0.8f, 0.8f, 0.8f, 1.0f);
GLint otcMatrix = glGetUniformLocation(program, "objectToClipMatrix");
GLint oteMatrix = glGetUniformLocation(program, "objectToEyeMatrix");
multMatrix(g_mvp, g_modelView, g_proj);
glUniformMatrix4fv(otcMatrix, 1, false, g_mvp);
glUniformMatrix4fv(oteMatrix, 1, false, g_modelView);
}
static GLuint
compileShader(GLenum shaderType, const char *section, const char *define)
{
const char *sources[4];
char sdefine[64];
sprintf(sdefine, "#define %s\n", section);
sources[0] = "#version 330\n";
sources[1] = define;
sources[2] = sdefine;
sources[3] = shaderSource;
GLuint shader = glCreateShader(shaderType);
glShaderSource(shader, 4, sources, NULL);
glCompileShader(shader);
GLint status;
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if( status == GL_FALSE ) {
GLchar emsg[1024];
glGetShaderInfoLog(shader, sizeof(emsg), 0, emsg);
fprintf(stderr, "Error compiling GLSL shader (%s): %s\n", section, emsg );
fprintf(stderr, "Section: %s\n", sdefine);
fprintf(stderr, "Defines: %s\n", define);
fprintf(stderr, "Source: %s\n", sources[2]);
exit(0);
}
return shader;
}
GLuint
linkProgram(const char *define)
{
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, "VERTEX_SHADER", define);
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, "FRAGMENT_SHADER", define);
GLuint program = glCreateProgram();
glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader);
glBindAttribLocation(program, 0, "position");
glLinkProgram(program);
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
GLint status;
glGetProgramiv(program, GL_LINK_STATUS, &status );
if( status == GL_FALSE ) {
GLchar emsg[1024];
glGetProgramInfoLog(program, sizeof(emsg), 0, emsg);
fprintf(stderr, "Error linking GLSL program : %s\n", emsg );
fprintf(stderr, "Defines: %s\n", define);
exit(0);
}
return program;
}
void
initGL()
{
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LEQUAL);
g_quadFillProgram = linkProgram("#define PRIM_QUAD\n#define GEOMETRY_OUT_FILL\n");
g_quadLineProgram = linkProgram("#define PRIM_QUAD\n#define GEOMETRY_OUT_LINE\n");
}
void
setupForDisplay(int width, int height, float size, float* center)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, width, height);
setIdentity(g_proj);
setIdentity(g_modelView);
setIdentity(g_mvp);
// setup the projection
float aspect = width/(float)height;
setPersp(45.0f, aspect, 0.01f, 500.0f, g_proj);
// setup the model view matrix
translateMatrix(-center[0], -center[1], -center[2], g_modelView);
rotateMatrix(-90, 1, 0, 0, g_modelView); // z-up model
translateMatrix(0, 0, -size, g_modelView);
}
static void
checkGLErrors(std::string const & where = "")
{
GLuint err;
while ((err = glGetError()) != GL_NO_ERROR) {
std::cout << "Where = " << where << std::endl;
if (err == GL_INVALID_ENUM) {
std::cout << "GL_INVALID_ENUM\n";
} else
if (err == GL_INVALID_VALUE) {
std::cout << "GL_INVALID_VALUE\n";
} else
if (err == GL_INVALID_OPERATION) {
std::cout << "GL_INVALID_OPERATION\n";
} else
if (err == GL_INVALID_OPERATION) {
std::cout << "GL_INVALID_OPERATION\n";
} else
if (err == GL_OUT_OF_MEMORY) {
std::cout << "GL_OUT_OF_MEMORY\n";
} else {
std::cout << "Some other gl error \n";
}
}
}

View File

@ -0,0 +1,176 @@
#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <OpenGL/glu.h>
#import <wchar.h>
#import <iostream>
//
// Hooks back into the example code
//
extern void initOsd();
extern void updateGeom();
extern void display();
//
// Shared global state from the example
//
extern int g_width, g_height, g_frame;
//
// OSX application bootstrap
//
@class View;
@interface View : NSOpenGLView <NSWindowDelegate> {
NSRect m_frameRect;
BOOL m_didInit;
uint64_t m_previousTime;
NSTimer* m_timer;
}
- (void) animate;
@end
@implementation View
-(void)windowWillClose:(NSNotification *)note
{
[[NSApplication sharedApplication] terminate:self];
}
- (void) timerFired:(NSTimer*) timer
{
[self animate];
}
- (id) initWithFrame: (NSRect) frame
{
m_didInit = FALSE;
//
// Various GL state, of note is the 3.2 Core profile selection
// and 8x antialiasing, which we might want to disable for performance
//
int attribs[] = {
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFAColorSize, 32,
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
NSOpenGLPFANoRecovery,
kCGLPFASampleBuffers, 1,
kCGLPFASamples, 8,
0
};
NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc]
initWithAttributes:(NSOpenGLPixelFormatAttribute*) attribs];
self = [self initWithFrame:frame pixelFormat:fmt];
[fmt release];
m_frameRect = frame;
m_timer = [[NSTimer
scheduledTimerWithTimeInterval:1.0f/120.0f
target:self
selector:@selector(timerFired:)
userInfo:nil
repeats:YES] retain];
return self;
}
- (void) drawRect:(NSRect) theRect
{
if (!m_didInit) {
initOsd();
m_didInit = YES;
[[self window] setLevel: NSFloatingWindowLevel];
[[self window] makeKeyAndOrderFront: self];
[[self window] setTitle: [NSString stringWithUTF8String: "SimpleCPU"]];
}
// run the example code
display();
// make sure GL state is clean
assert(glGetError() == GL_NO_ERROR);
[[self openGLContext] flushBuffer];
}
- (void) animate
{
g_frame++;
updateGeom();
[self display];
}
@end
int main(int argc, const char *argv[])
{
//
// It seems that some ATI cards fall back to software when rendering geometry shaders
// but only *sometimes*. Post this notice so it's obvious that OSD isn't the problem.
//
// XXX(jcowles): we should only use vertex and fragment shaders to avoid this potential confusion
//
std::cout << "--------------------------------------------------------------------------------" << std::endl;
std::cout << "NOTICE: Some Apple hardware runs geometry shaders in software, which will cause" << std::endl;
std::cout << " this demo to run extremely slowly. That slowness is not related to OSD" << std::endl;
std::cout << " and can be avoided by not using OpenGL geometry shaders." << std::endl;
std::cout << "--------------------------------------------------------------------------------" << std::endl;
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSApplication *NSApp = [NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id appName = [[NSProcessInfo processInfo] processName];
id quitTitle = [@"Quit " stringByAppendingString:appName];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];
NSRect screenBounds = [[NSScreen mainScreen] frame];
g_width = 512;
g_height = 512;
NSRect viewBounds = NSMakeRect(0, 0, g_width, g_height);
View* view = [[View alloc] initWithFrame:viewBounds];
NSRect centered = NSMakeRect(NSMidX(screenBounds) - NSMidX(viewBounds),
NSMidY(screenBounds) - NSMidY(viewBounds),
viewBounds.size.width, viewBounds.size.height);
NSWindow *window = [[NSWindow alloc]
initWithContentRect:centered
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window setContentView:view];
[window setDelegate:view];
[window makeKeyAndOrderFront:nil];
[NSApp activateIgnoringOtherApps:YES];
[view release];
[NSApp run];
[pool release];
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,74 @@
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>
extern void initOsd();
extern void updateGeom();
extern void display();
extern int g_width, g_height, g_frame;
//
// ### Misc. GLUT Callback Methods
// Reshape is called when the window is resized, here we need the width and
// height so that we can correctly adjust the aspect ratio of the projection
// matrix.
//
void
reshape(int width, int height)
{
g_width = width;
g_height = height;
}
//
// Idle is called between frames, here we advance the frame number and update
// the procedural animation that is being applied to the mesh
//
void
idle()
{
g_frame++;
updateGeom();
glutPostRedisplay();
}
//
// ### Draw the Mesh
// Display handles all drawing per frame. We first call the setupForDisplay
// helper method to setup some uninteresting GL state and then bind the mesh
// using the buffers provided by our OSD objects
//
void
glutDisplay()
{
display();
glutSwapBuffers();
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA |GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(1024, 1024);
glutCreateWindow("CPU Subdivision Example");
//
// Setup glut, glew and some initial GL state
//
glutDisplayFunc(glutDisplay);
glutReshapeFunc(reshape);
glewInit();
initOsd();
//
// Start the main glut drawing loop
//
glutIdleFunc(idle);
glutMainLoop();
}

View File

@ -0,0 +1,38 @@
Setup:
======
* clone docco
git clone https://github.com/jashkenas/docco.git
* install node.js
http://nodejs.org/
* npm install commander
* sudo easy_install Pygments
Generate documentation:
=======================
$ ~/src/docco/bin/docco simpleCpuSubdivision.cpp
Trina's Setup
(setup above didn't work for me, here's what I did, YMMV)
To Generate docco html file:
* sudo easy_install Pygments
* install node from http://nodejs.org/
* put source into /usr/local/src
% cd /usr/local/src/node-VERSION
% ./configure
% make
% make install
% npm install -g docco
* docco should now be in /usr/local/bin
* rehash
* cd /your/source/code/directory
* docco yoursource.cpp
voila!
* docs go into /your/source/code/directory/docs

View File

@ -0,0 +1,142 @@
//
// Copyright (C) Pixar. All rights reserved.
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
//
//--------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------
#ifdef VERTEX_SHADER
layout (location=0) in vec3 position;
layout (location=1) in vec3 normal;
uniform mat4 objectToClipMatrix;
uniform mat4 objectToEyeMatrix;
out vec3 vPosition;
out vec3 vNormalEye;
void main()
{
// vertex position in object space
vPosition = position;
// vertex position in clip space
gl_Position = objectToClipMatrix * vec4(position, 1);
// surface normal in eye space
vNormalEye = (objectToEyeMatrix * vec4(normal, 0)).xyz;
}
#endif
//--------------------------------------------------------------
// Fragment Shader
//--------------------------------------------------------------
#ifdef FRAGMENT_SHADER
layout (location=0) out vec4 FragColor;
in vec3 vNormalEye;
in vec3 vPosition;
#define NUM_LIGHTS 2
struct LightSource {
vec4 position;
vec4 ambient;
vec4 diffuse;
vec4 specular;
};
uniform LightSource lightSource[NUM_LIGHTS];
vec4
lighting(vec3 Peye, vec3 Neye)
{
vec4 color = vec4(0);
vec4 material = vec4(0.4, 0.4, 0.8, 1);
for (int i = 0; i < NUM_LIGHTS; ++i) {
vec4 Plight = lightSource[i].position;
vec3 l = (Plight.w == 0.0)
? normalize(Plight.xyz) : normalize(Plight.xyz - Peye);
vec3 n = normalize(Neye);
vec3 h = normalize(l + vec3(0,0,1)); // directional viewer
float d = max(0.0, dot(n, l));
float s = pow(max(0.0, dot(n, h)), 500.0f);
color += lightSource[i].ambient * material
+ d * lightSource[i].diffuse * material
+ s * lightSource[i].specular;
}
color.a = 1;
return color;
}
void
main()
{
vec3 N = (gl_FrontFacing ? vNormalEye : -vNormalEye);
FragColor = lighting(vPosition, N);
FragColor = vec4(1,0,0,1);
}
#endif