1 // Copyright (C) 2009 The Android Open Source Project 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 #pragma version(1) 16 17 #pragma rs java_package_name(com.android.musicvis.vis4) 18 19 #include "rs_graphics.rsh" 20 21 // State 22 float gAngle; 23 int gPeak; 24 25 rs_program_vertex gPVBackground; 26 rs_program_fragment gPFBackground; 27 28 rs_allocation gTvumeter_background; 29 rs_allocation gTvumeter_peak_on; 30 rs_allocation gTvumeter_peak_off; 31 rs_allocation gTvumeter_needle; 32 rs_allocation gTvumeter_black; 33 rs_allocation gTvumeter_frame; 34 35 rs_program_store gPFSBackground; 36 37 #define RSID_POINTS 1 38 39 int root(void) { 40 rsgClearColor(0.f, 0.f, 0.f, 1.f); 41 42 // Draw the visualizer. 43 rsgBindProgramVertex(gPVBackground); 44 rsgBindProgramFragment(gPFBackground); 45 rsgBindProgramStore(gPFSBackground); 46 47 rs_matrix4x4 mat1; 48 float scale = 0.0041; 49 rsMatrixLoadTranslate(&mat1, 0.f, -90.0f * scale, 0.f); 50 rsMatrixScale(&mat1, scale, scale, scale); 51 rsgProgramVertexLoadModelMatrix(&mat1); 52 53 // draw the background image (416x233) 54 rsgBindTexture(gPFBackground, 0, gTvumeter_background); 55 rsgDrawQuadTexCoords( 56 -208.0f, -33.0f, 0.0f, // space 57 0.0f, 1.0f, // texture 58 208, -33.0f, 0.0f, // space 59 1.0f, 1.0f, // texture 60 208, 200.0f, 0.0f, // space 61 1.0f, 0.0f, // texture 62 -208.0f, 200.0f, 0.0f, // space 63 0.0f, 0.0f); // texture 64 65 // draw the peak indicator light (56x58) 66 if (gPeak > 0) { 67 rsgBindTexture(gPFBackground, 0, gTvumeter_peak_on); 68 } else { 69 rsgBindTexture(gPFBackground, 0, gTvumeter_peak_off); 70 } 71 rsgDrawQuadTexCoords( 72 140.0f, 70.0f, -1.0f, // space 73 0.0, 1.0f, // texture 74 196, 70.0f, -1.0f, // space 75 1.0f, 1.0f, // texture 76 196, 128.0f, -1.0f, // space 77 1.0f, 0.0f, // texture 78 140.0f, 128.0f, -1.0f, // space 79 0.0f, 0.0f); // texture 80 81 82 83 // Draw the needle (88x262, center of rotation at 44,217 from top left) 84 85 // set matrix so point of rotation becomes origin 86 rsMatrixLoadTranslate(&mat1, 0.f, -147.0f * scale, 0.f); 87 rsMatrixRotate(&mat1, gAngle - 90.f, 0.f, 0.f, 1.f); 88 rsMatrixScale(&mat1, scale, scale, scale); 89 rsgProgramVertexLoadModelMatrix(&mat1); 90 rsgBindTexture(gPFBackground, 0, gTvumeter_needle); 91 rsgDrawQuadTexCoords( 92 -44.0f, -102.0f+57.f, 0.0f, // space 93 0.0f, 1.0f, // texture 94 44.0f, -102.0f+57.f, 0.0f, // space 95 1.0f, 1.0f, // texture 96 44.0f, 160.0f+57.f, 0.0f, // space 97 1.0f, 0.0f, // texture 98 -44.0f, 160.0f+57.f, 0.0f, // space 99 0.0f, 0.0f); // texture 100 101 102 // restore matrix 103 rsMatrixLoadTranslate(&mat1, 0.f, -90.0f * scale, 0.f); 104 rsMatrixScale(&mat1, scale, scale, scale); 105 rsgProgramVertexLoadModelMatrix(&mat1); 106 107 // erase the part of the needle we don't want to show 108 rsgBindTexture(gPFBackground, 0, gTvumeter_black); 109 rsgDrawQuad(-100.f, -55.f, 0.f, 110 -100.f, -105.f, 0.f, 111 100.f, -105.f, 0.f, 112 100.f, -55.f, 0.f); 113 114 115 // draw the frame (472x290) 116 rsgBindTexture(gPFBackground, 0, gTvumeter_frame); 117 rsgDrawQuadTexCoords( 118 -236.0f, -60.0f, 0.0f, // space 119 0.0f, 1.0f, // texture 120 236, -60.0f, 0.0f, // space 121 1.0f, 1.0f, // texture 122 236, 230.0f, 0.0f, // space 123 1.0f, 0.0f, // texture 124 -236.0f, 230.0f, 0.0f, // space 125 0.0f, 0.0f); // texture 126 127 return 1; 128 } 129