History

Merge remote-tracking branch 'upstream/master'

Jeffrey Ventrella committed 13 years ago

Commit bbd85662 parents 7a24c50 b9781c247 files · +1595 −430Browse files

Showing the changes to interface/src/main.cpp (1 of 47 files). Show all

Unified · Split

interface/src/main.cpp+103−69
@@ -58,12 +58,15 @@ · 57 unmodified lines
5858 #include "ui/MenuColumn.h"
5959 #include "ui/Menu.h"
6060 #include "ui/TextRenderer.h"
61+#include "renderer/ProgramObject.h"
62+#include "renderer/ShaderObject.h"
6163
6264 #include "Camera.h"
6365 #include "Avatar.h"
6466 #include <AgentList.h>
6567 #include <AgentTypes.h>
6668 #include "VoxelSystem.h"
69+#include "Environment.h"
6770 #include "Oscilloscope.h"
6871 #include "UDPSocket.h"
6972 #include "SerialInterface.h"
@@ -120,29 +123,32 @@ char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; · 50 unmodified lines
120123 char starCacheFile[] = "cachedStars.txt";
121124 Stars stars;
122125
123−bool showingVoxels = true;
124−
125126 glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE);
126127
127128 VoxelSystem voxels;
128129
129130 bool wantToKillLocalVoxels = false;
130131
132+Environment environment;
133+
131134
132135 #ifndef _WIN32
133136 Audio audio(&audioScope, &myAvatar);
134137 #endif
135138
136139 #define IDLE_SIMULATE_MSECS 16 // How often should call simulate and other stuff
137− // in the idle loop?
140+ // in the idle loop? (60 FPS is default)
138141
139−// Where one's own agent begins in the world (needs to become a dynamic thing passed to the program)
140−glm::vec3 start_location(6.1f, 0, 1.4f);
141142
142−bool renderWarningsOn = false; // Whether to show render pipeline warnings
143+glm::vec3 start_location(6.1f, 0, 1.4f); // Where one's own agent begins in the world
144+ // (will be overwritten if avatar data file is found)
143145
144−bool statsOn = false; // Whether to show onscreen text overlay with stats
145−bool starsOn = false; // Whether to display the stars
146+bool renderWarningsOn = false; // Whether to show render pipeline warnings
147+bool renderStatsOn = false; // Whether to show onscreen text overlay with stats
148+bool renderVoxels = true; // Whether to render voxels
149+bool renderStarsOn = true; // Whether to display the stars
150+bool renderAtmosphereOn = true; // Whether to display the atmosphere
151+bool renderAvatarsOn = true; // Whether to render avatars
146152 bool paintOn = false; // Whether to paint voxels as you fly around
147153 VoxelDetail paintingVoxel; // The voxel we're painting if we're painting
148154 unsigned char dominantColor = 0; // The dominant color of the voxel we're painting
@@ -177,7 +183,7 @@ bool chatEntryOn = false; // Whether to show the chat entry · 28 unmodified lines
177183
178184 bool oculusOn = false; // Whether to configure the display for the Oculus Rift
179185 GLuint oculusTextureID = 0; // The texture to which we render for Oculus distortion
180−GLhandleARB oculusProgramID = 0; // The GLSL program containing the distortion shader
186+ProgramObject* oculusProgram = 0; // The GLSL program containing the distortion shader
181187 float oculusDistortionScale = 1.25; // Controls the Oculus field of view
182188
183189 //
@@ -302,6 +308,8 @@ void init(void) { · 118 unmodified lines
302308 voxels.setViewerAvatar(&myAvatar);
303309 voxels.setCamera(&myCamera);
304310
311+ environment.init();
312+
305313 handControl.setScreenDimensions(WIDTH, HEIGHT);
306314
307315 headMouseX = WIDTH/2;
@@ -678,13 +686,31 @@ void renderViewFrustum(ViewFrustum& viewFrustum) { · 370 unmodified lines
678686 void displaySide(Camera& whichCamera) {
679687 glPushMatrix();
680688
681− if (::starsOn) {
689+ if (::renderStarsOn) {
682690 // should be the first rendering pass - w/o depth buffer / lighting
683691
692+ // compute starfield alpha based on distance from atmosphere
693+ float alpha = 1.0f;
694+ if (::renderAtmosphereOn) {
695+ float height = glm::distance(whichCamera.getPosition(), environment.getAtmosphereCenter());
696+ if (height < environment.getAtmosphereInnerRadius()) {
697+ alpha = 0.0f;
698+
699+ } else if (height < environment.getAtmosphereOuterRadius()) {
700+ alpha = (height - environment.getAtmosphereInnerRadius()) /
701+ (environment.getAtmosphereOuterRadius() - environment.getAtmosphereInnerRadius());
702+ }
703+ }
704+
684705 // finally render the starfield
685− stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip());
706+ stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip(), alpha);
686707 }
687708
709+ // draw the sky dome
710+ if (::renderAtmosphereOn) {
711+ environment.renderAtmosphere(whichCamera);
712+ }
713+
688714 glEnable(GL_LIGHTING);
689715 glEnable(GL_DEPTH_TEST);
690716
@@ -699,23 +725,28 @@ void displaySide(Camera& whichCamera) { · 8 unmodified lines
699725 drawGroundPlaneGrid(10.f);
700726
701727 // Draw voxels
702− if (showingVoxels) {
728+ if (renderVoxels) {
703729 voxels.render();
704730 }
705731
706− // Render avatars of other agents
707− AgentList* agentList = AgentList::getInstance();
708− agentList->lock();
709− for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
710− if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) {
711− Avatar *avatar = (Avatar *)agent->getLinkedData();
712− avatar->render(0, ::myCamera.getPosition());
732+ if (::renderAvatarsOn) {
733+ // Render avatars of other agents
734+ AgentList* agentList = AgentList::getInstance();
735+ agentList->lock();
736+ for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
737+ if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) {
738+ Avatar *avatar = (Avatar *)agent->getLinkedData();
739+ avatar->render(0, ::myCamera.getPosition());
740+ }
713741 }
742+ agentList->unlock();
743+
744+ // Render my own Avatar
745+ myAvatar.render(::lookingInMirror, ::myCamera.getPosition());
714746 }
715− agentList->unlock();
716747
717748 // Render the world box
718− if (!::lookingInMirror && ::statsOn) { render_world_box(); }
749+ if (!::lookingInMirror && ::renderStatsOn) { render_world_box(); }
719750
720751 // brad's frustum for debugging
721752 if (::frustumOn) renderViewFrustum(::viewFrustum);
@@ -806,18 +837,16 @@ void displayOculus(Camera& whichCamera) { · 84 unmodified lines
806837 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WIDTH, HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
807838 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
808839
809− GLhandleARB shaderID = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
810− glShaderSourceARB(shaderID, 1, &DISTORTION_FRAGMENT_SHADER, 0);
811− glCompileShaderARB(shaderID);
812− ::oculusProgramID = glCreateProgramObjectARB();
813− glAttachObjectARB(::oculusProgramID, shaderID);
814− glLinkProgramARB(::oculusProgramID);
815− textureLocation = glGetUniformLocationARB(::oculusProgramID, "texture");
816− lensCenterLocation = glGetUniformLocationARB(::oculusProgramID, "lensCenter");
817− screenCenterLocation = glGetUniformLocationARB(::oculusProgramID, "screenCenter");
818− scaleLocation = glGetUniformLocationARB(::oculusProgramID, "scale");
819− scaleInLocation = glGetUniformLocationARB(::oculusProgramID, "scaleIn");
820− hmdWarpParamLocation = glGetUniformLocationARB(::oculusProgramID, "hmdWarpParam");
840+ ::oculusProgram = new ProgramObject();
841+ ::oculusProgram->attachFromSourceCode(GL_FRAGMENT_SHADER_ARB, DISTORTION_FRAGMENT_SHADER);
842+ ::oculusProgram->link();
843+
844+ textureLocation = ::oculusProgram->getUniformLocation("texture");
845+ lensCenterLocation = ::oculusProgram->getUniformLocation("lensCenter");
846+ screenCenterLocation = ::oculusProgram->getUniformLocation("screenCenter");
847+ scaleLocation = ::oculusProgram->getUniformLocation("scale");
848+ scaleInLocation = ::oculusProgram->getUniformLocation("scaleIn");
849+ hmdWarpParamLocation = ::oculusProgram->getUniformLocation("hmdWarpParam");
821850
822851 } else {
823852 glBindTexture(GL_TEXTURE_2D, ::oculusTextureID);
@@ -837,13 +866,13 @@ void displayOculus(Camera& whichCamera) { · 13 unmodified lines
837866
838867 glDisable(GL_BLEND);
839868 glEnable(GL_TEXTURE_2D);
840− glUseProgramObjectARB(::oculusProgramID);
841− glUniform1iARB(textureLocation, 0);
842− glUniform2fARB(lensCenterLocation, 0.287994, 0.5); // see SDK docs, p. 29
843− glUniform2fARB(screenCenterLocation, 0.25, 0.5);
844− glUniform2fARB(scaleLocation, 0.25 * scaleFactor, 0.5 * scaleFactor * aspectRatio);
845− glUniform2fARB(scaleInLocation, 4, 2 / aspectRatio);
846− glUniform4fARB(hmdWarpParamLocation, 1.0, 0.22, 0.24, 0);
869+ ::oculusProgram->bind();
870+ ::oculusProgram->setUniform(textureLocation, 0);
871+ ::oculusProgram->setUniform(lensCenterLocation, 0.287994, 0.5); // see SDK docs, p. 29
872+ ::oculusProgram->setUniform(screenCenterLocation, 0.25, 0.5);
873+ ::oculusProgram->setUniform(scaleLocation, 0.25 * scaleFactor, 0.5 * scaleFactor * aspectRatio);
874+ ::oculusProgram->setUniform(scaleInLocation, 4, 2 / aspectRatio);
875+ ::oculusProgram->setUniform(hmdWarpParamLocation, 1.0, 0.22, 0.24, 0);
847876
848877 glColor3f(1, 0, 1);
849878 glBegin(GL_QUADS);
@@ -857,8 +886,8 @@ void displayOculus(Camera& whichCamera) { · 7 unmodified lines
857886 glVertex2f(0, HEIGHT);
858887 glEnd();
859888
860− glUniform2fARB(lensCenterLocation, 0.787994, 0.5);
861− glUniform2fARB(screenCenterLocation, 0.75, 0.5);
889+ ::oculusProgram->setUniform(lensCenterLocation, 0.787994, 0.5);
890+ ::oculusProgram->setUniform(screenCenterLocation, 0.75, 0.5);
862891
863892 glBegin(GL_QUADS);
864893 glTexCoord2f(0.5, 0);
@@ -874,7 +903,7 @@ void displayOculus(Camera& whichCamera) { · 9 unmodified lines
874903 glEnable(GL_BLEND);
875904 glDisable(GL_TEXTURE_2D);
876905 glBindTexture(GL_TEXTURE_2D, 0);
877− glUseProgramObjectARB(0);
906+ ::oculusProgram->release();
878907
879908 glPopMatrix();
880909 }
@@ -895,7 +924,7 @@ void displayOverlay() { · 14 unmodified lines
895924
896925 //noiseTest(WIDTH, HEIGHT);
897926
898− if (displayHeadMouse && !::lookingInMirror && statsOn) {
927+ if (displayHeadMouse && !::lookingInMirror && renderStatsOn) {
899928 // Display small target box at center or head mouse target that can also be used to measure LOD
900929 glColor3f(1.0, 1.0, 1.0);
901930 glDisable(GL_LINE_SMOOTH);
@@ -917,7 +946,7 @@ void displayOverlay() { · 15 unmodified lines
917946 glLineWidth(1.0f);
918947 glPointSize(1.0f);
919948
920− if (::statsOn) { displayStats(); }
949+ if (::renderStatsOn) { displayStats(); }
921950 if (::logOn) { logger.render(WIDTH, HEIGHT); }
922951
923952 // Show menu
@@ -1202,13 +1231,23 @@ int setFullscreen(int state) { · 278 unmodified lines
12021231 }
12031232
12041233 int setVoxels(int state) {
1205− return setValue(state, &::showingVoxels);
1234+ return setValue(state, &::renderVoxels);
12061235 }
12071236
12081237 int setStars(int state) {
1209− return setValue(state, &::starsOn);
1238+ return setValue(state, &::renderStarsOn);
1239+}
1240+
1241+int setAtmosphere(int state) {
1242+ return setValue(state, &::renderAtmosphereOn);
1243+}
1244+
1245+int setRenderAvatars(int state) {
1246+ return setValue(state, &::renderAvatarsOn);
12101247 }
12111248
1249+
1250+
12121251 int setOculus(int state) {
12131252 bool wasOn = ::oculusOn;
12141253 int value = setValue(state, &::oculusOn);
@@ -1219,7 +1258,7 @@ int setOculus(int state) { · 4 unmodified lines
12191258 }
12201259
12211260 int setStats(int state) {
1222− return setValue(state, &::statsOn);
1261+ return setValue(state, &::renderStatsOn);
12231262 }
12241263
12251264 int setMenu(int state) {
@@ -1354,6 +1393,8 @@ void initMenu() { · 128 unmodified lines
13541393 menuColumnRender = menu.addColumn("Render");
13551394 menuColumnRender->addRow("Voxels (V)", setVoxels);
13561395 menuColumnRender->addRow("Stars (*)", setStars);
1396+ menuColumnRender->addRow("Atmosphere (A)", setAtmosphere);
1397+ menuColumnRender->addRow("Avatars", setRenderAvatars);
13571398 menuColumnRender->addRow("Oculus (o)", setOculus);
13581399
13591400 // Tools
@@ -1432,23 +1473,6 @@ void setupPaintingVoxel() { · 72 unmodified lines
14321473 shiftPaintingColor();
14331474 }
14341475
1435−void addRandomSphere(bool wantColorRandomizer) {
1436− float r = randFloatInRange(0.05,0.1);
1437− float xc = randFloatInRange(r,(1-r));
1438− float yc = randFloatInRange(r,(1-r));
1439− float zc = randFloatInRange(r,(1-r));
1440− float s = 0.001; // size of voxels to make up surface of sphere
1441− bool solid = false;
1442−
1443− printLog("random sphere\n");
1444− printLog("radius=%f\n",r);
1445− printLog("xc=%f\n",xc);
1446− printLog("yc=%f\n",yc);
1447− printLog("zc=%f\n",zc);
1448−
1449− voxels.createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer);
1450−}
1451−
14521476 const float KEYBOARD_YAW_RATE = 0.8;
14531477 const float KEYBOARD_PITCH_RATE = 0.6;
14541478 const float KEYBOARD_STRAFE_RATE = 0.03;
@@ -1533,9 +1557,10 @@ void key(unsigned char k, int x, int y) { · 78 unmodified lines
15331557
15341558 // Process keypresses
15351559 if (k == 'q' || k == 'Q') ::terminate();
1536− if (k == '/') ::statsOn = !::statsOn; // toggle stats
1537− if (k == '*') ::starsOn = !::starsOn; // toggle stars
1538− if (k == 'V' || k == 'v') ::showingVoxels = !::showingVoxels; // toggle voxels
1560+ if (k == '/') ::renderStatsOn = !::renderStatsOn; // toggle stats
1561+ if (k == '*') ::renderStarsOn = !::renderStarsOn; // toggle stars
1562+ if (k == 'V' || k == 'v') ::renderVoxels = !::renderVoxels; // toggle voxels
1563+ if (k == 'A') ::renderAtmosphereOn = !::renderAtmosphereOn;
15391564 if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging
15401565 if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at
15411566 if (k == 'O' || k == 'G') setFrustumOffset(MENU_ROW_PICKED); // toggle view frustum offset debugging
@@ -1629,6 +1654,9 @@ void* networkReceive(void* args) { · 87 unmodified lines
16291654 case PACKET_HEADER_ERASE_VOXEL:
16301655 voxels.parseData(incomingPacket, bytesReceived);
16311656 break;
1657+ case PACKET_HEADER_ENVIRONMENT_DATA:
1658+ environment.parseData(incomingPacket, bytesReceived);
1659+ break;
16321660 case PACKET_HEADER_BULK_AVATAR_DATA:
16331661 AgentList::getInstance()->processBulkAgentData(&senderAddress,
16341662 incomingPacket,
@@ -1674,6 +1702,7 @@ void idle(void) { · 39 unmodified lines
16741702 handControl.stop();
16751703 }
16761704
1705+ // Read serial port interface devices
16771706 if (serialPort.active && USING_INVENSENSE_MPU9150) {
16781707 serialPort.readData();
16791708 }
@@ -1699,7 +1728,11 @@ void idle(void) { · 19 unmodified lines
16991728
17001729 myAvatar.setGravity(getGravity(myAvatar.getPosition()));
17011730 myAvatar.simulate(deltaTime);
1702−
1731+
1732+ // Update audio stats for procedural sounds
1733+ audio.setLastAcceleration(myAvatar.getThrust());
1734+ audio.setLastVelocity(myAvatar.getVelocity());
1735+
17031736 glutPostRedisplay();
17041737 lastTimeIdle = check;
17051738 }
@@ -1733,6 +1766,7 @@ void reshape(int width, int height) { · 27 unmodified lines
17331766 glBindTexture(GL_TEXTURE_2D, 0);
17341767 }
17351768 } else {
1769+ camera.setAspectRatio(aspectRatio);
17361770 camera.setFieldOfView(fov = 60);
17371771 }
17381772

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t