-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 2013-03-12 18:19, schrieb Stefan Dösinger: > The test program is available at > https://84.112.174.163/~git/perftest file const_gl/const_gl.cpp. My server is currently turned off (and I should move this to github or somewhere at some point), so I've attached the test program here for reference.
Resolution and constant mode are hardcoded into it. Tab/space mixup thanks to Visual Studio. Compile the Linux version with g++ const_gl.cpp -o const_gl -lGL -lglut -lGLEW . A d3d version is attached as well. It does not load the same values when using the global constants, but this doesn't seem to affect performance. I haven't tested ARB shaders, but from the WoT results before and after patch 2, their behavior seems to be the same as GLSL and native d3d. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBAgAGBQJRP9WcAAoJEN0/YqbEcdMwdmoP/2LvEFpPpmTiZDzxqhp38WfU DKs2S8m1kP86fL55GwLtth289WC9MsQyOosOVOqt8r3YWZyckeisZyhdP2ez2KRV 9kgxMnEXwzcZBtmm/+nrl0FwJghy86AnZ0YJ9PpnCpY0k4VTQYjaWQALlyqtF+qm Uup4UE+m4yR4DoNL/u/161Zxh+OLOA8PXEhWWfDozNL/8yMlRfPs6gzLMN/oKTIL UMA90gesZWPt7/J2Bp0+OeZvMWqNa54A2akxsLvtxVP/rB8baym4iYLn5Y2IPXa2 lBqALc+POMcVk45FCgkzjUw5b/7ck9V5n0PKOw/9Jwrm8/ChHE4i0ZwGEmHzh3So y1d/KydwesYtyCadmlklgJy1J+CxyCd/fNVUmsNtpzDEo6OF7oEagvwBUlTnCdR9 W9B9lmpsDCuBIxEnAy7C3HEZ18o70HdoUsKe5hX8fVn5lnwFPWdp7hBA0nVbO0y0 Fybps006cQmc0Rm9nHJjeJ9JoGzl/iuSX0AnQ5fiJS6fS5RrrGAnFBEb1g2O879X pNSIgBdKUSSfGBoUZKKIy+GZzC+VhDm4UqhtSaYudlUB9pcoMDFYRGQ3Rk48kRuD tJ8Ah2VBYeFUvI+x4Xty9AtOwwFWYejNG+6cNNF3EOALz2JvhFKDEJCI0p7bdmgR XCfPxQyYN7+JGFw8JiO5 =RgiG -----END PGP SIGNATURE-----
#include <windows.h> #include <d3d9.h> #include <cstdio> #include <d3dx9.h> unsigned long time_limit = 0; static DWORD prev_time; static const struct { float x, y, z; } quad[] = { /* Front side */ { -1.0, -1.0, 0.0 }, { -1.0, 1.0, 0.0 }, { 1.0, -1.0, 0.0 }, { 1.0, 1.0, 0.0 }, }; static IDirect3DDevice9 *device; static HWND create_window(void) { WNDCLASSW wc = {0}; HWND ret; wc.lpfnWndProc = DefWindowProcW; wc.lpszClassName = L"cube_perftest_wc"; RegisterClassW(&wc); ret = CreateWindowW(L"cube_perftest_wc", L"ddadda", WS_CAPTION , 100, 100, 640, 480, 0, 0, 0, 0); ShowWindow(ret, SW_SHOW); return ret; } static HWND window; static const char *vs_txt = "vs_2_0\n" "dcl_position v0\n" "mov oPos, v0\n" "mov oT0, v0\n"; const char *ps_txt_const = "ps_2_0\n" #if 0 "def c0, 0.92341375, 0.34255252342, 1.51991844e-004, 1\n" "def c1, 0.347353422, 0.4633423421, 1.51991844e-003, 1\n" "def c2, 0.99609375, 0.00389099121, 1.51991844e-002, 1\n" "def c3, 0.53212311, 0.20389099121, 1.51991844e-001, 1\n" "def c4, 0.23452315, 0.00389099121, 1.452345122, 1\n" "def c5, 0.42345523, 0.01389099121, 2.33513123, 1\n" "def c6, 0.99609375, 0.20389099121, 1.51991844e-005, 1\n" "def c7, 0.99609375, 0.30389099121, 1.51991844e-005, 1\n" "def c8, 0.99609375, 0.40389099121, 1.51991844e-005, 1\n" "def c9, 0.25, -0.556640983, -0.0371089987, -0.654296994\n" "def c10, 0.173828006, 0.111327998, 0.0644529983, 255\n" "def c11, 0.00195299997, 0.0820309967, -0.0605470017, 0\n" "def c12, 0.220703006, -0.359375, -0.0625, -5\n" "def c13, 0.242188007, 0.126953006, -0.25, 0\n" "def c14, 0.0703129992, -0.0253909994, 0.148438007, 0\n" "def c15, -0.078125, 0.0136719998, -0.314453006, 0\n" "def c16, 0.117187999, -0.140625, -0.199219003, 0\n" "def c17, 2, -1, 0.499999583, 0.5\n" "def c18, 6.28318548, -3.14159274, 1, -1\n" "def c19, -1, -2, -3, -4\n" "def c20, 0, 1, 0.125, 0\n" #endif "dcl t0\n" "dp4 r0.x, t0, c0\n" "dp4 r0.y, t0, c1\n" "dp4 r0.z, t0, c2\n" "dp4 r0.w, t0, c3\n" "dp4 r0.x, r0, c4\n" "dp4 r0.y, r0, c5\n" "dp4 r0.z, r0, c6\n" "dp4 r0.w, r0, c7\n" "dp4 r0.x, r0, c8\n" "dp4 r0.y, r0, c9\n" "dp4 r0.z, r0, c10\n" "dp4 r0.w, r0, c11\n" "dp4 r0.x, r0, c12\n" "dp4 r0.y, r0, c13\n" "dp4 r0.z, r0, c14\n" "dp4 r0.w, r0, c15\n" "dp4 r0.x, r0, c16\n" "dp4 r0.y, r0, c17\n" "dp4 r0.z, r0, c18\n" "dp4 r0.w, r0, c19\n" "add r0, r0, c20\n" "mov oC0, r0\n" ; static IDirect3DDevice9 *create_device() { HRESULT hr; IDirect3D9 *d3d9; IDirect3DDevice9 *dev = NULL; D3DPRESENT_PARAMETERS presparm; IDirect3DVertexBuffer9 *cubebuffer = NULL; IDirect3DVertexDeclaration9 *decl = NULL; IDirect3DVertexShader9 *vs = NULL; IDirect3DPixelShader9 *ps = NULL; ID3DXBuffer *vs_code = NULL, *ps_code = NULL, *msgs = NULL; IDirect3DTexture9 *tex[3] = {NULL, NULL, NULL}; const float half[] = {0.5f, 0.5f, 0.5f, 0.5f}; unsigned int i; void *data; static const D3DVERTEXELEMENT9 decl_elements[] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, D3DDECL_END() }; window = create_window(); d3d9 = Direct3DCreate9(D3D_SDK_VERSION); if(!d3d9) return NULL; memset(&presparm, 0, sizeof(presparm)); presparm.BackBufferCount = 1; presparm.BackBufferFormat = D3DFMT_X8R8G8B8; presparm.BackBufferWidth = 1920; /* FIXME */ presparm.BackBufferHeight = 1080; presparm.AutoDepthStencilFormat = D3DFMT_D24X8; presparm.EnableAutoDepthStencil = FALSE; presparm.SwapEffect = D3DSWAPEFFECT_DISCARD; presparm.Windowed = FALSE; presparm.hDeviceWindow = window; presparm.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; presparm.MultiSampleType = D3DMULTISAMPLE_NONE; hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &presparm, &dev); d3d9->Release(); if(FAILED(hr)) goto err; hr = dev->CreateVertexBuffer(sizeof(quad), 0, 0, D3DPOOL_MANAGED, &cubebuffer, NULL); if(FAILED(hr)) goto err; cubebuffer->Lock(0, 0, &data, 0); memcpy(data, quad, sizeof(quad)); cubebuffer->Unlock(); dev->SetStreamSource(0, cubebuffer, 0, sizeof(*quad)); hr = D3DXAssembleShader(vs_txt, strlen(vs_txt), NULL, NULL, 0, &vs_code, &msgs); if (FAILED(hr)) { printf("vs msgs: %s\n", msgs->GetBufferPointer()); goto err; } hr = dev->CreateVertexShader((DWORD *)vs_code->GetBufferPointer(), &vs); if (FAILED(hr)) goto err; hr = D3DXAssembleShader(ps_txt_const, strlen(ps_txt_const), NULL, NULL, 0, &ps_code, &msgs); if (FAILED(hr)) { printf("ps msgs: %s\n", msgs->GetBufferPointer()); goto err; } hr = dev->CreatePixelShader((DWORD *) ps_code->GetBufferPointer(), &ps); if (FAILED(hr)) goto err; hr = dev->CreateVertexDeclaration(decl_elements, &decl); if (FAILED(hr)) goto err; dev->SetVertexShader(vs); dev->SetPixelShader(ps); dev->SetVertexDeclaration(decl); vs->Release(); ps->Release(); decl->Release(); cubebuffer->Release(); for (i = 0; i < 256; i++) { dev->SetPixelShaderConstantF(i, half, 1); } for (i = 0; i < sizeof(tex) / sizeof(*tex); i++) { D3DLOCKED_RECT lr; unsigned int y; D3DSURFACE_DESC desc; hr = dev->CreateTexture(1024, 768, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &tex[i], NULL); if (FAILED(hr)) goto err; hr = tex[i]->GetLevelDesc(0, &desc); if (FAILED(hr)) goto err; hr = tex[i]->LockRect(0, &lr, NULL, 0); if (FAILED(hr)) goto err; for (y = 0; y < desc.Height; y++) { memset(((BYTE *)lr.pBits) + lr.Pitch * y, 0xff, lr.Pitch); } tex[i]->UnlockRect(0); dev->SetTexture(i, tex[i]); } return dev; err: printf("Init error\n"); for (i = 0; i < sizeof(tex) / sizeof(*tex); i++) if (tex[i]) tex[i]->Release(); if (vs_code) vs_code->Release(); if (ps_code) ps_code->Release(); if (msgs) msgs->Release(); if (vs) vs->Release(); if (ps) ps->Release(); if (decl) decl->Release(); if (cubebuffer) cubebuffer->Release(); if (dev) { dev->SetVertexDeclaration(NULL); dev->SetPixelShader(NULL); dev->SetVertexShader(NULL); dev->SetStreamSource(0, NULL, 0, 0); dev->SetStreamSource(1, NULL, 0, 0); dev->Release(); } return NULL; } static void print_fps() { static unsigned long frames; DWORD time = GetTickCount(); frames++; /* every 1.5 seconds */ if (time - prev_time > 1500) { printf("approx %.2ffps\n", 1000.0 * frames / (time - prev_time)); prev_time = time; frames = 0; } } static void draw_loop() { MSG msg; HRESULT hr; IDirect3DSwapChain9 *swapchain; DWORD start; unsigned long frames = ~0UL; device->GetSwapChain(0, &swapchain); device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE ); start = GetTickCount(); while(!time_limit || (start + time_limit > GetTickCount())) { hr = device->Clear(0, NULL, D3DCLEAR_TARGET, 0x1a1a1a1a, 1.0, 0); if(FAILED(hr)) printf("Clear failed\n"); while(PeekMessageW(&msg, window, 0, 0, PM_REMOVE) != 0) { TranslateMessage(&msg); DispatchMessage(&msg); } device->BeginScene(); device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); device->EndScene(); hr = swapchain->Present(NULL, NULL, NULL, NULL, 0); if(FAILED(hr)) { printf("present failed\n"); break; } if(!time_limit) print_fps(); else { /* Don't time the first frame. AMD cards on Windows need a while to switch display modes * or slow first-time draws. */ frames++; if(frames == 0) start = GetTickCount(); } } printf("frames per second: %f\n", 1000.0 * ((float) frames) / ((float) time_limit)); swapchain->Release(); } int main(int argc, char*argv[]) { long ref; if(argc > 1) time_limit = atol(argv[1]); if(time_limit) { printf("Running for %lu seconds\n", time_limit); time_limit *= 1000; } device = create_device(); if(!device) return 1; draw_loop(); ref = device->Release(); printf("refcount %ld\n", ref); }
#include <stdio.h> #if defined(WIN32) #include <windows.h> #include <gl/glew.h> #include <gl/glut.h> static DWORD prev_time; #else #include <sys/time.h> static struct timeval prev_time; #ifdef __APPLE__ #include <OpenGL/gl.h> #include <GLUT/glut.h> #else #include <GL/glew.h> #include <GL/gl.h> #include <GL/glut.h> #endif #define min(a,b) ((a)<(b)?(a):(b)) #endif static const struct { float x, y, z; } quad[] = { /* Front side */ { -1.0, -1.0, 0.0 }, { -1.0, 1.0, 0.0 }, { 1.0, -1.0, 0.0 }, { 1.0, 1.0, 0.0 }, }; const char *vshader = "#version 120\n" "attribute vec4 vs_in0;\n" "void main()\n" "{\n" " gl_Position.xyzw = (vs_in0.xyzw);\n" " gl_TexCoord[0].xyzw = (vs_in0.xyzw);\n" "}\n"; #define USE_CONST 0 const char *fragshader = "#version 120\n" #if USE_CONST "const vec4 ps_c0 = vec4(0.92341375, 0.34255252342, 1.51991844e-004, 1);\n" "const vec4 ps_c1 = vec4(0.347353422, 0.4633423421, 1.51991844e-003, 1);\n" "const vec4 ps_c2 = vec4(0.99609375, 0.00389099121, 1.51991844e-002, 1);\n" "const vec4 ps_c3 = vec4(0.53212311, 0.20389099121, 1.51991844e-001, 1);\n" "const vec4 ps_c4 = vec4(0.23452315, 0.00389099121, 1.452345122, 1);\n" "const vec4 ps_c5 = vec4(0.42345523, 0.01389099121, 2.33513123, 1);\n" "const vec4 ps_c6 = vec4(0.99609375, 0.20389099121, 1.51991844e-005, 1);\n" "const vec4 ps_c7 = vec4(0.99609375, 0.30389099121, 1.51991844e-005, 1);\n" "const vec4 ps_c8 = vec4(0.99609375, 0.40389099121, 1.51991844e-005, 1);\n" "const vec4 ps_c9 = vec4(0.25, -0.556640983, -0.0371089987, -0.654296994);\n" "const vec4 ps_c10 = vec4(0.173828006, 0.111327998, 0.0644529983, 255);\n" "const vec4 ps_c11 = vec4(0.00195299997, 0.0820309967, -0.0605470017, 0);\n" "const vec4 ps_c12 = vec4(0.220703006, -0.359375, -0.0625, -5);\n" "const vec4 ps_c13 = vec4(0.242188007, 0.126953006, -0.25, 0);\n" "const vec4 ps_c14 = vec4(0.0703129992, -0.0253909994, 0.148438007, 0);\n" "const vec4 ps_c15 = vec4(-0.078125, 0.0136719998, -0.314453006, 0);\n" "const vec4 ps_c16 = vec4(0.117187999, -0.140625, -0.199219003, 0);\n" "const vec4 ps_c17 = vec4(2, -1, 0.499999583, 0.5);\n" "const vec4 ps_c18 = vec4(6.28318548, -3.14159274, 1, -1);\n" "const vec4 ps_c19 = vec4(-1, -2, -3, -4);\n" "const vec4 ps_c20 = vec4(0, 1, 0.125, 0);\n" #else "uniform vec4 ps_c0;\n" "uniform vec4 ps_c1;\n" "uniform vec4 ps_c2;\n" "uniform vec4 ps_c3;\n" "uniform vec4 ps_c4;\n" "uniform vec4 ps_c5;\n" "uniform vec4 ps_c6;\n" "uniform vec4 ps_c7;\n" "uniform vec4 ps_c8;\n" "uniform vec4 ps_c9;\n" "uniform vec4 ps_c10;\n" "uniform vec4 ps_c11;\n" "uniform vec4 ps_c12;\n" "uniform vec4 ps_c13;\n" "uniform vec4 ps_c14;\n" "uniform vec4 ps_c15;\n" "uniform vec4 ps_c16;\n" "uniform vec4 ps_c17;\n" "uniform vec4 ps_c18;\n" "uniform vec4 ps_c19;\n" "uniform vec4 ps_c20;\n" #endif "vec4 R0;\n" "void main()\n" "{\n" " R0.x = (dot(gl_TexCoord[0].xyzw, ps_c0.xyzw));\n" " R0.y = (dot(gl_TexCoord[0].xyzw, ps_c1.xyzw));\n" " R0.z = (dot(gl_TexCoord[0].xyzw, ps_c2.xyzw));\n" " R0.w = (dot(gl_TexCoord[0].xyzw, ps_c3.xyzw));\n" " R0.x = (dot(R0.xyzw, ps_c4.xyzw));\n" " R0.y = (dot(R0.xyzw, ps_c5.xyzw));\n" " R0.z = (dot(R0.xyzw, ps_c6.xyzw));\n" " R0.w = (dot(R0.xyzw, ps_c7.xyzw));\n" " R0.x = (dot(R0.xyzw, ps_c8.xyzw));\n" " R0.y = (dot(R0.xyzw, ps_c9.xyzw));\n" " R0.z = (dot(R0.xyzw, ps_c10.xyzw));\n" " R0.w = (dot(R0.xyzw, ps_c11.xyzw));\n" " R0.x = (dot(R0.xyzw, ps_c12.xyzw));\n" " R0.y = (dot(R0.xyzw, ps_c13.xyzw));\n" " R0.z = (dot(R0.xyzw, ps_c14.xyzw));\n" " R0.w = (dot(R0.xyzw, ps_c15.xyzw));\n" " R0.x = (dot(R0.xyzw, ps_c16.xyzw));\n" " R0.y = (dot(R0.xyzw, ps_c17.xyzw));\n" " R0.z = (dot(R0.xyzw, ps_c18.xyzw));\n" " R0.w = (dot(R0.xyzw, ps_c19.xyzw));\n" " R0.xyzw = (R0.xyzw + ps_c20.xyzw);\n" " gl_FragData[0].xyzw = (R0.xyzw);\n" "}\n"; #if 0 " R0.x = (dot(gl_TexCoord[0].xyzw, vec4(0.92341375, 0.34255252342, 1.51991844e-004, 1)));\n" " R0.y = (dot(gl_TexCoord[0].xyzw, vec4(0.347353422, 0.4633423421, 1.51991844e-003, 1)));\n" " R0.z = (dot(gl_TexCoord[0].xyzw, vec4(0.99609375, 0.00389099121, 1.51991844e-002, 1)));\n" " R0.w = (dot(gl_TexCoord[0].xyzw, vec4(0.53212311, 0.20389099121, 1.51991844e-001, 1)));\n" " R0.x = (dot(R0.xyzw, vec4(0.23452315, 0.00389099121, 1.452345122, 1)));\n" " R0.y = (dot(R0.xyzw, vec4(0.42345523, 0.01389099121, 2.33513123, 1)));\n" " R0.z = (dot(R0.xyzw, vec4(0.99609375, 0.20389099121, 1.51991844e-005, 1)));\n" " R0.w = (dot(R0.xyzw, vec4(0.99609375, 0.30389099121, 1.51991844e-005, 1)));\n" " R0.x = (dot(R0.xyzw, vec4(0.99609375, 0.40389099121, 1.51991844e-005, 1)));\n" " R0.y = (dot(R0.xyzw, vec4(0.25, -0.556640983, -0.0371089987, -0.654296994)));\n" " R0.z = (dot(R0.xyzw, vec4(0.173828006, 0.111327998, 0.0644529983, 255)));\n" " R0.w = (dot(R0.xyzw, vec4(0.00195299997, 0.0820309967, -0.0605470017, 0)));\n" " R0.x = (dot(R0.xyzw, vec4(0.220703006, -0.359375, -0.0625, -5)));\n" " R0.y = (dot(R0.xyzw, vec4(0.242188007, 0.126953006, -0.25, 0)));\n" " R0.z = (dot(R0.xyzw, vec4(0.0703129992, -0.0253909994, 0.148438007, 0)));\n" " R0.w = (dot(R0.xyzw, vec4(-0.078125, 0.0136719998, -0.314453006, 0)));\n" " R0.x = (dot(R0.xyzw, vec4(0.117187999, -0.140625, -0.199219003, 0)));\n" " R0.y = (dot(R0.xyzw, vec4(2, -1, 0.499999583, 0.5)));\n" " R0.z = (dot(R0.xyzw, vec4(6.28318548, -3.14159274, 1, -1)));\n" " R0.w = (dot(R0.xyzw, vec4(-1, -2, -3, -4)));\n" " R0.xyzw = (R0.xyzw + vec4(0, 1, 0.125, 0));\n" " gl_FragData[0].xyzw = (R0.xyzw);\n" #endif GLuint vbo, prog; static int init(void) { GLuint frag, vert; GLsizei len; char log[4096]; const float constants[] = { 0.92341375f, 0.34255252342f, 1.51991844e-004f, 1.0f, 0.347353422f, 0.4633423421f, 1.51991844e-003f, 1.0f, 0.99609375f, 0.00389099121f, 1.51991844e-002f, 1.0f, 0.53212311f, 0.20389099121f, 1.51991844e-001f, 1.0f, 0.23452315f, 0.00389099121f, 1.452345122f, 1.0f, 0.42345523f, 0.01389099121f, 2.33513123f, 1.0f, 0.99609375f, 0.20389099121f, 1.51991844e-005f, 1.0f, 0.99609375f, 0.30389099121f, 1.51991844e-005f, 1.0f, 0.99609375f, 0.40389099121f, 1.51991844e-005f, 1.0f, 0.25f, -0.556640983f, -0.0371089987f, -0.654296994f, 0.173828006f, 0.111327998f, 0.0644529983f, 255.0f, 0.00195299997f, 0.0820309967f, -0.0605470017f, 0.0f, 0.220703006f, -0.359375f, -0.0625f, -5.0f, 0.242188007f, 0.126953006f, -0.25f, 0.0f, 0.0703129992f, -0.0253909994f, 0.148438007f, 0.0f, -0.078125f, 0.0136719998f, -0.314453006f, 0.0f, 0.117187999f, -0.140625f, -0.199219003f, 0.0f, 2.0f, -1.0f, 0.499999583f, 0.5f, 6.28318548f, -3.14159274f, 1.0f, -1.0f, -1.0f, -2.0f, -3.0f, -4.0f, 0.0f, 1.0f, 0.125f, 0.0f }; #ifndef __APPLE__ glewInit(); #endif glGenBuffersARB(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(*quad), (void *) 0); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); vert = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vert, 1, &vshader, 0); glCompileShader(vert); glGetShaderInfoLog(vert, sizeof(log), &len, log); if (len > 0) { printf("Vertex shader log:\n"); printf("%s\n", log); } frag = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(frag, 1, &fragshader, 0); glCompileShader(frag); glGetShaderInfoLog(frag, sizeof(log), &len, log); if (len > 0) { printf("Fragment shader log:\n"); printf("%s\n", log); } prog = glCreateProgram(); glAttachShader(prog, vert); glAttachShader(prog, frag); glLinkProgram(prog); glDeleteShader(vert); glDeleteShader(frag); glBindAttribLocation(prog, 0, "vs_in0"); glGetProgramInfoLog(prog, sizeof(log), &len, log); if (len > 0) { printf("Program log:\n"); printf("%s\n", log); } glUseProgram(prog); #if !USE_CONST { unsigned int i; for (i = 0; i < 21; i++) { GLuint uniform; char name[16]; sprintf(name, "ps_c%u", i); uniform = glGetUniformLocation(prog, name); glUniform4fv(uniform, 1, constants + 4*i); } } #endif glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glClearColor(0.1f, 0.1f, 0.1f, 0.0f); if (glGetError() != GL_NO_ERROR) { printf("Setup failed\n"); return 1; } return 0; } #ifdef WIN32 static void print_fps() { static unsigned long frames; DWORD time = GetTickCount(); frames++; /* every 1.5 seconds */ if (time - prev_time > 1500) { printf("approx %.2ffps\n", 1000.0 * frames / (time - prev_time)); prev_time = time; frames = 0; } } #else static void print_fps() { static unsigned long frames; struct timeval now; unsigned long diff; gettimeofday(&now, NULL); diff = (now.tv_sec - prev_time.tv_sec) * 1000000 + now.tv_usec - prev_time.tv_usec; frames++; /* every 1.5 seconds */ if (diff > 1500000) { printf("approx %.2ffps\n", 1000000.0 * frames / diff); prev_time = now; frames = 0; } } #endif void display(void) { glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glutSwapBuffers(); print_fps(); if (glGetError() != GL_NO_ERROR) { printf("Draw failed\n"); } } int main(int argc, char** argv) { const unsigned int width = 1440, height=900; glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (width, height); glutCreateWindow (argv[0]); glutFullScreen(); if(init() != 0) { printf("Init error\n"); return 1; } glutDisplayFunc(display); glutIdleFunc(display); glutMainLoop(); return 0; }
const_d3d.cpp.sig
Description: PGP signature
const_gl.cpp.sig
Description: PGP signature