⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpumathlib.h

📁 这是在GPU上进行高速数字计算的数学库函数
💻 H
字号:
/*******************************************************************************
**
** The header file for the gpumathlib class
** The Jahshaka Project
** Copyright (C) 2000-2004 The Jahshaka Project.
** Released under the GNU General Public License
**
*******************************************************************************/
#ifndef GPUMATHLIB_H
#define GPUMATHLIB_H

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <glew.h>
#include <math.h>
#include <qstring.h>

//////////////////////////////////////////////////////////////////
//this is for gpgpu support, using pbuffers, currently disabled
//need to define this before calling gpumathlib as its also used in there
#ifdef NVIDIA_GPGPU
#ifndef WIN32
#include <GL/glx.h>
#endif
#endif


extern "C" {

//definitions at the top
#define PI                   3.14159265358979323846
#define TWO_PI               (PI * 2.0)

#define PIXEL_BUFFER_WIDTH          2048
#define PIXEL_BUFFER_HEIGHT         2048

//used for distortion, gradient and turbulence tables
#define DISTORTION_TABLE_SIZE           32
#define GRADIENT_TABLE_SIZE             ((DISTORTION_TABLE_SIZE * 2) + 2)
#define TURBULENCE_TEXTURE_SIZE         1024

//variables used in gpu functions
struct float4
{
    float                x;
    float                y;
    float                z;
    float                w;
};

struct float2
{
    float                x;
    float                y;
};

struct Image
{
    unsigned long 		 sizeX;
    unsigned long 		 sizeY;
    unsigned char*		 data;
};

//Vertex vertices[number_of_vertices];
struct Vertex
{
    float 					s, t;
    float 					x, y, z;
};

//dont think this is used anymore
struct pixel_t
{
    int        x;
    int        y;
};

////////////////////////////////////////////////////////////
//math utility routines

float sfrand(void);
float frand(void);

void normalize3f(float& x, float& y, float& z);
float normalizefloat4(float4& vector);
void get_cross_product_4( float4& result, float4 vector1, float4 vector2);
void normalize_vector4(float4& vector);
void get_vector_from_points(float4& vector, float4 point1, float4 point2);

////////////////////////////////////////////////////////////
//debugging
void check_gl(void);
void find_shader_program_error(unsigned char * source, char* program_name);
void debug_arbdata(void);

////////////////////////////////////////////////////////////
//data io routines

unsigned char* loadshaderfile(const char *name);
int ImageLoad(char* filename, Image* image);

//////////////////////////////////////////////////////////////
//texture generators
void initVertexNoiseConstants(int table_size, int*& permutation_table, float4*& gradient_table, int gradient_size);
void create_random_texture( int width, int height,GLuint & random_texture );
void create_contrast_texture( int width, int height, double density, double exponent, GLuint & contrast_texture );


//////////////////////////////////////////////////////////////
// OpenGL matrix tracking
void matrixInvert4x4(float* inverse, float* matrix);
void matrixSwapRows4x4(float* row1, float* row2);
void matrixPrint4x4(float* matrix, const char* name);
void matrixPrintTranspose4x4(float* matrix, const char* name);
void matrixMultiply4x4(float* matrix_out, float* matrix1, float* matrix2);
void getMVPMatrices(float* modelview, float* projection, float* mvp, float* modelviewIT, float* texture);
void matrixTranspose4x4(float* matrix);


//////////////////////////////////////////////////////////////
//for arb support

void loadJahshakaBasicArb( GLint width, GLint height, float camera_distance,
                           unsigned char* vertex_program,
                           GLuint& vertex_program_handle );

int countARBFPInstructions(GLubyte* fragment_program);
bool isAnARBFPInstruction(GLubyte* string);

//loads the shader in and checks to see if complex arb is supported
bool checkComplexArbSupport(QString name, int max_fp_instructions, int max_vp_instructions);

//////////////////////////////////////////////////////////////
//for gpgpu support

#ifdef NVIDIA_GPGPU
void create_pbuffer(int width, int height);
#endif // NVIDIA_GPU

}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -